Fórum

How to inoke method via URL from a portlet with liferay service builder

Smilelws2010 lwz, modificado 11 Anos atrás.

How to inoke method via URL from a portlet with liferay service builder

Regular Member Postagens: 160 Data de Entrada: 16/12/10 Postagens Recentes
HI

I created a sample service builder portlet with service.xml having foo as entity name. I have made remote-service="true".

My service.xml build looks fine and the portlet in general looks good with all the methods working fine.

Now I want to call a method using jsonws/http url, the method is implemeted in the src/package/service - localserviceimpl.java. I have not coded anything in the serviceimpl.java

I have read the following post,
http://www.liferay.com/documentation/liferay-portal/6.1/development/-/ai/json-web-services What is the [plugincontext mentioned in this? Is it the name mentioned in the below line
<service name="Plugin_SubscriptionService" provider="java:RPC" style="rpc" use="encoded"></service>
] Please help me in calling jsonws or how to generate that one correctly.

Some quick tip or guidance will be very helpful.

Thanks
Smile.
thumbnail
Gnaniyar Zubair, modificado 11 Anos atrás.

RE: How to inoke method via URL from a portlet with liferay service builder

Liferay Master Postagens: 722 Data de Entrada: 19/12/07 Postagens Recentes
1) Create Service.xml with this entry "remoter-service=true".
2) Run ant build-service
3) Run build-wsdd
4) Write required method in <Entity>ServiceImpl.
5) Makesure all the methods are created in <Entity>ServiceUtil
6) Call the URL like this to Access the custom method which will return JSON object.

http://localhost:8080/<custom-portletName>/json/
serviceClassName=<fullpath of <Entity>ServiceUtil&serviceMethodName=<methodName mentioned in ServiceUtil>&serviceParameters=&<parameters>


you can access abouveURL through javascript from your JSP file.


- Gnaniyar Zubair
Smilelws2010 lwz, modificado 11 Anos atrás.

RE: How to inoke method via URL from a portlet with liferay service builder

Regular Member Postagens: 160 Data de Entrada: 16/12/10 Postagens Recentes
Thanks a lot Gnaniyar for the steps.

Okay I have actually followed all your steps earlier too. but the differene is even though I set remote-service true, i was coding in <entity?localserviceImpl java and not <<entity>serviceImpl. Is that the reason why it is not working?

So if you have remote setting true, You should code in <Entity>ServiceImpl and leave the <Entity>LocalServiceImpl just with the skeleton code?

Thanks again.

Smile
thumbnail
Gnaniyar Zubair, modificado 11 Anos atrás.

RE: How to inoke method via URL from a portlet with liferay service builder

Liferay Master Postagens: 722 Data de Entrada: 19/12/07 Postagens Recentes
Smilelws2010 lwz:
Thanks a lot Gnaniyar for the steps.

Okay I have actually followed all your steps earlier too. but the differene is even though I set remote-service true, i was coding in <entity?localserviceImpl java and not <<entity>serviceImpl. Is that the reason why it is not working?

So if you have remote setting true, You should code in <Entity>ServiceImpl and leave the <Entity>LocalServiceImpl just with the skeleton code?

Thanks again.

Smile


All the basic crud method will be generated in LocalServiceUtil class. If you wish to write your own business logic other than what service builder generates, then you should write the methods in LocalServiceImpl. If you have a plan to publish your services ( or accessing from external application) to other system, then you should write your business logic in serviceImpl.

- Gnaniyar Zubair
Smilelws2010 lwz, modificado 11 Anos atrás.

RE: How to inoke method via URL from a portlet with liferay service builder

Regular Member Postagens: 160 Data de Entrada: 16/12/10 Postagens Recentes
Thanks a lot for having patience.

It worked for me. I had my logic in localserviceImpl and then had a serviceImpl class to which basically called my methods which were in the localserviceImpl class and then used serviceutil class to call my methods and I can now call my methods using URL using the format yu gave me earlier.

Thanks a lot.

Smile
Smilelws2010 lwz, modificado 11 Anos atrás.

RE: How to inoke method via URL from a portlet with liferay service builder

Regular Member Postagens: 160 Data de Entrada: 16/12/10 Postagens Recentes
HI Gnaniyar,

On hitting the url http://localhost:8080/sample-portlet/api/jsonws/?serviceClassName=com.sample.service.SampleServiceUtil&serviceMethodName=findemail&serviceParameters=&email=abc@abc.com

It is prompting for user name, password. Is there a way to avoid that? I saw the property to be added in portlat-ext - json.service.auth.token.enabled=false, but did not do much help.

Any thoughts or referrance.

Smile
Smilelws2010 lwz, modificado 11 Anos atrás.

RE: How to inoke method via URL from a portlet with liferay service builder

Regular Member Postagens: 160 Data de Entrada: 16/12/10 Postagens Recentes
How do we pass multiple parameters in the URL format you suggested.

THanks a lot for all the help
Smile
Smilelws2010 lwz, modificado 11 Anos atrás.

RE: How to inoke method via URL from a portlet with liferay service builder

Regular Member Postagens: 160 Data de Entrada: 16/12/10 Postagens Recentes
I am good just figured it out. I had a typo in my URL.

THANKS
viral bhat, modificado 9 Anos atrás.

RE: How to inoke method via URL from a portlet with liferay service builder

New Member Postagens: 5 Data de Entrada: 05/05/14 Postagens Recentes
Gnaniyar Zubair:
1) Create Service.xml with this entry "remoter-service=true".
2) Run ant build-service
3) Run build-wsdd
4) Write required method in <Entity>ServiceImpl.
5) Makesure all the methods are created in <Entity>ServiceUtil
6) Call the URL like this to Access the custom method which will return JSON object.

http://localhost:8080/<custom-portletName>/json/
serviceClassName=<fullpath of <Entity>ServiceUtil&serviceMethodName=<methodName mentioned in ServiceUtil>&serviceParameters=&<parameters>


you can access abouveURL through javascript from your JSP file.


- Gnaniyar Zubair



Thanks it also worked for me.