留言板

Class Cast Exception

Mansi Mistry,修改在8 年前。

Class Cast Exception

Junior Member 帖子: 31 加入日期: 14-9-30 最近的帖子
Hi,
We are developing portlets A and B. Have put the service builder in B portlet and using the services by putting the Jar in A portlet.
We have a class which is there is the service folder.
When running we are getting a ClassCastException for that class.

There is only one copy of the class file in B portlet . I saw similar posts with class cast issue which stated it is due to multiple class files.
But there is only one in this case.

It works when I put the jar file at the lib/ext folder and no copy in A and B.
But i need to make changes regularly and if I put it at the global level - each time I need to restart server. It takes lot of time.

Hoping for a solution with replacing jar in A portlet and avoiding server restart.

I am pasting the stacktrace -

java.lang.ClassCastException: org.lphi.cc.maintenance.rpc.model.SurveyInfo cannot be cast to org.lphi.cc.maintenance.rpc.model.SurveyInfo
      at org.lphi.cc.ProjectCatalogPortlet.serveResource(ProjectCatalogPortlet.java:458)
      at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:122)
      at com.liferay.portlet.ScriptDataPortletFilter.doFilter(ScriptDataPortletFilter.java:82)
      at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:116)
      at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:71)
      at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:112)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:96)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
      at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:487)
      at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412)
      at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)
      at com.liferay.portlet.InvokerPortletImpl.invoke(InvokerPortletImpl.java:601)
      at com.liferay.portlet.InvokerPortletImpl.invokeResource(InvokerPortletImpl.java:696)
      at com.liferay.portlet.InvokerPortletImpl.serveResource(InvokerPortletImpl.java:462)
      at com.liferay.portlet.PortletContainerImpl._doServeResource(PortletContainerImpl.java:792)
      at com.liferay.portlet.PortletContainerImpl.serveResource(PortletContainerImpl.java:152)
      at com.liferay.portlet.SecurityPortletContainerWrapper.serveResource(SecurityPortletContainerWrapper.java:166)
      at com.liferay.portlet.RestrictPortletContainerWrapper.serveResource(RestrictPortletContainerWrapper.java:166)
      at com.liferay.portal.kernel.portlet.PortletContainerUtil.serveResource(PortletContainerUtil.java:164)
      at com.liferay.portal.action.LayoutAction.processLayout(LayoutAction.java:364)
      at com.liferay.portal.action.LayoutAction.doExecute(LayoutAction.java:178)
      at com.liferay.portal.action.LayoutAction.execute(LayoutAction.java:79)
      at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
      at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
      at com.liferay.portal.struts.PortalRequestProcessor.process(PortalRequestProcessor.java:173)
      at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
      at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
      at com.liferay.portal.servlet.MainServlet.callParentService(MainServlet.java:546)
      at com.liferay.portal.servlet.MainServlet.service(MainServlet.java:523)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
      at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:169)
      at com.liferay.portal.servlet.filters.secure.SecureFilter.processFilter(SecureFilter.java:293)
      at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:59)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:204)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:109)
      at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:169)
      at com.liferay.portal.servlet.filters.jsoncontenttype.JSONContentTypeFilter.processFilter(JSONContentTypeFilter.java:42)
      at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:59)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:204)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:109)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:96)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
      at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:487)
      at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412)
      at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)
      at com.liferay.portal.servlet.FriendlyURLServlet.service(FriendlyURLServlet.java:160)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
      at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:169)
      at com.liferay.portal.servlet.filters.gzip.GZipFilter.processFilter(GZipFilter.java:123)
      at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:59)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:204)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:109)
      at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:169)
      at com.liferay.portal.servlet.filters.secure.SecureFilter.processFilter(SecureFilter.java:293)
      at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:59)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:204)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:109)
      at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:169)
      at com.liferay.portal.servlet.filters.i18n.I18nFilter.processFilter(I18nFilter.java:243)
      at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:59)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:204)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:109)
      at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:169)
      at com.liferay.portal.servlet.filters.jsoncontenttype.JSONContentTypeFilter.processFilter(JSONContentTypeFilter.java:42)
      at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:59)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:204)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:109)
      at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:169)
      at com.liferay.portal.servlet.filters.autologin.AutoLoginFilter.processFilter(AutoLoginFilter.java:263)
      at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:59)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:204)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:109)
      at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:169)
      at com.liferay.portal.servlet.filters.sso.ntlm.NtlmPostFilter.processFilter(NtlmPostFilter.java:83)
      at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:59)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:204)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:109)
      at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:169)
      at com.liferay.portal.sharepoint.SharepointFilter.processFilter(SharepointFilter.java:88)
      at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:59)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:204)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:109)
      at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:169)
      at com.liferay.portal.servlet.filters.virtualhost.VirtualHostFilter.processFilter(VirtualHostFilter.java:226)
      at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:59)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:204)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:109)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:185)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:96)
      at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:738)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:204)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:109)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:165)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:96)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:165)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:96)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:185)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:96)
      at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:96)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
      at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)
