Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

This is a follow on article from Jersey JAX-RS filters and interceptors execution order for a simple GET request. This time instead of a GET request I'll be looking at a POST request.

For the sake of brevity this article builds on top of the classes already created in the earlier article and also makes use of the classes from this article - Writing a custom MessageBodyReader to process POST body data with Jersey. Please review both of these articles first if you haven't already done so.

Making a POST request to the /hello URI ends up executing the following filters and interceptors...

It's mostly the same as the execution flow for a GET request, except prior to the resource class being called there are calls to the reader interceptor and then the message body reader classes. After the resource class is run, the execution order remains the same as for a GET request.

Now what if instead of using a custom message body reader we used a standard @FormParam annotation to pass a value to the resource? Here's a new resource class that implements just that...
@Produces({ "text/plain" })
public class HelloPostResource2 {
public String sayHello(@FormParam("name") String name)
.debug(">>> MyResource 2");
return "Hello " + name;

This class has a @Consumes("application/x-www-form-urlencoded") annotation on the @POST method to specify that form data is being expected. The parameter to the sayHello() method is now annotated with @FormParam and is changed to a simple String data type. The path is changed to /hello2.

Sending a POST request to the /path2 URI produces the following execution order...

As expected the message body reader is not called at all, but the reader interceptor is. This is because the message body reader that was created for the first POST resource doesn't match for the new resource and hence never gets executed.

That sums up how a POST request is processed in a standard use case. I'll be following up soon with an article on what happens during cases where an exception is thrown. Keep an eye out for future posts, I'll link them here as they are available.


A quick disclaimer...

Although I put in a great effort into researching all the topics I cover, mistakes can happen. Use of any information from my blog posts should be at own risk and I do not hold any liability towards any information misuse or damages caused by following any of my posts.

All content and opinions expressed on this Blog are my own and do not represent the opinions of my employer (Oracle). Use of any information contained in this blog post/article is subject to this disclaimer.
Hi! You can search my blog here ⤵
NOTE: (2022) This Blog is no longer maintained and I will not be answering any emails or comments.

I am now focusing on Atari Gamer.