Liferay JAX-RS service

General Blogs August 16, 2017 By sejal patel

 Liferay 7 bolster for creating and deploying JAX-RS based REST services.

JAX-RS is the JEE standards based approach for creating REST web services. As far as building up the real administrations it basically utilizes an explanation based approach,where one improves strategies in Java classes with comments, for example, @GET, @POST, @Path and so forth.

In this post, we will examine about liferay JAX-RS service . Following are some prerequisite to implement liferay JAX-RS service 


1. Liferay 7 must be installed

2.Eclipse neon

3.Java 1.8 

Configure liferay JAX-RS service :

Now, lets understand the steps to generate JAX-RS Service as follow,

1.To create a liferay workspace in ide follow the following steps.

     File Menu ->New-> Select Liferay workspace

    Upon creation of the workspace, the structure should look like below 


2.To create rest module in ide follow the following steps

  File Menu -> New->Click on Liferay Module Project. Fill up the detail as follow,

  Project Name: enter appropriate name e.g :":Rest-Services-Demo-rest"

  Project Template Name: Select :"rest"

3. update gradle dependencies with below and run the gradle build task

dependencies {

 compileOnly group: "", name: "", version: "2.0.1"

 compileOnly group: "org.osgi", name: "org.osgi.service.component.annotations", version: "1.3.0"

 compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "2.0.0"

 compileOnly group: "com.liferay.portal", name: "", version: "2.0.0"

 compileOnly group: "com.liferay.portal", name: "com.liferay.portal.impl", version: "2.0.0"

 compile group: 'com.liferay', name: 'com.liferay.osgi.util', version: '1.0.0'

 compileOnly project(":modules:Rest-Services-Demo:Rest-Services-Demo-api")

 compileOnly project(":modules:Rest-Services-Demo:Rest-Services-Demo-service")


4.Configuring CXF Endpoints

Liferay supports JAX-RS via the Apache CXF implementation. CXF endpoints are context paths where the JAX web services are deployed to and accessible from.

We can configure CXFEndpoint from “/src/main/resources/configuration/com.liferay.portal.remote.cxf.common.configuration.CXFEndpointPublisherConfiguration-cxf “ file 



5.Configuring REST Extenders

We can configure REST Extenders from /src/main/resources/configuration/ file.



For above configuration services will be deployed and can be accessible by following URL


6.Publishing JAX-WS RS Services

Liferay creates REST Component with sample methods, so edit the RestServicesDemoRestApplication class that returns Student objects as JSON


@Component(immediate = true, service = Application.class,

configurationPid = "",

configurationPolicy = ConfigurationPolicy.OPTIONAL,property={"jaxrs.application=true"})

public class RestServicesDemoRestApplication extends Application {

      public Set<Object> getSingletons() {

             return Collections.<Object>singleton(this);


 private StudentLocalService studentLocalService;


  public void setLeaveLocalService(StudentLocalService studentLocalService){






  public String getLeave(@PathParam("studentId") long studentId){

       Student student = null;

       String jsonString = null;

     try {

                student = studentLocalService.getStudent(studentId);

                jsonString = JSONFactoryUtil.serialize(student);

        } catch (Exception e) {



     return jsonString;



7.Liferay REST Extender Configuration :

    Deploy the rest module in liferay server.

     Click on Control Panel -> Configuration -> System Settings 

     Search for REST ->Click on REST Extender

     Click on the configuration and you can see the deployed module specified context paths. 


To access rest service use following examples:

Liferay 7 begins with context /o unlike in Liferay 6 with/c


Liferay Screenlet

General Blogs August 16, 2017 By sejal patel

Liferay provides the screenlets, which are the readymade screen for the faster android app development for Liferay apps. Liferay Screens for Android contains several Screenlets that you can use in your Android apps.

Liferay offers bunch of screenlets which is called Screenlet Library. You can know more about it from following link,



1. Liferay 7 must be installed.

2. Android Studio .

Configure Login screenlet:

Before we discuss steps to implement screenlets, it is important for you to understand that Android project configuration. You can learn about Android project in Liferay from following link,

Now, lets understand the steps to generate screenlet as follow,

1. Create new project in android studio

a) To create an android project in Android studio, follow the following steps and click next,

                   File->New Project ->Fill up the detail as follow,

                   Application Name: Provide appropriate name e.g." LoginScreenletDemo"

                   Company Domain: provide appropriate name e.g."com.enprowess.loginscreenletdemo”

b) Select form factor and click next,For this example, I selected phone and template and maximum SDK as API 15 Android 4.0.3

c) Select Empty Activity from this screen and click next ,

d) Provide activity name and click on finish. In this example, I provided activity name as " LoginActivity",

e) On click of finish, you will see following folder structure created,


2. Add Liferay libraries for screenlets

Liferay provides bunch of screenlets. In order to get access to those screenlet, you need to add dependency in file as follow. After adding dependency sync the project to get access of Liferay screenlets.

android {
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'


. . . .

. . . .

compile ''
compile ''
compile ''
compile ''
compile ''
compile 'net.the4thdimension:android-utils:2.0.4'

3. Configure login Screenlet for logging into Liferay instance.

Configure UI for logging activity by adding the following code in your activity_login.xml

<?xml version="1.0" encoding="utf-8"?>
    xmlns:liferay ""

        liferay:layoutId="@layout/login_default" />

4.Configure liferay server  

You can configure Liferay server details in server_context.xml under your res/values folder. Please see following code snipped for the reference.

<?xml version="1.0" encoding="utf-8"?>
    <string name="liferay_server"></string>
    <integer name="liferay_company_id">20116</integer>
    <integer name="liferay_portal_version">70</integer>

Following is the quick summery for the attributes to configure,

liferay_server : Server address of your Liferay instance is running.

liferay_company_id : Company id for the instance

liferay_portal_version : Liferay version server is running Liferay 7 (70)



Screenlet provides the interfaces to get a result of web service calls by mobile SDK. For login, you need to implement LoginListener which provides following two methods that you need to implement.

i) onLoginSuccess()

ii) onLoginFailure()



6.Run Application

Select your application -> click on run icon -> Create new Virtual Device -> Select Phone and then model of your choice then click next -> Select System image (for testing I used Nouget) -> Finally select orientation (I selected Portrait view) and click on finish

You will see your first Liferay login screenlet as follow,



Showing 2 results.