Foros de discusión

Error cast using ServiceBuilder

Daniel Fernandez, modificado hace 6 años.

Error cast using ServiceBuilder

Junior Member Mensajes: 29 Fecha de incorporación: 29/03/17 Mensajes recientes
I,m using liferay 7 with Tomcat 8, i need to insert a product on my data base using Service Builder.

I,ve been searching on internet to do the insert method in my personal portlet that is in another package, i do all the dependencies and imports, and it really works, but when I run de project and execute my method i had an error like this:
(" java.lang.ClassCastException: com.sun.proxy.$Proxy470 cannot be cast to com.serviceBuilder.service.ProductoLocalService")


My codeemoticonThis code is in my personal porlet in module DatosPersonales)
Producto prod = ProductoLocalServiceUtil.createProducto(0); ("The error apears in this line")
prod.setCodigo("Codigo");
prod.setValor("Valor");
prod.setDescripcion("Descripcion");
prod.setID(1);
prod = ProductoLocalServiceUtil.addProducto(prod);

I think is all right, but when i execute my code this error apears.

It might be an error creating my Service Builder, but i thin is all right, the error apears in my class ProductoLocalServiceUtil, doing method createProducto();

My codeemoticonThis code is in module ServiceBuilder in my package com.serviceBuilder.service)
public static com.serviceBuilder.model.Producto createProducto(int ID) {
return getService().createProducto(ID); ("This line sends my to another method")
}

Another method:
public static ProductoLocalService getService() {
return _serviceTracker.getService();
}
In the lasth method i get the error in return, i think is not working properly and i don´t know why this error apears.

If you know how to solve it please help me and the comunity.

Thanks a lot, Best Regards.
thumbnail
David H Nebinger, modificado hace 6 años.

RE: Error cast using ServiceBuilder

Liferay Legend Mensajes: 14918 Fecha de incorporación: 2/09/06 Mensajes recientes
I think you'll find things to be a lot easier if you create an addProduct(codigo,valor,description) method to ProductoLocalServiceImpl class. This tends to remove all of the class loader/proxy stuff from your front end and also properly encapsulates your data access in the data access layer.

For example, there is logic in creating the product id, this isn't really something your front end should be doing but something you want to do in the data access layer so you can control how those ids are generated and assigned.






Come meet me at the 2017 LSNA!
Daniel Fernandez, modificado hace 6 años.

RE: Error cast using ServiceBuilder

Junior Member Mensajes: 29 Fecha de incorporación: 29/03/17 Mensajes recientes
David H Nebinger:
I think you'll find things to be a lot easier if you create an addProduct(codigo,valor,description) method to ProductoLocalServiceImpl class. This tends to remove all of the class loader/proxy stuff from your front end and also properly encapsulates your data access in the data access layer.

For example, there is logic in creating the product id, this isn't really something your front end should be doing but something you want to do in the data access layer so you can control how those ids are generated and assigned.






Come meet me at the 2017 LSNA!



I create the method in ProductoLocalServiceIml but how can i call this method in my portlet? And how can i insert my data into de database qith this simple method? Have you got the code?
thumbnail
David H Nebinger, modificado hace 6 años.

RE: Error cast using ServiceBuilder

Liferay Legend Mensajes: 14918 Fecha de incorporación: 2/09/06 Mensajes recientes
When you add the method to ProductoLocalServiceImpl, you rebuild the services and the method will be added to the api layer.

From there, you'll find ProductoLocalServiceUtil.addProduct() or, if you're using OSGi, you can inject the ProductoLocalService into your action handler and call it that way.

This process allows you to really build up the data access logic (and even the business logic) within the data access layer. Your UI can then invoke the data access logic when it needs but doesn't need to manage all of the details.






Come meet me at the 2017 LSNA!
Daniel Fernandez, modificado hace 6 años.

RE: Error cast using ServiceBuilder

Junior Member Mensajes: 29 Fecha de incorporación: 29/03/17 Mensajes recientes
David H Nebinger:
When you add the method to ProductoLocalServiceImpl, you rebuild the services and the method will be added to the api layer.

