File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Services and the fly likes  java.io.IOException: Server returned HTTP response code: 401 for URL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark " java.io.IOException: Server returned HTTP response code: 401 for URL " Watch " java.io.IOException: Server returned HTTP response code: 401 for URL " New topic
Author

java.io.IOException: Server returned HTTP response code: 401 for URL

Amit A Rathore
Greenhorn

Joined: Jun 10, 2009
Posts: 5
Hi,

I have been facing an issue for quite some time.

I have make 2 webservice calls, 1st call is to webservice running in Axis2 and deployed in Weblogic9.1 and the 2nd call is from the 1st webservice (running under axis2) to another webservice running under Weblogic9.1 and is using weblogic webservices. 2nd set of webservices are secured using basic http authentication.

Below is the code that accesses 2nd webservice and is written in 1st webservice implementation:

java.net.Authenticator.setDefault(new my.custom.authenticator.BasicHTTPAuthenticator("username", "password"));
MyAppWebServiceEndpoint_Impl ws = new MyAppWebServiceEndpoint_Impl("http://myserver:7001/myappws/snwebservice?WSDL");
MyAppWebServiceEndpointPort port = (MyAppWebServiceEndpointPort) ws.getMyAppWebServiceEndpointPort("username", "password");


Here,
MyAppWebServiceEndpoint_Impl and MyAppWebServiceEndpointPort is autogenerated by weblogic clientgen utility.
BasicHTTPAuthenticator is a custom authenticator which has just setters & getters and extends java.net.Authenticator.

Following the exception i am getting:

weblogic.webservice.wsdl.WSDLParseException: Failed to retrieve WSDL from http://myserver:7001/myappws/snwebservice?WSDL. Please check the URL and make sure that it is a valid XML file java.io.IOException: Server returned HTTP response code: 401 for URL: http://myserver:7001/myappws/snwebservice?WSDL
at weblogic.webservice.wsdl.DefinitionFactory.createDefinition(DefinitionFactory.java:160)
at weblogic.webservice.wsdl.WSDLParser.<init>(WSDLParser.java:50)
at weblogic.webservice.WebServiceFactory.createFromWSDL(WebServiceFactory.java:109)
at weblogic.webservice.core.rpc.ServiceImpl.<init>(ServiceImpl.java:94)
at com.mycompany.myapp.ws.client.MyAppWebServiceEndpoint_Impl.<init>(MyAppWebServiceEndpoint_Impl.java:22)
at Test.createServiceEndPoint(Test.java:72)
at Test.main(Test.java:21)

When i deploy axis2 in tomcat5.5, it works fine and when i move the while axis2 to weblogic it throws the above error.

Please provide some help.
Chintan Rajyaguru
Ranch Hand

Joined: Aug 19, 2001
Posts: 341
I am not familiar with WebLogic but are you sure your client code is correct? Is the line ws.getMyAppWebServiceEndpointPort("username", "password"); allowed in WebLogic client? I am not aware of any method that takes username and password as arguments. May be it is WebLogic specific.

Look at the code 401 description here. Assuming your username and password are correct, try hitting the WSDL URL in a browser. You should be asked for username and password in a popup and see what happens.

Finally, do you have to set any proxy settings when you run from WebLogic?


ChintanRajyaguru.com
SOADevelopment.com - Coming soon!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.io.IOException: Server returned HTTP response code: 401 for URL