Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Thomas Berg
[Resolved] Custom Post Login Redirect
January 7, 2010 4:48 AM
Answer

Thomas Berg

Rank: Regular Member

Posts: 134

Join Date: September 7, 2009

Recent Posts

Hi,

I've been developing a HOOK that runs a custom PostLoginAction class on the event "login.events.post", using Liferay 5.2.3 (Tomcat-bundle)

I think i've read most of the countless "Redirect after login" - questions that's been posted in the forums but haven't been able to get this working.

In my class CustomPostLogin, i've got the following code:

1Map<String, String[]> params = new HashMap<String, String[]>();
2params.put("p_l_id", new String[] {"PUB.1.1"});
3LastPath lastPath = new LastPath(StringPool.BLANK, "/web/guest/some-page", params);
4session.setAttribute(WebKeys.LAST_PATH, lastPath);


My hook also includes a portal.properties with the following setting:

1auth.forward.by.last.path=true


However, when running the code I get this exception:

 1java.lang.ClassCastException: com.liferay.portal.struts.LastPath cannot be cast to com.liferay.portal.struts.LastPath
 2    com.liferay.portal.struts.PortalRequestProcessor.getLastPath(PortalRequestProcessor.java:407)
 3    com.liferay.portal.struts.PortalRequestProcessor.process(PortalRequestProcessor.java:146)
 4    org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
 5    org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
 6    javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
 7    com.liferay.portal.servlet.MainServlet.callParentService(MainServlet.java:608)
 8    com.liferay.portal.servlet.MainServlet.service(MainServlet.java:846)
 9    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
10    com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:154)
11    com.liferay.portal.servlet.filters.secure.SecureFilter.processFilter(SecureFilter.java:282)
12    com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:91)
13    com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:154)
14    com.liferay.portal.sharepoint.SharepointFilter.processFilter(SharepointFilter.java:193)
15    com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:91)
16    com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:154)
17    com.liferay.portal.servlet.filters.virtualhost.VirtualHostFilter.doFilter(VirtualHostFilter.java:148)
18    com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:154)
19    com.liferay.portal.servlet.filters.threadlocalcache.ThreadLocalCacheFilter.processFilter(ThreadLocalCacheFilter.java:55)
20    com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:91)
21    com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:154)
22    com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:94)
23    org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:738)


I also noticed that when using the alternate constructor for com.liferay.portal.struts.LastPath

1LastPath lastPath = new LastPath(StringPool.BLANK, "/web/guest/some-page");

i get a NullPointerException:

 119:51:15,734 ERROR MainServlet:794 - com.liferay.portal.kernel.events.ActionException: java.lang.NullPointerException
 2com.liferay.portal.kernel.events.ActionException: java.lang.NullPointerException
 3    at se.miun.portal.account.CustomPostLogin.run(CustomPostLogin.java:139)
 4    at com.liferay.portal.kernel.events.InvokerAction.run(InvokerAction.java:52)
 5    at com.liferay.portal.events.EventsProcessorImpl.processEvent(EventsProcessorImpl.java:92)
 6    at com.liferay.portal.events.EventsProcessorImpl.process(EventsProcessorImpl.java:79)
 7    at com.liferay.portal.events.EventsProcessorUtil.process(EventsProcessorUtil.java:64)
 8    at com.liferay.portal.servlet.MainServlet.service(MainServlet.java:789)
 9    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
10    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
11    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
12    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:154)
13    at com.liferay.portal.servlet.filters.secure.SecureFilter.processFilter(SecureFilter.java:282)
14    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:91)
15    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
16    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
17    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:154)
18    at com.liferay.portal.sharepoint.SharepointFilter.processFilter(SharepointFilter.java:193)
19    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:91)
20    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
21    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
22    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:154)
23    at com.liferay.portal.servlet.filters.virtualhost.VirtualHostFilter.doFilter(VirtualHostFilter.java:148)
24    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
25    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
26    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:154)
27    at com.liferay.portal.servlet.filters.threadlocalcache.ThreadLocalCacheFilter.processFilter(ThreadLocalCacheFilter.java:55)
28    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:91)
29    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
30    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
31    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:154)
32    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:94)
33    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
34    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
35    at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:738)
36    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
37    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
38    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
39    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
40    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
41    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
42    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
43    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
44    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
45    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
46    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
47    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
48    at java.lang.Thread.run(Thread.java:619)
49Caused by: java.lang.NullPointerException
50    at java.util.HashMap.<init>(HashMap.java:223)
51    at java.util.LinkedHashMap.<init>(LinkedHashMap.java:195)
52    at com.liferay.portal.struts.LastPath.<init>(LastPath.java:47)
53    at com.liferay.portal.struts.LastPath.<init>(LastPath.java:39)
54    at se.miun.portal.account.CustomPostLogin.run(CustomPostLogin.java:130)
55    ... 45 more


