Match Request VS Content URL in AEM-6.4

Avatar

Avatar

sunitac70336244

Avatar

sunitac70336244

sunitac70336244

03-07-2019

Dear All,

I have below requirement in my AEM-6.4

Step-1

Extract plan id from cookie/session/http header (I want to write a dummy request for now For example I should get PlanId value as 197881 from cookie/session/http header)

Step-2

I want to Extract plan id from my content path URL (My dummy content path is /content/VignetteContent , as shown below.)

1784124_pastedImage_5.png

Step-3

If plan ID match (request vs content URL) then Continue Otherwise Reject.

Can anybody let me know how can I do this one in AEM-6.4?

Thanks

Sunita

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

Arun_Patidar

MVP

Total Posts

2.9K

Likes

999

Correct Answer

829

Avatar

Arun_Patidar

MVP

Total Posts

2.9K

Likes

999

Correct Answer

829
Arun_Patidar
MVP

08-07-2019

I am not sure what is your requirement but you can try with setAttribute if possible 

filter code

request.setAttribute("planID","197881");

request.setAttribute("locationId","1234");

request.getRequestDispatcher("/servletpath").forward(request, response);

servlet code

String planId = request.getAttribute("planID");

String locationId = request.getAttribute("locationId");

Otherwise

You can add Query String in the url like below

response.sendRedirect("servletPath?planId="+planId+"&locationId="+locationId);

String planid = request.getParameter("planId");

String locationId = request.getParameter("locationId");

Answers (8)

Answers (8)

Avatar

Avatar

sunitac70336244

Avatar

sunitac70336244

sunitac70336244

08-07-2019

Hi Arun,

Please see my comments below.

From where you need to pass those two parameters in the request?

currently just in my code SlingHttpServletRequest request

is it after redirecting from the filter?

Yes.

Avatar

Avatar

Arun_Patidar

MVP

Total Posts

2.9K

Likes

999

Correct Answer

829

Avatar

Arun_Patidar

MVP

Total Posts

2.9K

Likes

999

Correct Answer

829
Arun_Patidar
MVP

08-07-2019

Hi,

From where you need to pass those two parameters in the request?

is it after redirecting from the filter?

Avatar

Avatar

sunitac70336244

Avatar

sunitac70336244

sunitac70336244

07-07-2019

Dear All,

My requirement is like below.

my-page is an AEM page while i need to pass 2 URL parameters as planID=197881 and locationID=1234 like below.

http://localhost:4502/my-page?planID=197881&locationID=1234

Can anybody please help me for any sample code

Thanks

Avatar

Avatar

sunitac70336244

Avatar

sunitac70336244

sunitac70336244

05-07-2019

Dear All,

Can you please anybody help me on below requirement

But , I am not sure how to Provide the planID as URL params in the servlet call and compare. Can you please help me on this?

Also I am new to servlet.

Avatar

Avatar

sunitac70336244

Avatar

sunitac70336244

sunitac70336244

05-07-2019

Hi Arun,

I am new to query string. Can you please give me some example?

Avatar

Avatar

Arun_Patidar

MVP

Total Posts

2.9K

Likes

999

Correct Answer

829

Avatar

Arun_Patidar

MVP

Total Posts

2.9K

Likes

999

Correct Answer

829
Arun_Patidar
MVP

05-07-2019

Hi,

Can't you add parameters as query string?

Avatar

Avatar

sunitac70336244

Avatar

sunitac70336244

sunitac70336244

05-07-2019

Hi Arun,

Thanks For your reply.

Now I need to Provide the planID as URL params in the servlet call and compare that planID with the JCR Property of the content (Step-2).

So I have written the code like below.

But , I am not sure how to Provide the planID as URL params in the servlet call and compare. Can you please help me on this?

@SlingServlet(resourceTypes = "sunita/components/structure/page", methods="GET", selectors="model")
public class PlanService extends SlingAllMethodsServlet{
Logger log = LoggerFactory.getLogger(this.getClass());

private static final long serialVersionUID = 1L;
   
ResourceResolver resourceResolver;

public void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)throws ServletException,IOException{
  response.setContentType("text/html");
  try {
   // Get the resource (a node in the JCR) using ResourceResolver from the request
   resourceResolver = request.getResourceResolver();
   request.getParameter("");
   log.info("resourceResolver ----==="+resourceResolver);

   //Specify the node of interest in the suffix on the request
   String nodePath = request.getRequestPathInfo().getSuffix();
   if(nodePath != null){
    Resource resource = resourceResolver.getResource(nodePath);
    log.info("resource is === "+resource);
    // Adapt resource properties to variables using ValueMap, and log their values
    Resource parent = resource.getChild("plan");
    log.info("PARAENT resource is === "+parent);
    ValueMap valueMap=parent.adaptTo(ValueMap.class);
    response.getOutputStream().println("<h3>");
    response.getOutputStream().println("PlanID is");
    response.getOutputStream().println("</h3><br />");   
    log.info("PLANID from Content URL/JCR is === "+ valueMap.get("planID").toString());       
    response.getOutputStream().println(valueMap.get("planID").toString());

Avatar

Avatar

Arun_Patidar

MVP

Total Posts

2.9K

Likes

999

Correct Answer

829

Avatar

Arun_Patidar

MVP

Total Posts

2.9K

Likes

999

Correct Answer

829
Arun_Patidar
MVP

04-07-2019

Hi,

Use sling filters, few example

Get cookies in filter and map request path to node/resource and get property planID and do compare action.

aem63app-repo/DemoCookieFilter.java at master · arunpatidar02/aem63app-repo · GitHub

aem63app-repo/CustomScreenFilter.java at master · arunpatidar02/aem63app-repo · GitHub