Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
k venkatesh
How to generate json api for plugins portlet
April 17, 2012 10:11 PM
Answer

k venkatesh

Rank: Junior Member

Posts: 50

Join Date: February 20, 2012

Recent Posts

Hi all,
I want to generate json api calls from java script for plugins portlet in Liferay6.0.6.I am familier with ext development, but I am unable to generate json api for plugins portlet, If any one knows please reply as early as possible.

Thanks In advance.
Ravi Kumar Gupta
RE: How to generate json api for plugins portlet
April 17, 2012 10:41 PM
Answer
k venkatesh
RE: How to generate json api for plugins portlet
April 18, 2012 9:18 PM
Answer
Ravi Kumar Gupta
RE: How to generate json api for plugins portlet
April 18, 2012 10:14 PM
Answer

Ravi Kumar Gupta

Rank: Liferay Legend

Posts: 1303

Join Date: June 23, 2009

Recent Posts

What do you want to say here.. ?
k venkatesh
RE: How to generate json api for plugins portlet
April 18, 2012 11:10 PM
Answer

k venkatesh

Rank: Junior Member

Posts: 50

Join Date: February 20, 2012

Recent Posts

sorry Ravi kumar I forgot to mention my message,
I followed the links what you have given to me, but it is for ext environment.
I want to call Json service api from javascript in plugins development. If you know any idea please let me know.
k venkatesh
RE: How to generate json api for plugins portlet
April 27, 2012 2:26 AM
Answer

k venkatesh

Rank: Junior Member

Posts: 50

Join Date: February 20, 2012

Recent Posts

Please can any one help me to generate Json Service api for plugins portlet. Still I am unable to generate these Json service api for plugins.
Thanks in advance.
Michał Kolenda
RE: How to generate json api for plugins portlet
April 27, 2012 2:37 AM
Answer

Michał Kolenda

Rank: New Member

Posts: 18

Join Date: November 25, 2010

Recent Posts

k venkatesh:
Please can any one help me to generate Json Service api for plugins portlet. Still I am unable to generate these Json service api for plugins.
Thanks in advance.


Describe your problem more precisely, please. What do you mean by writing that you are unable to generate JSON service API for plugins? The ant build-service task doesn't work?
k venkatesh
RE: How to generate json api for plugins portlet
April 27, 2012 9:35 PM
Answer

k venkatesh

Rank: Junior Member

Posts: 50

Join Date: February 20, 2012

Recent Posts

I have generated Javascript Json Api calls in Liferay 5.2.1 ext environment according to this "http://www.liferay.com/community/wiki/-/wiki/1071674/JSON+Service+API/maximized" link.

Now I am working in Liferay 6.0.6 in plugins development.The same stuff what I have followed in above link that I want to generate in plugins environment, but it is not working.

Did I miss anything for your queries ,let me Know.

please can any one suggest me ,this would be great helpful to me

Thanks in advance.
Joe D
RE: How to generate json api for plugins portlet
July 23, 2012 1:51 PM
Answer

Joe D

Rank: New Member

Posts: 12

Join Date: April 19, 2012

Recent Posts

Hi,

Does anyone have this working? We're using Liferay 6.1 and we have two separate plugins: ext (abc-portal-ext) and service builder (xyz-service-portlet)

I want to generate JSON from the service builder. Is there any way to do it? I read a lot of document but they're all refer to the old EXT environment which service builder is build in there.

The ext_service.js (or /ext/service.js) is not generate at all when I do ant compile deploy on ext plug-in.

Thanks
Harish Kumar
RE: How to generate json api for plugins portlet
July 24, 2012 9:01 AM
Answer

Harish Kumar

Rank: Expert

Posts: 474

Join Date: July 31, 2010

Recent Posts

Hi Joe,


Joe D:
Hi,

Does anyone have this working? We're using Liferay 6.1 and we have two separate plugins: ext (abc-portal-ext) and service builder (xyz-service-portlet)

I want to generate JSON from the service builder. Is there any way to do it? I read a lot of document but they're all refer to the old EXT environment which service builder is build in there.

The ext_service.js (or /ext/service.js) is not generate at all when I do ant compile deploy on ext plug-in.

Thanks


Following are the steps to register and expose your custom portlet to JSON API -

1. Annotate xyzServiceImpl class with @JSONWebService

2. Add the following snippet in portlet's web.xml -

