Fórum

Access Liferay Rest Service using Java

thumbnail
Sebastian Sommerfeld, modificado 10 Anos atrás.

Access Liferay Rest Service using Java

Junior Member Postagens: 40 Data de Entrada: 06/12/10 Postagens Recentes
Hi guys

I'm trying to access one of liferays built-in rest Services via Java. This is the URL (GET-Request):
http://SERVERNAME/api/jsonws/user/get-user-by-email-address/company-id/" + companyId + "/email-address/" + email

The response is always stating {"exception":"Authenticated access required"}.

Does anybody know how I can pass login information? If nesseccary I would switch to POST, but I still need a hint for authentication.

Update: I'm using liferay 6.2

Can anybody help me out please?

Thanks and regards
Sebastian
thumbnail
Harish Kumar, modificado 10 Anos atrás.

RE: Access Liferay Rest Service using Java

Expert Postagens: 483 Data de Entrada: 31/07/10 Postagens Recentes
You can pass the credentials as part of url like below

http://youremail@emailhost.com:password@yourHost.com:8080/api/secure/jsonws/user/get-user-by-email-address/company-id/10154/email-address/test%40liferay.com
thumbnail
Sebastian Sommerfeld, modificado 10 Anos atrás.

RE: Access Liferay Rest Service using Java

Junior Member Postagens: 40 Data de Entrada: 06/12/10 Postagens Recentes
Great thanks. Be arware, that you have to encode the username if your liferay is using email instead of screenname. test@liferay.com will break the url, test%40liferay.com won't.

http://youremail%40emailhost.com:password@yourHost.com:8080/api/secure/jsonws/user/get-user-by-email-address/company-id/10154/email-address/test%40liferay.com

So now I'm able to consume the service. But now I got another issue. I'm trying to deserialise the json string using Google Gson.

String service = ... /// the url
ClientRequest cr = new ClientRequest(service);
String json = cr.post(String.class).getEntity();
User user = new Gson().fromJson(json, User.class);

The response is this error: Unable to invoke no-args constructor for interface com.liferay.portal.model.User. Register an InstanceCreator with Gson for this type may fix this problem.

Thats because User is an interface and not instanceable. How can I convert the json string to an object that I don't have to write on my own? Is there a class implementing com.liferay.portal.model.User that I can use instead of the interface?

Thanks for your help and regards.
Sebastian
thumbnail
Harish Kumar, modificado 10 Anos atrás.

RE: Access Liferay Rest Service using Java

Expert Postagens: 483 Data de Entrada: 31/07/10 Postagens Recentes
Sebastian,

you can make use of UserImpl .
thumbnail
Sebastian Sommerfeld, modificado 10 Anos atrás.

RE: Access Liferay Rest Service using Java

Junior Member Postagens: 40 Data de Entrada: 06/12/10 Postagens Recentes
Hi guys

I'm able to comsume some services now. For a few days actually. Previous tipps proved to be helpful. For converting JSON to Java-class I'm using a small helper class to map JSON params to class members - something I initially tried to avoid but turned out be helpful and not that much work after all.

Now I'm running into a strange Problem. Some Services work fine, some not. I cannot consume the expando JSON Service.

URL
http://ext2365s:8380/api/jsonws/expandovalue/get-json-data/company-id/10157/class-name/com.liferay.portal.model.User/table-name/CUSTOM_FIELDS/column-name/customernumbers/classpk/11402


Result (doesn't matte if I'm logged in or anonymous):
Sometimes:  Forbidden - You do not have permission to access the requested resource.
Most of the times: {"exception":"No JSON web service action associated with path /expandovalue/get-json-data and method GET for /"}


Using GET or POST makes no difference. The permissions for my field are set at least to view for all roles (guest, power user, user, owner). Owner has all permissions checked.


Does anyone know how I can consume the expando get-data Service? If there is a bigger issue I would be open to some kind of workaround. Maybe there are some additional soap services so I can call another service to get my expando values ...

Thanks guys and regards
Sebastian
thumbnail
Tomáš Polešovský, modificado 10 Anos atrás.

RE: Access Liferay Rest Service using Java

Liferay Master Postagens: 676 Data de Entrada: 13/02/09 Postagens Recentes
Hi Sebastian,

do you use preemptive authentication?

Thanks.
thumbnail
Anil T, modificado 9 Anos atrás.

RE: Access Liferay Rest Service using Java

Expert Postagens: 313 Data de Entrada: 14/01/12 Postagens Recentes
Hi,

I too had the same issue with the expando fields rest api. I am able to update the custom field value from the browser but same link is not working from the java application.

Facing following exception;

{"exception":"No JSON web service action associated with path \/expandovalue\/add-value and method POST for \/"}


Please provide some solution if anyone has got solution.

Thanks,
Anil T