2013-10-25 20 views
0

我正在使用像這樣的彈簧配置來添加CustomHandler。它工作正常。根據documentation - customHandlerResolver每個代理被調用一次Spring JAX-WS-使用Custom HandlerResolver添加動態頭文件

這就是問題所在。我需要爲每個SOAP請求添加一個動態安全令牌標頭,並且由於該處理程序僅被調用一次,因此我的令牌會在一定時間後過期,所以我無法設置刷新的令牌。

<bean id="myServicePort" class="org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean"> 
     <property name="serviceInterface" value="org.my.myService" /> 
     <property name="wsdlDocumentUrl" value="classpath:wsdl/mysoap.wsdl" /> 
     <property name="namespaceUri" value="http://services.mycom.org" /> 
     <property name="serviceName" value="OrderService" /> 
     <property name="endpointAddress" ref="OrderEndPoint" /> 
     <property name="handlerResolver" ref="customHandlerResolver"/> 
    </bean> 

回答

0

正如我所說的HandlerResolver只調用一次,無論bean的範圍是什麼。我使用CXF - org.apache.cxf.jaxws.JaxWsProxyFactoryBean來獲得對bean創建的更多控制,與Spring自身創建代理的上述Spring代理不同。

<bean id="proxyFactory" 
    class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean"> 
    <property name="serviceClass" value="org.my.myService"/> 
    <property name="address" value="http://localhost:9002/HelloWorld"/> 
    </bean> 

在我的客戶端代碼

//Set a handler 
proxyFactory.setHandlers(Arrays.asList((Handler) new TokenHandler(Token))); 
OrderService orderServicePort= (myService) proxyFactory.create(); 

//Call service method, as SOAP message has desired dynamic header 
orderServicePort.getXXX() 

這完美的作品,比我最初的Spring配置

0

您是否嘗試過使用bean作用域原型。

<bean id="myServicePort" class="org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean" scope="prototype"> 
    <property name="serviceInterface" value="org.my.myService" /> 
    <property name="wsdlDocumentUrl" value="classpath:wsdl/mysoap.wsdl" /> 
    <property name="namespaceUri" value="http://services.mycom.org" /> 
    <property name="serviceName" value="OrderService" /> 
    <property name="endpointAddress" ref="OrderEndPoint" /> 
    <property name="handlerResolver" ref="customHandlerResolver"/> 

+0

我試過,但customHandleResolver方法只調用一次更簡潔。我甚至將customHandlerResolver作爲原型。還是一樣的行爲。 – pingu