Fórum

Create JSON web service Portlet

thumbnail
hamza jemai, modificado 10 Anos atrás.

Create JSON web service Portlet

Junior Member Postagens: 40 Data de Entrada: 04/12/12 Postagens Recentes
Hi,
Can anyone know how to create JSON web service using JAVA, and can i create a portlet how generate JSON file and consume them in the same portlet or i should create a service liferay to create the JSON and consume his output in anather portlet?
Thannks
thumbnail
subhash lamba, modificado 10 Anos atrás.

RE: Create JSON web service Portlet

Regular Member Postagens: 136 Data de Entrada: 07/07/13 Postagens Recentes
Hi hamza jemai..
You can easly create JSON web service in portlet.
and also you can access in another portlet. But my suggestion is if you wont to access only in another portlet then no need to create JOSN web service you need to create local Services and you can access in another portlet.
what is you requirement plz tell me?
thumbnail
hamza jemai, modificado 10 Anos atrás.

RE: Create JSON web service Portlet

Junior Member Postagens: 40 Data de Entrada: 04/12/12 Postagens Recentes
Hi subhash lamba,
Thanks for your reply, i have a javascript file in my portlet how need a JSON file, this file contains same data from my dataBase, so i need to create a json file in a web Service with java to crete this file dinamiclly from my DB. I have learned that Liferay give us JSON Service to generate file, so how can i do this.
Thanks
thumbnail
subhash lamba, modificado 10 Anos atrás.

RE: Create JSON web service Portlet

Regular Member Postagens: 136 Data de Entrada: 07/07/13 Postagens Recentes
create web service like this...

1. Go to service/impl folder which is generated after bould the services.
2. XXXServiceImpl.java file where XXX is you DB table name
3.

@JSONWebService
public String planResubscription(long userId,long newPlanId,String subscriptionType) throws SystemException, PortalException
{
return "your data"
}
4. Bould the service
5. Copy *.service.jar and paste to lib/ext folder in tomcat.

------------------------------------------------------------------

This is another way to access JSON responce. May b You require like this


1. Create method in you controller

@ResourceMapping(value="getPlan")
@ResponseBody
public void getPlan(ResourceRequest request,ResourceResponse response) throws PortalException, SystemException, IOException
{

long planId=Long.parseLong(request.getParameter("planId"));
plan planData= planLocalServiceUtil.getplan(planId);
System.out.println(planData.getPlanDescription());
JSONObject json = JSONFactoryUtil.createJSONObject();
json.put("description", planData.getPlanDescription());
json.put("planName", planData.getPlanTitle());
json.put("planPrice", planData.getPlanPriceMonthly());
json.put("planPriceYearly", planData.getPlanPriceYearly());
json.put("planId", planData.getPlanId());
json.put("planFeature1", planData.getPlanFeature1());
json.put("planFeature2", planData.getPlanFeature2());
json.put("planFeature3", planData.getPlanFeature3());
response.getWriter().write(json.toString());
}
2. Generate URL
<portlet:resourceURL var="getPlan" id="getPlan" ></portlet:resourceURL>

3. Code in you jsp file (java script)

$.ajax({
dataType: "json",
url:"<%= getPlan %>",
data:{planId:event.planId},

success:function(data)
{

// logic

}
});

Would you like this or anything else?
thumbnail
hamza jemai, modificado 10 Anos atrás.

RE: Create JSON web service Portlet

Junior Member Postagens: 40 Data de Entrada: 04/12/12 Postagens Recentes
Thanks,
My problem is how to crete my own JSON web service, In My portlet I have sama Javascript code how need a JSON file like an input, so my idea is to crete a json WEB service how generate a JSON file with my Data( this data is from My Demoticon , i try this exemple http://www.liferay.com/fr/web/james.falkner/blog/-/blogs/yet-another-liferay-json-service-example but i want to crete my own methode, for exemple a JSON web service how create data from DB.

Thanks
David Ilechukwu, modificado 10 Anos atrás.

RE: Create JSON web service Portlet

Regular Member Postagens: 154 Data de Entrada: 07/06/10 Postagens Recentes
Hamza,
I think it might be very helpful if you could describe the use case scenario of exactly what you are trying to do.
Creating JSON Services on Liferay is something quite trivial to do, but your question is very vague.

Please explain EXACTLY what it is you are trying to achieve.
Hope this helps.
thumbnail
hamza jemai, modificado 10 Anos atrás.

RE: Create JSON web service Portlet

Junior Member Postagens: 40 Data de Entrada: 04/12/12 Postagens Recentes
Thanks David for your reply,
I want to include http://timeline.verite.co/ in Liferya Portlet, this project need a JSON file in Input, so my solution is to create a JSON file from my DB using Liferay JSON API and JAVA this JSON file will be creted dynamically
You see?
Thanks