Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Joel Peterson
Service Builder with non-DB data source
March 8, 2010 3:20 PM
Answer

Joel Peterson

Rank: New Member

Posts: 22

Join Date: February 18, 2010

Recent Posts

Is there an equivalent tool to ServiceBuilder for web services that do not use Liferay's database as the datasource? We have web services with WSDL documents on a different server that we want to use for our datasource but we also want to be able to make use of the other features that ServiceBuilder provides, such as auto-generating the javascript proxy files and JSON wrappers for the services.

Essentially we want to generate everything that ServiceBuilder generates, but instead of using Hibernate to retrieve the data we just want empty stubs that we can implement on our own.

We are currently using Liferay 5.2.2 Community Edition.

Any information/help would be appreciated,

Joel Peterson
Joel Peterson
RE: Service Builder with non-DB data source
September 22, 2011 12:00 PM
Answer

Joel Peterson

Rank: New Member

Posts: 22

Join Date: February 18, 2010

Recent Posts

In case anybody had the same question I will post the steps here.

Brett Swaim gave a presentation on web services at Liferay WCS 2011 that had the solution to this for at least the upcoming Liferay 6.1 and maybe earlier versions of 6.

1) Create a service.xml file in your plugin to use service builder
2) Create an entity for your service, but do not put any columns in it
3) Run ant build-service to generate the service layer. When Liferay sees an entity with no columns, it creates the service layer without the database/persistence/ORM layer
4) Add methods for your various services to the implementation in the YourServiceLocalServiceImpl class
5) Code the methods to make the data requests to wherever you plan on getting data from
6) Deploy your plugin, you can now make use of YourServiceLocalServiceUtil to fetch your data.

Also, if you create a remote-service through service builder and then generate a WSDD file from your service, Liferay will generate the JSON layer in a service.js file in your project that can be used to call your service from javascript code.
Stian Sigvartsen
RE: Service Builder with non-DB data source
September 22, 2011 12:43 PM
Answer

Stian Sigvartsen

Rank: Junior Member

Posts: 98

Join Date: August 27, 2010

Recent Posts

Thanks for sharing this.
I'm sure I will have a need for this in the not too distant future because I work with an n-tier architecture with a powerful middle server providing web services and BPM capability.

-Stian
Gwowen Fu
RE: Service Builder with non-DB data source
January 24, 2013 10:26 AM
Answer

Gwowen Fu

Rank: Expert

Posts: 267

Join Date: December 27, 2010

Recent Posts

Joel Peterson:

1) Create a service.xml file in your plugin to use service builder
2) Create an entity for your service, but do not put any columns in it


I am having question about these two steps.

I created service.xml under "C:\liferay-plugins-sdk-6.1.1\portlets\testservice-portlet\docroot\WEB-INF" folder, is this the right place?

I want to create a JSON web service called "greeting". What's wrong with my service.xml?
1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.0.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_0_0.dtd">
3<service-builder package-path="com.testservice">
4    <author>user</author>
5    <namespace>testservice</namespace>
6    <entity name="greeting" local-service="true" remote-service="true" json-enabled="true"></entity>
7</service-builder>


When I run "build-service", no code is generated and there is NullPointerException:

