JAX WS client cannot authenticate

前端 未结 2 1624
小鲜肉
小鲜肉 2020-12-31 14:04

I\'m trying to consume a secure (HTTPS schema) web-service with help of standard JAVA 7 JAX WS tools. This web-service requires authentication.

I have already succes

2条回答
  •  长发绾君心
    2020-12-31 14:30

    Your issue is not relating to SSL certificate. Your issue is relating to Authentication. Service instance need to be able to access WSDL content (before your stub invoke actual web method) but It failed, that is why you got that error.

    You have 2 solutions:

    1. Register default Authenticator:

      static {
      
          java.net.Authenticator.setDefault(new java.net.Authenticator() {
      
              @Override
              protected java.net.PasswordAuthentication getPasswordAuthentication() {
                  return new java.net.PasswordAuthentication("myuser", "mypasswd".toCharArray());
              }
          });
      }
      
    2. Download WSDL document and save it to LOCAL storage then use local WSDL file. For this solution, you have to create Service instance, NOT use generated code as you did.

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

提交回复
热议问题