Pages

Friday, 1 August 2014

Passing Custom SOAP Headers in ADF Mobile

Usecase:
This document shows how custom SOAP Headers can be passed in ADF Mobile to make web service calls. 

Pre-requisites:
JDeveloper Version - 11.1.2.4.0 with Mobile support
For the purpose of this demo, I am using a basic Hello service secured with the OWSM policy ‘oracle/wss_username_token_service_policy’. Additionally, the service responds to only those clients who send a custom SOAP Header with value ‘ClientABC’. Any other value in the header will receive “Invalid Client---Access denied.” as response. You may create the service on similar lines or use the attached service from here (Note that this service has been created in 12.1.2.0.0 build)

Steps:
  1. Create a new ADF Mobile application.
  2. In the ApplicationController project, create a data control for the WSDL URL of the above service.
  3. Since we need to pass some additional header information in the SOAP Envelope, we need to implement the method public SoapHeader[] getAdditionalSoapHeaders() in our own way.
To do this, in the ApplicationController project, create a new Java Class. Call it ‘CustomHeaderClass.java’. Let the class extend SOAPProvider from the package oracle.adfinternal.model.adapter.webservice.provider.soap.SOAPProvider.




Implement the getAdditionalSoapHeaders() method as shown:

    public SoapHeader[] getAdditionalSoapHeaders() {
        System.out.println("In getAdditionalSoapHeaders");
        SoapHeader header[] = new SoapHeader[2];
        SoapHeader token = null;
        SoapHeader user = null;
        SoapHeader pass = null;
    
        header[0] = new SoapHeader(
                    "www-testNamespace.com","ClientName","ClientABC"); //specify the namespace, tag name and the client value
        header[1] = new SoapHeader(
                    "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd","Security");
        token = new SoapHeader(
                   "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd","UsernameToken");
        user = new SoapHeader(
                   "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd","Username","weblogic");
        pass = new SoapHeader(
                   "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd","Password","weblogic1");
        header[1].addChild(token);
        token.addChild(user);
        token.addChild(pass); 
        return header;
}
In my case, a valid request structure was as below. Thus, the above code was based on this structure.


<?xml version = '1.0' encoding = 'UTF-8'?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:ns2="http://project1/"> 
<env:Header>
<ClientName xmlns="www-testNamespace.com">ClientABC</ClientName>
 <ns1:Security>
<ns1:UsernameToken>
<ns1:Username>weblogic</ns1:Username>
<ns1:Password>weblogic1</ns1:Password>
  </ns1:UsernameToken>
 </ns1:Security>
</env:Header>
<env:Body>
 <ns2:helloWorld/>
 </env:Body>
</env:Envelope>


  1. Also, open the DataControls.dcx file and search for provider="oracle.adfinternal.model.adapter.webservice.provider.soap.SOAPProvider". Change this default provider to point to the Provider class we just implemented. In this case, change the line to provider=" application.CustomHeaderClass”.

   5. D&D the method in the DC to an AMX page along with an output text box. If you invoke the method and check the request in the analyzer, you should be able to see the headers being passed.



References:





No comments:

Post a Comment