Over a million developers have joined DZone.

Powerful Tactic to Use Exception Mapper in Dropwizard

When developing RESTful web services, people are often confused with handling exceptions. This post will explain a powerful tactic for using exception mapper with the Dropwizard framework.

· Integration Zone

Is iPaaS solving the right problems? Not knowing the fundamental difference between iPaaS and dPaaS could cost you down the road. Brought to you in partnership with Liaison Technologies.

Dropwizard exception mapper

Problem

When developing RESTful web services, people are often confused with handling exceptions. This post will explain a powerful tactic for using exception mapper with the Dropwizard framework. JAX-RS specification has already introduced exception mappers for handling such a situation in a great way. We will see how this problem was addressed in an effective way by using Dropwizard infrastructure.

How?

Now we will see how we can address this problem by checking out some real code with Dropwizard framework.

There are three steps involved for achieving this:

  1. Introduce a custom exception
  2. Write an exception mapper for our newly introduced exception
  3. Throw the custom exception from our REST API

Custom Exception

Please share the article with your friends and provider your comments in the sidebar if any…

For a detailed code example refer https://github.com/cloudskol/dropwizardskol

Thank you!       

Discover the unprecedented possibilities and challenges, created by today’s fast paced data climate and why your current integration solution is not enough, brought to you in partnership with Liaison Technologies.

Topics:
jax-rs ,rest api ,rest ,restful web services ,dropwizard ,framework ,api ,restful

Published at DZone with permission of Thamizh Arasu, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}