0

I have created service using service builder and put the sample entity in liferay service.xml file.

My service.xml

<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.2.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_2_0.dtd">
<service-builder package-path="com.temp">
  <namespace></namespace>

  <entity name="Student" local-service="true" remote-service="true">
  </entity>

  <entity name="Foo" uuid="true" local-service="true" remote-service="true">
    <!-- PK fields -->
    <column name="fooId" type="long" primary="true" />

    <!-- 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 package-path="com.liferay.portlet.asset" entity="AssetEntry" />
    <reference package-path="com.liferay.portlet.asset" entity="AssetTag" />
  </entity>
</service-builder>

after building the service I have added one method in FooServiceImpl.java as below,

@JSON
public JSONObject verifyService (String action){
  System.out.println("action----->"+action);
  JSONObject actionData=JSONFactoryUtil.createJSONObject();

  actionData.put("success", true);
  return actionData;
}

I build the service and able to access it via localhost:8080/api/jsonws with admin credential.

Now when I call this service with below curl command

curl http://localhost:8080/api/jsonws/XXXX-Portlets.foo/verify-service -u test@liferay.com:test -d action='temp'

I am able to get the action parameter value in my implemented method. Now I would like to get below value posted from curl,

curl http://localhost:8080api/jsonws/XXXXX-Portlets.foo/verify-service -u test@liferay.com:test -d '{"action":"verify"}'

I am not able to get this json in my web service!!

I have tried adding the following

curl -H "Content-Type: application/json" -H "Accept: application/json -XPOST ...."

to curl and change the parameter type from string to jsonObject but no luck.

Is there any annotation I'm missing here?

Nekresh
  • 2,948
  • 23
  • 28
Abhishek Suthar
  • 674
  • 1
  • 8
  • 27
  • What do you want is to pass JSON object as parameter to remote service, right? – Parkash Kumar Oct 07 '15 at 08:30
  • http://stackoverflow.com/questions/19296578/passing-json-object-in-url-of-restful-web-service-in-android – Parkash Kumar Oct 07 '15 at 08:32
  • parkash I am able to get it by below URL , curl http://localhost:8080/api/jsonws/XXXX-Portlets.foo/verify-service \ -u test@liferay.com:test \ -d action='{"action":"verify"}'. But if I am hitting like second CURL command shown in description then i am not able to get the this '{"action":"verify"}'. – Abhishek Suthar Oct 07 '15 at 08:55
  • URL parameter is key-value pair. Therefore, you need to pass it like action='{"action":"verify"}', where left hand side action is name of the param. – Parkash Kumar Oct 07 '15 at 09:12
  • Well, if you are passing single value for action, then why are you bothered to pass JSON object. just pass it like action=verify – Parkash Kumar Oct 07 '15 at 09:13
  • That is the issue I want to handle the json paramter like second approach only (-d '{"action":"verify"}') that is why I have asked this question.I don't want to pass like action = 'paramter value'... – Abhishek Suthar Oct 07 '15 at 11:02
  • ultimately I want the second approach of curl to be handle with my webservice ...how can I do that... – Abhishek Suthar Oct 07 '15 at 11:05

0 Answers0