Message Boards

JSON Web Service not appearing in /api/jsonws

Christopher Virtucio, modified 6 Years ago.

JSON Web Service not appearing in /api/jsonws

Junior Member Posts: 33 Join Date: 9/26/17 Recent Posts
Hi.

I used service-builder to generate a simple bundle. I followed the tutorial for registering the service as a JSON Web Service. This is the interface:

@JSONWebService
@OSGiBeanProperties(property =  {
	"json.web.service.context.name=bar", "json.web.service.context.path=Foo"}, service = FooService.class)
@ProviderType
@Transactional(isolation = Isolation.PORTAL, rollbackFor =  {
	PortalException.class, SystemException.class})
public interface FooService extends BaseService {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this interface directly. Always use {@link FooServiceUtil} to access the foo remote service. Add custom service methods to {@link com.liferay.docs.tasks.service.impl.FooServiceImpl} and rerun ServiceBuilder to automatically copy the method declarations to this interface.
	 */

	/**
	* Returns the OSGi service identifier.
	*
	* @return the OSGi service identifier
	*/
	public java.lang.String getOSGiServiceIdentifier();	
}


And this is the implementation:


@ProviderType
@Component(
        service = FooService.class
        )
public class FooServiceImpl extends FooServiceBaseImpl {

    @JSONWebService
    public String hello() {
        // TODO Auto-generated method stub
        return "Hello, world";
    }
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never reference this class directly. Always use {@link com.liferay.docs.tasks.service.FooServiceUtil} to access the foo remote service.
	 */


Much appreciated.
thumbnail
Ashish Singh, modified 6 Years ago.

RE: JSON Web Service not appearing in /api/jsonws

Junior Member Posts: 45 Join Date: 12/1/16 Recent Posts
All remote-enabled services (i.e., service.xml entities with the property remote-service="true") are exposed as JSON web services.
https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/registering-json-web-services

Please check if you have added this property.
Christopher Virtucio, modified 6 Years ago.

RE: JSON Web Service not appearing in /api/jsonws

Junior Member Posts: 33 Join Date: 9/26/17 Recent Posts
Ashish Singh:
All remote-enabled services (i.e., service.xml entities with the property remote-service="true") are exposed as JSON web services.
https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/registering-json-web-services

Please check if you have added this property.


Hi, thanks for responding.

My service.xml file has the required properties.


<!--?xml version="1.0"?-->


<service-builder package-path="com.liferay.docs.tasks">
        <namespace>FOO</namespace>
        <entity local-service="true" name="Foo" remote-service="true" uuid="true">

                <!-- PK fields -->

                <column name="fooId" primary="true" type="long" />

                <!-- Group instance -->

                <column name="groupId" type="long" />

                <!-- Audit fields -->

                <column name="companyId" type="long" />
                <column name="userId" type="long" />
                <column name="userName" type="String" />
                <column name="createDate" type="Date" />
                <column name="modifiedDate" type="Date" />

                <!-- Other fields -->

                <column name="field1" type="String" />
                <column name="field2" type="boolean" />
                <column name="field3" type="int" />
                <column name="field4" type="Date" />
                <column name="field5" type="String" />

                <!-- Order -->

                <order by="asc">
                        <order-column name="field1" />
                </order>

                <!-- Finder methods -->

                <finder name="Field2" return-type="Collection">
                        <finder-column name="field2" />
                </finder>

                <!-- References -->

                <reference entity="AssetEntry" package-path="com.liferay.portlet.asset" />
                <reference entity="AssetTag" package-path="com.liferay.portlet.asset" />
        </entity>
</service-builder>


Both the api and service bundles are also able to start, resolve and install correctly. They appear as ACTIVE when I run blade sh lb.
Christopher Virtucio, modified 6 Years ago.

RE: JSON Web Service not appearing in /api/jsonws

Junior Member Posts: 33 Join Date: 9/26/17 Recent Posts
Bump.
Christopher Virtucio, modified 6 Years ago.

RE: JSON Web Service not appearing in /api/jsonws

Junior Member Posts: 33 Join Date: 9/26/17 Recent Posts
I did some debugging and none of this class's methods get called when I deploy the bundles: https://github.com/liferay/liferay-portal/blob/master/portal-impl/src/com/liferay/portal/jsonwebservice/JSONWebServiceActionsManagerImpl.java.

I'm pretty sure these have something to do with JSONWebService registration because they fire off when the core services are loaded on startup.
thumbnail
Fernando Fernandez, modified 6 Years ago.

RE: JSON Web Service not appearing in /api/jsonws

Expert Posts: 396 Join Date: 8/22/07 Recent Posts
Hi,

Not sure if this helps or even if it's related to the problem but I seem to remember that, in 6.2, just enabling the remote service was not enough. The local methods were created automatically in *LocalServiceImpl but the remote methods had to be created manually in the *ServiceImpl class.

I haven't done this from scratch in 7, so I don't know what changed.

HTH anyway.

Fernando
Christopher Virtucio, modified 6 Years ago.

RE: JSON Web Service not appearing in /api/jsonws

Junior Member Posts: 33 Join Date: 9/26/17 Recent Posts
Fernando Fernandez:
Hi,

Not sure if this helps or even if it's related to the problem but I seem to remember that, in 6.2, just enabling the remote service was not enough. The local methods were created automatically in *LocalServiceImpl but the remote methods had to be created manually in the *ServiceImpl class.

I haven't done this from scratch in 7, so I don't know what changed.

HTH anyway.

Fernando


Well, I added a simple method that returns a String to the *ServiceImpl, and that didn't seem to work. I also tried re-running mvn service-builder:build after adding the custom method (the Javadoc says this is required to add the method to the *Service interface; this should really be in the official documentation........). That didn't work either.

Since you mentioned *LocalServiceImpl, I decided to try adding one of its methods to *ServiceImpl and then re-running mvn service-builder:build to re-create the *Service interface. No dice........
Chris Lynch, modified 5 Years ago.

RE: JSON Web Service not appearing in /api/jsonws

New Member Posts: 4 Join Date: 4/1/14 Recent Posts
Was there a solution?   We are experiencing the same issue.
Chris Lynch, modified 5 Years ago.

RE: JSON Web Service not appearing in /api/jsonws

New Member Posts: 4 Join Date: 4/1/14 Recent Posts
The problem centers around the schemaVersion problem of the Release_ table. This column does not exist in 6.2. During the upgrade process the schemaVersion column is set to 0.0.1 for an existing service. Meanwhile the bnd file defaults to Liferay-Require-SchemaVersion: 1.0.0.This can be overcome by extending UpgradeStepRegistrator to change the version from 0.0.1 to 1.0.0.