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

Previously I wrote a post about using a custom exception mapper in your RESTful service with Jersey. This article looks at the execution order of all of the filters, interceptors, readers and writers that get called along the way in this scenario.

This article relies on the code and some of the explanation from the following articles, be sure to go over those first:

I am not covering the execution order prior to getting to the Resource class as that's been covered in the previous articles I've written (linked above) and since it varies depending on whether you use GET or POST methods and if any message body readers are used.

So lets see what happens when a request is made to the /exception URI of the service that's been built up so far...

Since the Resource class in this case simply throws a HelloException, execution shifts straight to the ExceptionMapper. Then the container response filter and writer interceptor are called. Behaviour after this point depends on how the exception mapper is implemented.

I've implemented two versions of the exception mapper, one that used a standard String entity and one that used the actual HelloException as the entity itself. The latter version meant that an entity writer (message body writer) is used to transform the exception (entity) into output from the service. If the Exception is used as the entity, the message body writer is invoked, otherwise nothing further from your service is called.

The execution order is quite straight forward for cases where an exception is thrown from your Resource code, and can be very powerful. This approach can be used to catch and process exceptions and to generate valid responses from your service, instead of simply letting Jersey return the usual 500 error.


Please leave your comments or feedback below!
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 remove caked on stickers from old game carts

How to pass parameters to your PHP script via the command line

jPhotoFrame new layout engine explained with examples

Atari Lynx Multi SD Card cartridge review

Jersey JAX-RS filters and interceptors execution order when throwing Exceptions

Why I'll never renew a domain with GoDaddy again

Fake AirPods - HBQ-i7 TWS wireless headset teardown

How to fix Postman error - Failed to import data: format not recognized

Switching out macOS Mail for Microsoft Outlook

Using DeoxIT to repair old game catridges

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