java - Apache CXF(简单前端): 'Already connected' 中的问题

标签 java web-services spring soap cxf

我是第一次使用 apache CXF。我正在尝试建立基于 CXF 的连接 simple front end ( Configuration notes ) 技术。我真的看不出我做错了什么,但我收到了一个奇怪的错误(见下文)。我也已将此问题发布到 users@cxf.apache.org,但我还没有收到回复。也许这里有人可以提供帮助。

这里包装的服务 bean 是一个 Spring/JPA 服务,它对网络一无所知,我想使用简单的前端将其发布为网络服务,而不必使用 Jax-ws 等对其进行注释。(这在理论上是有效的)。这是我的配置:

服务器:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:simple="http://cxf.apache.org/simple"
xmlns:soap="http://cxf.apache.org/bindings/soap"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:cs="http://[www.mycompany.com]/coupon/service"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://cxf.apache.org/bindings/soap http://cxf.apache.org/schemas/configuration/soap.xsd
    http://cxf.apache.org/simple http://cxf.apache.org/schemas/simple.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"
    default-autowire="byType"
    >

<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-http.xml" /> 
<import resource="classpath:META-INF/cxf/cxf-extension-http-binding.xml" /> 
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

<!—my service implementation -->
<import resource="classpath*:persistenceContext.xml" /> 

<!--  serviceClass points to an interface -->
<simple:server id="server" serviceBean="couponService"
    serviceClass="[com.mycompany].MyServiceInterface"
    bindingId="http://apache.org/cxf/binding/http"
    address="/${wsdl.path}"
    serviceName="cs:couponService"
    endpointName="cs:couponServicePort"
    >
    <simple:dataBinding>
        <bean class="org.apache.cxf.aegis.databinding.AegisDatabinding" />
    </simple:dataBinding>
    <simple:binding>
        <soap:soapBinding version="1.2" mtomEnabled="true" />
    </simple:binding>
</simple:server>

<context:property-placeholder location="classpath:service.properties" />
</beans>

客户:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:simple="http://cxf.apache.org/simple"
xmlns:soap="http://cxf.apache.org/bindings/soap"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:oxm=http://www.springframework.org/schema/oxm
xmlns:cs="http://[www.mycompany.com]/coupon/service"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://cxf.apache.org/bindings/soap http://cxf.apache.org/schemas/configuration/soap.xsd
    http://cxf.apache.org/simple http://cxf.apache.org/schemas/simple.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd"
    default-autowire="byType"
    >


<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-http.xml" /> 
<import resource="classpath:META-INF/cxf/cxf-extension-http-binding.xml" /> 
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />


<simple:client id="couponService" wsdlLocation="${wsdl.url}?wsdl"
    serviceName="cs:couponService"
    endpointName="cs:couponServicePort"
    transportId="http://schemas.xmlsoap.org/soap/http"
    address="${wsdl.url}"
    bindingId="http://apache.org/cxf/binding/http"
    serviceClass="[com.mycompany].MyServiceInterface">
    <simple:dataBinding>
        <bean class="org.apache.cxf.aegis.databinding.AegisDatabinding" />
    </simple:dataBinding>
    <simple:binding>
        <soap:soapBinding mtomEnabled="true" version="1.2" />
    </simple:binding>
</simple:client>

<context:property-placeholder location="classpath:service.properties" />

在客户端,我将生成的服务注入(inject)我的 Web 应用程序(我正在使用 wicket,但这应该是无关紧要的),当我调用它的服务方法时,我从 java.net.HttpURLConnection 得到一个 IllegalStateException 说连接是已经打开了。这是堆栈跟踪:

java.lang.IllegalStateException: IllegalStateException invoking http://localhost:9999/services/coupon: Already connected
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.mapException(HTTPConduit.java:2058)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:2048)
at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:66)
at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:639)
at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:243)
at org.apache.cxf.binding.http.interceptor.DatabindingOutSetupInterceptor.handleMessage(DatabindingOutSetupInterceptor.java:91)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:243)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:487)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:313)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:265)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
at org.apache.cxf.frontend.ClientProxy.invoke(ClientProxy.java:68)
at $Proxy30.createIndividualUserCouponsJob(Unknown Source)
at [com.mycompany].coupons.web.app.dummycontent.DummyContentInitializer.addSomeIndividualCoupons(DummyContentInitializer.java:84)
at [com.mycompany].coupons.web.app.dummycontent.DummyContentInitializer.addSomeCoupons(DummyContentInitializer.java:68)
at [com.mycompany].coupons.web.app.dummycontent.DummyContentInitializer.init(DummyContentInitializer.java:50)
at org.apache.wicket.Application.callInitializers(Application.java:843)
at org.apache.wicket.Application.initializeComponents(Application.java:678)
at org.apache.wicket.protocol.http.WicketFilter.init(WicketFilter.java:725)
at org.apache.wicket.protocol.http.WicketServlet.init(WicketServlet.java:219)
at javax.servlet.GenericServlet.init(GenericServlet.java:241)
at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:433)
at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:256)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:40)
at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:617)
at org.mortbay.jetty.servlet.Context.startContext(Context.java:139)
at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1218)
at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:500)
at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:448)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:40)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:117)
at org.mortbay.jetty.Server.doStart(Server.java:220)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:40)
at [com.mycompany].coupons.web.test.Start.main(Start.java:45)
Caused by: java.lang.IllegalStateException: Already connected
at java.net.HttpURLConnection.setFixedLengthStreamingMode(HttpURLConnection.java:103)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.thresholdNotReached(HTTPConduit.java:1889)
at org.apache.cxf.io.AbstractThresholdOutputStream.close(AbstractThresholdOutputStream.java:99)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1980)

这发生在第一次进行服务调用时,并且在此之前打开的唯一 URLConnection 是 wsdl 的 URLConnection。

我在网上搜索了类似的问题,但我发现的只是一个使用 rest 的错误,该错误已被修复。我正在尝试使用简单的前端,因为我的服务没有使用 jax-ws 注释进行注释,我希望保持这种状态。

有人可以帮忙吗?提前致谢。

肖恩

最佳答案

我自己找到了解决方案:我需要在 http 管道中关闭分块(我一个字都不懂 :-))。不管怎样,它是这样工作的:

<http-conf:conduit name="*.http-conduit">
    <http-conf:client AllowChunking="false" />
</http-conf:conduit>

关于java - Apache CXF(简单前端): 'Already connected' 中的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3061935/

相关文章:

java - CertPathBuilderException : unable to find valid certification path was 8. 5 网络部署

java - Spring Boot 中单个资源使用 @RepositoryRestController 和 @RepositoryRestResource 的冲突

spring - SessionStatus object.setComplete() 是否清除所有 session 属性或仅适用于使用它的 Controller ?

java - 将组件保留在后台以便稍后在 javafx 中重用它们

c# - 将 JSON 集合发送到 ASMX Web 服务

java - Jackson - 将 json 反序列化为通用类型

c# - SOAP 泛型类型序列化

java - 无法在 Spring Boot 应用程序中使用 AWS SDK(套接字不是由该工厂创建的)

java - 为什么这段代码不尊重我最后的分割模式

java - 使用 Gson get() 从 Json 获取值