aspose file tools*
The moose likes Web Services and the fly likes Passing Authentication Parameters while consuming a web service Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Passing Authentication Parameters while consuming a web service" Watch "Passing Authentication Parameters while consuming a web service" New topic
Author

Passing Authentication Parameters while consuming a web service

Shruti Sharma
Ranch Hand

Joined: Mar 25, 2010
Posts: 55
Hi,

I am facing a problem:

There is a web service that I need to consume. When I write a standolone test client and run it through the 'main' method it runs well. But when I try to run through my web application the authentication fails.

Here is the code snippet that I am trying:

****************************************************

try{
String urlString = "http://10.192.79.22:9081/VaCMSSPIDeRDrillDown/VaCmsSpiderServiceImplService/WEB-INF/wsdl/SPDR.wsdl";
//String urlString = "http://localhost:9082/VaCMSSPIDeRDrillDown/VaCmsSpiderServiceImplService/WEB-INF/wsdl/SPDR.wsdl";

String nameSpace = "http://www.deloitte.com/VaCMS";
String serviceName = "VaCmsSpiderServiceImplService";
QName qName = new QName(nameSpace, serviceName);


URL url = new URL(urlString);
VaCmsSpiderServiceImplPortProxy serviceProxy = new VaCmsSpiderServiceImplPortProxy(url, qName);

Map<String, List<String>> headers = new HashMap<String, List<String>>();
headers.put("Username", Collections.singletonList("CMS_SPIDER_DD"));
headers.put("Password", Collections.singletonList("CMS_SPIDER_DD"));

((BindingProvider)serviceProxy._getDescriptor().getProxy()).getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS, headers);


VaCmsCaseInfoByClientId request2 = new VaCmsCaseInfoByClientId();
VaCmsCaseInfoByClientIdRequest clientId = new VaCmsCaseInfoByClientIdRequest();
clientId.setClientId(2100035757L);
request2.setArg0(clientId);

VaCmsCaseInfoResponse response2 = serviceProxy.getVaCmsCaseInfoByClientId(request2);
System.out.println(response2.getReturnCode());
System.out.println(response2.getReturnMessage());

}catch(Exception e){
e.printStackTrace();
}

************************************************************************

Please note the way I am passing the authentication parameters. The same code works when run as main method but the authentication is failing if I run through the web application.

Please assist. It is somewhat urgent.

Thank you,
-Shruti
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Passing Authentication Parameters while consuming a web service