servlet get activation/deactivation | Community
Skip to main content
New Participant
October 16, 2015
Solved

servlet get activation/deactivation

  • October 16, 2015
  • 7 replies
  • 1482 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by JustinEd3

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.

7 replies

Employee
October 16, 2015

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"));
smacdonald2008
New Participant
October 16, 2015

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. 

Lokesh_Shivalingaiah
New Participant
October 16, 2015

Samuel, can you elaborate your usecase little more and what are you trying to achieve ?

New Participant
October 16, 2015

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"

New Participant
October 16, 2015

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()); } }
New Participant
October 16, 2015

This is the solution:

String page_path=request.getHeader("path"); String request_type=request.getHeader("action");
JustinEd3Accepted solution
Employee
October 16, 2015

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.