1

I have: Eclispse Version: 2019-06 (4.12.0) Build id: 20190614-1200

Liferay 7.2.0 CE GA1. I use Gradle.

I followed this tutorial: https://www.liferaystack.com/2017/11/rest-extender-and-jax-rs-restful-web-service-in-liferay-7-dxp.html

I created a rest module.

I created two file of configuration inside the folder "src/main/resources/configuration":

com.liferay.portal.remote.cxf.common.configuration.CXFEndpointPublisherConfiguration-cxf.properties

Code:

contextPath=/my-rest-service
authVerifierProperties=auth.verifier.BasicAuthHeaderAuthVerifier.urls.includes=*

com.liferay.portal.remote.rest.extender.configuration.RestExtenderConfiguration-rest.properties

Code:

contextPaths=/my-rest-service

    jaxRsServiceFilterStrings=(component.name=com.liferaystack.application.MyRestServiceApplication)

This is the MyRestWebserviceApplication.java:

package com.liferaystack.application;

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.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Application;

import org.osgi.service.component.annotations.Component;
import org.osgi.service.jaxrs.whiteboard.JaxrsWhiteboardConstants;

/**
 * @author pinoteam
 */
@ApplicationPath("/my-rest-service")
@Component(immediate = true, service = Application.class)
public class MyRestWebserviceApplication extends Application {

    public Set<Object> getSingletons() {
        return Collections.<Object>singleton(this);
    }

    @GET
    @Produces("text/plain")
    public String working() {
        return "It works!";
    }

    @GET
    @Path("/morning")
    @Produces("text/plain")
    public String hello() {
        return "Good morning!";
    }

    @GET
    @Path("/mattina")
    @Produces("text/plain")
    public String helloGa() {
        return "Good morning!";
    }

    @GET
    @Path("/morning/{name}")
    @Produces("text/plain")
    public String morning(
        @PathParam("name") String name,
        @QueryParam("drink") String drink) {

        String greeting = "Good Morning " + name;

        if (drink != null) {
            greeting += ". Would you like some " + drink + "?";
        }

        return greeting;
    }

}

I run build and deploy. The app is active, but nothing work.

In control panel i have not any Rest Extender Configuration and i have not api at any url.

what am i missing? any idea?

MarioProject
  • 417
  • 4
  • 25
  • Please [upgrade](https://liferay.dev/blogs/-/blogs/security-patches-for-liferay-portal-6-2-7-0-and-7-1) and edit your question to contain the steps that you took in the form of a [mcve], don't just link to a full external tutorial that everyone who wants to help you has to get through. – Olaf Kock May 26 '20 at 11:43
  • 1
    I updated the question. – MarioProject May 26 '20 at 12:16

1 Answers1

0

The tutorial you link is for Liferay 7.0 - the package/path names of the configuration files might have changed, and I've seen a context path being declared in bnd.bnd, rather than those property files - things might have changed since then.

An alternative starting point might be the blade sample, which is written for 7.2, and provides a Whiteboard-properties in the Java class:

@Component(
    property = {
        JaxrsWhiteboardConstants.JAX_RS_APPLICATION_BASE + "=/users",
        JaxrsWhiteboardConstants.JAX_RS_NAME + "=Users"
    },
    service = Application.class
)
public class UsersRestService extends Application {

    @GET
    @Path("/list")
    @Produces("text/plain")
    public String getUsers() {
        ...
    }
...

That plugin's configuration file is rather trivial (looks optional on first glance, but don't take my word for it)

Olaf Kock
  • 46,930
  • 8
  • 59
  • 90
  • It works! Thank you. Now i have responses. I have another problem. I updated getUsers but my changes have no effect. I empty cache of Liferay but i see the same response of the first deploy. – MarioProject May 27 '20 at 13:17
  • That would be a new question. But note that just changing data you get back from database doesn't change their persistent version - you'll need to store that data explicitly. – Olaf Kock May 27 '20 at 13:30
  • I created another questione because I think the problem is another: https://stackoverflow.com/questions/62046354/liferay-7-2-module-deploy-does-not-update-api – MarioProject May 27 '20 at 15:06