我似乎无法找到一种在不使用 SOAPHandler 的情况下将自定义 header 添加到来自 Web 服务客户端的 Soap 请求的方法。我四处寻找替代方案,而 BindingProvider 似乎可以为我完成这项工作。但它没有用。我不确定我在这里错过了什么。 这是我希望我的请求看起来像:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://xx.xx.xx/xxx/provisioning/ws">
<soapenv:Header>
<ws:XXXSecurity xmlns:ws="http://xx.xx.xx/xx/security/ws">
<ws:Identification type="TrustedApplicationIdentification">
<ws:ApplicationId>xx</ws:ApplicationId>
</ws:Identification>
</ws:xxSecurity>
<ws:xxLocale xmlns:ws="http://xx.xx.xx/xx/presentation/webservice/locale">
<ws:clientLocale>en_US</ws:clientLocale>
</ws:xxLocale>
</soapenv:Header>
<soapenv:Body>
<ws:GetAllNonProvisionedServers/>
</soapenv:Body>
</soapenv:Envelope>
这里是代码:
Provisioning service = new Provisioning(url, qName);
ProvisioningPort servicePort = service.getProvisioningPort();
servicePort = service.getProvisioningPort();
Map<QName, List<String>> headersMap = new HashMap<QName, List<String>>();
String mySoapHeader = "<ws:Identification type=\"TrustedApplicationIdentification\">"
+ "<ws:ApplicationId>Password123$</ws:ApplicationId>"
+ "</ws:Identification>" ;//+ "</soapenv:Header>";
List<String> mySOAPHeaders = new ArrayList<String>();
mySOAPHeaders.add(mySoapHeader);
headersMap.put(qSecurityName, mySOAPHeaders);
System.out.println(MessageContext.HTTP_REQUEST_HEADERS);
BindingProvider bp = (BindingProvider) servicePort;
List<Server> findAllNonProvisionedServers = servicePort
.findAllNonProvisionedServers();
最佳答案
我已经使用 org.apache.axiom.soap.SOAPFactory 类来设置我的 WS-Addressing SOAP header 。请告诉我您调用网络服务所使用的 API,以便我可以帮助您。
关于java - 如何在不使用 SoapHandler 的情况下通过 jaxb 将自定义 header 添加到 SOAP 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12427876/