4 Replies Latest reply on Mar 7, 2008 3:59 PM by peterj

    webmethod within a jsp-file

    fugee47

      packaging and deploying the following code works (i think so, because a wsdl is generated and i can access it).

      package helloservice.endpoint;

      import javax.jws.WebMethod;
      import javax.jws.WebService;
      import javax.ejb.Stateless;
      i
      @Stateless
      @WebService
      public class Hello {
      private String message = new String("Hello, ");

      @WebMethod
      public String sayHello(String name) {
      return message + name + ".";
      }
      }


      Now i want to execute "sayHello" within a jsp-file, and i dont get it to work. how does it work ????

        • 1. Re: webmethod within a jsp-file
          fugee47

          i forgot to say that the jsp is in an extra war-file

          • 2. Re: webmethod within a jsp-file
            peterj

            Accessing a web method from a jsp (or servlet) is no different from accessing a web method from any other client. The JBossWS documentation contains the necessary steps for building a client.

            • 3. Re: webmethod within a jsp-file
              fugee47

              now i got a standalone java-client working:
              package simpleclient;

              import javax.xml.ws.WebServiceRef;
              import helloservice.endpoint.HelloService;
              import helloservice.endpoint.Hello;

              public class HelloClient {
              @WebServiceRef(wsdlLocation="http://localhost:8080/helloservice/Hello?wsdl")
              static HelloService service = new HelloService();

              public static void main(String[] args) {
              System.out.println("Retrieving the port from the following service: " + service);
              Hello port = service.getHelloPort();
              System.out.println("Invoking the sayHello operation on the port.");
              String name;
              if (args.length > 0) {
              name = args[0];
              } else {
              name = "No Name";
              }
              String response = port.sayHello(name);
              System.out.println(response);
              }
              }


              but when i copy the code into a new function and access it from within a jsp-file, i get errors.

              package simpleclient;

              import javax.xml.ws.WebServiceRef;
              import helloservice.endpoint.HelloService;
              import helloservice.endpoint.Hello;

              public class HelloClient {
              @WebServiceRef(wsdlLocation="http://localhost:8080/helloservice/Hello?wsdl")
              static HelloService service = new HelloService();

              public static String say(String args) {
              Hello port = service.getHelloPort();
              String name;
              if (args != null) {
              name = args;
              } else {
              name = "No Name";
              }
              String response = port.sayHello(name);
              return response;
              }
              }



              ERROR [ServiceDelegateImpl] Cannot create proxy for SEI helloservice.endpoint.Hello from: vfsfile:/opt/jboss-5.0.0.Beta4/server/default/deploy/
              11:51:14,647 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
              java.lang.IllegalArgumentException: helloservice.endpoint.Hello is not an interface

              i dont understand this error, since the standalone client does not complain about helloservice.endpoint.Hello being not an interface (and it is one !!)

              • 4. Re: webmethod within a jsp-file
                peterj

                You never said you were using beta software! Looks like a classloader issue to me, and the classloader in 5.0 beta4 is very broke.

                Using 5.0 beta 4, if I create the web service, then generate the WSDL, and then use wsconsume to generate the client stubs, there is always a stub whose name matches the name of the class that implements the web service. Then, when my servlet attempts to create the web service connection, I get the same "xxx is not an interface" exception. Apparently, web services is using the wrong classloader repository to look up the class - it is looking in the more global classloader repository which contains the web service implementation class, which of course, is not an interface. It should, instead, be using the classloader repository for the war file, in which case it will find the interface for which it is looking.

                Interestingly enough, if I develop my web service using a top-down approach (wsdl first, then generate stubs, and implement based on those stubs) it works. That is because both the global classloader repository and the war classloader repository agree that the class in question is really an interface.

                Let me try the top-down approach in 4.2.2, back in a second. It works. Hmm, let me try the bottom-up approach in 4.2.2. That works also. Moral of the story - when things don't work, if you are using a beta of the next version, fall back to a qualified, released version and try it there - it just might work.