2
votes

(and if so, how?)

I have a Liferay portlet that was built using service builder that provides services to other portlets and I am wondering if I can use the same jar in my servlets. So far I haven't been successful. I tried creating a portlet and tried calling the same services from that portlet and that didn't work either. So I must be missing something in the configuration of the portlet and servlet that allows those services to be utilized. What did I miss?

Running Liferay 6.1.1 Tomcat (7) bundle on Windows if that makes a difference...

1
It might be worth checking this out liferay.com/web/antonio.junior/blog/-/blogs/12168124 (make sure in your portlets service.xml that the Entity's remote-service set to true) - user1853325
Thanks Rhod. Web Services was not exactly the direction I was looking to go. It seems to me that if you develop a large number of portlets that represent a full application, you won't want to have to replicate the services needed in each portlet. All you would need is a general services portlet that would make those services available to other portlets. But I doubt that you would have to expose those services as web services to make them available. Is it not possible to just drop the services jar into your lib folder and use the classes exposed there? - Pete Helgren

1 Answers

4
votes

Make sure your servlet uses the PortalDelegateServlet of Liferay. Otherwise, it will not have access to the Liferay service API (which eventually is used by the classes of your service builder generated classes).

<?xml version="1.0" encoding="UTF-8"?>
<web-app ...>
    ...
    <servlet>
        <servlet-name>my-servlet</servlet-name>
        <servlet-class>com.liferay.portal.kernel.servlet.PortalDelegateServlet</servlet-class>
        <init-param>
            <param-name>servlet-class</param-name>
            <param-value>org.example.YourOwnServlet</param-value>
        </init-param>
        <init-param>
            <param-name>sub-context</param-name>
            <param-value>do-something</param-value>
        </init-param>
    <servlet>
</web-app>

Don't forget to fill out the correct init parameters:

  • servlet-class is the class representing your servlet
  • sub-context is the subcontext your servlet should listen to

When deployed, your servlet will be accessible through the following URL:

http://localhost:8080/delegate/do-something