Tribune

Home » Liferay Portal » English » 3. Development

Vista Combinata Vista Piatta Vista ad Albero
Discussioni [ Precedente | Successivo ]
toggle
Hubert Dabrowski
ClassCastException while overriding struts action
16 aprile 2012 6.20
Risposta

Hubert Dabrowski

Punteggio: New Member

Messaggi: 2

Data di Iscrizione: 16 aprile 2012

Messaggi recenti

Hello,

I'm trying to override struts actions EditConfigurationAction and UpdateLayoutAction but Liferay throws an exception while opening any portlet configuration or adding a portlet to page. Other actions like EditTemplateAction are working correctly.

I've tried this on both 6.1.0 and 6.1.0 GA1.

 1
 2<?xml version="1.0"?>
 3<!DOCTYPE hook PUBLIC "-//Liferay//DTD Hook 6.1.0//EN" "http://www.liferay.com/dtd/liferay-hook_6_1_0.dtd">
 4
 5<hook>   
 6    <portal-properties>portal.properties</portal-properties>
 7    <language-properties>content/Language.properties</language-properties>
 8    <language-properties>content/Language_en.properties</language-properties>
 9    <language-properties>content/Language_pl.properties</language-properties>
10    <struts-action>
11        <struts-action-path>/portlet_configuration/edit_configuration</struts-action-path>
12        <struts-action-impl>pl.eo.liferay.audit.action.EditConfigurationActionHook</struts-action-impl>
13    </struts-action>
14    <struts-action>
15        <struts-action-path>/portal/update_layout</struts-action-path>
16        <struts-action-impl>pl.eo.liferay.audit.action.UpdateLayoutActionHook</struts-action-impl>
17    </struts-action>
18</hook>

Action:
1
2public class EditConfigurationActionHook extends BaseStrutsAction {   
3    @Override
4    public String execute(StrutsAction originalStrutsAction,
5            HttpServletRequest request, HttpServletResponse response)
6            throws Exception {
7        return originalStrutsAction.execute(originalStrutsAction, request, response);
8    }

Exception:
 1
 2ERROR [render_portlet_jsp:154] java.lang.ClassCastException: com.liferay.portal.struts.ActionAdapter cannot be cast to com.liferay.portal.struts.PortletActionAdapter
 3        at com.liferay.portal.struts.PortletRequestProcessor.processActionCreate(PortletRequestProcessor.java:304)
 4        at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:230)
 5        at com.liferay.portal.struts.PortletRequestProcessor.process(PortletRequestProcessor.java:230)
 6        at com.liferay.portlet.StrutsPortlet.include(StrutsPortlet.java:239)
 7        at com.liferay.portlet.StrutsPortlet.doView(StrutsPortlet.java:152)
 8        at com.liferay.portal.kernel.portlet.LiferayPortlet.doDispatch(LiferayPortlet.java:211)
 9        at javax.portlet.GenericPortlet.render(GenericPortlet.java:233)
10        at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:100)
11        at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:64)
12        at com.liferay.portlet.InvokerPortletImpl.invoke(InvokerPortletImpl.java:651)
13        at com.liferay.portlet.InvokerPortletImpl.invokeRender(InvokerPortletImpl.java:722)
14        at com.liferay.portlet.InvokerPortletImpl.render(InvokerPortletImpl.java:426)
15        at org.apache.jsp.html.portal.render_005fportlet_jsp._jspService(render_005fportlet_jsp.java:1215)
16        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
17        at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
18        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
19        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
20        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
21        at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
22        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)

Action:
 1
 2public class UpdateLayoutActionHook extends BaseStrutsPortletAction {
 3    @Override
 4    public void processAction(StrutsPortletAction originalStrutsPortletAction,
 5            PortletConfig portletConfig, ActionRequest actionRequest,
 6            ActionResponse actionResponse) throws Exception {
 7        originalStrutsPortletAction.processAction(originalStrutsPortletAction, portletConfig, actionRequest, actionResponse);
 8    }
 9}

Exception:
 1
 2ERROR [StripFilter:59] java.lang.ClassCastException: com.liferay.portal.struts.PortletActionAdapter cannot be cast to com.liferay.portal.struts.ActionAdapter
 3java.lang.ClassCastException: com.liferay.portal.struts.PortletActionAdapter cannot be cast to com.liferay.portal.struts.ActionAdapter
 4        at com.liferay.portal.struts.PortalRequestProcessor.processActionCreate(PortalRequestProcessor.java:485)
 5        at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:230)
 6        at com.liferay.portal.struts.PortalRequestProcessor.process(PortalRequestProcessor.java:174)
 7        at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
 8        at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
 9        at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
