Fórumok

Service builder in liferay

Abhi Ed, módosítva 11 év-val korábban

Service builder in liferay

Regular Member Bejegyzések: 118 Csatlakozás dátuma: 2012.06.04. Legújabb bejegyzések
I want to access a web service in my code. That web service is basically rest web service.
My question is :
1> Does liferay support rest ful web services?
2> Do I need to create a plugin portlet which contains custom liferay service calling utility?
3>My service calling utility won't be creating any database table in liferay.I just need to call a web service ,so that I can access it in navigation.vm
Then my concern is what will service.xml contain for my case?

Any Suggesstions??
thumbnail
David H Nebinger, módosítva 11 év-val korábban

RE: Service builder in liferay

Liferay Legend Bejegyzések: 14919 Csatlakozás dátuma: 2006.09.02. Legújabb bejegyzések
If you are just consuming an existing web service, SB will not be something you'd use.

While you can create an entity w/o columns to define shared methods at a service level, these methods cannot return your own POJO entities (they can return primitives, things from java.util, Strings, or other entity objects) due to class loader issues.

You can consume web services using whatever client package you want (jaxb, axis, axis2, etc). Just code it up as you would for any java app consuming the service and you're good to go.
Abhi Ed, módosítva 11 év-val korábban

RE: Service builder in liferay

Regular Member Bejegyzések: 118 Csatlakozás dátuma: 2012.06.04. Legújabb bejegyzések
Thanks David.
But how can my velocity code call that external web service?
Any suggestions?
Abhi Ed, módosítva 11 év-val korábban

RE: Service builder in liferay

Regular Member Bejegyzések: 118 Csatlakozás dátuma: 2012.06.04. Legújabb bejegyzések
Abhi Ed:
Thanks David.
But how can my velocity code call that external web service?
Any suggestions?



I have to access that web service in my navigation.vm
thumbnail
David H Nebinger, módosítva 11 év-val korábban

RE: Service builder in liferay

Liferay Legend Bejegyzések: 14919 Csatlakozás dátuma: 2006.09.02. Legújabb bejegyzések
You handle this by registering a spring bean in the root context.

In your velocity code, you'll then do something like:

#set( $webServiceClient = $utilLocator.findUtil("my.web.service.spring.bean.id") )
#if( $webServiceClient)
  #set( $result = $webServiceClient.callMethod() )
#end


The keys here are that your spring bean is named "my.web.service.spring.bean.id". Also the callMethod() method must return a value (used or unused) so you can use the #set directive.
Abhi Ed, módosítva 11 év-val korábban

RE: Service builder in liferay

Regular Member Bejegyzések: 118 Csatlakozás dátuma: 2012.06.04. Legújabb bejegyzések
David H Nebinger:
You handle this by registering a spring bean in the root context.

In your velocity code, you'll then do something like:

#set( $webServiceClient = $utilLocator.findUtil("my.web.service.spring.bean.id") )
#if( $webServiceClient)
  #set( $result = $webServiceClient.callMethod() )
#end


The keys here are that your spring bean is named "my.web.service.spring.bean.id". Also the callMethod() method must return a value (used or unused) so you can use the #set directive.



Thanks David.
I need some enlightenment for following:
1> what do you mean by registering a spring bean in the root context? Which root context?And by bean u mean bean of the web service?
2>I guess i will be needing a code snippet like the following to call my web service:
ResponseEntity<Map> resp = template
.exchange(
"http://10.135.30.12:8081/NextgenReportServices/customReportList",
HttpMethod.PUT, new HttpEntity<String>(userID),
Map.class);

But how this can be done here?
thumbnail
David H Nebinger, módosítva 11 év-val korábban

RE: Service builder in liferay

Liferay Legend Bejegyzések: 14919 Csatlakozás dátuma: 2006.09.02. Legújabb bejegyzések
Actually I'll point you at the recent Wiki page I did for Piwik integration: http://www.liferay.com/community/wiki/-/wiki/Main/Adding+Piwik+Web+Analytics+to+Liferay.

It calls a restful web service in Piwik, but the basics are in there for registering a spring bean in Liferay's root context.

Basically you'll create an interface like:

public interface MyWebServiceClient {
  boolean callMethod();
}


You'll have the implementation of the interface that actually does the web service call.

You add the spring bean definition, and then you can use the velocity code I presented earlier to access the spring bean and invoke the client call.
Abhi Ed, módosítva 11 év-val korábban

RE: Service builder in liferay

Regular Member Bejegyzések: 118 Csatlakozás dátuma: 2012.06.04. Legújabb bejegyzések
I downloaded piwik-liferay-1.1.zip from the pointer u referred.
I guess I am referring to the correct code section.
There I can see model,servlet and util packages.As i don't know the functionality which ur code is providing, I can't understand lot of stuffs.
However, if u can tell which section will serve my purpose, u'll save my time as well as effort.
Regards
Abhi