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.


Have comments or feedback on what I wrote? Please share them below! Found this useful? Consider sending me a small tip.
comments powered by Disqus
Other posts you may like...
Hi! You can search my blog here ⤵
Or browse the recent top tags...

Recent Blog Posts

How to fix Google Cloud SDK dev server error - No module named ipaddr

Adorable but totally metal - Metal Earth 3D Guardians of the Galaxy Groot model kit

Riverside Expressway Cam shut down permanently

Inserting Google DFP ads with Backbone, Underscore and jQuery

How to resolve the domain is already mapped to a project error in Google App Engine

A quick look at the Nyko Super MiniBoss wireless controllers for the SNES mini

Loading and displaying a collection from bootstrapped data in Backbone.js

Add this handy function to your Bash profile file to display the compiled JDK version for a .class file

How does PCBWay stack up as a low budget PCB fab

Resolving the Cannot reference X before supertype constructor is called compiler error in Java

Recent Galleries

BMB-012 Nanoblock T-Rex Skeleton Model assembly

Tiny Arcade revision 6 kit assembly and decal application

Atari Lynx repair - Part 5 - McWill LED screen mod installation

Atari Lynx repair - Part 4 - screen cover replacement

Atari Lynx repair - Part 2 - re-capping the motherboard

Atari Lynx repair - Part 3 - broken speaker replacement

Atari Lynx repair - Part 1 - introduction and case disassembly

Building a custom Atari Lynx game box storage shelf unit in a day

Protecting old Atari Lynx game boxes with snug fit plastic sleeves

Monument Valley 2 is released and does not disappoint

Blogs and Friends

Matt Moores Blog
Georgi's FlatPress Guide
Perplexing Permutations
The Security Sleuth
Ilia Rogatchevski
Travelling Fairy

Blog Activity

Blog Activity