10        at com.liferay.portal.servlet.MainServlet.callParentService(MainServlet.java:533)
11        at com.liferay.portal.servlet.MainServlet.service(MainServlet.java:510)
12        at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
13        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
14        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
15        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:72)
16        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:121)
17        at com.liferay.portal.servlet.filters.strip.StripFilter.processFilter(StripFilter.java:304)
18        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
19        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
20        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
21        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:113)
22        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:121)
23        at com.liferay.portal.servlet.filters.gzip.GZipFilter.processFilter(GZipFilter.java:123)
24        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
25        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
26        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
27        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:121)
28        at com.liferay.portal.servlet.filters.secure.SecureFilter.processFilter(SecureFilter.java:201)
29        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
30        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
31        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
32        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:121)
33        at com.liferay.portal.servlet.filters.sso.ntlm.NtlmPostFilter.processFilter(NtlmPostFilter.java:83)
34        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
35        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
36        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
37        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:121)
38        at com.liferay.portal.sharepoint.SharepointFilter.processFilter(SharepointFilter.java:80)
39        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
40        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
41        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
42        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:121)
43        at com.liferay.portal.servlet.filters.virtualhost.VirtualHostFilter.processFilter(VirtualHostFilter.java:209)
44        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
45        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
46        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
47        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:184)
48        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:92)
49        at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:738)
50        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
51        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
52        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:164)
53        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:92)
54        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:164)
55        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:92)
56        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:184)
57        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:92)
58        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:70)
59        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
60        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
61        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
62        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
63        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
64        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
65        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
66        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928)
67        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
68        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
69        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
70        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539)
71        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:300)
72        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
73        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
74        at java.lang.Thread.run(Thread.java:662)


I was unable to find a reason why this doesn't work so could someone tell me whether I'm doing anything wrong or is it a Liferay bug?

Regards
Hubert
David H Nebinger
RE: ClassCastException while overriding struts action
16 aprile 2012 6.36
Risposta

David H Nebinger

Punteggio: Liferay Legend

Messaggi: 7157

Data di Iscrizione: 1 settembre 2006

Messaggi recenti

Class cast exceptions for the same class are always class loader issues.

You didn't mention how you were deploying this; I'm guessing a hook, which won't work because it's in a different class loader than the portal.
Hubert Dabrowski
RE: ClassCastException while overriding struts action
16 aprile 2012 6.51
Risposta

Hubert Dabrowski

Punteggio: New Member

Messaggi: 2

Data di Iscrizione: 16 aprile 2012

Messaggi recenti

Does this mean there is currently no way to use a hook to override a struts action that is a part of the portal and not one of its portlets?

I'm asking because there is no information about such limitation and I've successfully overriden actions from portlets that are bundled with Liferay.
David H Nebinger
RE: ClassCastException while overriding struts action
16 aprile 2012 6.53
Risposta

David H Nebinger

Punteggio: Liferay Legend

Messaggi: 7157

Data di Iscrizione: 1 settembre 2006

Messaggi recenti

That's pretty much it. I know folks have tried overriding struts actions via a hook, you might try searching the forums for a possible solution.

The easiest method is to do this via an EXT plugin, since you don't have to worry about the class loader issues at that point. And hey, that's what the ext plugin is for...
Ondřej Životský
RE: ClassCastException while overriding struts action
1 ottobre 2012 7.18
Risposta

Ondřej Životský

Punteggio: Junior Member

Messaggi: 28

Data di Iscrizione: 11 marzo 2011

Messaggi recenti

I got the same problem today, so for everyone who has this problem...

1) first Exception - ActionAdapter cannot be cast to PortletActionAdapter - means you implemneted BaseStrutsAction instead of BaseStrutsPortletAction
2) second Exception - PortletActionAdapter cannot be cast to ActionAdapter - means you implemneted BaseStrutsPortletAction instead of BaseStrutsAction

I hope it helps someone
Ondrej
Angelos Varvitsiotis
RE: ClassCastException while overriding struts action
26 marzo 2013 7.25
Risposta

Angelos Varvitsiotis

Punteggio: New Member

Messaggi: 6

Data di Iscrizione: 26 luglio 2011

Messaggi recenti

You sure did help me! I was trying to add a configuration tab by hook'ing the portlet_configuration portlet. Extending BaseStrutsPortletAction and returning the right forward did the trick. Thanks!