DZone Forums
Go Back   DZone Forums > Community > Languages & Frameworks > Java
Reload this Page Problem while invoking web service through code
Notices
Reply
 
LinkBack Thread Tools Display Modes
  (#1 (permalink)) Old
Member
 
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Oct 2008
Question Problem while invoking web service through code - 10-31-2008, 03:01 PM

I have a web service developed using AXIS deployed on Weblogic 8.1

Another web application cotaining GUI deployed on Weblogic 10 tries to access this web service through code.
This piece of code to invoke the web service is written in Action Class present inside web application. (Struts is used in GUI based web app)

When the code tries to invoke web service I am getting following error.

(401)Unauthorized xxx
at org.apache.axis.transport.http.HTTPSender.readFrom Socket(HTTPSender.java:630)
at org.apache.axis.transport.http.HTTPSender.invoke(H TTPSender.java:128)
at org.apache.axis.strategies.InvocationStrategy.visi t(InvocationStrategy.java:71)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain .java:150)
at org.apache.axis.SimpleChain.invoke(SimpleChain.jav a:120)
at org.apache.axis.client.AxisClient.invoke(AxisClien t.java:180)
at org.apache.axis.client.Call.invokeEngine(Call.java :2564)
at org.apache.axis.client.Call.invoke(Call.java:2553)
at org.apache.axis.client.Call.invoke(Call.java:1753)
at com.ebv.app.web.action.UCS77_1ProcessOfficialChang eSaveDetailsAction.invokeAx(UCS77_1ProcessOfficial ChangeSaveDetailsAction.java:243)
at com.ebv.app.web.action.UCS77_1ProcessOfficialChang eSaveDetailsAction.callUCS77_1ProcessOfficialChang eWebService(UCS77_1ProcessOfficialChangeSaveDetail sAction.java:173)
at com.ebv.app.web.action.UCS77_1ProcessOfficialChang eSaveDetailsAction.processAction(UCS77_1ProcessOff icialChangeSaveDetailsAction.java:133)
at com.ebv.framework.web.action.EBVAction.execute(EBV Action.java:106)
at org.apache.struts.action.RequestProcessor.processA ctionPerform(RequestProcessor.java:421)
at org.apache.struts.action.RequestProcessor.process( RequestProcessor.java:226)
at org.apache.struts.action.ActionServlet.process(Act ionServlet.java:1164)
at org.apache.struts.action.ActionServlet.doPost(Acti onServlet.java:415)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:727)

The web service URL is as follows:
http://10.140.96.5:7808/services/ucs...7_1-v0001.soap

However
When I try to hit the webservice URL directly on browser login window appears where same username/password I provide which are passed in code to invoke the web service. I get the success page indicating that web service is invoked on hitting enter.

The method used in UCS77_1ProcessOfficialChangeSaveDetailsAction.java to invoke web service is as follows:
public String invokeAx
(
String xmlMessage,
String webServiceURL,
String webServiceOperation,
String username,
String password)
{
String xmlResponse = null;
Call webServiceCall = null;
InputStream input = new ByteArrayInputStream(xmlMessage.getBytes());
Service service = new Service();
try
{
webServiceCall = (Call) service.createCall();
SOAPEnvelope env = new SOAPEnvelope(input);
SOAPEnvelope resEnv = null;
webServiceCall.setTargetEndpointAddress(new URL(webServiceURL));
webServiceCall.setOperationName(new QName(webServiceOperation));
webServiceCall.setUsername(username);
webServiceCall.setPassword(password);
try
{
resEnv = webServiceCall.invoke(env);
}
catch (AxisFault e)
{
e.printStackTrace();
Message responseMessage = webServiceCall.getResponseMessage();
SOAPEnvelope soapXml = (SOAPEnvelope) responseMessage.getSOAPEnvelope();
xmlResponse = new String(soapXml.toString().getBytes(AppConstants.UT F8),AppConstants.UTF8);
}

if (xmlResponse == null)
{
xmlResponse = resEnv.toString();
}
}
catch (Exception e1)
{
e1.printStackTrace();
}

return xmlResponse;
}

Both the weblogic server reside on two different AIX machines.

Can anybody tell what's the problem while invoking web service through code?
Attached Images
File Type: jpg UCS77_1_WebService.JPG (83.6 KB, 1 views)
Reply With Quote
  (#2 (permalink)) Old
Member
 
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Oct 2009
Default Were you able to fix this problem? - 10-07-2009, 03:46 AM

One of my developers is facing the exact same problem and has been unable to resolve it. I was wondering if you were able to resolve it and if yes could you share the resolution? I'll greatly appreciate your help
Reply With Quote
  (#3 (permalink)) Old
Member
 
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Oct 2008
Default 10-07-2009, 08:05 AM

Unfortunately I have not yet got the solution for this.
But I guess it is a problem with the version of weblogic.
The code works on weblogic 8.1 but has problems with weblogic version 10
Reply With Quote
  (#4 (permalink)) Old
Member
 
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Oct 2008
Default 10-07-2009, 08:09 AM

Bingo!!!
I think we have got the solution to the problem.

Modify code provided above to invoke the web service with following 2 lines of code:

webServiceCall.setProperty(Call.USERNAME_PROPERTY, username);
webServiceCall.setProperty(Call.PASSWORD_PROPERTY, password);

This should resolve the problem of unauthorized xxx
Reply With Quote
  (#5 (permalink)) Old
Member
 
Posts: 19
Thanks: 0
Thanked 1 Time in 1 Post
Join Date: Jan 2008
Location: Germany, Munich
Send a message via MSN to mende
Default 10-09-2009, 01:57 PM

I had the same problem today.... This helped me:

For JAXWS:
Code:
HelloService service = new HelloService();
Hello proxy = (service.getHelloPort());
((BindingProvider)proxy).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "hello");
((BindingProvider)proxy).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "world");


Ceterum censeo Carthaginem esse delendam.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SOALIB - Service Oriented Architecture Libraries soalib Web Services, SOA & ESB 0 01-04-2009 11:18 PM
Remote debugging problem in application startup code satisha123 Eclipse 0 12-24-2008 05:52 AM
Eclipse Axis Web Service rajivbandaru Eclipse 0 12-07-2008 11:16 AM
Problem debugging SWT/JFace code... jorgedieguez Eclipse 1 08-19-2008 05:37 PM
Java Service Provider problem island Java 0 03-30-2008 11:39 AM


Copyright 1997-2009, DZone, Inc.
vBulletin Skin developed by: vBStyles.com