Fórumok
Access Liferay Rest Service using Java
Sebastian Sommerfeld, módosítva 10 év-val korábban
Access Liferay Rest Service using Java
Junior Member Bejegyzések: 40 Csatlakozás dátuma: 2010.12.06. Legújabb bejegyzések
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
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
Harish Kumar, módosítva 10 év-val korábban
RE: Access Liferay Rest Service using Java
Expert Bejegyzések: 483 Csatlakozás dátuma: 2010.07.31. Legújabb bejegyzések
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
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
Sebastian Sommerfeld, módosítva 10 év-val korábban
RE: Access Liferay Rest Service using Java
Junior Member Bejegyzések: 40 Csatlakozás dátuma: 2010.12.06. Legújabb bejegyzések
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
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
Harish Kumar, módosítva 10 év-val korábban
RE: Access Liferay Rest Service using Java
Expert Bejegyzések: 483 Csatlakozás dátuma: 2010.07.31. Legújabb bejegyzések
Sebastian,
you can make use of UserImpl .
you can make use of UserImpl .
Sebastian Sommerfeld, módosítva 10 év-val korábban
RE: Access Liferay Rest Service using Java
Junior Member Bejegyzések: 40 Csatlakozás dátuma: 2010.12.06. Legújabb bejegyzések
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
Result (doesn't matte if I'm logged in or anonymous):
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
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
Tomáš Polešovský, módosítva 10 év-val korábban
RE: Access Liferay Rest Service using Java
Liferay Master Bejegyzések: 676 Csatlakozás dátuma: 2009.02.13. Legújabb bejegyzések
meera prince, módosítva 10 év-val korábban
RE: Access Liferay Rest Service using Java
Liferay Legend Bejegyzések: 1111 Csatlakozás dátuma: 2011.02.08. Legújabb bejegyzések
Hi
Please have a look into following link
http://www.liferaysavvy.com/2014/02/liferay-plugin-portlet-json-web_2559.html
http://www.liferaysavvy.com/2012/11/java-client-to-consuming-liferay-json.html
http://www.liferaysavvy.com/2012/11/liferay-android-application.html
Regards,
Meera Prince
Please have a look into following link
http://www.liferaysavvy.com/2014/02/liferay-plugin-portlet-json-web_2559.html
http://www.liferaysavvy.com/2012/11/java-client-to-consuming-liferay-json.html
http://www.liferaysavvy.com/2012/11/liferay-android-application.html
Regards,
Meera Prince
Anil T, módosítva 9 év-val korábban
RE: Access Liferay Rest Service using Java
Expert Bejegyzések: 313 Csatlakozás dátuma: 2012.01.14. Legújabb bejegyzések
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
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