This discussion is archived
1 Reply Latest reply: Jun 3, 2011 2:27 PM by 864479 RSS

URGENT: Jax-WS metro with HTTP basic authentication?

830049 Newbie
Currently Being Moderated
Hello,

How can I set the username and password while consume the web service? Please teach me.

I tried the following code, but failed.

URL wsdl = new URL("http://ws1:12345678@localhost:8080/PortalWS/TestService?wsdl");
TestServiceService stub = new TestServiceService(wsdl);                                                                                                                                  
                         
TestService proxy = stub.getTestServicePort();
               
((BindingProvider)proxy).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "ws1");
((BindingProvider)proxy).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "12345678");


It raised the following exception,

javax.xml.ws.WebServiceException: Failed to access the WSDL at: http://ws1:12345678@localhost:8080/PortalWS/TestService?wsdl. It failed with:
     Got Server returned HTTP response code: 401 for URL: http://ws1:12345678@localhost:8080/PortalWS/TestService?wsdl while opening stream from http://ws1:12345678@localhost:8080/PortalWS/TestService?wsdl.
     at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(RuntimeWSDLParser.java:188)
     at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:170)
     at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:135)
     at com.sun.xml.ws.client.WSServiceDelegate.parseWSDL(WSServiceDelegate.java:275)
     at com.sun.xml.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:238)
     at com.sun.xml.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:186)
     at com.sun.xml.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:111)
     at javax.xml.ws.Service.<init>(Service.java:92)
     at mo.gov.economia.portalws.testservice.TestServiceService.<init>(TestServiceService.java:50)
     at mo.dse.ws.test.Test.main(Test.java:22)
Caused by: java.io.IOException: Got Server returned HTTP response code: 401 for URL: http://ws1:12345678@localhost:8080/PortalWS/TestService?wsdl while opening stream from http://ws1:12345678@localhost:8080/PortalWS/TestService?wsdl
     at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.createReader(RuntimeWSDLParser.java:857)
     at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.resolveWSDL(RuntimeWSDLParser.java:298)
     at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:155)
     ... 8 more
Caused by: java.io.IOException: Server returned HTTP response code: 401 for URL: http://ws1:12345678@localhost:8080/PortalWS/TestService?wsdl
     at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1196)
     at java.net.URL.openStream(URL.java:1007)
     at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.createReader(RuntimeWSDLParser.java:842)
     ... 10 more

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points