package com.demo.train;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.rmi.ServerException;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.sling.SlingServlet;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
import org.apache.sling.jcr.api.SlingRepository;
import org.json.simple.JSONObject;
import java.util.UUID;
@SlingServlet(paths="/bin/convertPropsAsJson", methods = "POST", metatype=true)
public class HandleClaim extends org.apache.sling.api.servlets.SlingAllMethodsServlet {
private static final long serialVersionUID = 23426532342349515L;
@Reference
private SlingRepository repository;
public void bindRepository(SlingRepository repository) {
this.repository = repository;
}
@Override
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServerException, IOException {
try
{
//Get the submitted form data that is sent from the
//CQ web page
String id = UUID.randomUUID().toString();
String value1 = request.getParameter("value1");
String value2 = request.getParameter("value2");
String value3 = request.getParameter("value3");
//Encode the submitted form data to JSON
JSONObject obj=new JSONObject();
obj.put("id",id);
obj.put("value1",value1);
obj.put("value2",value2);
obj.put("value3",value3);
//Get the JSON formatted data
String jsonData = obj.toJSONString();
//Return the JSON formatted data
response.getWriter().write(jsonData);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
Now we can split and use our jsonData as per our requirement.
Isn't the resolution via path deprecated in favor of resource type resolution?
ReplyDelete