Skip to main content
jebs89
New Participant
August 23, 2018

While trying to login to AEM using POST having request body, the resource recognizes it as a GET and does not give the request body

  • August 23, 2018
  • 15 replies
  • 5277 views

http://localhost:4502/ecat/j_security_check?j_username=abc&j_password=abc&resource=/ecat/apps/cat/injectorwebhook is the POST URL used to login to our application and land on the servlet path /ecat/apps/cat/injectorwebhook. It has a request body containing a json snippet. When i do a request.getMethod() in the servlet i get it as a GET and could not have a hold on the json from the request body. Why is it treated as a GET method? how to retrieve the body json from the request?

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

15 replies

joerghoh
Employee
August 24, 2018

Please find this request in the server logs; in the request log you should find this request and it will clearly identify what method was used.

Jörg

jebs89
jebs89Author
New Participant
August 24, 2018

i use a URL http://admin:admin@localhost:4502/ecat/apps/cat/injectorwebhook. This takes me to the servlet and is treated as a POST and all is good.


Logs:

inside MerlionWebhookServlet dopost

Method: POST

jsonRequestText : {

  "fragments": {

    "DDD001017_id06": {

      "targetLangs": ["es_XC", "zh_XC"]

    },

    "EEE001018_id01": {

      "targetLangs": ["fr_FR"]

    }

  }

}

But due to dependent system behavior i cannot use this URL. What is the difference in behavior between these two URLs?

arunpatidar
New Participant
August 23, 2018

Hi,

Can you share your servlet code skeleton(remove business logic) ?

Arun Patidar
smacdonald2008
New Participant
August 23, 2018

Are you logging into AEM itself or building a login component to a specific site built via AEM?

jebs89
jebs89Author
New Participant
August 24, 2018

I am logging into AEM itself and hitting the resource located at 'resource'

arunpatidar
New Participant
August 23, 2018

Hi,

To get request payload JOSN you need to read InputStream, e.g.

StringBuilder stringBuilder = new StringBuilder();

try(BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(request.getInputStream()))) {

    char[] charBuffer = new char[1024];

    int bytesRead;

    while ((bytesRead = bufferedReader.read(charBuffer)) > 0) {

        stringBuilder.append(charBuffer, 0, bytesRead);

    }

}

Arun Patidar
jebs89
jebs89Author
New Participant
August 23, 2018

Hi Arun. Thanks for your reply. I understand that we can use your code to extract request body from a POST call. But in my case my POST call is identified as a GET by my servlet. Now how can i get the request body?

arunpatidar
New Participant
August 23, 2018

Hi,

Server semantics for GET, however, are restricted such that a body, if any, has no semantic meaning to the request.

The GET method means retrieve whatever information ([...]) is identified by the Request-URI.

Can't you make POST request to http://localhost:4502/ecat/j_security_check?j_username=abc&j_password=abc&resource=/ecat/a pps/cat/injectorwebhook  ?

Arun Patidar