2 Replies Latest reply on Oct 14, 2008 6:54 PM by peterj

    Web Service - what needs to be in the .war?

    clarkvalentine

      Hi,

      I'm more or less a newbie to Java EE, and I'm attempting to design a web service that accepts incoming SOAP requests and does (something). I've been playing with sample code, but I can't get anything to deploy correctly. For some reason, I cannot find a good, solid list of what needs to be in a .war file for a web service.

      So? Can anyone give me a nickel tour of a .war file as JBoss expects to see it? Is it different whether I use a servlet, an EJB, or both in my design?

      Thanks,

      - Clark Valentine, Java EE n00b

        • 1. Re: Web Service - what needs to be in the .war?
          peterj

          In a WAR filer all you need are the POJO web service and the web.xml.

          Simple hello service:

          package ws.simple;
          @javax.jws.WebService
          public class HelloService {
           @javax.jws.WebMethod
           public String sayHello(String name) {
           return "Hello, " + name;
           }
          }


          The web.xml:
          <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
           version="2.5"
          >
           <servlet>
           <servlet-name>HelloService</servlet-name>
           <servlet-class>ws.simple.HelloService</servlet-class>
           </servlet>
           <servlet-mapping>
           <servlet-name>HelloService</servlet-name>
           <url-pattern>/hello</url-pattern>
           </servlet-mapping>
          </web-app>


          And the contents of the resulting hello.war:
          WEB-INF/web.xml
          WEB-INF/classes/ws/simple/HelloService.class

          Caveat: The above was transcribed from a slightly more complex web service, so it might have typos, but other than that it should be all you need.

          • 2. Re: Web Service - what needs to be in the .war?
            peterj

            If your web service is EJB-based, all you need is a jar file with the web service class.

            Add two more annotations to the class:

            ...
            @javax.jws.Stateless
            @org.jboss.wsf.spi.annotation.WebContext(contextRoot="/hello", urlPattern="/hello")
            @WebService
            public class HelloService {...}


            And the contents of hello.jar:
            ws/simple/HelloService.class