1 Reply Latest reply: Jul 15, 2013 1:04 PM by 1025266 RSS

    WSDL Client

    1025266

      Hello,

      I made a WSDL client and now I've seen that java has a native client JAX-WS that I could of use.

      My original client knows how to use PKCS11 and how to set HTTP header vars(including basic HTTP authentication).

      I don't know how to translate PKCS11 and HTTP header vars in JAX-WS.

      I should find a place where to specify a SSLSocketFactory in JAX-WS.

       

      I started with the example from here: http://www.mkyong.com/webservices/jax-ws/jax-ws-hello-world-example/ and I tried to add these 2 functionalities.

      But the problem line is at

      {Service service = Service.create(url, qname);}
      

      and I can't add here my new functionality.

       

      What should I do?

      This is the client:

      package com.mkyong.client;
      import java.net.URL;
      import javax.xml.namespace.QName;
      import javax.xml.ws.Service;
      import com.mkyong.ws.HelloWorld;
      
      public class HelloWorldClient{
          public static void main(String[] args) throws Exception {
          URL url = new URL("http://localhost:9999/ws/hello?wsdl");
              QName qname = new QName("http://ws.mkyong.com/", "HelloWorldImplService");
              Service service = Service.create(url, qname);
              HelloWorld hello = service.getPort(HelloWorld.class);
              System.out.println(hello.getHelloWorldAsString("mkyong"));
          }
      }
      

       

       

      Thank you

        • 1. Re: WSDL Client
          1025266

          This is what I tryed:

           

                      URL url = new URL(protocol+"://"+host+":"+port+servicePath);
                      QName portName = new QName(protocol+"://"+host+":"+port, servicePath);
                      System.out.println("URL IS "+url.toString());
                      Service service = Service.create(url, portName);
                      OnlineSIUIDef portSIUI = service.getPort(OnlineSIUIDef.class);
          
                      BindingProvider bindingProvider = (BindingProvider)portSIUI;
                      Map requestContext = bindingProvider.getRequestContext();
                      requestContext.put(BindingProvider.USERNAME_PROPERTY, SIUI_USERNAME);
                      requestContext.put(BindingProvider.PASSWORD_PROPERTY, SIUI_PASSWORD);
          
                      PKCS11 pk11 = new PKCS11();
                      pk11.loadSecurityProviders();
                      RetStruct statD = pk11.getKeyManagerFactory();
                      if(statD.succes) {
                          kKeyManagerFactory = (KeyManagerFactory)statD.returnParameters.get("KeyManagerFactory");
                      } else {
                          System.out.println("Eroare "+statD.errMessage);
                      }
                      SSLContext context = SSLContext.getInstance("TLS");
                      context.init(kKeyManagerFactory.getKeyManagers(), null, null);
                      factory = context.getSocketFactory();
                      
                      Dispatch<SOAPMessage> dispatch = service.createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE);
                      dispatch.getRequestContext().put (JAXWSProperties.SSL_SOCKET_FACTORY, factory);
                      dispatch.getRequestContext().put(BindingProvider.SOAPACTION_URI_PROPERTY, protocol+"://"+host+":"+port+servicePath);
          
                      OnlineSIUIDef hello = service.getPort(OnlineSIUIDef.class);
                      System.out.println(hello.getOnlineSIUIDefString("mkyong"));
          

           

          The error is at line 4 - before setting the user, password and the SSL Context.

          So the error is normal because the application never got to the line where the user, password and ssl context was set.

          But how do I set these before line 4?

           

          The error is

          Exception in thread "main" javax.xml.ws.WebServiceException: Failed to access the WSDL at: https://www.siui.ro:443/svapntws/services/SiuiWS?wsdl. It failed with:

              Got Server returned HTTP response code: 401 for URL: https://www.siui.ro:443/svapntws/services/SiuiWS?wsdl while opening stream from https://www.siui.ro:443/svapntws/services/SiuiWS?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)