Web service request (>8KB) failed with apache cxf client on JBOSS - HTTP response '411: Length Required'

混江龙づ霸主 提交于 2020-07-22 22:20:58

问题


A web application is using the apache cxf client to send requests to a remote web service.

When this web application is deployed on Tomcat everything is OK.

The requests failed to be sent when this web application is deployed on JBOSS AND the size of the body (envelope) is greater than 8 KB; the error below got generated:

17:57:15,387 WARNING [org.apache.cxf.phase.PhaseInterceptorChain (ConnectorExecutor-21) Interceptor for xxx#{http://cxf.apache.org/jaxws/dispatch}Invoke has thrown exception, unwinding now: org.apache.cxf.interceptor.Fault: Could not send Message.
  at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:64)
  at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
  at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:531)
  at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:461)
  at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:364)
  at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:317)
  at org.apache.cxf.endpoint.ClientImpl.invokeWrapped(ClientImpl.java:352)
  at org.apache.cxf.jaxws.DispatchImpl.invoke(DispatchImpl.java:381)
  at org.apache.cxf.jaxws.DispatchImpl.invoke(DispatchImpl.java:241)
  ...
  at java.util.concurrent.FutureTask.run(Unknown Source) [rt.jar:1.7.0_45]
  at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.7.0_45]
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.7.0_45]
  at 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 with ...
  at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1554)
  at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1493)
  at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1401)
  at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
  at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:648)
  at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
  ... 17 more

The HTTP stream mode seems to have switched to chunked.

What do you think of this first assumption?

It can be found in the official apache cxf documentation that it is possible to provide a spring configuration file in order to change the cxf client behavior.

What is the configuration file content?


回答1:


I answer to my own question, because after additional tests, the configuration described below worked for me.

First, the error was probably generated because the cxf client automatically switched to chunked transfer mode; indeed the configuration change described in this answer forces the cxf client to not use chunking and then requests get successfully sent with envelope size greater than 8 KB.

The cxf client behavior can be changed using a Spring configuration file, according to the official cxf apache documentation:

  • https://cxf.apache.org/docs/client-http-transport-including-ssl-support.html
  • https://cxf.apache.org/docs/configuration.html

There is no need to change the lines of code of the java client.

- 1- cxf configuration file

Create a 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 to add this system property to java command.

The value is the URL that points to cxf.xml file, a windows example is shown below:

-Dcxf.config.file.url=file:/C:/JBoss-7.1.1.Final/standalone/configuration/cxf.xml

There is below an example for 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 the WARNING message generated when the request is sent

16:23:03,388 INFO  [org.apache.cxf.bus.spring.ControlledValidationXmlBeanDefinitionReader] (ConnectorExecutor-1) Loading XML bean definitions from 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 to locate Spring NamespaceHandler for XML schema namespace [http://cxf.apache.org/transports/http/configuration]
Offending resource: URL [file:/C:/JBoss-7.1.1.Final/standalone/configuration/cxf.xml]

    at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:80) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.error(BeanDefinitionParserDelegate.java:316) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]

I think that the NamespaceHandler for http://cxf.apache.org/transports/http/configuration XML schema namespace should be found because there is this jar below:

C:/JBoss-7.1.1.Final/modules/org/apache/cxf/main/cxf-rt-transports-http-2.4.6.jar

Anyway, the webservice request is successfuly sent !!



来源:https://stackoverflow.com/questions/36055056/web-service-request-8kb-failed-with-apache-cxf-client-on-jboss-http-respons

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!