如何在java中添加soap标头
我有一个来自 Oracle 的 NO-.net Web 服务 要访问我需要添加肥皂头。如何在java中添加soap标头?
Authenticator.setDefault(new ProxyAuthenticator("username", "password"));
System.getProperties().put("proxySet", "true");
System.setProperty("http.proxyHost", "IP");
System.setProperty("http.proxyPort", "port");
proxy = new RegPresMed_Service(new URL("webservice")).getRegPresMed();
((BindingProvider) proxy).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "realwebservice");
((BindingProvider) proxy).getRequestContext().put("com.sun.xml.ws.request.timeout", new Integer(60000));
((BindingProvider) proxy).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "webserviceUsername");
((BindingProvider) proxy).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "webservicePassword");
有这个必要吗?
((BindingProvider) proxy).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "webserviceUsername");
((BindingProvider) proxy).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "webservicePassword");
我的肥皂头是这样的:
<wsse:Security soapenv:mustUnderstand="1"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-6"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>username</wsse:Username>
<wsse:Password
Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">password</wsse:Password>
<wsse:Nonce
EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">randomnaumber==</wsse:Nonce>
<wsu:Created>dateCreated</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我努力让这个工作正常进行。这就是为什么我将在这里添加一个完整的解决方案:
我的目标是将此标头添加到 SOAP 信封中:
首先创建一个
SOAPHeaderHandler
类。setHandlerChain
来使用新链配置绑定实例。”I struggled to get this working. That's why I'll add a complete solution here:
My objective is to add this header to the SOAP envelope:
First create a
SOAPHeaderHandler
class.setHandlerChain
is required to configure the binding instance with the new chain."我遇到了同样的问题,并通过删除 xmlns:wsu 属性解决了它。尝试不要将其添加到 usernameToken 中。希望这也能解决您的问题。
i was facing the same issue and solved it by removing the xmlns:wsu attribute.Try not adding it in the usernameToken.Hope this solves your issue too.
Maven依赖
配置类
结果xml
Maven dependency
Configuration class
Result xml