srirachablender
srirachablender

Reputation: 89

How can I retrieve POST data from a Jetty AbstractHandler handle() method?

Searched SO quite a bit, but didn't see any posts that seemed to match my particular situation/question.

Using Jetty, I have a Handler class extending org.eclipse.jetty.server.handler.AbstractHandler.

The handle method is as follows:

@Override
    public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
                       throws IOException, ServletException {

I need to grab the POST data sent in the request, as if like this:

curl -H "Content-Type: application/json" -d '{"url":"http://www.example.com"}' http://localhost:8080/

Basically, I'm sending a POST request to my localhost with a JSON dictionary keyed on 'url'. How can I retrieve that POST data?

Upvotes: 4

Views: 7356

Answers (1)

Joakim Erdfelt
Joakim Erdfelt

Reputation: 49515

Use the standard servlet features available to from the HttpServletRequest parameter in the Handler.handle() method.

The HttpServletRequest has 2 methods that have access to the request body.

Then just use either of those 2 using standard java IO techniques.

Upvotes: 9

Related Questions