cancel
Showing results for 
Search instead for 
Did you mean: 

Webservice with HTTP authentication

Former Member
0 Kudos

Hi,

how do i supply the userid an password for a http authenticated webservice. I already choose the option for http authentication on the security tab on the logical port.

Alos tried to find it in the Visual Admin to the server but i am stuck.

Greetings Danny.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

There are two ways to do this

<b>Option 1: Hard code the Username/Password</b>

For this, use the method _setUser and _setPassword.

These are methods for your model class Request_<WebService>_PortType.... (the model class for the webservice). I invoked these methods in the wdDoInit method of the component controller class.

For example, i imported the WSDL for the RFC SXMB_GET_MESSAGE_LIST and used it like this:

Request_SXMB_GET_MESSAGE_LISTPortType_SXMB_GET_MESSAGE_LIST oRequest = 
new Request_SXMB_GET_MESSAGE_LISTPortType_SXMB_GET_MESSAGE_LIST();
oRequest._setUser("bcuser");
oRequest._setPassword("password");

<b>Option 2: Use HTTP Destinations</b>

Open Visual Administrator and goto node Services, Destination Service. Create a HTTP destination with the URL of the webservice, maybe choose basic authentication and give the username / password. Now, you could use this HTTP destination in the component controller class. Even though there is a method _setHTTPDestinationName, this did not work for me. I had to write the following code to retrieve the URL, username, password from the HTTP destination

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.net.HttpURLConnection;

	InitialContext ctx ;
	Object obj;
	DestinationService dstService;
	Destination destination;
	HTTPDestination httpDestination ;
	HttpURLConnection httpurlconnection = null;
	Properties destprop = null;
	String url = "";
	String username = "";
	String password = "";
		ctx = new InitialContext();
		obj = ctx.lookup(DestinationService.JNDI_KEY);
		dstService = (DestinationService) obj;		
		destination = dstService.getDestination("HTTP","NC_IS");
		destprop = destination.getDestinationProperties();
		httpDestination = (HTTPDestination) destination;
		url = httpDestination.getUrl();
		username = destprop.getProperty("USERNAME");
		password = destprop.getProperty("PASSWORD");   

(I know the java code sucks and the purists will hang me; nevertheless it works)

Besides the code, you need to do the following as well:

(1) In the Package explorer, select your project, right click, cick on "Set Additional Libraries.."

(2) Select security.class and tc/sec/destinations/interface

(3) Click on menu Project > Properties, goto Webdynpro refereces node in the tree and add the following

(a) Interface References: tcsecdestinations~interface

(b) Service References: tcsecdestinations~service

All the best, try option 1 first before you embark on the second one.

Regards, Parag.

Former Member
0 Kudos

Parag,

Case with HTTP destination.

Probably this also shoudl works (and is much simpler to use):


Request_SXMB_GET_MESSAGE_LISTPortType_SXMB_GET_MESSAGE_LIST oRequest 
  = new Request_SXMB_GET_MESSAGE_LISTPortType_SXMB_GET_MESSAGE_LIST();
oRequest._setHTTPDestinationName("NC_IS");

Valery Silaev

EPAM Systems

http://www.NetWeaverTeam.com

Former Member
0 Kudos

Hi Parag,

i tried option 1 with following coding in my controller:

//@@begin javadoc:wdDoInit()

/** Hook method called to initialize controller. */

//@@end

public void wdDoInit()

{

//@@begin wdDoInit()

//$$begin Service Controller(119040844)

Request_FindServiceSoap_findAddress RFf = new Request_FindServiceSoap_findAddress();

RFf._setUser("xxxxx");

RFf._setPassword("yyyyy");

wdContext.nodeRequest_FindServiceSoap_findAddress().bind(RFf);

//$$end

//@@end

}

Without success.

Still gives me the message 401 not authorised

Will try option 2 now but am a bit confused why we need to retreive the userid and password and password.

Greetings Danny.

Former Member
0 Kudos

Hello Danny,

Sorry, my 2 days of WD Java experience ends here. It worked for me with a SAP RFC webservice (soap/rfc). A stupid question, did you try the webservice URL in the browser ? Does it popup a authentication dialog box ? Please check the URL and the username/password.

About your other query, we need to retrieve the userid/password to pass it on to the _setUser and _setPassword method. I should have mentioned this in my example.

Valery,

You are right, that's the simpler method but did not work for me for the same webservice and i got a 401 just like Danny. Fortunately, the _setUser worked so i was luckier than Danny.

Hope you find a solution Danny.

Regards, Parag.

Former Member
0 Kudos

Hi Parag,

yes it works in the browser and i managed to get the webservice to work in a .net environment and a normal J2EE environment using AXIS.

Greetings Danny.

Seems there is still work for the Web Dynpro team to get webservices less compilcated to get it to work.

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Danny,

Here are some webblogs regarding authentication.

https://www.sdn.sap.com/irj/sdn?rid=/webcontent/uuid/adcfa85d-0501-0010-a398-80a47b8e3fc2 [original link is broken]

Former Member
0 Kudos

Hi,

Checked this reference but is all about setting up security on the J2EE server.

I am looking on how to consume an http authenticated webservice.

Thanks Danny.