Netflix / netflix-commons

Common utilities for Netflix OSS projects
Apache License 2.0
162 stars 81 forks source link

Adding new commons library for generic Jersey-Guice utility classes. #8

Closed elandau closed 10 years ago

elandau commented 10 years ago

Generic Jersey ExceptionMapper with Guice based plugin architecture to allow for context based default exception mapping.

Here's how to add a custom default mapper MyExceptionMapper

new JerseyServletModule() {
    @Override
    protected void configureServlets() {
        Multibinder<CustomThrowableExceptionMapper> mappers = Multibinder.newSetBinder(binder(), CustomThrowableExceptionMapper.class);
        mappers.addBinding().to(MyExceptionMapper.class);

        Map<String, String> params = new HashMap<String, String>();
        params.put(PackagesResourceConfig.PROPERTY_PACKAGES, 
                        "com.netflix.jersey.guice.providers.exception;");

        serve("/*").with(GuiceContainer.class, params);
        binder().bind(GuiceContainer.class).asEagerSingleton();
    }
}