cancel
Showing results for 
Search instead for 
Did you mean: 

how to set user and password in adaptive web service model

Former Member
0 Kudos

Hi all,

In adaptive web service model, the following methods for web service model are not supported any more:

wdContext.currentXXXXElement().modelObject()._setUser("username");
wdContext.currentXXXXElement().modelObject()._setPassword("password");

What's the new methods which have the same function in adaptive web service model? I know I could create some web service proxies in visual admin and set userName and passWord there, but I just want to know to how to hard code this information in the web dnypro program.

Thanks!

Regards,

Hui

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hui,

From <a href="https://www.sdn.sap.com/irj/sdn/wiki?path=/display/wdjava/faq-Models-AdaptiveWebService&">FAQ - Models - Adaptive Web Service</a>:

<i>nvalidResponseCodeException: Invalid Response Code: (401) Unauthorized...: The user / password provided for the WSDL was wrong or you have chosen the option No logical destinations in AWS model importer. <u>Note that for the case the WS provider requires authentication for the WSDL one <b>must</b> use the WS destinations option in the importer as WS destinations are the only way to configure authentication data needed at runtime.</u>

</i>

Valery Silaev

SaM Solutions

http://www.sam-solutions.net

Former Member
0 Kudos

Hi valery,

Thanks for your reply. But My problem is not to set the user and password for the wsdl file during the import of wsdl. Actually I import the wsdl file from a ftp server. And I didn't get any error or expception when I import the wsdl.

My problem is the web service (not the wsdl) I want to call in web dynpro requires an authentication. I want to set the user and password in the code.

Thanks!

Regards,

Hui

Former Member
0 Kudos

Hi ,

<b>are the only way to configure authentication data needed at runtime.</b>

Former Member
0 Kudos

Hui,

According to FAQ this is the only option.

Here is the totaly untested code you might try as well:


import javax.xml.rpc.Stub;
import com.sap.tc.webdynpro.model.webservice.api.IWDWSInvocationModifier;
import com.sap.engine.services.webservices.espbase.client.dynamic.DInterfaceInvoker;
...
wdContext.currentXXXXElement().modelObject().wdSetInvocationModifier(
  new IWDWSInvocationModifier() {
    public void doModifyInvocation(final Object port) {
      if ( port instanceof Stub ) {
        final Stub stub = (Stub)port;
        stub._setProperty(Stub.USERNAME_PROPERTY,  "username");
        stub._setProperty(Stub.PASSWORD_PROPERTY, "password");
      } else if (port instanceof DInterfaceInvoker) {
        final DInterfaceInvoker invoker = (DInterfaceInvoker)port;
        invoker.setProperty(Stub.USERNAME_PROPERTY,  "username");
        invoker.setProperty(Stub.PASSWORD_PROPERTY, "password");
      } else
         throw new RuntimeException("This 'clever' hack does not work"); 
    }
    public void doModifyAfterInvocation() {}
  }
);

Actually, I write this code without IDE (so some names could be mispelled and syntax errors are possible) and never try it (so it can fail on deployment/run-time), but who knows, probably it works. If my assumption about port parameter is wrong you'll see error on screen.

Valery Silaev

SaM Solutions

http://www.sam-solutions.net

Former Member
0 Kudos

Hi Valery,

wonderful! It works and I didn't change any code.

Thanks a lot!

BeGanz
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Valery,

your solution invoking the IWDSInvocationModifier-API should work but there is a simpler solution based on invoking the IWDWSModelClassExecutable-API directly.

  /**
   * Set WS-Runtime invocation property for the web service. Properties allowed here 
   * are the properties listed as name constants in {@link javax.xml.rpc.Stub}.
   * @param key Key of the invocation property
   * @param value Value of the invocation property
   */
  IWDWSModelClassExecutable.setInvokerProperty(String key, Object value) 

NOTE: Normally username and password are set by defining the Logical WS Destinations.

Regards, Bertram

Former Member
0 Kudos

Hi Bertram,

Where can I get more information about the input parameter key. The values for the key must be some fixed values like "user", "password" and other stuff. Where to find the related documentation?

Former Member
0 Kudos

Bertram,

Thanks for hint -- actually my IDE is very outdated and I didn't noticed this interface among jars on server.

<b>You definitely have to update FAQ entry</b>

VS

Former Member
0 Kudos

Hui,

Read across the lines: constants of <a href="http://java.sun.com/j2ee/1.4/docs/api/javax/xml/rpc/Stub.html">javax.xml.rpc.Stub</a> class are valid property names, so:


import javax.xml.rpc.Stub;
...
wdContext.currentXXXXElement().modelObject()
  .setInvokerProperty(Stub.USERNAME_PROPERTY,  "username");
wdContext.currentXXXXElement().modelObject()
  .setInvokerProperty(Stub.PASSWORD_PROPERTY, "password");

Valery Silaev

SaM Solutions

http:/www.sam-solutions.net

Message was edited by:

Valery Silaev -- added link to API docs

BeGanz
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Hui,

see <a href="http://java.sun.com/j2ee/1.4/docs/api/javax/xml/rpc/Stub.html">JavaDoc of class javax.xml.rpc.Stub</a>.

Regards, Bertram

Former Member
0 Kudos

Hi,

This is regarding the solution given by Bertram Ganz and Valery Silaev

I am using SAP NetWeaver Developer Studio Version: 7.0.07 (Build id: 20060324033) and I could import the WSDL. Do i need to import any extra jar files or add any environmental variables to get the class IWDWSInvocationModifier and IWDWSModelClassExecutable?

I am trying to resolve the nvalidResponseCodeException: Invalid Response Code: (401) Unauthorized

N.B.

I could see the IWDWSInvocationModifier at

E:\SAP\IDE\IDE70\eclipse\plugins\com.sap.tc.webdynpro.model.webservice_2.0.0\lib\_webdynpro_model_webservice.jar

Thanks in advance

-Kailash

Edited by: Aftermarket Team on Jan 4, 2008 12:19 PM

Answers (0)