Foren

Web service with file parameter

Asterios Vounotrypidis, geändert vor 8 Jahren.

Web service with file parameter

New Member Beiträge: 3 Beitrittsdatum: 23.09.14 Neueste Beiträge
Hi, I am trying to create a web service with a file parameter. For example:

@JSONWebService(method = "POST")
public void dadlImport (File file) {
System.out.println ("FILE");
}

But I get this error:
No JSON web service action with path ... and method null for //{{projectname}}

Is there anybody who can tell me what to do to fix this problem.

Thank you very much.
thumbnail
Chandan Sharma, geändert vor 8 Jahren.

RE: Web service with file parameter

Junior Member Beiträge: 63 Beitrittsdatum: 28.05.12 Neueste Beiträge
When you have a Json Webservice with parameters then you have to call the service using same parameter otherwise you will get the following error.

No JSON web service action associated with path /testsrv/test-method and method POST for //test-portlet

let's have an example:

@JSONWebService(value="test-method", method="POST")
   public void testMethod(String messageId, Map data) {
             ...
 }


if you call this method using jquery and "data" variable is not a valid map object then you will get this error:
$.post('/api/jsonws/test-portlet.testsrv/test-method', {
              "messageId" : messageId,
           "data" :   data
  });

but on the other hand if we parse the "data" object as a valid map object or json (json is a valid map object in javascript) then you will not get the error.

var dataStr = JSON.stringify(data);
     $.post('/api/jsonws/test-portlet.testsrv/test-method', {
             "messageId" : messageId,
           "data" :   dataStr
     });


So My suggestion is to pass the proper parameter to overcome the problem.

Thanks
Chandan
Asterios Vounotrypidis, geändert vor 8 Jahren.

RE: Web service with file parameter

New Member Beiträge: 3 Beitrittsdatum: 23.09.14 Neueste Beiträge
I would like to upload a file. Lets see an example:

See image 1 what I wrote in eclipse.
Then image 2 what I try to do in api/jsonws?

and then image3 -> the error in eclipse... which is: (06:28:59,338 ERROR [http-bio-8086-exec-61][JSONWebServiceServiceAction:97] No JSON web service action with path /patientassessment/dadl-import and method null for //...)
thumbnail
Chandan Sharma, geändert vor 8 Jahren.

RE: Web service with file parameter (Antwort)

Junior Member Beiträge: 63 Beitrittsdatum: 28.05.12 Neueste Beiträge
Hi Asterios Vounotrypidis,

There is no problem with your method, as i said the rest call is not posting the proper parameter to the server that's why you are getting this error.

It seems Liferay JSON UI has some limitation to call the post service with file parameter. I also got the same problem. but you can achieve this using java rest client. and to test this service you can use chrome Advance Rest Client plugin. see the below example i have created.

method:
@JSONWebService(method = "POST")
	public JSONObject getSomeFile(File file){
		JSONObject obj = null;
		System.out.println("my file uploaded...");
		obj = JSONFactoryUtil.createJSONObject();
		obj.put("name", "Chandan");
		obj.put("job", "architect");
		return obj;
	}


test this method using Advance Rest Client in Chrome:

Thanks
Chandan