8 Replies Latest reply on Aug 11, 2006 9:55 AM by chamillard

    JSR181 Web Service Client

    chamillard

      Hi Folks,

      I'm deploying a simple EJB 3.0 web service using the following code (based on the hello-jaxws sample that comes with the Java EE 5 distribution):

      package endpoint;
      
      import javax.ejb.Stateless;
      import javax.jws.WebService;
      import javax.jws.WebMethod;
      
      @WebService
      @Stateless
      public class Hello
      {
       @WebMethod
       public String getHello(String name)
       {
       return "Hello " + name + "!";
       }
      }


      I'm packaging it into a JAR and deploying to JBoss 4.0.4.GA, and the WSDL shows up fine from http://localhost:8080/jbossws. The WSDL name is as expected (http://localhost:8080/hello/Hello?wsdl).

      I'm using wsimport to generate the client stub code using the following ant task:

      <target name="get-artifacts-windows" if="windows">
       <exec executable="${javaee.home}/bin/wsimport.bat">
       <arg line="-keep -d ./build/classes http://localhost:8080/hello/Hello?wsdl"/>
       </exec>
       </target>


      This also seems to work as expected, and my test client (shown below) will compile.

       /*
       * Client.java
       */
      
      package client;
      
      import javax.xml.ws.WebServiceRef;
      import endpoint.jaws.HelloService;
      import endpoint.jaws.Hello;
      
      public class Client
      {
       @WebServiceRef(wsdlLocation="http://localhost:8080/hello/Hello?wsdl")
       static HelloService service;
      
       public static void main(String[] args)
       {
       Client client = new Client();
       client.doHello();
       }
      
       public void doHello()
       {
       try
       {
       Hello port = service.getHelloPort();
       String ret = port.getHello(System.getProperty("user.name"));
       System.out.println("Hello result = " + ret);
       }
       catch(Exception e)
       {
       e.printStackTrace();
       }
       }
      }


      Unfortunately, when I try to actually run the client, I get the following:

      [java] java.lang.NullPointerException
      [java] at client.Client.doHello(Client.java:28)
      [java] at client.Client.main(Client.java:21)

      I added debugging statements and determined that the method generated by wsimport to get the port doesn't seem to be working properly, but that's as far as I can get!

      Can anyone help me resolve this problem?

      Thanks in advance,
      Tim

      PS I'm certainly willing to use wstools instead of wsimport, but I couldn't find an example for generating a client using a JAX-WS client (rather than a JAX-RPC client)

        • 1. Re: JSR181 Web Service Client
          sappenin

          In your client, when you call the endpoint, can you confirm that the "System.getProperty("user.name")" call is returning a non-null value?

           String ret = port.getHello(System.getProperty("user.name"));
          


          My guess is that "System.getProperty("user.name")" might be returning null on you. Try the demo/test with a hand-coded string instead.

          Also, in you Endpoint's code, you might want to check for a null string passed into the function, and deal with it so that the code doesn't barf. Perhaps something like this:

          @WebMethod
           public String getHello(String name)
           {
           if(name == null || "".equals(name))
           {
           return "Invalid Name";
           }
           else
           return "Hello " + name + "!";
           }
          


          • 2. Re: JSR181 Web Service Client
            chamillard

            Thanks for the prompt response! Unfortunately, it's the previous line in the client code that's killing me:

            Hello port = service.getHelloPort();


            Here's the HelloService.java file generated by wsimport:

            package endpoint.jaws;
            
            import java.net.MalformedURLException;
            import java.net.URL;
            import javax.xml.namespace.QName;
            import javax.xml.ws.Service;
            import javax.xml.ws.WebEndpoint;
            import javax.xml.ws.WebServiceClient;
            
            
            /**
             * This class was generated by the JAXWS SI.
             * JAX-WS RI 2.0_01-b15-fcs
             * Generated source version: 2.0
             *
             */
            @WebServiceClient(name = "HelloService", targetNamespace = "http://endpoint/jaws", wsdlLocation = "http://localhost:8080/hello/Hello?wsdl")
            public class HelloService
             extends Service
            {
            
             private final static URL HELLOSERVICE_WSDL_LOCATION;
            
             static {
             URL url = null;
             try {
             url = new URL("http://localhost:8080/hello/Hello?wsdl");
             } catch (MalformedURLException e) {
             e.printStackTrace();
             }
             HELLOSERVICE_WSDL_LOCATION = url;
             }
            
             public HelloService(URL wsdlLocation, QName serviceName) {
             super(wsdlLocation, serviceName);
             }
            
             public HelloService() {
             super(HELLOSERVICE_WSDL_LOCATION, new QName("http://endpoint/jaws", "HelloService"));
             }
            
             /**
             *
             * @return
             * returns Hello
             */
             @WebEndpoint(name = "HelloPort")
             public Hello getHelloPort() {
             return (Hello)super.getPort(new QName("http://endpoint/jaws", "HelloPort"), Hello.class);
             }
            
            }
            


            Additional debugging statements indicate that my service object is null when I try to call the getHelloPort method. I thought that the following in the client code would be creating the object for me (since this is straight from the Sun example):
            @WebServiceRef(wsdlLocation="http://localhost:8080/hello/Hello?wsdl")
            static HelloService service;


            Any idea why this wouldn't be happening?

            Thanks,
            Tim

            (I did make sure I'm getting the user name OK as well).

            • 3. Re: JSR181 Web Service Client
              sappenin

              I haven't used wsimport. I would suggest creating your client with wstools that comes with JBoss 4.0.4GA. You'll want to download JBossWS 1.0.2 (or later), and also make sure you have the most recent download of EJB3.

              I'm not 100% on this, but I don't think that JBossWS (which is what JBoss App server uses to create annotated web-services from EJB3s) will work with the Sun JWSDP (Sun Java Web Services Developer Pack). It looks like you're using wsimport from the JWSDP? Have you tried using wstools instead (per the JBossWS user guide)?

              • 4. Re: JSR181 Web Service Client
                sappenin

                Ok, so maybe I'm wrong on the JWSDP thing....

                This person seems to have been able to use the Sun JWSDP on Jboss 4.0.3.

                http://www.jboss.org/index.html?module=bb&op=viewtopic&t=85703

                • 5. Re: JSR181 Web Service Client
                  shadens

                  At the moment, it seems JbossWS doesn't impement Jax-WS.
                  And WebserviceRef annotation exists as a name, but it is without implementation.

                  Anyone of JBoss Staff can confirm ?

                  Bye

                  • 6. Re: JSR181 Web Service Client

                    I've tried it to no avail. Had jaxws20 app running in Tomcat wihout any problems. Moved it to JBoss 4.0.2 and it complained about saaj*.jar s'. Unfortunately, unified classloader doesnt allow you to load the saaj-impl and saaj jars after the jboss-saaj jar has loaded. As it turned out, this was just the begining of my problems on this.

                    Although I could be wrong on this, I think jboss wants you to use stateless session beans with web services annotations to essentially do annotated web services.

                    • 7. Re: JSR181 Web Service Client
                      chamillard

                      I actually do have the endpoint as an annotated stateless session bean; the problem appears to be on the client side when I try to consume the service using JAX-WS.

                      Thanks,
                      Tim

                      • 8. Re: JSR181 Web Service Client
                        chamillard

                        Hey Folks,

                        I've resolved my problem. I apologize to all, because the problem was caused by the way I was trying to run the client rather than by anything to do with JBoss. I was trying to run the client using a straight java call rather than using the appclient.bat file provided by Sun (which does lots of configuration stuff behind the scenes).

                        Thanks again to everyone, and sorry for using bandwidth for a non-JBoss problem.

                        Cheers,
                        Tim