Java JAX WS客户端无法进行身份验证

Java JAX WS客户端无法进行身份验证,java,web-services,authentication,jax-ws,webservice-client,Java,Web Services,Authentication,Jax Ws,Webservice Client,我正试图在标准Java7JAX WS工具的帮助下使用一个安全的(HTTPS模式)web服务。 此web服务需要身份验证 我已经成功地将证书添加到本地java密钥库中。 在wsimport工具的帮助下,我从WSDL文件生成了所有需要的类 现在,我尝试使用以下调用运行一个简单的测试: public class ReportingWebServiceTest { static ReportingServiceService service; static ReportingServic

我正试图在标准Java7JAX WS工具的帮助下使用一个安全的(HTTPS模式)web服务。 此web服务需要身份验证

我已经成功地将证书添加到本地java密钥库中。 在
wsimport
工具的帮助下,我从WSDL文件生成了所有需要的类

现在,我尝试使用以下调用运行一个简单的测试:

public class ReportingWebServiceTest {
    static ReportingServiceService service;
    static ReportingService port;

    @BeforeClass
    public static void setUpBeforeClass(){
        service = new ReportingServiceService();
        port = service.getReportingServicePort();
        Map<String, Object> rContext = ((BindingProvider) port).getRequestContext();
        Map<String, List<String>> headers = new HashMap<String, List<String>>();
        headers.put("Authorization", Collections.singletonList("Basic YWRtaW5AYWRhcHRsb2dpYy5jb206MTIxMjE****="));

//      headers.put("Username", Collections.singletonList("*****@******.com"));
//      headers.put("Password", Collections.singletonList("********"));
        rContext.put(MessageContext.HTTP_REQUEST_HEADERS, headers);
//      rContext.put(BindingProvider.USERNAME_PROPERTY, "*****@******.com");
//      rContext.put(BindingProvider.PASSWORD_PROPERTY, "********");
    }   

    @Test
    public void test() {
        WEBCAMPAIGNROW row = port.getCampaignRowById(14081);
        toConsole(row.toString());
    }

    protected static void toConsole(String msg) {
        System.out.println(msg);
    }
}
公共类ReportingWebServiceTest{
静态报告服务服务;
静态报告服务端口;
@课前
公共静态无效SetupForeClass(){
服务=新的ReportingServiceService();
port=service.getReportingServicePort();
Map rContext=((BindingProvider)端口).getRequestContext();
Map headers=newhashmap();
headers.put(“授权”、Collections.singletonList(“基本YWRtaW5AYWRhcHRsb2dpYy5jb206MTIxMjE****=”);
//headers.put(“Username”,Collections.singletonList(“******@******.com”);
//headers.put(“密码”、Collections.singletonList(“**********”);
rContext.put(MessageContext.HTTP_请求_头,头);
//rContext.put(BindingProvider.USERNAME_属性,******@*********.com);
//rContext.put(BindingProvider.PASSWORD_属性,**********);
}   
@试验
公开无效测试(){
WEBCAMPAIGNROW行=port.getCampaignRowById(14081);
toConsole(row.toString());
}
受保护的静态void toConsole(字符串msg){
System.out.println(msg);
}
}
运行测试时,会出现以下异常:

javax.xml.ws.WebServiceException: Failed to access the WSDL at: https://reporting-stage.admp.mtv3.adtlgc.com/admp/ReportingService?wsdl. It failed with: 
    Got Server returned HTTP response code: 401 for URL: https://reporting-stage.admp.mtv3.adtlgc.com/admp/ReportingService?wsdl while opening stream from https://reporting-stage.admp.mtv3.adtlgc.com/admp/ReportingService?wsdl.
    at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(RuntimeWSDLParser.java:173)
    at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:155)
    at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:120)
    at com.sun.xml.internal.ws.client.WSServiceDelegate.parseWSDL(WSServiceDelegate.java:257)
    at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:220)
    at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:168)
    at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:96)
    at javax.xml.ws.Service.<init>(Service.java:77)
    at com.enreach.admp.reporting.ReportingServiceService.<init>(ReportingServiceService.java:42)
    at me.enreach.automation.mtv3.ReportingWebServiceTest.setUpBeforeClass(ReportingWebServiceTest.java:26)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.io.IOException: Got Server returned HTTP response code: 401 for URL: https://reporting-stage.admp.mtv3.adtlgc.com/admp/ReportingService?wsdl while opening stream from https://reporting-stage.admp.mtv3.adtlgc.com/admp/ReportingService?wsdl
    at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.createReader(RuntimeWSDLParser.java:842)
    at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.resolveWSDL(RuntimeWSDLParser.java:283)
    at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:140)
    ... 23 more
