com.washingtonpost.dropwizard:dropwizard-json-exceptions

Washington Post Master Public Parent POM

Лицензия

Лицензия

Категории

Категории

DropWizard Контейнер Микросервисы JSON Данные
Группа

Группа

com.washingtonpost.dropwizard
Идентификатор

Идентификатор

dropwizard-json-exceptions
Последняя версия

Последняя версия

2.0.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

Washington Post Master Public Parent POM
Система контроля версий

Система контроля версий

https://github.com/washingtonpost/dropwizard-json-exceptions

Скачать dropwizard-json-exceptions

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/com.washingtonpost.dropwizard/dropwizard-json-exceptions/ -->
<dependency>
    <groupId>com.washingtonpost.dropwizard</groupId>
    <artifactId>dropwizard-json-exceptions</artifactId>
    <version>2.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.washingtonpost.dropwizard/dropwizard-json-exceptions/
implementation 'com.washingtonpost.dropwizard:dropwizard-json-exceptions:2.0.0'
// https://jarcasting.com/artifacts/com.washingtonpost.dropwizard/dropwizard-json-exceptions/
implementation ("com.washingtonpost.dropwizard:dropwizard-json-exceptions:2.0.0")
'com.washingtonpost.dropwizard:dropwizard-json-exceptions:jar:2.0.0'
<dependency org="com.washingtonpost.dropwizard" name="dropwizard-json-exceptions" rev="2.0.0">
  <artifact name="dropwizard-json-exceptions" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.washingtonpost.dropwizard', module='dropwizard-json-exceptions', version='2.0.0')
)
libraryDependencies += "com.washingtonpost.dropwizard" % "dropwizard-json-exceptions" % "2.0.0"
[com.washingtonpost.dropwizard/dropwizard-json-exceptions "2.0.0"]

Зависимости

compile (1)

Идентификатор библиотеки Тип Версия
io.dropwizard : dropwizard-jersey jar 1.0.5

provided (1)

Идентификатор библиотеки Тип Версия
org.slf4j : slf4j-api jar 1.7.21

test (5)

Идентификатор библиотеки Тип Версия
junit : junit jar 4.12
org.skyscreamer : jsonassert jar 1.2.3
com.fasterxml : jackson-xml-databind jar 0.6.2
xmlunit : xmlunit jar 1.6
org.slf4j : slf4j-simple jar 1.7.21

Модули Проекта

Данный проект не имеет модулей.

dropwizard-json-exceptions

Reusable ExceptionMappers for Dropwizard Apps that want more verbose JSON error outputs

Dropwizard intentionally provides pretty obtuse error messages to the end user; if you're interested in providing additional JSON-formatted exceptions for any exceptions that happen during execution of your REST endpoints, then just add this JAR to your classpath and turn off the Dropwizard server's standard exception mappers.

For example, the kinds of responses you'll get from a REST endpoint in your service that encounters a JsonProcessingException might look like:

{
    "code": 400,
    "message": "Unable to process JSON",
    "details": "Unexpected token (END_OBJECT), expected FIELD_NAME: missing property 'type' that is to contain type id  (for class com.washingtonpost.arc.ans.v0_3.model.Story)"
}

Dropwizard Compatability Matrix

Dropwizard Version Peer-Authenticator Version
0.8.* 1.x.y
0.9.* N/A
1.0.* 2.x.y

Integration

Add this JAR to your Dropwizard -server's POM

<dependency>
    <groupId>com.washingtonpost.dropwizard</groupId>
    <artifactId>dropwizard-json-exceptions</artifactId>
    <version>${version.wp.dropwizard.exceptions}</version>
</dependency>

Then in your application configuration, just turn off the server default exception mappers:

server: 
    registerDefaultExceptionMappers: false

In your Application class itself, you can either auto-detect the ExceptionMappers with a guice module configuration like:

import com.hubspot.dropwizard.guice.GuiceBundle;

public class MyAppApplication extends Application<MyAppConfiguration> {
    private GuiceBundle<MyAppConfiguration> guiceBundle;

    @Override
    public void initialize(Bootstrap<MyAppConfiguration> bootstrap) {
        guiceBundle = GuiceBundle.<MyAppConfiguration>newBuilder()
                .addModule(new FooModule())
                .enableAutoConfig("com.washingtonpost.dropwizard.exceptions.mappers")
                .setConfigClass(MyAppConfiguration.class)
                .build();

Alternatively, you can just manually add whatever exception mappers you want directly to your Jersey ResourceConfig:

import com.washingtonpost.dropwizard.exceptions.mappers.JsonProcessingExceptionMapper;
import com.washingtonpost.dropwizard.exceptions.mappers.RuntimeExceptionMapper;

public class MyAppApplication extends Application<MyAppConfiguration> {

    @Override
    public void run(MyAppConfiguration configuration, Environment environment) throws Exception {
        environment.jersey().register(new JsonProcessingExceptionMapper(true));
        environment.jersey().register(new RuntimeExceptionMapper());
        

Configuring Verbosity and Response Formats

The ExceptionMappers in this JAR contain default constructors that create output messages with "details" and in a JSON format.

You can control either of those behaviors by turning details off or providing a MediaType (like MediaType.APPLICATION_JSON_TYPE):

    ExceptionMapper noDetailsXmlMapper = 
        new JsonProcessingExceptionMapper(false, MediaType.APPLICATION_XML_TYPE);

Note: be mindful of the potential security concerns (information leak) by setting details=true in your runtime exception mapper.

com.washingtonpost.dropwizard

The Washington Post

Версии библиотеки

Версия
2.0.0
1.1.2
1.1.1
1.1.0
1.0.0