Developing an external service class that does not rely on service builder in Liferay7 is very concise and requires only 2 points of annotation:
- Defined in the front of the class:
@ApplicationPath ("/pathxxx")
- Method before definition:
@GET
@Path ("/actionxxx")
@Produces ("Text/plain")
Example: getting a registered user
Import Com.liferay.portal.kernel.model.user;import Com.liferay.portal.kernel.service.userlocalservice;import Java.util.collections;import Java.util.set;import Javax.ws.rs.applicationpath;import Javax.ws.rs.GET;import Javax.ws.rs.path;import Javax.ws.rs.produces;import Javax.ws.rs.core.application;import Org.osgi.service.component.annotations.component;import org.osgi.service.component.annotations.reference;@ Applicationpath ("/allUsers ") @Component (Immediate=true, property = {"jaxrs.application=true"}, Service= Application.class) Public classUsersrestservice extends Application {@Override PublicSet<object>getsingletons () {returnCollections.singleton ((Object) This); } @GET @Path ("/list ") @Produces ("Text/plain") PublicString getAllUsers () {StringBuilder result=NewStringBuilder (); for(User User: _userlocalservice.getusers (-1, -1) {result.append (User.getfullname ())). Append (", \ n"); } returnresult.tostring (); } @Reference Public voidSetuserlocalservice (Userlocalservice userlocalservice) {_userlocalservice=Userlocalservice; } Privateuserlocalservice _userlocalservice;}
OSGi syntax is really concise.
Liferay7 BPM Portal Development 34:liferay7 External service class generation (Restservice Get Url)