cancel
Showing results for 
Search instead for 
Did you mean: 

Using Web Dynpro authentication for a Web Service call

Former Member
0 Kudos

Hi all,

I want to develop a Web Dynpro that calls a Web Service running on the same Web AS (7.0). The Web Dynpro will be integrated in a Portal. The web service that has to be called is automatically generated when we create a guided procedure :

http://help.sap.com/saphelp_nw2004s/helpdata/en/44/44c59fd7c72e84e10000000a155369/frameset.htm

In my Web Dynpro, I imported the WSDL of this WS and created a model.

The first time I tried to call the WS in my Web Dynpro I got an authentication error :

Service call exception; nested exception is: com.sap.engine.services.webservices.jaxrpc.exceptions.InvalidResponseCodeException: Invalid Response Code: (401) Unauthorized. The requested URL was:"http://<myHostName>:50100/GPRuntimeFacadeWS/GPProcessExposing?style=document&pid=CA544E9B629A11DB91480017A48D672A&pver=0.5"

So I hard-coded an HTTP authentication :

model._setUser("myWASuser");

model._setPassword("myPassword");

And the Web Service call now works.

Now the next step is that the WS call is made by the user that runs the Web Dynpro. So I found this documentation :

http://help.sap.com/saphelp_nw04/helpdata/en/59/e8e95d1eba48dfa86ae91ad8816f5d/frameset.htm

It would resolve my authentication problem, AND the transport issue : at the moment the Web Service URL is stored in the Logical Port of the WD model, and at transport time, a rebuild of the WD project will be needed.

So I applied what is said in the doc : from the point of view of the Web Service consumer, I just had to add :

model._setHTTPDestinationName("STARTGP");

(where STARTGP is the name of the destination I created in the Visual Administrator with a "Logon Ticket" authentication.)

before the execute(), and I removed my hardcoded authentication.

Unfortunately, nothing changes... I still get a 401 authentication error.

Does anyone have an idea about this ? Or maybe a workaround ?

Thanks in advance for any suggestion.

Regards,

Julien

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Try below steps

• Add jars

o security.class

o tc/sec/destinations/interface

• Setting WebDynpro project property

o Project>Properties>Web Dynpro References-->Interface references

&#61607; Name=tcsecdestinations~interface

o Project>Properties>Web Dynpro References-->Service reference

&#61607; Name=webservices

&#61607; Name=tcsecdestinations~service

• Dynamically Set httpdestination and Call web service

final InitialContext ctx = new InitialContext();

final DestinationService dstService = (DestinationService)ctx.lookup(DestinationService.JNDI_KEY);

if (dstService== null)

throw new NamingException ("Destination service not available");

final Destination destination = dstService.getDestination("HTTP"," DestinationName");

// getting user name

Properties destprop = destination.getDestinationProperties();

String username = destprop.getProperty("USERNAME");

String password = destprop.getProperty("PASSWORD");

final HTTPDestination httpDestination = (HTTPDestination) destination;

HttpURLConnection httpConnection = httpDestination.getURLConnection();

String httpURL = String.valueOf(httpConnection.getURL());

Request_AdvLocationVer1ViDocument_getLocation obj=wdContext.currentRequest_AdvLocationVer1ViDocument_getLocationElement().modelObject();

obj._setHTTPDestinationName("DestinationName ");

obj._setUser( user );

obj._setPassword(pass);

obj._setEndPoint(httpURL);

obj.execute();

Rahul

Former Member
0 Kudos

Rahul, Anilkumar,

thanks for answering and sorry for the delay.

Rahul,

as far as I understand the Destination you create uses Basic Authentication and not logon ticket. This would be a problem in my case because we need to know who starts the Web Service.

Anilkumar,

the difference with what you describe is that I do not create the Web Service myself : it is an automatically generated Web Service which is created when we create a Guided Procedure in the Portal. So I don't know how I could go through your steps :

1. created a EJB .

While creating the Webservice definition , go to tge features tab and select "athuntication" and choose Basic radiobutton.

2. In webservice configuration select athuntication mechanism as "HTTP athuntication" and transport protocol as "HTTP".

