Wsimport генерирует Java-классы - ошибка 401 - PullRequest
0 голосов
/ 04 сентября 2018

Я создал js классы wsimport. WSDL я импортировал запрос аутентификации.

Я использовал этот пример:

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

В auth.txt был следующий код:

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

Он успешно создал классы Java.

Мой код Java:

    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");

Первая строка вызвала следующее исключение:

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

пример взят из: http://www.titorec.net/wordpress/2015/10/01/importando-webservice-wsdl-com-autenticacao-java-wsimport/

...