Fórum

Extending an existing service: OrganizationService

John O'Neill, modificado 11 Anos atrás.

Extending an existing service: OrganizationService

Junior Member Postagens: 36 Data de Entrada: 10/09/10 Postagens Recentes
I'm trying to extend a few new methods on the OrganizationService, com.liferay.portal.service.OrganizationService. As I follow the directions in the code, it let's me know the following:


@JSONWebService
@Transactional(isolation = Isolation.PORTAL, rollbackFor =  {
	PortalException.class, SystemException.class})
public interface OrganizationService {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this interface directly. Always use {@link OrganizationServiceUtil} to access the organization remote service. Add custom service methods to {@link com.liferay.portal.service.impl.OrganizationServiceImpl} and rerun ServiceBuilder to automatically copy the method declarations to this interface.
	 */


To start I have simply copied an existing method and renamed it. I then went to the liferay/portal-impl/build.xml file to run the ant-task build-service and I have the following error below.

Am I following the best standard to accomplish adding a new method to the OrganizationService?
Is this the correct way to run ServiceBuilder on pre-exisiting Liferay code?
What is wrong with the ant task?

Best,
John O


Buildfile: C:\aws\liferay-portal-src-6.1.0-ce-ga1\portal-impl\build.xml
build-service:
     [java] Loading file:/C:/aws/liferay-portal-src-6.1.0-ce-ga1/portal-impl/classes/system.properties
     [java] Oct 6, 2012 6:22:56 AM com.liferay.portal.kernel.log.Jdk14LogImpl info
     [java] INFO: Global lib directory 
     [java] Oct 6, 2012 6:22:56 AM com.liferay.portal.kernel.log.Jdk14LogImpl info
     [java] INFO: Portal lib directory /C:/aws/liferay-portal-src-6.1.0-ce-ga1/util-java/classes/
     [java] 06:22:56,539 INFO  [EasyConf:122] Refreshed the configuration of all components
     [java] 06:22:57,169 INFO  [ConfigurationLoader:56] Properties for /C:/aws/liferay-portal-src-6.1.0-ce-ga1/portal-impl/classes/portal loaded from [file:/C:/aws/liferay-portal-src-6.1.0-ce-ga1/portal-impl/classes/com/liferay/portal/tools/dependencies/portal-tools.properties, file:/C:/aws/liferay-portal-src-6.1.0-ce-ga1/portal-impl/classes/portal.properties]
     [java] Loading file:/C:/aws/liferay-portal-src-6.1.0-ce-ga1/portal-impl/classes/portal.properties
     [java] Loading file:/C:/aws/liferay-portal-src-6.1.0-ce-ga1/portal-impl/classes/com/liferay/portal/tools/dependencies/portal-tools.properties
     [java] java.lang.NullPointerException
     [java] 	at com.liferay.portal.kernel.io.unsync.UnsyncStringReader.<init>(UnsyncStringReader.java:33)
     [java] 	at com.liferay.util.xml.XMLSafeReader.<init>(XMLSafeReader.java:25)
     [java] 	at com.liferay.portal.xml.SAXReaderImpl.read(SAXReaderImpl.java:413)
     [java] 	at com.liferay.portal.kernel.xml.SAXReaderUtil.read(SAXReaderUtil.java:151)
     [java] 	at com.liferay.portal.tools.servicebuilder.ServiceBuilder._getContentDocument(ServiceBuilder.java:3833)
     [java] 	at com.liferay.portal.tools.servicebuilder.ServiceBuilder._getContent(ServiceBuilder.java:3756)
     [java] 	at com.liferay.portal.tools.servicebuilder.ServiceBuilder.<init>(ServiceBuilder.java:544)
     [java] 	at com.liferay.portal.tools.servicebuilder.ServiceBuilder.<init>(ServiceBuilder.java:430)
     [java] 	at com.liferay.portal.tools.servicebuilder.ServiceBuilder.main(ServiceBuilder.java:146)
     [java] 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     [java] 	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
     [java] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
     [java] 	at java.lang.reflect.Method.invoke(Unknown Source)
     [java] 	at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:217)
     [java] 	at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:152)
     [java] 	at org.apache.tools.ant.taskdefs.Java.run(Java.java:771)
     [java] 	at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:221)
     [java] 	at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:135)
     [java] 	at org.apache.tools.ant.taskdefs.Java.execute(Java.java:108)
     [java] 	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
     [java] 	at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
     [java] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
     [java] 	at java.lang.reflect.Method.invoke(Unknown Source)
     [java] 	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
     [java] 	at org.apache.tools.ant.Task.perform(Task.java:348)
     [java] 	at org.apache.tools.ant.Target.execute(Target.java:390)
     [java] 	at org.apache.tools.ant.Target.performTasks(Target.java:411)
     [java] 	at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
     [java] 	at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
     [java] 	at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
     [java] 	at org.eclipse.ant.internal.launching.remote.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
     [java] 	at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
     [java] 	at org.eclipse.ant.internal.launching.remote.InternalAntRunner.run(InternalAntRunner.java:424)
     [java] 	at org.eclipse.ant.internal.launching.remote.InternalAntRunner.main(InternalAntRunner.java:138)
