This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Web Services and the fly likes JAX-WS Authentication problem  -javax.xml.ws.WebServiceException Response: '401: Unauthorized' Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "JAX-WS Authentication problem  -javax.xml.ws.WebServiceException Response: Watch "JAX-WS Authentication problem  -javax.xml.ws.WebServiceException Response: New topic
Author

JAX-WS Authentication problem -javax.xml.ws.WebServiceException Response: '401: Unauthorized'

Ganesh Gowtham
Ranch Hand

Joined: Mar 30, 2005
Posts: 225

Dear Friends ,

i am doing Webservice using JAX-WS technology .
client - jaxws one (exposed to client with WSDL ) and - calls 2nd service implemented in JAX-WS which has authentication

communication between client - jaxws one (exposed to client with WSDL ) is OK .

communication between jaxws one (exposed to client with WSDL ) and - calls 2nd service - exception occured due to authentication

javax.xml.ws.WebServiceException Response: '401: Unauthorized' for url: 'http://host/HelloService'
at com.sun.xml.ws.wsdl.WSDLContext.<init>(WSDLContext.java:68)
at com.sun.xml.ws.client.WSServiceDelegate.parseWSDL(WSServiceDelegate.java:207)
at com.sun.xml.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:165)
at com.sun.xml.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:49)
at weblogic.wsee.jaxws.spi.WLSProvider.createServiceDelegate(WLSProvider.java:18)

Caused by: java.io.FileNotFoundException: Response: '401: Unauthorized' for url: 'http://host/HelloService'


i had written autheticator class also

one more thing this works good as Junit (stand alone ) and in Tomcat

when i am deploying in weblogic i am getiing above exception .



calling class snippet
---------------------



Please suggest what needs to be done ? ( it is working as Junit and in tomcat ... in weblogic it is giving problem )


Thanks, Ganesh Gowtham
http://ganesh.gowtham.googlepages.com
Amit A Rathore
Greenhorn

Joined: Jun 10, 2009
Posts: 5
Hi Ganesh,
Did you find a solution to this problem? Even I am facing the same problem and have wasted 3 days without success. If you have solved it, can you please write your solution here....

--
Cherio
ASR
Ganesh Gowtham
Ranch Hand

Joined: Mar 30, 2005
Posts: 225

HI Amit ,

Are you getting this authentication issue in tomcat (or) weblogic ?.

Tomcat means i do have solution ,infact for weblogic i didnt try even now as it is not in priyority list .
Amit A Rathore
Greenhorn

Joined: Jun 10, 2009
Posts: 5
Let me explain what I have done.

I have 2 make 2 webservice calls. 1 set of webservices are running under axis2 1.1 which are not secured and 2nd set of webservices are running under weblogic which are secured using basic HTTP authentication. Both these services are deployed in Weblogic 9.1.

My client program makes a call to webservices running in axis2 which inturn invokes webservices running in weblogic webservices and pass authentication details to this services using Authenticator class.

This was working fine when my axis2 was deployed under tomcat, the issue occured when I moved Axis2 to weblogic container.

Does that help you to understand the problem.


STACK TRACE:
weblogic.webservice.wsdl.WSDLParseException: Failed to retrieve WSDL from http://myserver:9001/myws/snwebservice?WSDL. Please check the URL and make sure that it is a valid XML file [java.io.FileNotFoundException: Response: '401: Unauthorized' for url: 'http://myserver:9001/myws/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)
Ganesh Gowtham
Ranch Hand

Joined: Mar 30, 2005
Posts: 225

Hi Amit

infact i faced the same problem ... since tomcat --> weblogic migration is not priority it stopped working on this .

can uyou try this
Amit A Rathore
Greenhorn

Joined: Jun 10, 2009
Posts: 5
Ganesh,
Here is my code snippet:

// BasicHTTPAuthenticator is a subclass of java.net.Authenticator
Authenticator.setDefault(new BasicHTTPAuthenticator("myuser", "mypassword"));

// instantiate the endpoint impl. This Impl file is autogenerated as result of Weblogic ServiceGen
SupernovaWebServiceEndpoint_Impl ws = new SupernovaWebServiceEndpoint_Impl("http://myserver:9001/myws/snwebservice?WSDL");

