java - Web service request (>8KB) failed with apache cxf client on JBOSS - HTTP response '411: Length Required' -
a web application using apache cxf client send requests remote web service.
when web application deployed on tomcat ok.
the requests failed sent when web application deployed on jboss , size of body (envelope) greater 8 kb; error below got generated:
17:57:15,387 warning [org.apache.cxf.phase.phaseinterceptorchain (connectorexecutor-21) interceptor xxx#{http://cxf.apache.org/jaxws/dispatch}invoke has thrown exception, unwinding now: org.apache.cxf.interceptor.fault: not send message. @ org.apache.cxf.interceptor.messagesenderinterceptor$messagesenderendinginterceptor.handlemessage(messagesenderinterceptor.java:64) @ org.apache.cxf.phase.phaseinterceptorchain.dointercept(phaseinterceptorchain.java:263) @ org.apache.cxf.endpoint.clientimpl.doinvoke(clientimpl.java:531) @ org.apache.cxf.endpoint.clientimpl.invoke(clientimpl.java:461) @ org.apache.cxf.endpoint.clientimpl.invoke(clientimpl.java:364) @ org.apache.cxf.endpoint.clientimpl.invoke(clientimpl.java:317) @ org.apache.cxf.endpoint.clientimpl.invokewrapped(clientimpl.java:352) @ org.apache.cxf.jaxws.dispatchimpl.invoke(dispatchimpl.java:381) @ org.apache.cxf.jaxws.dispatchimpl.invoke(dispatchimpl.java:241) ... @ java.util.concurrent.futuretask.run(unknown source) [rt.jar:1.7.0_45] @ java.util.concurrent.threadpoolexecutor.runworker(unknown source) [rt.jar:1.7.0_45] @ java.util.concurrent.threadpoolexecutor$worker.run(unknown source) [rt.jar:1.7.0_45] @ java.lang.thread.run(unknown source) [rt.jar:1.7.0_45] caused by: org.apache.cxf.transport.http.httpexception: http response '411: length required' when communicating ... @ org.apache.cxf.transport.http.httpconduit$wrappedoutputstream.handleresponseinternal(httpconduit.java:1554) @ org.apache.cxf.transport.http.httpconduit$wrappedoutputstream.handleresponse(httpconduit.java:1493) @ org.apache.cxf.transport.http.httpconduit$wrappedoutputstream.close(httpconduit.java:1401) @ org.apache.cxf.transport.abstractconduit.close(abstractconduit.java:56) @ org.apache.cxf.transport.http.httpconduit.close(httpconduit.java:648) @ org.apache.cxf.interceptor.messagesenderinterceptor$messagesenderendinginterceptor.handlemessage(messagesenderinterceptor.java:62) ... 17 more
the http stream mode seems have switched chunked.
what think of first assumption?
it can found in official apache cxf documentation possible provide spring configuration file in order change cxf client behavior.
what configuration file content?
i answer own question, because after additional tests, configuration described below worked me.
first, error generated because cxf client automatically switched chunked transfer mode; indeed configuration change described in answer forces cxf client not use chunking , requests sent envelope size greater 8 kb.
the cxf client behavior can changed using spring configuration file, according official cxf apache documentation:
- https://cxf.apache.org/docs/client-http-transport-including-ssl-support.html
- https://cxf.apache.org/docs/configuration.html
there no need change lines of code of java client.
- 1- cxf configuration file
create cxf.xml spring configuration file:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:http-conf="http://cxf.apache.org/transports/http/configuration" xmlns:jaxws="http://cxf.apache.org/jaxws" xsi:schemalocation=" http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <http-conf:conduit name="*.http-conduit"> <http-conf:client allowchunking="false"/> </http-conf:conduit> </beans>
- 2- cxf.config.file.url java system property
edit jboss batch or script files in order add system property java command.
the value url points cxf.xml file, windows example shown below:
-dcxf.config.file.url=file:/c:/jboss-7.1.1.final/standalone/configuration/cxf.xml
there below example linux/unix:
-dcxf.config.file.url=file:///home/jay/as/jboss-7.1.1.final/standalone/configuration/cxf.xml
- 3- restart jboss
- 4- test
- 5- ignore warning message generated when request sent
16:23:03,388 info [org.apache.cxf.bus.spring.controlledvalidationxmlbeandefinitionreader] (connectorexecutor-1) loading xml bean definitions url [file:/c:/jboss-7.1.1.final/standalone/configuration/cxf.xml] 16:23:06,535 warning [org.jboss.wsf.stack.cxf.client.configuration.jbosswsspringbusfactory] (connectorexecutor-1) initial_app_context_creation_failed_msg: org.springframework.beans.factory.parsing.beandefinitionparsingexception: configuration problem: unable locate spring namespacehandler xml schema namespace [http://cxf.apache.org/transports/http/configuration] offending resource: url [file:/c:/jboss-7.1.1.final/standalone/configuration/cxf.xml] @ org.springframework.beans.factory.parsing.failfastproblemreporter.error(failfastproblemreporter.java:68) [spring-beans-3.1.2.release.jar:3.1.2.release] @ org.springframework.beans.factory.parsing.readercontext.error(readercontext.java:85) [spring-beans-3.1.2.release.jar:3.1.2.release] @ org.springframework.beans.factory.parsing.readercontext.error(readercontext.java:80) [spring-beans-3.1.2.release.jar:3.1.2.release] @ org.springframework.beans.factory.xml.beandefinitionparserdelegate.error(beandefinitionparserdelegate.java:316) [spring-beans-3.1.2.release.jar:3.1.2.release]
i think namespacehandler http://cxf.apache.org/transports/http/configuration xml schema namespace should found because there jar below:
c:/jboss-7.1.1.final/modules/org/apache/cxf/main/cxf-rt-transports-http-2.4.6.jar
anyway, webservice request successfuly sent !!
Comments
Post a Comment