Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
ruchi sharma
java.lang.ClassCastException: $Proxy234
April 10, 2012 8:22 AM
Answer

ruchi sharma

Rank: Junior Member

Posts: 95

Join Date: March 24, 2011

Recent Posts

Hello ,

Getting the following exception

Caused by: java.lang.ClassCastException: $Proxy234 cannot be cast to com.ubmi.portlet.articledisplaylist.service.ArticleDisplayListLocalService
at com.ubmi.portlet.articledisplaylist.service.ArticleDisplayListLocalServiceUtil.getService(ArticleDisplayListLocalServiceUtil.java:313)
at com.ubmi.portlet.articledisplaylist.service.ArticleDisplayListLocalServiceUtil.getArticlesByCurrentAuthor(ArticleDisplayListLocalServiceUtil.java:232)
at org.apache.jsp.jsp.view_jsp._jspService(view_jsp.java:294)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
... 196 more

Do not have any clue why exception this is coming??
Any suggestions to make it working ??

Thanks
Ruchi
David H Nebinger
RE: java.lang.ClassCastException: $Proxy234
April 10, 2012 9:09 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 7917

Join Date: September 1, 2006

Recent Posts

Yes, you're incorrectly referencing a local service instance within the impl class.

The impl class has access to everything you need (it extends the appropriate base classes, has access to the persistence layer, etc.). You shouldn't be trying to get an actual instance pointer to the local service, just use what's available or fall back to the BlahLocalServiceUtil() class if you're going outside of your current impl class.
ruchi sharma
RE: java.lang.ClassCastException: $Proxy234
April 11, 2012 2:34 AM
Answer

ruchi sharma

Rank: Junior Member

Posts: 95

Join Date: March 24, 2011

Recent Posts

David H Nebinger:
Yes, you're incorrectly referencing a local service instance within the impl class.

The impl class has access to everything you need (it extends the appropriate base classes, has access to the persistence layer, etc.). You shouldn't be trying to get an actual instance pointer to the local service, just use what's available or fall back to the BlahLocalServiceUtil() class if you're going outside of your current impl class.


Hello David,
Thanks for the response firstly.
Well, I got your point and I am not trying to get instance of local service directly, I am using simply the method being generated by service builder.
Below you can seen the code snippet (hope this make sense and make situation clear to you)

