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();
yousafsajjad
  • 973
  • 2
  • 18
  • 34

3 Answers3

0

I have used org.apache.axiom.soap.SOAPFactory class to set my WS-Addressing SOAP Headers. Let me know the API that you are using to call web service, so that I can try helping you.

Hemanth
  • 647
  • 7
  • 17
  • I am using wsimport to create all the java stub classes and using them to make the web service call. I am not sure how to update the header information on a java object. – yousafsajjad Sep 19 '12 at 14:41
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);

The above example will show you how to add MIME headers to the web service request. Above code can be used as reference. But it is not a full working solution. In my opinion MemberSubmissionEndpointReference will work for WS-Addressing. Please check for other header parameters.

There are other ways of generating the ws client, which will allow you to set headers with ease. Please try them as well.

Hemanth
  • 647
  • 7
  • 17
0

Thank you guys but it seemed like SOAPHandler is the right way to go, so I am going that way.

yousafsajjad
  • 973
  • 2
  • 18
  • 34