掲示板

Service Builder with non-DB data source

14年前 に Joel Peterson によって更新されました。

Service Builder with non-DB data source

New Member 投稿: 22 参加年月日: 10/02/18 最新の投稿
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
12年前 に Joel Peterson によって更新されました。

RE: Service Builder with non-DB data source

New Member 投稿: 22 参加年月日: 10/02/18 最新の投稿
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.
thumbnail
12年前 に Stian Sigvartsen によって更新されました。

RE: Service Builder with non-DB data source

Regular Member 投稿: 103 参加年月日: 10/08/27 最新の投稿
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
11年前 に Gwowen Fu によって更新されました。

RE: Service Builder with non-DB data source

Expert 投稿: 315 参加年月日: 10/12/27 最新の投稿
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?
<!--?xml version="1.0" encoding="UTF-8"?-->

<service-builder package-path="com.testservice">
	<author>user</author>
	<namespace>testservice</namespace>
	<entity name="greeting" local-service="true" remote-service="true" json-enabled="true"></entity>
</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:
[echo] 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
[echo] Jan 24, 2013 5:03:29 PM com.liferay.portal.kernel.log.Jdk14LogImpl info
[echo] INFO: Global shared lib directory /C:/liferay-plugins-sdk-6.1.1/lib/
[echo] Jan 24, 2013 5:03:29 PM com.liferay.portal.kernel.log.Jdk14LogImpl info
[echo] INFO: Global lib directory /C:/liferay-portal-6.1.1-ce-ga2/tomcat-7.0.27/lib/ext/
[echo] Jan 24, 2013 5:03:29 PM com.liferay.portal.kernel.log.Jdk14LogImpl info
[echo] INFO: Portal lib directory /C:/liferay-portal-6.1.1-ce-ga2/tomcat-7.0.27/webapps/ROOT/WEB-INF/lib/
[echo] Jan 24, 2013 5:03:29 PM com.liferay.portal.kernel.log.Jdk14LogImpl info
[echo] 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]
[echo] 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
[echo] 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
[echo] java.lang.NullPointerException
[echo] at com.liferay.portal.tools.servicebuilder.ServiceBuilder._parseEntity(ServiceBuilder.java:4848)
[echo] at com.liferay.portal.tools.servicebuilder.ServiceBuilder.<init>(ServiceBuilder.java:636)
[echo] at com.liferay.portal.tools.servicebuilder.ServiceBuilder.main(ServiceBuilder.java:151)
[mkdir] Created dir: C:\liferay-plugins-sdk-6.1.1\portlets\testservice-portlet\docroot\WEB-INF\service-classes
compile-java:
[zip] 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.
[delete] Deleting directory C:\liferay-plugins-sdk-6.1.1\portlets\testservice-portlet\docroot\WEB-INF\service-classes
BUILD SUCCESSFUL

Thanks!
Gwowen
thumbnail
11年前 に David H Nebinger によって更新されました。

RE: Service Builder with non-DB data source

Liferay Legend 投稿: 14919 参加年月日: 06/09/02 最新の投稿
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?
11年前 に Gwowen Fu によって更新されました。

RE: Service Builder with non-DB data source

Expert 投稿: 315 参加年月日: 10/12/27 最新の投稿
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
thumbnail
11年前 に Michele Zanarotti によって更新されました。

RE: Service Builder with non-DB data source

Junior Member 投稿: 94 参加年月日: 12/02/20 最新の投稿
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.