我使用 wsimport 构建我的 java 类。在第一个肥皂请求中,我得到了一个 SecurityToken。在其他请求中,我必须将此 token 放入 header 中。我怎样才能做到这一点?
我在网上找不到任何东西。
<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)
最佳答案
这取决于您在客户端使用的框架。可以找到一个如何做到这一点的示例 here .
关于java - 将 SecurityContextToken 设置为 SOAP header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21938278/