From there, you'll find ProductoLocalServiceUtil.addProduct() or, if you're using OSGi, you can inject the ProductoLocalService into your action handler and call it that way.

This process allows you to really build up the data access logic (and even the business logic) within the data access layer. Your UI can then invoke the data access logic when it needs but doesn't need to manage all of the details.






Come meet me at the 2017 LSNA!


So i add this method:

Producto prod = ProductoLocalServiceUtil.createProducto(0); ("The error apears in this line")
prod.setCodigo("Codigo");
prod.setValor("Valor");
prod.setDescripcion("Descripcion");
prod.setID(1);
prod = ProductoLocalServiceUtil.addProducto(prod);

To ProductoLocalServiceImpl and rebuild services and that's it?
thumbnail
David H Nebinger, modificado hace 6 años.

RE: Error cast using ServiceBuilder

Liferay Legend Mensajes: 14918 Fecha de incorporación: 2/09/06 Mensajes recientes
Okay, setting a 1 as the id (or using 0 as the argument for createProducto() call), may not have the effect you want, depending upon how you're set up for primary key assignment.

For example, if you're using a DB-generated sequence then your <column /> primary key should have the right stuff for the value.

If you didn't add anything, the common practice is to use the counterLocalService.increment(Producto.class.getName()) to create a unique ID for the createProducto() call.

Also, since you are in the ProductoLocalServiceImpl class, you don't have to use ProductoLocalServiceUtil.createProducto(0) or ProductoLocalServiceUtil.addProducto(), you can just simply call createProducto(0) because the methods are available via a super class.

But otherwise yes, that's it. You add your methods to ProductoLocalServiceImpl (I usually add convenience methods for adding, updating, querying, etc), rebuild services and the methods will be available for your UI to invoke.







Come meet me at the 2017 LSNA!
Daniel Fernandez, modificado hace 6 años.

RE: Error cast using ServiceBuilder

Junior Member Mensajes: 29 Fecha de incorporación: 29/03/17 Mensajes recientes
My method does not work, i don´t know how to add Producto into my database.

Thanks a lot for your early replays David.
thumbnail
David H Nebinger, modificado hace 6 años.

RE: Error cast using ServiceBuilder

Liferay Legend Mensajes: 14918 Fecha de incorporación: 2/09/06 Mensajes recientes
Does not work how? You get an exception? Compile time errors? It looks like it adds but is not in the database? How do you define "does not work"?







Come meet me at the 2017 LSNA!
Daniel Fernandez, modificado hace 6 años.

RE: Error cast using ServiceBuilder

Junior Member Mensajes: 29 Fecha de incorporación: 29/03/17 Mensajes recientes
When i execute my code, this error apears, i don´t know how to solve it. I looked so much examples and other people with the same code as mine works properly but mine no.