This became a lenghty post but hopefully informative. Is this some sort of bug or have I done something stupid :-)

Thanks for reading

/ Thomas
Shagul Khajamohideen
RE: Custom Post Login Redirect
January 6, 2010 12:43 PM
Answer

Shagul Khajamohideen

Rank: Liferay Master

Posts: 759

Join Date: September 27, 2007

Recent Posts

Hi Thomas,

LastPath.java is in portal-impl. Any class in portal-impl is not meant to be used in plugins.

You may have to do this in the Ext environment.

Best Regards,
Shagul
Thomas Berg
RE: Custom Post Login Redirect
January 7, 2010 2:17 AM
Answer

Thomas Berg

Rank: Regular Member

Posts: 134

Join Date: September 7, 2009

Recent Posts

Hi Shagul,

Thanks for your reply.

I'm not including portal-impl.jar in my hook but have referenced tomcat/webapps/ROOT/WEB-INF/lib/portal-impl.jar as an external jar on the build-path and set it as a dependency in liferay-plugin-package.properties.

But of course, you're right, by using a hook (plugin) there will be another class-loader involved. I really like the idea of not touching the core of Liferay, using only plugins. I'll have to think of some other solution to this. Thanks again for your answer

Best regards

Thomas
Nicolas Grolleau
RE: Custom Post Login Redirect
January 7, 2010 6:38 AM
Answer

Nicolas Grolleau

Rank: Junior Member

Posts: 90

Join Date: November 12, 2009

Recent Posts

I think you should make your plugin run in the server classpath.

try to add a context.xml file in docroot\META-INF:
<Context>
<Loader
loaderClass="com.liferay.support.tomcat.loader.PortalClassLoader"
/>
</Context>


That's what's done in sample-struts-liferay-portlet to be able to use liferay struts in plugin.
But this works only for tomcat.

Or you'll have to wait for next version of liferay to be able to replace struts actions in hooks.
Shagul Khajamohideen
RE: Custom Post Login Redirect
January 7, 2010 7:08 AM
Answer

Shagul Khajamohideen

Rank: Liferay Master

Posts: 759

Join Date: September 27, 2007

Recent Posts

Hi Thomas,

Most of the ext is coming to the plugins in the next release/trunk. Take a look at the below forum post.

EXT vs Plugins

Also in the latest/trunk you will not be able to include portal-impl.jar as a dependency as you did in your current liferay-plugin-package.properties. Ant build script will fail.

Take a look at the below ticket.

Prevent inclusion of portal-impl.jar in plugins

The idea is to make is easy to extend and easy to revert by just undeploying the plugins.

Hope this helps.

-Shagul
Thomas Berg
RE: Custom Post Login Redirect
January 7, 2010 7:45 AM
Answer

Thomas Berg

Rank: Regular Member

Posts: 134

Join Date: September 7, 2009

Recent Posts

Nicolas:

Thanks for your suggestion. I tried including context.xml but got the same result.
Anyway, I managed to get the needed functionality by doing a simple redirect instead of using LastPath. Problem solved :-)

Shagul:

That sounds great, could be the final piece of the plugins puzzle!
I'm itching do implement customizations but have been reluctant to using the extension environment.

So, thanks for helping and for sharing awesome news :-)
Sasha Privalov
RE: Custom Post Login Redirect
August 4, 2010 7:06 AM
Answer

Sasha Privalov

Rank: Junior Member

Posts: 29

Join Date: May 6, 2009

Recent Posts

Even though you already resolved your problem, you may be interested in my solution - I managed to use the LastPath class from the hook plugin this way:

1                Class classLastPath = PortalClassLoaderUtil.getClassLoader().loadClass("com.liferay.portal.struts.LastPath");
2                Constructor constructorLastPath = classLastPath.getConstructor(new Class[] {String.class, String.class, Map.class});
3                session.setAttribute(WebKeys.LAST_PATH, constructorLastPath.newInstance(new Object[] {context, path, params}));