cancel
Showing results for 
Search instead for 
Did you mean: 

SOAP header authentication for external webservice to use in WebDynpro Java

Former Member
0 Kudos

Hi All,

We are working on SAP EP 7.31 and Adaptive Web Service Model.

The requirement is to develop a SSO application by passing portal user-id to external webservice which will grant the access to third party system. But to access that external webservice, authentication is required thru SOAP header. As shown in attached image, the parameters are <web:User> and <web:Pwd> that needs to be set for authentication.

I understand, I need to use interface 'IWDWSInvocationModifier' and method 'doModifyInvocation' to set the SOAP header. But not able to understand how to set the parameters programatically.

Please help, how do I need to authenticate using SOAP header in webdynpro java.

Thanks,

Amol.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Daniel,

I have already gone thru the document, also I checked FAQ - Models - Adaptive Web Service - Web Dynpro Java - SCN Wiki and blog . Below is the code, I used for setting header. But not sure, if it is correct or not. I am waiting for my VPN connection, to test the below code. Once done, will get back with result.


public void doModifyInvocation(Object port) {

  // TODO Auto-generated method stub

  // Creating the SOAP Header node.

           DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();

           docBuilderFactory.setNamespaceAware(true);

           DocumentBuilder docBuilder;

           try {

             docBuilder = docBuilderFactory.newDocumentBuilder();

           } catch (ParserConfigurationException e) {

             // TODO Log the Exception

             return;

           }

            Document soapDoc = docBuilder.newDocument();

             Element soapEnv = soapDoc.createElementNS("http://schemas.xmlsoap.org/soap/envelop","soapenv:Envelope");

             Element soapHeader = soapDoc.createElement("soapenv:Header");

             Element webAuthHeader = soapDoc.createElement("web:AuthHeader");

             Element webUser = soapDoc.createElement("web:User");

             webUser.setTextContent("User_Code from FS");

            

             Element webPwd = soapDoc.createElement("web:Pwd");

             webPwd.setTextContent("Pwd_code from FS");

            

             webAuthHeader.appendChild(webUser);

             webAuthHeader.appendChild(webPwd);

            

             soapHeader.appendChild(webAuthHeader);

             soapEnv.appendChild(soapHeader);

            

//            soapDoc.appendChild(soapEnv);

            

  SOAPHeaderInterface headerInterface = SOAPHeaderIFactory.getInterface(port);

  // Adds the output SOAP Header to the next proxy request.

  try {

  headerInterface.setOutputHeader(null, soapEnv);

// headerInterface.setOutputHeader(null, soapHeader);

  } catch (MarshalException e) {

  // TODO Auto-generated catch block

  e.printStackTrace();

  }

         

  }

Thanks,

Amol.

daniel_ruiz2
Active Contributor
0 Kudos

hi Amol, this looks rather odd.. I would assume you already have a proxy created to consume the service, so you probably just need to provide the POJO directly in setOutputHeader... nonetheless, you seem to be on the right track, I'm sure you'll find a solution that works soon. D.

Former Member
0 Kudos

Hi Daniel,

How do I set and supply proxies in setOutputHeader method. Could you please elaborate more.

Thanks,

Amol.

daniel_ruiz2
Active Contributor
0 Kudos

hi Amol, I just don't have a system available, otherwise I would code you a DC with all of it.. I'd have to decompile the class located in the AS and check what the setOutputHeader really expects as second parameter.. an Object can really be anything, and the parameter name does not help either.. plus, I cannot find documentation, javadoc or anything really about such in SDN or using Google, which just shows how good documented the NW AS really is. Even thou I mentioned 'looks odd', it may as well be correct the approach you used or at least the approach SAP expects people to use. Just give your solution a go, perhaps your code will work straight away. D.

Former Member
0 Kudos

A bit late in reply, but finally I am able to set the SOAP header in Webdynpro Java. Below are the high level steps I followed:

1) Import the webservice WSDL and create AWS model. While importing, mention the service group name, that will be used in step 5 below.

2) In execute method of component controller write below code (consider above WSDL snippet). Note, that after creating model, proxies are not created for <SOAP:Header> part, but created only for <SOAP:Body> part of WSDL.