Caused by: java.io.IOException: Server returned HTTP response code: 401 for URL: https://reporting-stage.admp.mtv3.adtlgc.com/admp/ReportingService?wsdl
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1626)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
    at java.net.URL.openStream(URL.java:1037)
    at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.createReader(RuntimeWSDLParser.java:827)
    ... 25 more
javax.xml.ws.WebServiceException:在以下位置访问WSDL失败:https://reporting-stage.admp.mtv3.adtlgc.com/admp/ReportingService?wsdl. 失败的原因是:
获取服务器返回的URL的HTTP响应代码:401:https://reporting-stage.admp.mtv3.adtlgc.com/admp/ReportingService?wsdl 当从https://reporting-stage.admp.mtv3.adtlgc.com/admp/ReportingService?wsdl.
位于com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(RuntimeWSDLParser.java:173)
位于com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:155)
位于com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:120)
在com.sun.xml.internal.ws.client.wsservicedegate.parseWSDL(wsservicedegate.java:257)
在com.sun.xml.internal.ws.client.WSServiceDelegate上。(WSServiceDelegate.java:220)
在com.sun.xml.internal.ws.client.WSServiceDelegate上。(WSServiceDelegate.java:168)
位于com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:96)
位于javax.xml.ws.Service。(Service.java:77)
在com.enreach.admp.reporting.ReportingServiceService上。(ReportingServiceService.java:42)
at me.enreach.automation.mtv3.ReportingWebServiceTest.setUpBeforeClass(ReportingWebServiceTest.java:26)
在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处
在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)中
在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)中
位于java.lang.reflect.Method.invoke(Method.java:606)
位于org.junit.runners.model.FrameworkMethod$1.runReflectVeCall(FrameworkMethod.java:47)
位于org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
位于org.junit.runners.model.FrameworkMethod.invokeeexplosive(FrameworkMethod.java:44)
位于org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
位于org.junit.runners.ParentRunner.run(ParentRunner.java:309)
位于org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
位于org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
位于org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
位于org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
位于org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
位于org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
原因:java.io.IOException:Get服务器返回了URL的HTTP响应代码:401:https://reporting-stage.admp.mtv3.adtlgc.com/admp/ReportingService?wsdl 当从https://reporting-stage.admp.mtv3.adtlgc.com/admp/ReportingService?wsdl
位于com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.createReader(RuntimeWSDLParser.java:842)
位于com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.resolveWSDL(RuntimeWSDLParser.java:283)
位于com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:140)
... 23多
原因:java.io.IOException:服务器返回了URL的HTTP响应代码:401:https://reporting-stage.admp.mtv3.adtlgc.com/admp/ReportingService?wsdl
位于sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1626)
位于sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
在java.net.URL.openStream(URL.java:1037)
位于com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.createReader(RuntimeWSDLParser.java:827)
... 25多
正如您所看到的,我尝试应用三种不同的身份验证技术,但没有任何运气。这三种情况的例外情况都是一样的。 我做错了什么

另外,如果我尝试在浏览器中访问WSDL,我在代码中使用的凭据确实可以正常工作。

让我们尝试几件事:

1.)您知道服务器需要什么样的身份验证吗

2.)当您尝试访问时,是否看到任何内容?e、 g.我假设有一个IP白名单或什么的,你会在那里输入凭据或类似的?因为我在那里什么也看不见

3.)对于代码,我通过HTTP向安全Web服务进行身份验证:

ReportingServiceService新的ReportingServiceService();
报告
BindingProvider.ENDPOINT_ADDRESS_PROPERTY
static {

    java.net.Authenticator.setDefault(new java.net.Authenticator() {

        @Override
        protected java.net.PasswordAuthentication getPasswordAuthentication() {
            return new java.net.PasswordAuthentication("myuser", "mypasswd".toCharArray());
        }
    });
}
Service service  = Service.create(
                    new URL(**"file:///C:/reportingService.wsdl"**), 
                    new QName("http://services.app/", "ReportingService")
               );

// ...

binding.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "myuser");   
binding.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "mypasswd");