wsimport 生成 java 类 - 401 错误

问题描述 投票:0回答:1

我用 wsimport java 类生成。我导入的 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/

java wsdl wsimport
1个回答
0
投票

你能说说你是怎么解决的吗,现在我也遇到了同样的问题。

© www.soinside.com 2019 - 2024. All rights reserved.