1 Reply Latest reply on May 13, 2010 4:38 PM by Phillip Davey

    Example of a Servlet Web service on Glassfish

    Phillip Davey Newbie

      I was trying to put together a non-EE webservice (war deployment) in glassfish, but I couldn't find any examples of what to do so eventually I pieced together some stuff and thought I'd share it. 


      This is not what I actually wrote, it is an example based off of it, so if you find things that would make this not compile or error, it's because this hasn't been run. 


      If you have any improvements or suggestions, let me know...I've not done much with webservices.



      • Webservice



      @WebService(name="AnyNameSimpleWebService", serviceName="simpleWebService")
      @HandlerChain(file="webservice-handler-chain.xml")
      public class SimpleWebService implements SimpleRemote //interface w/ response() declared
      {
      
          @WebMethod
          public String raiseEvent(String event) {
           try {
                Events.instance().raiseAsynchronousEvent(event);
                return "Event raised";
           }
           catch (Exception e) {
                return e.getMessage();
           }
          }
      }
      




      • Handler Chain (in root of classpath /WEB-INF/classes)



      <?xml version="1.0" encoding="UTF-8"?>
      <handler-chains xmlns="http://java.sun.com/xml/ns/javaee">
        <handler-chain>
          <handler>
            <handler-name>org.jboss.seam.webservice.SOAPRequestHandler</handler-name>
            <handler-class>org.jboss.seam.webservice.SOAPRequestHandler</handler-class>
          </handler>
        </handler-chain>
      </handler-chains>
      




      • web.xml



          <servlet>
              <servlet-name>SimpleWebService</servlet-name>
              <servlet-class>org.imaginary.SimpleWebService</servlet-class>
          </servlet>
          <servlet-mapping>
              <servlet-name>SimpleWebService</servlet-name>
              <url-pattern>/simpleWebService</url-pattern>
          </servlet-mapping>