// get the endPointPort
SupernovaWebServiceEndpointPort port = (SupernovaWebServiceEndpointPort) ws.getSupernovaWebServiceEndpointPort();

So in this code where will I add your suggested code. I thought setting Authenticator before invocation should've handled it and it does it successfully when it runs under tomcat.

--
Cheers
ASR
sai mishra
Greenhorn

Joined: Jul 07, 2009
Posts: 1
hey guys any luck.. i am also running into the same issue inside weblogic
Ganesh Gowtham
Ranch Hand

Joined: Mar 30, 2005
Posts: 225

Hi Amit,

Did you solution for this issue , if so could you please let us know the procedure you had followed .

Amit Rathore wrote:Ganesh,
Here is my code snippet:

// BasicHTTPAuthenticator is a subclass of java.net.Authenticator
Authenticator.setDefault(new BasicHTTPAuthenticator("myuser", "mypassword"));

// instantiate the endpoint impl. This Impl file is autogenerated as result of Weblogic ServiceGen
SupernovaWebServiceEndpoint_Impl ws = new SupernovaWebServiceEndpoint_Impl("http://myserver:9001/myws/snwebservice?WSDL");

// get the endPointPort
SupernovaWebServiceEndpointPort port = (SupernovaWebServiceEndpointPort) ws.getSupernovaWebServiceEndpointPort();

So in this code where will I add your suggested code. I thought setting Authenticator before invocation should've handled it and it does it successfully when it runs under tomcat.

--
Cheers
ASR
Amit A Rathore
Greenhorn

Joined: Jun 10, 2009
Posts: 5
Hi Ganesh,
No luck yet. I had kept this at the back burner. I have raised this issue in other forums as well but no luck yet.

If you get something, do let me know.

--
Cheers
Amit
Matthew L Williams
Greenhorn

Joined: Apr 18, 2007
Posts: 2
For those who may stumble on this trying to find the answer this is what I did to get it to work.



Note that I think is is not a particularly elegant solution. I think that it would be much better to be using an Authenticator or a SOAPHandler however in Weblogic 10.3.2 (and from others who have posted similar questions on the web also in previous versions of weblogic) neither of these methods appears to work.

Its also worth noting that in order to get this to work either the url to get the wsdl needs to be unsecured or you need a local copy of the wsdl and to change the static initialiser of the gererated service class

HTH

Matt
Ganesh Gowtham
Ranch Hand

Joined: Mar 30, 2005
Posts: 225

HI Mathew , the same snippet works pretty well for me .
finally i copied the wsdl to host(which is secured) to weblogic server . which works for me ...

i think the solution you gave me works in axis version ..

Thanks for reply
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39578
    
  27
The proper way to secure a JAX-WS web service is really to use WS-Security, not HTTP authentication. All major JAX-WS implementations support that.


Ping & DNS - updated with new look and Ping home screen widget
Ganesh Gowtham
Ranch Hand

Joined: Mar 30, 2005
Posts: 225

Ulf Dittmer wrote:The proper way to secure a JAX-WS web service is really to use WS-Security, not HTTP authentication. All major JAX-WS implementations support that.


This is case , where i expose soem service which in-turn i comsume others service ( whose implementation is HTTP Authentication based )
Rasheed Muhammad
Greenhorn

Joined: Dec 15, 2003
Posts: 4
Axis2 does not support Rampart with JAX-WS service so we need to do HTTP or manual authentication.
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 468
    
    2
Axis2 does not support Rampart with JAX-WS service so we need to do HTTP or manual authentication.

Apart from this thread being 2 years old, I don't know, that statement can't be serious, can it? even if we put ourselves back to the time of year 2010.
http://axis.apache.org/axis2/java/rampart/
Maybe I miss the point?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JAX-WS Authentication problem -javax.xml.ws.WebServiceException Response: '401: Unauthorized'
 
Similar Threads
JAX-WS - please help convert proxy to BindingProvider for HTTP auth
JAX-WS Consuming Exchange Web Services with java using glassfish, error authentication: Unauthorized
Change address location webservice
Error in JAXWS client web service usig dynamic url
How to add the security header in SOAP request?