Fóruns

Início » Liferay Portal » English » 3. Development

Visualização combinada Visão plana Exibição em árvore
Tópicos [ Anterior | Próximo ]
toggle
Sergey B
How to submit objects to JSON web services?
23 de Abril de 2012 18:25
Resposta

Sergey B

Ranking: New Member

Mensagens: 15

Data de entrada: 20 de Novembro de 2011

Mensagens recentes

Using LR 6.1 CE on Tomcat. I have custom services generated by the service builder using remote-service="true" attribute, out of the box JSON UI provided by Liferay is working great. I can browse to it: http://localhost:8080/my-portlet/api/jsonws/ and retrieve objects, for example:

1
2GET: http://localhost:8080/my-portlet/api/secure/jsonws/item/retrieve-items
3RESPONSE: [{"companyId":10154,"itemId":1,"groupId":10198,"name":"Test Item 1","userId":10196},{"companyId":10154,"itemId":2,"groupId":10198,"name":"Test Item 2","userId":10196}]


But when I try to submit a similarly encoded object back for creation, it fails to get parsed correctly and all values comes through as 0 or null, for example:

1POST: http://localhost:8080/athletics-portlet/api/secure/jsonws/exercise/create
2POST parameters:
3newExercise:{"companyId":10154,"groupId":10198,"name":"Test Item 3","userId":10196}
4 newExercise:com.amstatz.model.impl.ExerciseImpl ----> This parameter has '+' in front of it and is needed for JSON Web Service to know what kind of object to the request is.
5RESPONSE: {"exception":"com.liferay.portal.NoSuchRoleException: No Role exists with the key {companyId=0, name=Owner}"}


Also tried submitting all the parameters as separate form fields, but that didn't work either. Is there an easy way to accomplish this, especially from Java?

Tried using CXF to expose the service, but couldn't get past an issue with missing namespace handlers, even tried manually aggregating these files and placing them in every imaginable location but LR still couldn't find it when deploying.

I would like to write a client to submit and read data to my custom services generated by the Service Builder (JSON, SOAP or other solutions as long as security is integrated), but finding it very difficult to find any working examples outside of simple hello world that submits a string and gets a string back. Any help would be greatly appreciated.
Olaf Kock
RE: How to submit objects to JSON web services?
9 de Maio de 2012 15:58
Resposta

Olaf Kock

LIFERAY STAFF

Ranking: Liferay Legend

Mensagens: 3428

Data de entrada: 23 de Setembro de 2008

Mensagens recentes

Sorry, can't help too much here. As you have mentioned in another thread, you're still looking for an answer here, so I reply, hoping that somebody will pick it up when it's more recently changed.
Have you compared this with the Liferay API JSON calls and implementation?
Juan Gonzalez
RE: How to submit objects to JSON web services?
9 de Maio de 2012 23:45
Resposta

Juan Gonzalez

LIFERAY STAFF

Ranking: Liferay Legend

Mensagens: 2795

Data de entrada: 28 de Outubro de 2008

Mensagens recentes

python shi
RE: How to submit objects to JSON web services?
22 de Novembro de 2012 18:03
Resposta

python shi

Ranking: New Member

Mensagens: 11

Data de entrada: 2 de Julho de 2012

Mensagens recentes

I also have the problem, in my POST json string contian a array object, it can't convert in service side.

my service method :
> public String searchFile(String userName, String keywords, ArrayList<String>
> folderPaths)
>
> POST json string:
> {"method":search-file,
> "params":{"keywords":"log4j.xml","userName":"pythonshi","folderPaths":["/officeHK/shipment-doc/air/export/August2012","/officeHK/shipment-doc/air/export/October­2012"]},
> "id":100, "jsonrpc":"2.0"}
> it return:
> {"id":100,"error":{"code":-32603,"message":"java.lang.ClassCastException:­
> Unable to cast value to type: java.util.ArrayList"},"jsonrpc":"2.0"}

If any configure to set the convertion?
Đỗ Nguyên Thạnh
RE: How to submit objects to JSON web services?
18 de Janeiro de 2013 17:36
Resposta

Đỗ Nguyên Thạnh

Ranking: New Member

Mensagens: 4

Data de entrada: 23 de Agosto de 2012

Mensagens recentes

same problem:
Unable to cast value to type: java.util.ArrayList"},"jsonrpc":"2.0"
can anyone help me solve this?
Zain Abideen
RE: How to submit objects to JSON web services?
24 de Janeiro de 2015 08:29
Resposta

Zain Abideen

Ranking: New Member

Mensagens: 5

Data de entrada: 8 de Agosto de 2014

Mensagens recentes

Hi

@sergey can you please post here the code snippet that you used to send this POST call... I need an example which combines inner parameters with object parameters.

Thanking you in anticipation