compile:
BUILD SUCCESSFUL
Total time: 8 seconds
</init></init></init></init>
thumbnail
Hitoshi Ozawa, modificado 11 Anos atrás.

RE: Extending an existing service: OrganizationService

Liferay Legend Postagens: 7942 Data de Entrada: 24/03/10 Postagens Recentes
Sorry, but the best practice is not to modify liferay's source code. See the following page for information on how to customize liferay.

http://www.liferay.com/documentation/liferay-portal/6.1/development/-/ai/extending-and-customizing-lifer-3
John O'Neill, modificado 11 Anos atrás.

RE: Extending an existing service: OrganizationService

Junior Member Postagens: 36 Data de Entrada: 10/09/10 Postagens Recentes
Thank you Hitoshi. If I read the documentation correctly, I should create a new service hook plugin, copy the existing com.liferay.portal.service.impl.OrganizationServiceImpl code, modify to my needs and run the ServiceBuilder on the new service hook? Does this sound right?

Best,
John O
thumbnail
Hitoshi Ozawa, modificado 11 Anos atrás.

RE: Extending an existing service: OrganizationService

Liferay Legend Postagens: 7942 Data de Entrada: 24/03/10 Postagens Recentes
No exactly. You won't be able to run service builder on existing liferay entity definition. You'll need to create a new entity definition that uses liferay's existing services. Run service builder on the newly defined entity definition.

I found this to be better technique than using expando because my entity definition/interfaces will remain separate from liferay's entity definition/interfaces.
John O'Neill, modificado 11 Anos atrás.

RE: Extending an existing service: OrganizationService

Junior Member Postagens: 36 Data de Entrada: 10/09/10 Postagens Recentes
I've tried to implement using the Eclipse Liferay hook for services, extend the OrganizationLocalServiceWrapper, expose the search() methods and mark it as a @JSONWebService. I've run into this problem below... Is there I've missed?

17:12:43,964 INFO  [pool-2-thread-8][PluginPackageUtil:1033] Reading plugin package for PBPServices-hook
Oct 14, 2012 5:12:44 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
17:12:44,037 INFO  [pool-2-thread-8][HookHotDeployListener:550] Registering hook for PBPServices-hook
#########------------------------------------------#########
######### Initiating new PBPCalendarServiceWrapper #########
#########------------------------------------------#########
#########--------------------------------------------#########
######### Initiating new ExtOrganizationLocalService #########
#########--------------------------------------------#########
17:12:44,061 INFO  [pool-2-thread-8][HookHotDeployListener:690] Hook for PBPServices-hook is available for use
17:12:44,076 ERROR [pool-2-thread-8][JSONWebServiceServiceAction:54] java.lang.NullPointerException
java.lang.NullPointerException
        at com.liferay.portal.jsonwebservice.JSONWebServiceConfigurator.configure(JSONWebServiceConfigurator.java:101)
        at com.liferay.portal.jsonwebservice.JSONWebServiceServiceAction.<init>(JSONWebServiceServiceAction.java:51)
        at com.liferay.portal.jsonwebservice.JSONWebServiceServlet.getJSONAction(JSONWebServiceServlet.java:169)
        at com.liferay.portal.servlet.JSONServlet.init(JSONServlet.java:52)
        at com.liferay.portal.kernel.servlet.PortalClassLoaderServlet.portalInit(PortalClassLoaderServlet.java:76)
        at com.liferay.portal.kernel.util.PortalLifecycleUtil.register(PortalLifecycleUtil.java:64)
        at com.liferay.portal.kernel.util.PortalLifecycleUtil.register(PortalLifecycleUtil.java:56)
        at com.liferay.portal.kernel.servlet.PortalClassLoaderServlet.init(PortalClassLoaderServlet.java:47)
        at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1266)
        at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1185)
        at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1080)
        at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5015)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5302)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:895)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:871)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615)
        at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1099)
        at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1621)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
        at java.util.concurrent.FutureTask.run(FutureTask.java:138)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
        at java.lang.Thread.run(Thread.java:619)
</init>
thumbnail
Hitoshi Ozawa, modificado 11 Anos atrás.

RE: Extending an existing service: OrganizationService

Liferay Legend Postagens: 7942 Data de Entrada: 24/03/10 Postagens Recentes
I should have asked this earlier but are you trying to extend OrganizationService to use it in your own portlets or liferay's basic functionality?

