Rest api, services bean

Hi, I am trying to use rest-services.xml

Follow the next step of I am doing:
1.) Create Interface and Bean Services

package net.ezmovil.ezinfo.service;

import net.ezmovil.ezinfo.entity.Dpi;

public interface DpiService {
    String NAME = "ezinfo_DpiService";

    String dpiByFacesId(String faceid);
    String Test(String faceid);

}

package net.ezmovil.ezinfo.service;

import com.haulmont.cuba.core.EntityManager;
import com.haulmont.cuba.core.Persistence;
import com.haulmont.cuba.core.Transaction;
import org.springframework.stereotype.Service;

import javax.inject.Inject;

@Service(DpiService.NAME)
public class DpiServiceBean implements DpiService {

    @Inject
    private Persistence persistence;

    @Override
    public String dpiByFacesId(String faceid) {
        String _faceid = null;
        try (Transaction tx = persistence.createTransaction()) {
            EntityManager em = persistence.getEntityManager();
            _faceid = (String) em.createQuery("select cui_id from ezinfo$Faces f where f.id = :faceid")
                    .setParameter("faceid", faceid)
                    .getSingleResult();
            tx.commit();
        }

        return _faceid;
    }

    @Override
    public String Test(String faceid) {
        String _return = "Hola ezMovil";
        return _return;
    }
}

rest-services.xml

<?xml version="1.0" encoding="UTF-8"?>
<services xmlns="http://schemas.haulmont.com/cuba/rest-services-v2.xsd">
    <service name="ezinfo_DpiService">
        <method name="Test">
            <param name="stringParam" type="java.lang.String"/>
        </method>
    </service>
</services>

web-app.properties
cuba.rest.servicesConfig = +net/ezmovil/ezinfo/rest-services.xml
cuba.rest.client.id = client
cuba.rest.client.secret = secret
cuba.rest.client.tokenExpirationTimeSec = 300
cuba.rest.maxUploadSize = 20971520


2.) Consume LOGIN v2 REST API

http://192.168.0.6:8080/ezinfo/rest/v2/oauth/token
Headers , Body …
This returm me the token

3.) Consume my Services
http://192.168.0.6:8080/ezinfo/rest/v2/services/ezinfo_DpiService/Test

Headers:
Authorization : Bearer acb8ff15-b58c-4507-8fe1-4368d3d144c0
Content-type : application/json

Return me:

{
“error”: “Service method not found”,
“details”: “ezinfo_DpiService.Test()”
}

Guys , what do you think I am doing bad ?
I use the documentation from 6.4.

Hi guys, I setup “rest-services.xml” under main root package +net.ezmovil.net but this directory under web have other “web” name directory, where exactly could be the “rest-services.xml” ?

Hi,

You should pass stringParam parameter e.g:

http://192.168.0.6:8080/ezinfo/rest/v2/services/ezinfo_DpiService/Test?stringParam=foo

Thanks Vlad, i consume using this but thas its like GET and works well, but how is using POST, do you have other example.

Regards

In case of POST you need to send JSON in request body:

{
  "stringParam": "foo"
}