Foros de discusión
Delegate Servlet cannot access liferay utility beans
Carlos Alonso Vega, modificado hace 6 años.
Delegate Servlet cannot access liferay utility beans
New Member Mensajes: 10 Fecha de incorporación: 8/11/17 Mensajes recientes
Hi all,
I am trying to build a delegate servlet that needs to know the list of connected users in Liferay (using com.liferay.portal.service.UserLocalServiceUtil)
I had no problem getting a simple delegated servlet to work and say Hello when deployed in Liferay, but when I try to use UserLocalServiceUtil I get this exception
Reading docs it seems that a delegate server could access core portal utilities, but could I be wrong. Any help or advice will be appreciated.
This is the servlet
at web.xml
TIA
Carlos
I am trying to build a delegate servlet that needs to know the list of connected users in Liferay (using com.liferay.portal.service.UserLocalServiceUtil)
I had no problem getting a simple delegated servlet to work and say Hello when deployed in Liferay, but when I try to use UserLocalServiceUtil I get this exception
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'com.liferay.portal.service.UserLocalService' is defined
Reading docs it seems that a delegate server could access core portal utilities, but could I be wrong. Any help or advice will be appreciated.
This is the servlet
package es.upna.liferay;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portal.service.UserServiceUtil;
import com.liferay.portal.model.User;
import java.util.List;
public class myDelegateServlet extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
out.println("");
out.println("");
out.println("");
out.println("<title>My delegate Servlet</title>");
out.println("");
out.println("");
out.println("<h1>My delegate Servlet at " + request.getContextPath() + "</h1>");
int userCount = UserLocalServiceUtil.getUsersCount();
List<user> users = UserLocalServiceUtil.getUsers(0, userCount);
out.print("Connected Users:");
for (User user : users)
{
out.print("<li>User: "+user.getUserId()+"</li>" );
}
out.println("");
out.println("");
}
catch (Exception e)
{
out.print("Exception! "+e.getMessage() );
}
finally {
out.close();
}
}
...
</user>
at web.xml
<servlet>
<servlet-name>myDelegateServlet</servlet-name>
<servlet-class>com.liferay.portal.kernel.servlet.PortalDelegateServlet</servlet-class>
<init-param>
<param-name>servlet-class</param-name>
<param-value>es.upna.liferay.myDelegateServlet</param-value>
</init-param>
<init-param>
<param-name>sub-context</param-name>
<param-value>myDelegateServlet</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
TIA
Carlos