[Console output redirected to file:C:\workspace-liferay\.metadata\.plugins\com.liferay.ide.eclipse.sdk\sdk.log]
Buildfile: C:\liferay-plugins-sdk-6.1.1\portlets\testservice-portlet\build.xml
build-service:
Loading jar:file:/C:/liferay-portal-6.1.1-ce-ga2/tomcat-7.0.27/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/system.properties
Jan 24, 2013 5:03:29 PM com.liferay.portal.kernel.log.Jdk14LogImpl info
INFO: Global shared lib directory /C:/liferay-plugins-sdk-6.1.1/lib/
Jan 24, 2013 5:03:29 PM com.liferay.portal.kernel.log.Jdk14LogImpl info
INFO: Global lib directory /C:/liferay-portal-6.1.1-ce-ga2/tomcat-7.0.27/lib/ext/
Jan 24, 2013 5:03:29 PM com.liferay.portal.kernel.log.Jdk14LogImpl info
INFO: Portal lib directory /C:/liferay-portal-6.1.1-ce-ga2/tomcat-7.0.27/webapps/ROOT/WEB-INF/lib/
Jan 24, 2013 5:03:29 PM com.liferay.portal.kernel.log.Jdk14LogImpl info
INFO: Properties for portal loaded from [jar:file:/C:/liferay-portal-6.1.1-ce-ga2/tomcat-7.0.27/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/com/liferay/portal/tools/dependencies/portal-tools.properties, jar:file:/C:/liferay-portal-6.1.1-ce-ga2/tomcat-7.0.27/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/portal.properties]
Loading jar:file:/C:/liferay-portal-6.1.1-ce-ga2/tomcat-7.0.27/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/portal.properties
Loading jar:file:/C:/liferay-portal-6.1.1-ce-ga2/tomcat-7.0.27/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/com/liferay/portal/tools/dependencies/portal-tools.properties
java.lang.NullPointerException
at com.liferay.portal.tools.servicebuilder.ServiceBuilder._parseEntity(ServiceBuilder.java:4848)
at com.liferay.portal.tools.servicebuilder.ServiceBuilder.<init>(ServiceBuilder.java:636)
at com.liferay.portal.tools.servicebuilder.ServiceBuilder.main(ServiceBuilder.java:151)
Created dir: C:\liferay-plugins-sdk-6.1.1\portlets\testservice-portlet\docroot\WEB-INF\service-classes
compile-java:
Warning: skipping zip archive C:\liferay-plugins-sdk-6.1.1\portlets\testservice-portlet\docroot\WEB-INF\lib\testservice-portlet-service.jar because no files were included.
Deleting directory C:\liferay-plugins-sdk-6.1.1\portlets\testservice-portlet\docroot\WEB-INF\service-classes
BUILD SUCCESSFUL

Thanks!
Gwowen
David H Nebinger
RE: Service Builder with non-DB data source
January 24, 2013 9:24 PM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 7004

Join Date: September 1, 2006

Recent Posts

Are you using oracle jdk 6 for the build? If you open the file in the eclipse visual editor for service builder, does it report an error in the content?
Gwowen Fu
RE: Service Builder with non-DB data source
January 25, 2013 9:41 AM
Answer

Gwowen Fu

Rank: Expert

Posts: 267

Join Date: December 27, 2010

Recent Posts

David H Nebinger:
Are you using oracle jdk 6 for the build? If you open the file in the eclipse visual editor for service builder, does it report an error in the content?


Hi David,

Yes, I am using JDK 1.6. I am using Eclipse Indigo, I opened service.xml and no error is reported in the content.
I clicked on the Overview tab and noticed there is a "Build Services" link, I clicked on that link and was able to generate Java codes.

Thanks, you are the best!
Gwowen
Michele Zanarotti
RE: Service Builder with non-DB data source
April 8, 2013 3:31 AM
Answer

Michele Zanarotti

Rank: Junior Member

Posts: 82

Join Date: February 20, 2012

Recent Posts

Hi. I know this is a very old question.

I'm using this strategy to build web services of my own. But when adding custom methods to xxxServiceImpl , i cannot see them regenerated when calling 'build services' in xxxServiceUtil, so the code is broken. For example :
I added the custom1() method to class xxxServiceImpl. I run 'build service'. The generated xxxServiceSoap class is now calling a method xxxServiceUtil.custom1() , but this method is not present in xxxServiceUtil !!! , despite my addition to the ServiceImpl version. I couldn't find any reason why this is happening.

If I go through each generated file (like xxxSoap) and replace 'Util' with 'Impl', everything works perfectly, also the web service is working with a test client. But rewriting the code that way each time is very annoying.

Am I forgetting to put something in the service xml ? It's only defined as a pure single entity without any column, finder or whatever.

I tried everything, with lf6.1 GA1 and GA2.