2010-06-17 52 views
2

我第一次使用apache CXF。我試圖根據CXF simple front endConfiguration notes)技術建立連接。我無法真正看到我做錯了什麼,但我得到一個奇怪的錯誤(見下文)。我也發佈了這個問題到[email protected],但我還沒有收到答覆。也許這裏有人可以幫忙。Apache CXF(簡單前端)中的問題:'已連接'

這裏包裝的服務bean是Spring/JPA服務,它不知道任何有關Web的內容,我想用簡單的前端將它作爲Web服務發佈,而不必使用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" /> 

在客戶端,我注入了生成的服務到我的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的。

我在網上搜索了類似的問題,但是我發現所有的問題都是使用已經修復的問題。我正嘗試使用簡單的前端,因爲我的服務沒有使用jax-ws註釋進行註釋,我想保留它。

有人可以幫忙嗎?提前致謝。

肖恩

回答

1

我找到了解決辦法自己:我需要把在HTTP管道分塊關閉(我真的不明白這一點:-)的話)。無論如何,它的工作原理是這樣的:

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