11:34:24,790 ERROR [http-nio-8080-exec-4][PortletServlet:109] javax.portlet.PortletException: java.lang.ClassCastException: com.sun.proxy.$Proxy472 cannot be cast to com.serviceBuilder.service.ProductoLocalService
javax.portlet.PortletException: java.lang.ClassCastException: com.sun.proxy.$Proxy472 cannot be cast to com.serviceBuilder.service.ProductoLocalService
at com.liferay.portal.kernel.portlet.LiferayPortlet.callActionMethod(LiferayPortlet.java:202)
at com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet.callActionMethod(MVCPortlet.java:392)
at com.liferay.portal.kernel.portlet.LiferayPortlet.processAction(LiferayPortlet.java:93)
at com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet.processAction(MVCPortlet.java:249)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:71)
at com.liferay.portlet.CheckboxParametersPortletFilter.doFilter(CheckboxParametersPortletFilter.java:57)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:68)
at com.liferay.portlet.CheckboxParametersPortletFilter.doFilter(CheckboxParametersPortletFilter.java:57)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:68)
at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:48)
at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:105)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at com.liferay.portal.osgi.web.servlet.context.helper.internal.ServletContextHelperRegistrationImpl$PortletServletWrapper.service(ServletContextHelperRegistrationImpl.java:427)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.eclipse.equinox.http.servlet.internal.registration.EndpointRegistration.service(EndpointRegistration.java:153)
at org.eclipse.equinox.http.servlet.internal.servlet.FilterChainImpl.doFilter(FilterChainImpl.java:50)
at com.liferay.portal.osgi.web.servlet.context.helper.internal.ServletContextHelperRegistrationImpl$RestrictPortletServletRequestFilter.doFilter(ServletContextHelperRegistrationImpl.java:447)
at org.eclipse.equinox.http.servlet.internal.registration.FilterRegistration.doFilter(FilterRegistration.java:121)
at org.eclipse.equinox.http.servlet.internal.servlet.FilterChainImpl.doFilter(FilterChainImpl.java:45)
at org.eclipse.equinox.http.servlet.internal.servlet.ResponseStateHandler.processRequest(ResponseStateHandler.java:70)
at org.eclipse.equinox.http.servlet.internal.context.DispatchTargets.doDispatch(DispatchTargets.java:117)
at org.eclipse.equinox.http.servlet.internal.servlet.RequestDispatcherAdaptor.include(RequestDispatcherAdaptor.java:48)
at com.liferay.portlet.InvokerPortletImpl.invoke(InvokerPortletImpl.java:529)
at com.liferay.portlet.InvokerPortletImpl.invokeAction(InvokerPortletImpl.java:575)
at com.liferay.portlet.InvokerPortletImpl.processAction(InvokerPortletImpl.java:334)
at com.liferay.portlet.PortletContainerImpl._doProcessAction(PortletContainerImpl.java:413)
at com.liferay.portlet.PortletContainerImpl.processAction(PortletContainerImpl.java:117)
at com.liferay.portlet.SecurityPortletContainerWrapper.processAction(SecurityPortletContainerWrapper.java:94)
at com.liferay.portlet.RestrictPortletContainerWrapper.processAction(RestrictPortletContainerWrapper.java:75)
at com.liferay.portal.kernel.portlet.PortletContainerUtil.processAction(PortletContainerUtil.java:114)
at com.liferay.portal.action.LayoutAction.processLayout(LayoutAction.java:314)
at com.liferay.portal.action.LayoutAction.doExecute(LayoutAction.java:178)
at com.liferay.portal.action.LayoutAction.execute(LayoutAction.java:75)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:425)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228)
at com.liferay.portal.struts.PortalRequestProcessor.process(PortalRequestProcessor.java:170)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at com.liferay.portal.servlet.MainServlet.callParentService(MainServlet.java:568)
at com.liferay.portal.servlet.MainServlet.service(MainServlet.java:545)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:119)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:142)
at com.liferay.portal.monitoring.internal.servlet.filter.MonitoringFilter.processFilter(MonitoringFilter.java:180)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:207)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:112)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:142)
at com.liferay.portal.servlet.filters.uploadservletrequest.UploadServletRequestFilter.processFilter(UploadServletRequestFilter.java:93)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:207)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:112)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:142)
at com.liferay.portal.servlet.filters.secure.SecureFilter.processFilter(SecureFilter.java:303)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:207)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:112)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:142)
at com.liferay.portal.servlet.filters.jsoncontenttype.JSONContentTypeFilter.processFilter(JSONContentTypeFilter.java:42)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:207)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:112)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:115)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:720)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:466)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:391)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:318)
at com.liferay.portal.servlet.FriendlyURLServlet.service(FriendlyURLServlet.java:172)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:119)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:142)
at com.liferay.portal.monitoring.internal.servlet.filter.MonitoringFilter.processFilter(MonitoringFilter.java:180)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:207)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:112)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:142)
at com.liferay.portal.security.sso.ntlm.internal.servlet.filter.NtlmPostFilter.processFilter(NtlmPostFilter.java:107)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:207)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:112)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:188)
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:188)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:96)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:142)
at com.liferay.portal.servlet.filters.uploadservletrequest.UploadServletRequestFilter.processFilter(UploadServletRequestFilter.java:93)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:207)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:112)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:142)
at com.liferay.portal.servlet.filters.strip.StripFilter.processFilter(StripFilter.java:336)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:207)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:112)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:142)
at com.liferay.portal.servlet.filters.gzip.GZipFilter.processFilter(GZipFilter.java:125)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:207)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:112)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:142)
at com.liferay.portal.servlet.filters.secure.SecureFilter.processFilter(SecureFilter.java:303)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:207)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:112)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:142)
at com.liferay.portal.servlet.filters.i18n.I18nFilter.processFilter(I18nFilter.java:269)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:207)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:112)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:142)
at com.liferay.portal.servlet.filters.etag.ETagFilter.processFilter(ETagFilter.java:86)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:207)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:112)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:142)
at com.liferay.portal.servlet.filters.jsoncontenttype.JSONContentTypeFilter.processFilter(JSONContentTypeFilter.java:42)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:207)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:112)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:142)
at com.liferay.portal.servlet.filters.autologin.AutoLoginFilter.processFilter(AutoLoginFilter.java:268)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:207)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:112)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:142)
at com.liferay.portal.sharepoint.SharepointFilter.processFilter(SharepointFilter.java:88)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:207)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:112)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:142)
at com.liferay.portal.servlet.filters.virtualhost.VirtualHostFilter.processFilter(VirtualHostFilter.java:260)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:207)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:112)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:188)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:96)
at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:176)
at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145)
at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92)
at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:394)
at com.liferay.portal.servlet.filters.urlrewrite.UrlRewriteFilter.processFilter(UrlRewriteFilter.java:65)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:207)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:112)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:168)
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:168)
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:188)
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:115)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassCastException: com.sun.proxy.$Proxy472 cannot be cast to com.serviceBuilder.service.ProductoLocalService
at com.serviceBuilder.service.ProductoLocalServiceUtil.getService(ProductoLocalServiceUtil.java:255)
at com.serviceBuilder.service.ProductoLocalServiceUtil.createProducto(ProductoLocalServiceUtil.java:89)
at com.atam.extranet.portlet.DatosPersonalesPortlet.verDatosSocio(DatosPersonalesPortlet.java:85)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.liferay.portal.kernel.portlet.LiferayPortlet.callActionMethod(LiferayPortlet.java:184)
... 181 more
11:34:26,161 ERROR [http-nio-8080-exec-4][render_portlet_jsp:131] null
java.lang.ClassCastException: com.sun.proxy.$Proxy472 cannot be cast to com.serviceBuilder.service.ProductoLocalService
at com.serviceBuilder.service.ProductoLocalServiceUtil.getService(ProductoLocalServiceUtil.java:255)
at com.serviceBuilder.service.ProductoLocalServiceUtil.createProducto(ProductoLocalServiceUtil.java:89)
at com.atam.extranet.portlet.DatosPersonalesPortlet.verDatosSocio(DatosPersonalesPortlet.java:85)
at com.liferay.portal.kernel.portlet.LiferayPortlet.callActionMethod(LiferayPortlet.java:184)
at com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet.callActionMethod(MVCPortlet.java:392)
at com.liferay.portal.kernel.portlet.LiferayPortlet.processAction(LiferayPortlet.java:93)
at com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet.processAction(MVCPortlet.java:249)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:71)
at com.liferay.portlet.CheckboxParametersPortletFilter.doFilter(CheckboxParametersPortletFilter.java:57)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:68)
at com.liferay.portlet.CheckboxParametersPortletFilter.doFilter(CheckboxParametersPortletFilter.java:57)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:68)
at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:48)
at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:105)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at com.liferay.portal.osgi.web.servlet.context.helper.internal.ServletContextHelperRegistrationImpl$PortletServletWrapper.service(ServletContextHelperRegistrationImpl.java:427)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.eclipse.equinox.http.servlet.internal.registration.EndpointRegistration.service(EndpointRegistration.java:153)
at org.eclipse.equinox.http.servlet.internal.servlet.FilterChainImpl.doFilter(FilterChainImpl.java:50)
at com.liferay.portal.osgi.web.servlet.context.helper.internal.ServletContextHelperRegistrationImpl$RestrictPortletServletRequestFilter.doFilter(ServletContextHelperRegistrationImpl.java:447)
thumbnail
David H Nebinger, modificado hace 6 años.

