dropwizard icon indicating copy to clipboard operation
dropwizard copied to clipboard

Unable to use custom ExceptionMapper in 0.8 due to changes in Jersey 2

Open rjnichols opened this issue 12 years ago • 2 comments

Under Jersey 1.x it was possible to remove the Dropwizard standard LoggingExceptionMapper during application configuration like so -

    for (Iterator<Object> it = environment.jersey().getResourceConfig().getSingletons().iterator(); it.hasNext();) {
        Object object = it.next();
        if (LoggingExceptionMapper.class.isAssignableFrom(object.getClass())) {
            it.remove();
        }
    }

However, on dropwizard 0.8rc1 Jersey now returns an unmodifiable collection this for the getSingletons() call -

@Override
public final Set<Object> getSingletons() {
    if (cachedSingletonsView == null) {
        cachedSingletons = _getSingletons();
        cachedSingletonsView = Collections.unmodifiableSet(cachedSingletons == null ? new HashSet<>() : cachedSingletons);
    }

    return cachedSingletonsView;
}

... so the configuration can no longer be changed after it has been registered.

Is there a workaround for this issue?

rjnichols avatar Nov 25 '14 22:11 rjnichols

Sounds like a duplicate of #710

jplock avatar Nov 25 '14 23:11 jplock

Yes, sorry this can be closed.

rjnichols avatar Nov 25 '14 23:11 rjnichols