0

I genrated with wsimport java classes. the wsdl I imported request a authentication.

I used this example:

wsimport -Xauthfile C:\auth.txt -keep http://example.com/test?wsdl -s c:\path\to\source\

In the auth.txt was the following code:

http://user:password@http://example.com/test?wsdl

It has successfully created the java classes.

My java code:

    OrderService service = new OrderService();
    Order port = service.getOrderPort();
    BindingProvider bp = (BindingProvider) port;
    bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "endpoint");
    bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "user");
    bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "password");

The first line caused the following exception:

Exception in thread "main" javax.xml.ws.WebServiceException: No access to WSDL at: http://example.com/test?wsdl. Access unsuccessful with: 
Server returned HTTP response code: 401 for URL: http://example.com/test?wsdl.
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(RuntimeWSDLParser.java:250)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:231)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:194)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:163)
at com.sun.xml.internal.ws.client.WSServiceDelegate.parseWSDL(WSServiceDelegate.java:348)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:306)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:215)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:196)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:192)
at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:104)
at javax.xml.ws.Service.<init>(Service.java:77)
at com.innovabee.member.OrderService.<init>(OrderService.java:42)
at webserviceefa.Webservice.main(Webservice.java:42)

Caused by: java.io.IOException: Server returned HTTP response code: 401 for URL: http://example.com/test?wsdl
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1894)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
at java.net.URL.openStream(URL.java:1045)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.createReader(RuntimeWSDLParser.java:984)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.resolveWSDL(RuntimeWSDLParser.java:385)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:216)
... 11 more

the example is from: http://www.titorec.net/wordpress/2015/10/01/importando-webservice-wsdl-com-autenticacao-java-wsimport/

muzychuk
  • 288
  • 1
  • 2
  • 13
reiga
  • 31
  • 2
  • Have you tried your URL without "?wsdl" ? And maybe you can provide your credentials in a different [way](https://stackoverflow.com/questions/7071366/java-web-service-client-basic-authentication). – m4gic Sep 04 '18 at 14:43
  • ok, thanks i used this solution and it works. not the nicest solution and it seems nobody has a better solution, but it runs. – reiga Sep 18 '18 at 19:41

0 Answers0