Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
nic nic
JSON web services
July 13, 2012 8:43 AM
Answer

nic nic

Rank: New Member

Posts: 3

Join Date: August 3, 2009

Recent Posts

Hi,

I am new in Liferay and I am trying to use some of the JSON web services. The version I use is 6.1 CE bundled with tomcat 7.

I am trying to build a client using jersey http client to add a fileEntry but I get an error when the service is invoked.

"exception":"No JSON web service action associated with path /dlapp/add-file-entry and method POST for /"}

My code is :

ClientConfig cc = new DefaultClientConfig();
cc.getClasses().add(MultiPartWriter.class);

Client client = Client.create(cc);
client.addFilter(new HTTPBasicAuthFilter("test", "test123;;"));

WebResource webResource = client.resource(UriBuilder.fromUri("http://localhost:8080/api/jsonws/dlapp/add-file-entry").build());
// WebResource webResource = client.resource(UriBuilder.fromUri("http://localhost:8080/api/secure/jsonws/dlapp/get-file-entry").build());

File file = new File("C:/demo.txt");

FormDataMultiPart form = new FormDataMultiPart();
form.field("repositoryId", "12709");
form.field("folderId", "12887");
form.field("sourceFileName", "demo.txt");
form.field("title", "demo.txt");
form.field("file", file, MediaType.MULTIPART_FORM_DATA_TYPE);

// form.field("fileEntryId", "13102");

ClientResponse response = webResource.type(MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);

System.out.println(response.getEntity(String.class));

I have also tried to get a fileEntry (commented lines) and it works ok!

Any ideas what is wrong??

Any help would be much appreciated.
Hitoshi Ozawa
RE: JSON web services
July 14, 2012 2:08 AM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7949

Join Date: March 23, 2010

Recent Posts

That usually means your uri is wrong.

Go to the following address to check json api's and do a test upload using provided web from at the bottom of the page
http://localhost:8080/api/jsonws/

e.g.
http://localhost:8080/api/jsonws/?signature=/dlapp/add-file-entry-10-repositoryId-folderId-sourceFileName-mimeType-title-description-changeLog-is-size-serviceContext

http://localhost:8080/api/jsonws/dlapp/add-file-entry


I think there is a "secure" between the "api" and "jsonws"

BTW, your commented out uri has it. :-)
nic nic
RE: JSON web services
July 14, 2012 8:41 AM
Answer

nic nic

Rank: New Member

Posts: 3

Join Date: August 3, 2009

Recent Posts

Hi Hitoshi, thank you for the reply.

I have tried with the "secure" part in the url but the result was the same.

The code of the page http://localhost:8080/api/jsonws/?signature=/dlapp/add-file-entry-9-repositoryId-folderId-sourceFileName-mimeType-title-description-changeLog-file-serviceContext has a form action <form action="/api/secure/jsonws/dlapp/add-file-entry" enctype="multipart/form-data" id="execute" method="POST">
so the url seems to be the same and the action seems also to be the same.

When I upload a file from the web page it does work though while from the java code it doesn't !
The same thing happens with addFolder function.

I have tried coding with apache http client with MultipartEntity or BasicNameValuePair and UrlEncodedFormEntity but the result is still the same. I have no idea what I may be missing.

Any ideas?
Hitoshi Ozawa
RE: JSON web services
July 14, 2012 8:01 PM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7949

Join Date: March 23, 2010

Recent Posts

I just look at the source of the method's example page to get the uri and the form inputs.
nic nic
RE: JSON web services
July 16, 2012 3:58 AM
Answer

nic nic

Rank: New Member

Posts: 3

Join Date: August 3, 2009

Recent Posts

It was really stupid mistake....
it worked with httpclient, I had forgotten to include all the parameters in the request..

Thanks
Cesar Quinteiro
RE: JSON web services
February 8, 2013 10:48 AM
Answer

Cesar Quinteiro

Rank: Junior Member

Posts: 34

Join Date: October 18, 2011

Recent Posts

nic nic:
It was really stupid mistake....
it worked with httpclient, I had forgotten to include all the parameters in the request..

Thanks


can you please post the code that finally works for you

thanks

Participate in the State of Liferay Community 2017. Help the community and even win some prizes!