Anyway I will make some tests with the information you gave me and I'll let you know if the problem is solved.

An other point is that since NW04s SP8, the way to generate WD models has changed : now we have two ways to generate Web Service proxies, the old way (Import Web Service Model) which is now marked as deprecated, and the new way (Import ADAPTIVE Web Service Model) which does not allow anymore to call the methods setHTTPDestinationName(),setUser(),_setPassword(), etc.

Did you already tried this new possibility ? Which one would you recommend ?

I also have an additional question : When we modify a logical destination in the Visual Administrator, do you know if we have to restart the J2EE engine ?? Or is there a kind of cache that has to be refreshed ?? It seems that my modifications are not taken into account...

Regards,

Julien

Message was edited by:

Julien LATOURNERIE

Message was edited by:

Julien LATOURNERIE

Former Member
0 Kudos

Hi Julien,

I have created Basic Authentication but there is a option to create Logon Ticket.

> I also have an additional question : When we modify a logical destination in the Visual > Administrator, do you know if we have to restart the J2EE engine ?? Or is there a kind of > cache that has to be refreshed ?? It seems that my modifications are not taken into > account...

you don't need to restart J2EE Engine :).

Rahul

Answers (2)

Answers (2)

Former Member
0 Kudos

Hello Julien,

I have a scenario similar to yours. A client webdynpro application accessing a EJB methods exposed as web service. Those EJB's methods calls R3 RFC's. The client requirements' was to allow SSO through all the layers (Webdynpro -> EJB WS -> RFC). The Webdynpro and EJB's are deployed on the same WAS.

Solution:

1 - Create a RFC Destination on Visual Administration provide the R3 connection parameters and set the Authentication for "Current User (Logon Ticket)". Save your Destination;

2 - In your EJB Project open your Web Service Configuration, on the Security page, set:

Authentication Mechanism: HTTP Authentication

Basic (username/password)

Use SAP Logon Ticket

3 - In your EJB, implement the following code to create JCO Client for the RFC invocations:

Object obj = ctx.lookup(DestinationService.JNDI_KEY);
    DestinationService dstService = (DestinationService) obj;
    RFCDestination dst = (RFCDestination) dstService.getDestination("RFC", "<YOUR_RFC_DESTINATION_NAME>");
    Properties jcoProperties = dst.getJCoProperties();
    JCO.Client jcoClient = JCO.createClient(jcoProperties);

4 - In your EAR Project, open your "application-j2ee-engine.xml" and add the References:

"tc/sec/destinations/service" as Service

"tc/sec/destinations/interface" as Interface.

5 - Create your EAR File and Deploy;

6 - Check if the web service now requires Authentication: go to http://<host>:<port>/index.html and click on Web Services Navigator. Test your Web Service. Your Web Service should requiere you to log in before execute the test;

7 - Go back to your Visual Administrator and create a HTTP Destination. Provide your WS URL (should be something like "http://<host>:<port>/<WS_NAME>/Config1?style=document"). Choose Authentication: Logon Ticket. Save your Destination;

8 - Go to your webdynpro project, import your WS Model. (If you have already created it, you have to delete it and import it again, refer to this blog on how to reimport WS Models: /people/bertram.ganz/blog/2005/10/10/how-to-reimport-web-service-models-in-web-dynpro-for-java How To Reimport Web Service Models in Web Dynpro for Java );

9 - Open your model's Logical Ports node, go to the Security tab, and choose "Use SAP Logon Ticket";

10 - In your webdynpro code, before you call the ws invocation (should be something like that: <YOUR_NODE_DEFINITION>.modelObject().execute();), include the following line:

<YOUR_NODE_DEFINITION>.modelObject()._setHTTPDestinationName("<YOUR_HTTP_DESTINATION_NAME>");

11 - Save All Metadata and deploy your Webdynpro App. Test your results.

I hope it helps you, as the documentation on how to implement this scenario is scattered through the SDN and all the SAP help portal.

Best regards,

Paulo.

Former Member
0 Kudos

Hi Julien,

I have replied to this similar topic here

This will aviod to get rid of hardcoding in your application.

Regards, Anilkumar