<servlet>
<servlet-name>JSON Web Service Servlet</servlet-name>
<servlet-class>com.liferay.portal.kernel.servlet.PortalClassLoaderServlet</servlet-class>
<init-param>
<param-name>servlet-class</param-name>
<param-value>com.liferay.portal.jsonwebservice.JSONWebServiceServlet</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>JSON Web Service Servlet</servlet-name>
<url-pattern>/api/jsonws/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>JSON Web Service Servlet</servlet-name>
<url-pattern>/api/secure/jsonws/*</url-pattern>
</servlet-mapping>

3. build and deploy the portlet. A file named service.js will be created in the docroot/js folder.

4. you can check the list of registered services with http://localhost:8080/<portlet>/api/jsonws


I've tried this on Liferay 6.1EE and its working fine!!


HTH
Regards
Harish Kumar
RE: How to generate json api for plugins portlet
July 24, 2012 9:09 AM
Answer

Harish Kumar

Rank: Expert

Posts: 474

Join Date: July 31, 2010

Recent Posts

Hi Venkatesh,


k venkatesh:
I have generated Javascript Json Api calls in Liferay 5.2.1 ext environment according to this "http://www.liferay.com/community/wiki/-/wiki/1071674/JSON+Service+API/maximized" link.

Now I am working in Liferay 6.0.6 in plugins development.The same stuff what I have followed in above link that I want to generate in plugins environment, but it is not working.

Did I miss anything for your queries ,let me Know.

please can any one suggest me ,this would be great helpful to me

Thanks in advance.



Following is sample code snippet using AUI to retrieve the list of MBCategory -

<script src="/html/js/liferay/service.js" type="text/javascript"></script>
<span id="resultDiv"></span>

<script>
var A = AUI();
A.use('aui-io-request', function(aui) {
Liferay.Service.MB.MBCategory.getCategories({
groupId : themeDisplay.getScopeGroupId()
}, function(message) {
var exception = message.exception;
if (!exception) {
var result = '';
for(var i=0;i<message.length;i++)
{
result = result + (i+1) + ". " + message.name + "<br/>";
}
document.getElementById("resultDiv").innerHTML = result;
} else {
alert("fail");
}
});
});

</script>



HTH
Regards,
Joe D
RE: How to generate json api for plugins portlet
July 25, 2012 6:18 PM
Answer

Joe D

Rank: New Member

Posts: 12

Join Date: April 19, 2012

Recent Posts

Thanks a lot Harish.

When I tried to access http://localhost:8080/xyz-service-portlet/api/jsonws I got: 404 - File or directory not found.
Harish Kumar
RE: How to generate json api for plugins portlet
July 26, 2012 11:01 PM
Answer

Harish Kumar

Rank: Expert

Posts: 474

Join Date: July 31, 2010

Recent Posts

Hi Joe,

Joe D:
Thanks a lot Harish.

When I tried to access http://localhost:8080/xyz-service-portlet/api/jsonws I got: 404 - File or directory not found.


Are you able to access liferay JSONWS API using http://localhost:8080/api/jsonws

Regards,
Joe D
RE: How to generate json api for plugins portlet
July 30, 2012 8:21 PM
Answer

Joe D

Rank: New Member

Posts: 12

Join Date: April 19, 2012

Recent Posts

Hi Harish,

Yes, I able to access http://localhost:8080/api/jsonws but not my custom plugin.

Do you have any issues when you do build-wsdd? I could not get it to work if the return-type="Collection" for finder methods.
Here is the thread.

http://www.liferay.com/community/forums/-/message_boards/message/12889759


Thanks
Armaz Mellati
RE: How to generate json api for plugins portlet
October 16, 2012 6:52 AM
Answer

Armaz Mellati

Rank: Junior Member

Posts: 94

Join Date: October 30, 2009

Recent Posts

Harish Kumar:


4. you can check the list of registered services with http://localhost:8080/<portlet>/api/jsonws



Hi

I wish someone could say something about what the <portlet> part is for a portlet called "foo". Is it the portlet ID as foo_WAR_fooportlet ? or is it just "foo" ? Or something else ? I have not been able to find out what that should be.

Hope someone can help.

Regards
Armaz
Harish Kumar
RE: How to generate json api for plugins portlet
October 16, 2012 9:40 PM
Answer

Harish Kumar

Rank: Expert

Posts: 474

Join Date: July 31, 2010

Recent Posts

Hi Armaz

Its portlet context i.e your portlet project name.
Nehal Hyder
RE: How to generate json api for plugins portlet
April 9, 2013 5:26 AM
Answer

Nehal Hyder

Rank: New Member

Posts: 2

Join Date: July 23, 2012

Recent Posts

Please add this in web.xml of the project and i hope issue will be solved..if anybody is facing this issue..
for me its solved now

<listener>
<listener-class>com.liferay.portal.kernel.spring.context.PortletContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>JSON Servlet</servlet-name>
<servlet-class>com.liferay.portal.kernel.servlet.PortalClassLoaderServlet</servlet-class>
<init-param>
<param-name>servlet-class</param-name>
<param-value>com.liferay.portal.servlet.JSONServlet</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>JSON Servlet</servlet-name>
<url-pattern>/api/json/*</url-pattern>
</servlet-mapping>

Participate in the State of Liferay Community 2017. Help the community and even win some prizes!