Fórum

How to acces sesssion bean from Servlet

thumbnail
Gustavo Oliveira, modificado 8 Anos atrás.

How to acces sesssion bean from Servlet

New Member Postagens: 3 Data de Entrada: 05/10/15 Postagens Recentes
Hi,
How to acces sesssion bean from Servlet? I've tried to find on these requests:

ServiceContextThreadLocal.getServiceContext().getRequest(), HttpServletRequest and unwrapping from HttpServletRequestWrapper. But I cant find it.

Thanks
thumbnail
Neil Griffin, modificado 8 Anos atrás.

RE: How to acces sesssion bean from Servlet

Liferay Legend Postagens: 2655 Data de Entrada: 27/07/05 Postagens Recentes
Are you developing a JSF portlet?
thumbnail
Gustavo Oliveira, modificado 8 Anos atrás.

RE: How to acces sesssion bean from Servlet

New Member Postagens: 3 Data de Entrada: 05/10/15 Postagens Recentes
Yes, Its a JSF portlet. Everything is working fine. My only problem is that I have a Servlet that handles Facebook login responses and I need to access one of my session beans.

And yes, I tried getting it from HttpServletRequest.

Thanks
thumbnail
Neil Griffin, modificado 8 Anos atrás.

RE: How to acces sesssion bean from Servlet

Liferay Legend Postagens: 2655 Data de Entrada: 27/07/05 Postagens Recentes
In general I recommend that you avoid writing servlets that exist inside of a portlet WAR. The reason why is because they do not enjoy the protections of Liferay PortletURLs. That means that a security mechanism (other than Liferay Portal's permission system) must be used to protect unauthorized users from accessing a servlet. Another problem is that servlets do not participate in the portlet lifecycle, which is why it is difficult to get access to the portlet session.

In general it is better to use a ResourceURL that invokes the RESOURCE_PHASE of the portlet lifecycle. For a JSF portlet, I recommend that you write a JSF ResourceHandler (which works both in webapps and portlets). An example would be the jsf2-export-pdf-portlet demo. Another option would be to extend GenericFacesPortlet and @Override the serveResource(ResourceRequest,ResourceResponse) method.
thumbnail
Gustavo Oliveira, modificado 8 Anos atrás.

RE: How to acces sesssion bean from Servlet

New Member Postagens: 3 Data de Entrada: 05/10/15 Postagens Recentes
Ok then, I will check this demo.

Thank you very much
thumbnail
Gustavo Oliveira, modificado 8 Anos atrás.

RE: How to acces sesssion bean from Servlet

Junior Member Postagens: 98 Data de Entrada: 23/09/15 Postagens Recentes
Hi Neil,
Im using the resourceRequest now, the only problem is that I cant find any parameter that Facebook added on the request.

Not even trying this: PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(resourceRequest)).getParameterMap();

To integrate my portlet with Facebook API I need to send them a Redirect URI that after authentication they will send back an authenticationToken as param. What do you suggest?

Thanks
thumbnail
Juan Gonzalez, modificado 8 Anos atrás.

RE: How to acces sesssion bean from Servlet

Liferay Legend Postagens: 3089 Data de Entrada: 28/10/08 Postagens Recentes
Hi Gustavo,

did you set

<requires-namespaced-parameters>false</requires-namespaced-parameters>


in liferay-portlet.xml?
thumbnail
Gustavo Oliveira, modificado 8 Anos atrás.

RE: How to acces sesssion bean from Servlet

Junior Member Postagens: 98 Data de Entrada: 23/09/15 Postagens Recentes
Hi Juan,
Nope, let me check with <requires-namespaced-parameters>false</requires-namespaced-parameters>. But I was able to get it on doView.

Thanks
thumbnail
Gustavo Oliveira, modificado 8 Anos atrás.

RE: How to acces sesssion bean from Servlet

Junior Member Postagens: 98 Data de Entrada: 23/09/15 Postagens Recentes
It didnt change anything, I tried with true and false on <requires-namespaced-parameters>.

Im using version 6.2-ee-sp11.

The only way to get the parameter was overriding doView and using: PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(renderRequest)).getParameter

I think its better this way anyway, serveResource is called 9 times. doView is called only once.
thumbnail
Gustavo Oliveira, modificado 8 Anos atrás.

RE: How to acces sesssion bean from Servlet

Junior Member Postagens: 98 Data de Entrada: 23/09/15 Postagens Recentes
Oh, I was able to get it on doView:

@Override
protected void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException, IOException {

System.out.println("View: "+PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(renderRequest)).getParameter("code"));

super.doView(renderRequest, renderResponse);
}
thumbnail
Devang Patel, modificado 8 Anos atrás.

RE: How to acces sesssion bean from Servlet

Regular Member Postagens: 247 Data de Entrada: 19/01/15 Postagens Recentes
Hi Gustavo Oliveira,
Try this & this Links :-
Hope this will help.

Thanks,
Devang Patel