thumbnail
Andew Jardine,修改在8 年前。

RE: Class Cast Exception

Liferay Legend 帖子: 2416 加入日期: 10-12-22 最近的帖子
Hi Mansi,

Can you tell me what project type you are using? is it a maven project or using the SDK (ANT)?

.. can you also double check your lib/ext to make sure it's not hanging around (even as an old file name or something). I've had this happen to me before emoticon.
Mansi Mistry,修改在8 年前。

RE: Class Cast Exception

Junior Member 帖子: 31 加入日期: 14-9-30 最近的帖子
We are using SDK (ANT). And we did check the lib/ext folder several times and also the portlets to make sure we do not have it at multiple places. Not sure what must going wrong emoticon

Hey Andew can you also help me with 2 more posts . It would be nice to hear from you on them. We badly need help emoticon

Public and private URLs - firewall configuration, load balancing HAProxy
Document Library - confirmation popup before move to recycle bin


Thanks in Advance! emoticon
thumbnail
Andew Jardine,修改在8 年前。

RE: Class Cast Exception

Liferay Legend 帖子: 2416 加入日期: 10-12-22 最近的帖子
Hi Mansi,

Ok -- I've seen this problem in the past and done a half dozen things to try to resolve it. Honestly, I'm never quite sure which one is the actual solution but I have use this liittle recipe before.

1. Make sure the server is running.
2. Undeploy the plugin (and any plugin that is using the service-jar).
3. Stop the server
4. Assuming you are using tomcat, clear the TOMCAT_HOME/work and TOMCAT_HOME/temp -- delete the whole folder, tomcat will put them back for you on startup.
5. Start tomcat.
6. Deploy your plugins again

One other question regarding this ticket -- how are you including the jar in the dependent project? Are you taking the xxx-service.jar from Project A and manually copying it to Portlet B? or are you using the dependency configuration mechanisms?
Mansi Mistry,修改在8 年前。

RE: Class Cast Exception

Junior Member 帖子: 31 加入日期: 14-9-30 最近的帖子
Hi andew,
We are manually copying the service jar in the other portlet.
For us it did not work using the steps you suggested. Only putting at the global level works.
Also we want to avoid the server restart.
thumbnail
Andew Jardine,修改在8 年前。

RE: Class Cast Exception

Liferay Legend 帖子: 2416 加入日期: 10-12-22 最近的帖子
Right -- the server restart was just to purge the compiled cache files and stuff. Instead of copying the file manually, you could set a "required deployment context" as well. If you open the project that is USING your service.jar and then open the file /WEB-INF/liferay-plugin-package.properties. If you are using the Liferay IDE then then there is a nice GUI for this feature. The bottom right box allows you to set a dependency on the liferay plugin project that has the service jar in it. If you are not using the id, then you can manually add this entry to the file --


required-deployment-contexts=\
    <your-portlet-servlet-context-name>
</your-portlet-servlet-context-name>


.. then when you do a deployment, it will automatically copy the *-service.jar file from your SB plugin to your plugins WEB-INF/lib folder. Just another option to try to see if the "automatic" approach makes a difference (I can't see why, but you never know).

You could also set the portal so that every deployment first does an undeploy action --


    #
    # Set this to true to undeploy a plugin before deploying a new version. This
    # property will only be used if the property "hot.undeploy.enabled" is set
    # to true.
    #
    hot.undeploy.on.redeploy=true


.. that would ensure that you clean the plugin out before it is deployed which should eliminate cache problems (in theory).
Mansi Mistry,修改在8 年前。

RE: Class Cast Exception

Junior Member 帖子: 31 加入日期: 14-9-30 最近的帖子
I have already set the "required deployment context" for portlet A and it does not copy the jar.
For eg. if there is no service jar in A and we have set the deployment context and we deploy the portlet A.
We get this exception
com.liferay.portal.kernel.deploy.hot.HotDeployException: Error registering portlets

It does not copy the jar "automatically".
We will try this hot undeploy approach once but the manual copying of jar needs to be done.
thumbnail
Andew Jardine,修改在8 年前。

RE: Class Cast Exception

Liferay Legend 帖子: 2416 加入日期: 10-12-22 最近的帖子
Strange -- I just tried this on my side to make sure my memory wasn't failing me and it worked. In the case of requiering a plugin with service builder, it copied the jar for me as part of the deploy target. If I set a dependency on another plugin type (say a hook) and the hook is not present on the server then the deployment "fails" -- but in reality it is just held in queue until the missing dependency (hook) is deployed first.

Which version of the portal are you using?
thumbnail
Meera Prince,修改在8 年前。

RE: Class Cast Exception

Liferay Legend 帖子: 1111 加入日期: 11-2-8 最近的帖子
HI
Similar kind of issue you can try this post it may give some clue
https://www.liferay.com/community/forums/-/message_boards/message/33063340

Regards,
Meera Prince