Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
Smilelws2010 lwz
How to inoke method via URL from a portlet with liferay service builder
January 18, 2013 1:38 PM
Answer

Smilelws2010 lwz

Rank: Regular Member

Posts: 153

Join Date: December 16, 2010

Recent Posts

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
1<service name="Plugin_SubscriptionService" provider="java:RPC" style="rpc" use="encoded">
] Please help me in calling jsonws or how to generate that one correctly.

Some quick tip or guidance will be very helpful.

Thanks
Smile.
Gnaniyar Zubair
RE: How to inoke method via URL from a portlet with liferay service builder
January 19, 2013 3:36 AM
Answer

Gnaniyar Zubair

Rank: Liferay Master

Posts: 601

Join Date: December 19, 2007

Recent Posts

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
RE: How to inoke method via URL from a portlet with liferay service builder
January 22, 2013 5:51 AM
Answer

Smilelws2010 lwz

Rank: Regular Member

Posts: 153

Join Date: December 16, 2010

Recent Posts

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
Gnaniyar Zubair
RE: How to inoke method via URL from a portlet with liferay service builder
January 23, 2013 3:55 AM
Answer

Gnaniyar Zubair

Rank: Liferay Master

Posts: 601

Join Date: December 19, 2007

Recent Posts

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
RE: How to inoke method via URL from a portlet with liferay service builder
January 24, 2013 6:30 AM
Answer

Smilelws2010 lwz

Rank: Regular Member

Posts: 153

Join Date: December 16, 2010

Recent Posts

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
RE: How to inoke method via URL from a portlet with liferay service builder
January 24, 2013 10:01 AM
Answer

Smilelws2010 lwz

Rank: Regular Member

Posts: 153

Join Date: December 16, 2010

Recent Posts

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
RE: How to inoke method via URL from a portlet with liferay service builder
February 7, 2013 11:00 AM
Answer

Smilelws2010 lwz

Rank: Regular Member

Posts: 153

Join Date: December 16, 2010

Recent Posts

How do we pass multiple parameters in the URL format you suggested.

THanks a lot for all the help
Smile
Smilelws2010 lwz
RE: How to inoke method via URL from a portlet with liferay service builder
February 7, 2013 11:16 AM
Answer

Smilelws2010 lwz

Rank: Regular Member

Posts: 153

Join Date: December 16, 2010

Recent Posts

I am good just figured it out. I had a typo in my URL.

THANKS