0

Soap services are working fine after passing the parameters username and password under authentication tab in Soap UI but not working from java code.

Please find the Code as below:

ServicesLocator sl = new ServicesLocator();
ServicesSoapProxy proxy = new ServicesSoapProxy();
ServicesSoap serviceSoap = sl.getServicesSoap();

//Service s = new Service();
//Port port = s.getPort(); // if tried using service object s but s.getPort not coming in my code

Port port = (Port) sl.getPort(proxy.getEndpoint(),ServicesSoap.class);
BindingProvider prov = (BindingProvider)port;
prov.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "username");
prov.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "password");

//then calling SOAP Service 
serviceSoap.callExternalSOAPSERVICE();

Error as shown below:

faultCode: {http://xml.apache.org/axis/}HTTP
faultSubcode: 
 faultString: (401)Unauthorized
faultActor: 
 faultNode: 
 faultDetail: 
      {}:return code:  401

Please suggest on this.

Krishna
  • 233
  • 2
  • 6
  • 20

1 Answers1

0

Set HTTP Header, Authorization Basic "base64encoded username/password".

Something like below.

String authString = "username" + ":" + "password";
String authStringEnc = new BASE64Encoder().encode(authString.getBytes());

//Get the HTTP Header and set it like below.

objectXXX.header("Authorization", "Basic " + authStringEnc);"

//Call your service, now
Red Boy
  • 5,429
  • 3
  • 28
  • 41