RE: Error cast using ServiceBuilder

Liferay Legend Mensajes: 14918 Fecha de incorporación: 2/09/06 Mensajes recientes
Do you have a global service jar?







Come meet me at the 2017 LSNA!
Daniel Fernandez, modificado hace 6 años.

RE: Error cast using ServiceBuilder

Junior Member Mensajes: 29 Fecha de incorporación: 29/03/17 Mensajes recientes
I don`t have a global service jar, this is my structure of my proyect.

- I have a module named Datos who has the main portlet(In this portlet i call the method who gives me the error)

- I have another module named ServiceBuilder who has servicebuilder-api and servicebuilder-service, this sub-modules has default service builder classes.

I called method createProducto who is created in servicebuilder and i called from my portel in module datos.

I build services, build and deploy, and refresh gradle project to save de dependencies and methods.

If you want i can put the code here.

I have the same issue but i have the same code from other people, i don't know where i'm wrong.

Thanks for all david you are doing a great work.
thumbnail
David H Nebinger, modificado hace 6 años.

RE: Error cast using ServiceBuilder

Liferay Legend Mensajes: 14918 Fecha de incorporación: 2/09/06 Mensajes recientes
Oh, so this is LR7? I should have asked that sooner...

Is your portlet deployed as a module jar or as a portlet war?







Come meet me at the 2017 LSNA!
Daniel Fernandez, modificado hace 6 años.

RE: Error cast using ServiceBuilder

Junior Member Mensajes: 29 Fecha de incorporación: 29/03/17 Mensajes recientes
My portlet is deployed as a module jar.
thumbnail
David H Nebinger, modificado hace 6 años.

RE: Error cast using ServiceBuilder

Liferay Legend Mensajes: 14918 Fecha de incorporación: 2/09/06 Mensajes recientes
Well snap, brother, you're in OSGi world now. You shouldn't be using the Util classes at all. Those are meant for legacy usage scenarios.

Stick with using @Reference annotations to let OSGi inject your actual instances where you need them.







Come meet me at the 2017 LSNA!
Daniel Fernandez, modificado hace 6 años.

RE: Error cast using ServiceBuilder

Junior Member Mensajes: 29 Fecha de incorporación: 29/03/17 Mensajes recientes
So i use @References, in my personal portlet?? To refer my service builder??
Daniel Fernandez, modificado hace 6 años.

RE: Error cast using ServiceBuilder

Junior Member Mensajes: 29 Fecha de incorporación: 29/03/17 Mensajes recientes
Daniel Fernandez:
So i use @References, in my personal portlet?? To refer my service builder??


If i use @References to reffer to ProductoLocalServiceUtil, in the portal web of liferay is disabled my portlet, it is like my portlet does not work properly if i use de anotation @Reference.

Sorry if i repeat my structure but it's very important to keep the structure like this, and use all liferay (Database, modules, classes and methods) to insert into database producto or anything, i'm only need to create an insert who works properly:
-Main Module
[indent][/indent]- Datos
[indent][indent][/indent][/indent]- My personal Portlet named DatosPersonales
[indent][/indent]- ServiceBuilder
[indent][indent][/indent][/indent]- ServiceBuilder-service
[indent][indent][indent][/indent][/indent][/indent]- Default ServiceBuilder package with default ServiceBuilder classes

In my personal portlet, i have this method to do the insert but is still give me the same error of cast:

@Reference ProductoLocalServiceUtil p = new ProductoLocalServiceUtil();
@ProcessAction(name="verDatosSocio")
public void verDatosSocio(ActionRequest actionRequest, ActionResponse actionResponse){
actionResponse.setRenderParameter("jspPage","/jsp/datosPersonalesEdit.jsp");


try{
//ProductoLocalServiceUtil p = new ProductoLocalServiceUtil();
Producto prod = p.createProducto(5);
//Creamos el producto y seteamos los atributos con los valores que queramos asginar
prod.setID(5);
prod.setCodigo("Codigo");
prod.setValor("Valor");
prod.setDescripcion("Descripcion");
p.addProducto(prod);

}catch(SystemException e){
e.printStackTrace();
}
}
thumbnail
David H Nebinger, modificado hace 6 años.

RE: Error cast using ServiceBuilder

Liferay Legend Mensajes: 14918 Fecha de incorporación: 2/09/06 Mensajes recientes
No, you use the following:

@Reference
protected ProductoLocalService productoLocalService;

// then in code...
Producto p = productoLocalService.addProducto("Codigo", "Valor", "Descripcion");


So here's an example of how you create the add method in the service layer: https://github.com/dnebing/sb-upgrade-70/blob/SB-Module/modules/school/school-service/src/main/java/com/liferay/school/service/impl/CourseLocalServiceImpl.java#L73

And these lines are in a MVC action to inject the @Reference for CourseLocalService and use that reference to invoke the service: https://github.com/dnebing/sb-upgrade-70/blob/SB-Module/modules/add-course-web/src/main/java/com/liferay/school/addcourse/portlet/AddCourseMVCActionCommand.java#L40-L53

These two examples combine everything that I've been saying from the first reply: build out your business logic in the service builder layer and use OSGi references to inject the service builder layer into your portlet code where needed.

Forget all of the old 6.x blogs and other examples that tell you to use the ProductoLocalServiceUtil class, those blogs are now completely out of date and should not be used in Liferay 7 CE / Liferay DXP.





Come meet me at the 2017 LSNA!
Daniel Fernandez, modificado hace 6 años.

RE: Error cast using ServiceBuilder

Junior Member Mensajes: 29 Fecha de incorporación: 29/03/17 Mensajes recientes
David H Nebinger:
No, you use the following:

@Reference
protected ProductoLocalService productoLocalService;

// then in code...
Producto p = productoLocalService.addProducto("Codigo", "Valor", "Descripcion");


So here's an example of how you create the add method in the service layer: https://github.com/dnebing/sb-upgrade-70/blob/SB-Module/modules/school/school-service/src/main/java/com/liferay/school/service/impl/CourseLocalServiceImpl.java#L73

And these lines are in a MVC action to inject the @Reference for CourseLocalService and use that reference to invoke the service: https://github.com/dnebing/sb-upgrade-70/blob/SB-Module/modules/add-course-web/src/main/java/com/liferay/school/addcourse/portlet/AddCourseMVCActionCommand.java#L40-L53

These two examples combine everything that I've been saying from the first reply: build out your business logic in the service builder layer and use OSGi references to inject the service builder layer into your portlet code where needed.

Forget all of the old 6.x blogs and other examples that tell you to use the ProductoLocalServiceUtil class, those blogs are now completely out of date and should not be used in Liferay 7 CE / Liferay DXP.





Come meet me at the 2017 LSNA!



So my code has to be like this no?

@Reference(unbind="-")
protected ProductoLocalService productoLocalService;
@ProcessAction(name="verDatosSocio")
public void verDatosSocio(ActionRequest actionRequest, ActionResponse actionResponse){
actionResponse.setRenderParameter("jspPage","/jsp/datosPersonalesEdit.jsp");
//Producto prod = null;
try{
Producto p = productoLocalService.createProducto(1);
//productoLocalService.createProducto(5);
//Creamos el producto y seteamos los atributos con los valores que queramos asginar
p.setID(5);
p.setCodigo("Codigo");
p.setValor("Valor");
p.setDescripcion("Descripcion");
productoLocalService.addProducto(p);

}catch(SystemException e){
e.printStackTrace();
}
}
thumbnail
David H Nebinger, modificado hace 6 años.

RE: Error cast using ServiceBuilder

Liferay Legend Mensajes: 14918 Fecha de incorporación: 2/09/06 Mensajes recientes
For accessing the service, yes. For doing the actual add, I tend to discourage this because the portlet code has to know how to generate IDs and that is bad design.






Come meet me at the 2017 LSNA!
Daniel Fernandez, modificado hace 6 años.

RE: Error cast using ServiceBuilder

Junior Member Mensajes: 29 Fecha de incorporación: 29/03/17 Mensajes recientes
That is what i looking for, add to the database, do you think that i'm doing wrong??

I'm sorry i don't know anything about liferay and i'm new programming in Eclipse, so i'm a noob.
srini vasulu, modificado hace 6 años.

RE: Error cast using ServiceBuilder

Regular Member Mensajes: 139 Fecha de incorporación: 22/02/11 Mensajes recientes
David H Nebinger:
No, you use the following:

@Reference
protected ProductoLocalService productoLocalService;

// then in code...
Producto p = productoLocalService.addProducto("Codigo", "Valor", "Descripcion");


So here's an example of how you create the add method in the service layer: https://github.com/dnebing/sb-upgrade-70/blob/SB-Module/modules/school/school-service/src/main/java/com/liferay/school/service/impl/CourseLocalServiceImpl.java#L73

And these lines are in a MVC action to inject the @Reference for CourseLocalService and use that reference to invoke the service: https://github.com/dnebing/sb-upgrade-70/blob/SB-Module/modules/add-course-web/src/main/java/com/liferay/school/addcourse/portlet/AddCourseMVCActionCommand.java#L40-L53

These two examples combine everything that I've been saying from the first reply: build out your business logic in the service builder layer and use OSGi references to inject the service builder layer into your portlet code where needed.

Forget all of the old 6.x blogs and other examples that tell you to use the ProductoLocalServiceUtil class, those blogs are now completely out of date and should not be used in Liferay 7 CE / Liferay DXP.





Come meet me at the 2017 LSNA!



Hi David,
I am also facing the same issue. i try to get the all the records using below code but getting error like below

code:List<SubmittalData> submitalsList = SubmittalDataLocalServiceUtil.getSubmittalDatas(-1, -1);
Error:java.lang.ClassCastException: com.sun.proxy.$Proxy491 cannot be cast to com.pb.submittal.service.service.SubmittalDataLocalService

and followed your links and added codel like below

@Reference(unbind = "-")
protected void setCourseLocalService(final SubmittalDataLocalService submittalDataLocalService) {
_submittalDataLocalService = submittalDataLocalService;
}

private SubmittalDataLocalService _submittalDataLocalService;
List<SubmittalData> submitalsList = _submittalDataLocalService.getSubmittalDatas(-1, -1);
now i am getting java.lang.NullPointerException
what is the issue in my code.
I am using liferay 7 OSGI(spring MVC portlet) war file
thumbnail
David H Nebinger, modificado hace 6 años.

RE: Error cast using ServiceBuilder

Liferay Legend Mensajes: 14918 Fecha de incorporación: 2/09/06 Mensajes recientes
You cannot use @Reference injection in your Spring beans as OSGi context injection is not available (two different containers, one Spring and one OSGi).

The first error, the one about the cast of the proxy, actually to me looks more like a class loader issue, such as if you have the API jar in your Spring web apps' WEB-INF/lib directory during deployment.
Ghulam Yaseen Shar, modificado hace 4 años.

RE: Error cast using ServiceBuilder

New Member Mensajes: 7 Fecha de incorporación: 25/09/19 Mensajes recientes
Hi David,

I am using liferay 7.2 with tomcat 9 and created JSF portlet and service builder without workspace, goal is to use custom created services in JSF portlet. 

Here is project structure: 

- jsf portlet root project TestJsf (Root)
--TestJSF-api
--TestJSF-service
--TestJSF-web(contain jsf portlet)


After that I have deployed services and api jar to liferay portal as standalone projects, Now error appearing while accessing service builder using *LocalServiceUtil as well as @Reference annotation, logs and project is also added. 

[code]Caused by: java.lang.ClassCastException: com.sun.proxy.$Proxy1164 cannot be cast to com.announcement.service.AnnouncementLocalService

Thanks