Instead of creating a hook, just create a portlet. Make the impl methods call liferay's OrganizationService. That is, instead of doing a java class extend, just use the existing service.
John O'Neill, modificado 11 Anos atrás.

RE: Extending an existing service: OrganizationService

Junior Member Postagens: 36 Data de Entrada: 10/09/10 Postagens Recentes
I'm calling these services in a mobile application, using JSON. My intent is to decorate or compose services on the Liferay framework.

Am I following the right approach? Do you have any ideas on my issue above?

Thanks,
John O
thumbnail
Hitoshi Ozawa, modificado 11 Anos atrás.

RE: Extending an existing service: OrganizationService (Resposta)

Liferay Legend Postagens: 7942 Data de Entrada: 24/03/10 Postagens Recentes
Instead of creating a hook, just create a new portlet and in the service.xml, make sure to enable remote service. In the service.xml, just have key to liferay's organization service and additional column information. In the impl method, just call methods on new columns with liferay's organization service.
John O'Neill, modificado 11 Anos atrás.

RE: Extending an existing service: OrganizationService

Junior Member Postagens: 36 Data de Entrada: 10/09/10 Postagens Recentes
Thank you Hitoshi... This was very helpful!

Best,
John O
John O'Neill, modificado 11 Anos atrás.

RE: Extending an existing service: OrganizationService

Junior Member Postagens: 36 Data de Entrada: 10/09/10 Postagens Recentes
Hitoshi,

I'm trying to return a composite object of Organization and Address from a custom Portlet. As I rebuild using the Service Builder, I get these errors below.

     [echo] Building PBPOrganization
compile-java:
    [javac] Compiling 18 source files to C:\aws\liferay-plugins-sdk-6.1.1\portlets\PBPPortlet-portlet\docroot\WEB-INF\service-classes
    [javac] C:\aws\liferay-plugins-sdk-6.1.1\portlets\PBPPortlet-portlet\docroot\WEB-INF\service\com\library\slayer\service\PBPOrganizationService.java:81: package com.library.slayer.service.pbp does not exist
    [javac] 	public java.util.List<com.library.slayer.service.pbp.pbporganizationaddress> findCitiesInRegion(
    [javac] 	                                                    ^
    [javac] C:\aws\liferay-plugins-sdk-6.1.1\portlets\PBPPortlet-portlet\docroot\WEB-INF\service\com\library\slayer\service\PBPOrganizationServiceClp.java:211: package com.library.slayer.service.pbp does not exist
    [javac] 	public java.util.List<com.library.slayer.service.pbp.pbporganizationaddress> findCitiesInRegion(
    [javac] 	                                                    ^
    [javac] C:\aws\liferay-plugins-sdk-6.1.1\portlets\PBPPortlet-portlet\docroot\WEB-INF\service\com\library\slayer\service\PBPOrganizationServiceUtil.java:90: package com.library.slayer.service.pbp does not exist
    [javac] 	public static java.util.List<com.library.slayer.service.pbp.pbporganizationaddress> findCitiesInRegion(
    [javac] 	                                                           ^
    [javac] C:\aws\liferay-plugins-sdk-6.1.1\portlets\PBPPortlet-portlet\docroot\WEB-INF\service\com\library\slayer\service\PBPOrganizationServiceWrapper.java:83: package com.library.slayer.service.pbp does not exist
    [javac] 	public java.util.List<com.library.slayer.service.pbp.pbporganizationaddress> findCitiesInRegion(
    [javac] 	                                                    ^
    [javac] C:\aws\liferay-plugins-sdk-6.1.1\portlets\PBPPortlet-portlet\docroot\WEB-INF\service\com\library\slayer\service\PBPOrganizationServiceClp.java:240: package com.library.slayer.service.pbp does not exist
    [javac] 		return (java.util.List<com.library.slayer.service.pbp.pbporganizationaddress>)ClpSerializer.translateOutput(returnObj);
    [javac] 		                                                     ^
</com.library.slayer.service.pbp.pbporganizationaddress></com.library.slayer.service.pbp.pbporganizationaddress></com.library.slayer.service.pbp.pbporganizationaddress></com.library.slayer.service.pbp.pbporganizationaddress></com.library.slayer.service.pbp.pbporganizationaddress>


I've added the following Composite class:
package com.library.slayer.service.pbp;

import com.liferay.portal.model.Address;
import com.liferay.portal.model.Organization;

public class PBPOrganizationAddress {

	private Organization org = null;
	private Address address = null;
	
	public PBPOrganizationAddress(Organization org, Address address) {
		super();
		this.org = org;
		this.address = address;
	}
	
	public Organization getOrg() {
		return org;
	}
	public void setOrg(Organization org) {
		this.org = org;
	}
	public Address getAddress() {
		return address;
	}
	public void setAddress(Address address) {
		this.address = address;
	}
}


Any thoughts?

John O