In view jsp
<%
List<AssetEntry> listEntry = (List<AssetEntry>)ArticleDisplayListLocalServiceUtil.getArticlesByCurrentAuthor(groupId, userId);
Iterator<AssetEntry> itrEnteries = listEntry.iterator();
while (itrEnteries.hasNext()) {
...........

In ArticleDisplayListLocalServiceUtil.java

public static java.util.List<com.liferay.portlet.asset.model.AssetEntry> getArticlesByCurrentAuthor(
long groupId, long userId)
throws com.liferay.portal.kernel.exception.SystemException {
return getService().getArticlesByCurrentAuthor(groupId, userId);
}

//call to get the local service instance.
public static ArticleDisplayListLocalService getService() {
if (_service == null) {
_service = (ArticleDisplayListLocalService)PortalBeanLocatorUtil.locate(ArticleDisplayListLocalService.class.getName());
}
return _service;
}

Any suggestions??
Thanks
Ruchi
David H Nebinger
RE: java.lang.ClassCastException: $Proxy234
April 11, 2012 5:31 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 7917

Join Date: September 1, 2006

Recent Posts

ruchi sharma:
In ArticleDisplayListLocalServiceUtil.java

public static java.util.List<com.liferay.portlet.asset.model.AssetEntry> getArticlesByCurrentAuthor(
long groupId, long userId)
throws com.liferay.portal.kernel.exception.SystemException {
return getService().getArticlesByCurrentAuthor(groupId, userId);
}

//call to get the local service instance.
public static ArticleDisplayListLocalService getService() {
if (_service == null) {
_service = (ArticleDisplayListLocalService)PortalBeanLocatorUtil.locate(ArticleDisplayListLocalService.class.getName());
}
return _service;
}



Seriously? That's all there is in the getService() method? Any getService() method I've seen SB generate includes the portlet class loader, a class loader proxy, ...

If that's all you've got in there, I'd say someone hacked away at the getService() method leaving you with some valid yet unworking code.
ruchi sharma
RE: java.lang.ClassCastException: $Proxy234
April 12, 2012 4:17 AM
Answer

ruchi sharma

Rank: Junior Member

Posts: 95

Join Date: March 24, 2011

Recent Posts

David H Nebinger:

Seriously? That's all there is in the getService() method? Any getService() method I've seen SB generate includes the portlet class loader, a class loader proxy, ...

If that's all you've got in there, I'd say someone hacked away at the getService() method leaving you with some valid yet unworking code.


Hello David

Yes, code is exactly the same .
Well I was trying to find the solution and I found the following thread
https://www.liferay.com/community/forums/-/message_boards/message/7129192
And in this forum one guy has also posted the solution
http://www.liferay.com/zh/community/wiki/-/wiki/Main/Using+Class+Loader+Proxy+classes+to+share+plugins+services
So just wondering is their any possibility to such kind of situation ??
Meanwhile I am trying to get the things mentioned in the forum and will try to dig into the problem to find some solution.

Any suggestions??
Thanks
Ruchi
David H Nebinger
RE: java.lang.ClassCastException: $Proxy234
April 12, 2012 6:02 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 7917

Join Date: September 1, 2006

Recent Posts

ruchi sharma:
And in this forum one guy has also posted the solution
http://www.liferay.com/zh/community/wiki/-/wiki/Main/Using+Class+Loader+Proxy+classes+to+share+plugins+services
So just wondering is their any possibility to such kind of situation ??


Nope. The description provided in that wiki is a shared code jar, certainly not a shared service implementation...

Take a look at the output from Service Builder. There's a true shared services implementation for you.

All of the implementation classes are based upon interfaces; only the interfaces go into the shared service jar.

All of the entities are also interfaces and are also serializable to handle crossing the web app class loader boundary.

The service jar will contain a number of actual CLP classes which implement the interface yet are actually dynamic method invokers based upon the Method and Class to invoke the actual method that is running remotely in a different web application.
ruchi sharma
RE: java.lang.ClassCastException: $Proxy234
April 12, 2012 7:13 AM
Answer

ruchi sharma

Rank: Junior Member

Posts: 95

Join Date: March 24, 2011

Recent Posts

Hello David
Thanks so much for your help, I really appreciate that.
Well hopefully I'll find some solution.

Regards
Ruchi
Hitoshi Ozawa
RE: java.lang.ClassCastException: $Proxy234
April 12, 2012 7:37 AM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7952

Join Date: March 23, 2010

Recent Posts

at com.ubmi.portlet.articledisplaylist.service.ArticleDisplayListLocalServiceUtil.getService(ArticleDisplayListLocalServiceUtil.java:313)


So, what on line 313?
ruchi sharma
RE: java.lang.ClassCastException: $Proxy234
April 12, 2012 8:05 AM
Answer

ruchi sharma

Rank: Junior Member

Posts: 95

Join Date: March 24, 2011

Recent Posts

Hi,

public static ArticleDisplayListLocalService getService() {
if (_service == null) {
_service = (ArticleDisplayListLocalService)PortalBeanLocatorUtil.locate(ArticleDisplayListLocalService.class.getName()); LIne 313
}

return _service;
}

Thanks
Ruchi
Hitoshi Ozawa
RE: java.lang.ClassCastException: $Proxy234
April 12, 2012 2:48 PM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7952

Join Date: March 23, 2010

Recent Posts

Trying to do something like in the following article? Hope the article will give you a clue to what's you're missing because the information you've given us so far is still incomplete for me to determine exactly which setting you're missing.

http://sampsa.sohlman.com/fi/home/-/blogs/liferay-junit-mocking-and-spring-beans;jsessionid=E410910E84174E9202C4207F2B190CC6
ruchi sharma
RE: java.lang.ClassCastException: $Proxy234
May 25, 2012 1:58 AM
Answer

ruchi sharma

Rank: Junior Member

Posts: 95

Join Date: March 24, 2011

Recent Posts

Hello David,
I compared the service method with other service methods, its not having any class loader and class loader proxy class.

I also to build the service again , resultantly all the classes are generated in the service folder except the Class Loader Proxy classes like XLocalServiceClp etc. and in other folders all classes are generated.
(Note: this X portlet is in ext folder )

Just wondering why sevice builder is not generating he clp classes so that my service method for port;let X would be same as others.

Any answer??
Thanks
Ruchi