Below we will provide a short tutorial about how to expose some services that you have developed in Liferay as web services. The procedure is quite straight forward and so you can easily migrate your existing classes
  1. First you have to add in your libraries (jaxws-api.jar, jaxws-rt.jar,jaxws-tools.jar)
    if you plan to deploy jax-ws web servvices to clean tomcat you also need these libaries
  2. Create a java class with the methods you want
  3. Add some annotation to your methods as the following example:
    @WebService(endpointInterface = "com.ext.portlet.test.Helper")
    public class HelperImpl {

    @WebMethod String sampleMethod(String field);
  4. Create sun-jaxws.xml under WEB-INF folder with the following content

    <?xml version="1.0" encoding="UTF-8"?>
    <endpoints version="2.0" xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime">
    <endpoint implementation="com.ext.portlet.test.HelperImpl" name="HelperImpl" url-pattern="/HelperImpl"/>
    </endpoints>

     

     

  5. Add jaxws listener to web.xml
    
    
    <listener>
    <listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class> 
    </listener>
    
    
  6. Create a servlet reference in web.xml
    <servlet> 
    <servlet-name>HelperImpl</servlet-name> 
    <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class> 
    <load-on-startup>10</load-on-startup> 
    </servlet>

    and the appropriate servlet mapping

    <servlet-mapping> 
    <servlet-name>HelperImpl</servlet-name> 
    <url-pattern>/HelperImpl</url-pattern> 
    </servlet-mapping>
  7. Restart Liferay and the wsdl is accessible through http://localhost:port/HelperImpl?wsdl

 

By admin