2014-02-21 39 views
1

我使用wsimport構建我的java類。在第一次請求肥皂時,我得到一個SecurityToken。在其他請求我必須把這個令牌頭。我怎樣才能做到這一點?將SecurityContextToken設置爲SOAP標題

我在網上發現了nothig。

<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss wssecurity-secext-1.0.xsd" xmlns:wsc="http://schemas.xmlsoap.org/ws/2005/02/sc"> 
      <wsc:SecurityContextToken> 
        <wsc:Identifier>__TOKEN__</wsc:Identifier> 
      </wsc:SecurityContextToken> 
    </wsse:Security> 

如果我通過實施例設置的表頭。我得到以下異常。任何想法?

SCHWERWIEGEND: SAAJ0120: Can't add a header when one is already present 
com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Can't add a header when one is already present. 
at com.sun.xml.internal.messaging.saaj.soap.impl.EnvelopeImpl.addHeader(EnvelopeImpl.java:114) 
at com.sun.xml.internal.messaging.saaj.soap.impl.EnvelopeImpl.addHeader(EnvelopeImpl.java:94) 
at client.header.WSSUsernameTokenSecurityHandler.handleMessage(WSSUsernameTokenSecurityHandler.java:47) 
at client.header.WSSUsernameTokenSecurityHandler.handleMessage(WSSUsernameTokenSecurityHandler.java:15) 
at org.apache.cxf.jaxws.handler.HandlerChainInvoker.invokeHandleMessage(HandlerChainInvoker.java:347) 
at org.apache.cxf.jaxws.handler.HandlerChainInvoker.invokeHandlerChain(HandlerChainInvoker.java:254) 
at org.apache.cxf.jaxws.handler.HandlerChainInvoker.invokeProtocolHandlers(HandlerChainInvoker.java:132) 
at org.apache.cxf.jaxws.handler.soap.SOAPHandlerInterceptor.handleMessageInternal(SOAPHandlerInterceptor.java:169) 
at org.apache.cxf.jaxws.handler.soap.SOAPHandlerInterceptor.access$000(SOAPHandlerInterceptor.java:71) 
at org.apache.cxf.jaxws.handler.soap.SOAPHandlerInterceptor$1.handleMessage(SOAPHandlerInterceptor.java:81) 
at org.apache.cxf.jaxws.handler.soap.SOAPHandlerInterceptor$1.handleMessage(SOAPHandlerInterceptor.java:78) 
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271) 
at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:530) 
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:463) 
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:366) 
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:319) 
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96) 
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:134) 
at $Proxy36.getWSR(Unknown Source) 
at client.WSClient.main(WSClient.java:160) 

回答

0

這取決於您在客戶端使用的框架。一個例子,如何做到這一點可以發現here