Request_ChangePasswordNoOldPassword request_ChangePasswordNoOldPassword = wdContext.nodeRequest_ChangePasswordNoOldPassword().createAndAddRequest_ChangePasswordNoOldPasswordElement().modelObject();

request_ChangePasswordNoOldPassword.wdSetInvocationModifier(new IWDWSInvocationModifier() {  

 

    SOAPHeaderInterface headerInterface = null;

    public void doModifyInvocation(Object port) {

    // TODO Auto-generated method stub

    // Creating the SOAP Header node.  

             DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();

             docBuilderFactory.setNamespaceAware(false);

             DocumentBuilder docBuilder;

             try {

               docBuilder = docBuilderFactory.newDocumentBuilder();

             } catch (ParserConfigurationException e) {

               // TODO Log the Exception

             wdComponentAPI.getMessageManager().reportException("Error in Executing webservice. Error Description is: " + e.getLocalizedMessage());

               return;

             }

             

              Document soapDoc = docBuilder.newDocument();

               Element AuthHeader = soapDoc.createElementNS("http://www.tmwsystems.com/WebFramework/","web:AuthHeader"); //Set the URI as mentioned in WSDL           

               Element User = soapDoc.createElement("web:User");            

               User.setTextContent(wdContext.currentContextElement().getUser_code());//Set the user

             

               Element Pwd = soapDoc.createElement("web:Pwd");//              

               Pwd.setTextContent(wdContext.currentContextElement().getPwd_code());//Set the password

                             

               AuthHeader.appendChild(User);

               AuthHeader.appendChild(Pwd);

           headerInterface = SOAPHeaderIFactory.getInterface(port);

    // Adds the output SOAP Header to the request.

    try {

    headerInterface.setOutputHeader(null, AuthHeader);  

    } catch (MarshalException e) {

    // TODO Auto-generated catch block

    wdComponentAPI.getMessageManager().reportException("Error in Executing webservice. Error Description is: " + e.getLocalizedMessage());

    e.printStackTrace();

    }

    }

 

    @Override

    public void doModifyAfterInvocation() {

    // TODO Auto-generated method stub

 

    }

    });

3) Deploy the webdynpro DC .

4) Create a provider system. Navigate to NWA->SOA->Technical Configurations->System Connections and click on ‘New’.

5) Create Service Group.Before creating service group, the webdynpro application needs to be deployed on the server.

    Go to NWA-> SOA->Application and Scenario Communication->Application Communication

    Select the application name (Webdynpro Project) -> Select Service group and click on Edit and select above created Provider system & Save.

Thanks,

Amol.

Answers (2)

Answers (2)

daniel_ruiz2
Active Contributor
0 Kudos

hi Amol,

you are looking into something like this:


MDL[ModelInstance] modelInstance = getModelInstance(MODEL_INSTANCE_KEY);

Request_[Operation] request_Operation = new Request_[Operation](modelInstance);

....

request_Operation.wdSetInvocationModifier(

     new IWDWSInvocationModifier() {

          public void doModifyInvocation(Object port) {

               SOAPHeaderInterface soapHeaderInterface = SOAPHeaderIFactory.getInterface(port);

               soapHeaderInterface.setOutputHeader([QName], [AuthHeader]);

          }

          public void doModifyAfterInvocation() {

          }


     }

);

I found something in SDN, this may help you too.. http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/900bbf94-a7a8-2910-e298-a651b4706...

Hope this info helps you somehow,

D.

govardan_raj
Contributor
0 Kudos

hi anmol ,

go through this

http://help.sap.com/saphelp_nw73/helpdata/en/fa/9b078eacf24887a8af46c45d09a7fb/content.htm

here in 7.4 you have to create service groups and and configure a connection ,

i.e http://host:port/nwa/ --> the choose SOA -->system connections -- choose new then follow the above link which clearly expalins step wise and here you can define the username and password

Regards

Govardan

Former Member
0 Kudos

Hi Govardan,

I tried maintaining user-id and password there, but it is not working as the header tags are customized one.

..Amol