Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Powerful Tactic to Use Exception Mapper in Dropwizard

DZone's Guide to

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 ·
Free Resource

The State of API Integration 2018: Get Cloud Elements’ report for the most comprehensive breakdown of the API integration industry’s past, present, and future.

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!       

Your API is not enough. Learn why (and how) leading SaaS providers are turning their products into platforms with API integration in the ebook, Build Platforms, Not Products from Cloud Elements.

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

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}