2

I can't seem to find a way to add in custom header to a Soap request from web service client without using SOAPHandler. I look around for alternatives and BindingProvider seems to do the the job for me. But it didn't work. I am not sure what am I missing here. Here's what I want my request to look like:

    <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>

here the code:

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();
4

3 回答 3

0
        MemberSubmissionEndpointReference endPointReference = new MemberSubmissionEndpointReference();
        Elements referenceParameters = endPointReference.referenceParameters;
        List<Element> elements = referenceParameters.elements;

        SOAPPartImpl soappartImpl = new SOAPPart1_1Impl();
        soappartImpl.addMimeHeader("SOAPAction", "http://www.abc.com/WebServices/UploadService/ProcessUpload");
        SOAPDocumentImpl soapdocumentimpl = new SOAPDocumentImpl(soappartImpl);     
        SOAPHeader ele = new Header1_1Impl(soapdocumentimpl, "");       
        elements.add(ele);

        ProvisioningPort port = service.getPort(endPointReference, EDMOnlineUploadServiceSoap.class, null);

上面的示例将向您展示如何将 MIME 标头添加到 Web 服务请求。以上代码可以作为参考。但这不是一个完整的工作解决方案。在我看来,MemberSubmissionEndpointReference 将适用于 WS-Addressing。请检查其他标头参数。

还有其他方法可以生成 ws 客户端,这将允许您轻松设置标头。请也尝试一下。

于 2012-09-25T14:07:49.317 回答
0

我使用了 org.apache.axiom.soap.SOAPFactory 类来设置我的 WS-Addressing SOAP Headers。让我知道您用来调用 Web 服务的 API,以便我可以尝试帮助您。

于 2012-09-17T15:27:34.657 回答
0

谢谢你们,但似乎 SOAPHandler 是正确的方法,所以我要这样做。

于 2012-10-10T21:28:36.477 回答