Hi,
I have a replicator that call a servlet. I need to recovery from the request the type of the operation: activate or deactivate.
public void handleRequest(SlingHttpServletRequest req) throws IOException { log.info("handleRequest"); Enumeration<String> parameterNames = req.getParameterNames(); while (parameterNames.hasMoreElements()) { String paramName = parameterNames.nextElement(); log.info("paramName "+paramName); String[] paramValues = req.getParameterValues(paramName); for (int i = 0; i < paramValues.length; i++) { String paramValue = paramValues[i]; log.info("paramValue "+paramValue); } } }
I have no parameters in output from this code and if i parse all the request:
private String getRequestType(SlingHttpServletRequest request) { try{ BufferedReader reader = request.getReader(); String line; while ((line = reader.readLine()) != null) { log.info("getRequestType "+line); } }catch(Exception e){ log.info(e.getMessage()); } return null; }
I have a print like this:
DurboSer 2.1 ContentType durboser/unstructured Encoding startPath /content/gimb_it/fullloading orderSiblings 2it,system,en,fullloading,fullloadingsinglerequest, orderChildren parentNodeTypes cq:Page,sling:OrderedFolder fullloading! jcr http://www.jcp.org/jcr/1.0 jcr:primaryType cq:Page jcr:createdBy admin jcr:created 2015-10-07T12:02:25.871+02:00 jcr:content jcr:primaryType cq:PageContent jcr:uuid $0f1eb7b5-0473-4fa3-aa8e-69b3dd105014 jcr:mixinTypes mix:versionable,! sling %http://sling.apache.org/jcr/sling/1.0 sling:resourceType gimb/components/page/fullLoading jcr:title fullloading jcr:created 2015-10-07T12:02:25.873+02:00! cq http://www.day.com/jcr/cq/1.0 cq:template /apps/gimb/templates/fullLoading cq:lastModifiedBy admin jcr:createdBy admin cq:lastModified 2015-10-07T12:02:25.874+02:00//
I can't find a parameter to know the type of the action.
The code above is from an activation, the deactivation has an empty request body
How can i know the type of the request?
Thanks
Solved! Go to Solution.
Views
Replies
Total Likes
Ah shoot, I'm sorry. You are correct -- these are passed as headers, not request parameters. Should have spotted that originally.
Incidentally, if you look at the replication log, you can see all the headers passed as part of the replication HTTP request.
Views
Replies
Total Likes
Hi,
Are you saying that for a POST request from the replication sender, you do not get any request parameters? Or that you do, but the values are all empty arrays?
The code above looks like it should work to get the parameters, but it is a bit convoluted.
I would just do
String action = slingRequest.getParameter("Action");
or better yet
ReplicationActionType action = ReplicationActionType.fromName(slingRequest.getParameter("Action"));
Views
Replies
Total Likes
Can you please explain your use case. What are you trying to do. Are you trying to invoke an AEM servlet from a custom replication handler?
I am not clear from your description.
Views
Replies
Total Likes
Samuel, can you elaborate your usecase little more and what are you trying to achieve ?
Views
Replies
Total Likes
Yes i'm trying to invoke an AEM servlet from a custom replication handler.
I don't know the name of the parameter so i have produced the snippet above to iterate all the parameters.
I think it is impossible that the request doesn't have parameters therefore there is an error in my snippet.
I will try to get the parameter "Action"
Views
Replies
Total Likes
The Action parameter is null. I have also tried with this wothout result
public void handleRequest(SlingHttpServletRequest req) throws IOException { log.info("handleRequest"); Map<String, RequestParameter[]> map = req.getRequestParameterMap(); for (Map.Entry<String, RequestParameter[]> entry : map.entrySet()) { log.info(entry.getKey() + "/" + entry.getValue()); } }
Views
Replies
Total Likes
This is the solution:
String page_path=request.getHeader("path"); String request_type=request.getHeader("action");
Views
Replies
Total Likes
Ah shoot, I'm sorry. You are correct -- these are passed as headers, not request parameters. Should have spotted that originally.
Incidentally, if you look at the replication log, you can see all the headers passed as part of the replication HTTP request.
Views
Replies
Total Likes