Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default Exception Mapper re-worked #4908

Merged
merged 5 commits into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ public class ExceptionMapperFactory implements ExceptionMappers {

private static final Logger LOGGER = Logger.getLogger(ExceptionMapperFactory.class.getName());

private static final ExceptionMapper<Throwable> DEFAULT_EXCEPTION_MAPPER = new DefaultExceptionMapper();

/**
* Configurator which initializes and register {@link ExceptionMappers} instance into {@link InjectionManager} and
* {@link BootstrapBag}.
Expand Down Expand Up @@ -129,7 +127,7 @@ private <T extends Throwable> ExceptionMapper<T> find(final Class<T> type, final
}
}
}
return mapper == null ? (ExceptionMapper<T>) DEFAULT_EXCEPTION_MAPPER : mapper;
return mapper;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

package org.glassfish.jersey.internal;
package org.glassfish.jersey.server;

import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper;

public class DefaultExceptionMapper implements ExceptionMapper<Throwable> {
class DefaultExceptionMapper implements ExceptionMapper<Throwable> {
@Override
public Response toResponse(Throwable exception) {
return (exception instanceof WebApplicationException)
Expand Down
176 changes: 106 additions & 70 deletions core-server/src/main/java/org/glassfish/jersey/server/ServerRuntime.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ error.closing.commit.output.stream=Error while closing the output stream in orde
error.closing.finder=Error while closing {0} resource finder.
error.exception.mapping.original.exception=An exception mapping did not successfully produce and processed a response. Logging the original error.
error.exception.mapping.processed.response.error=A response error mapping did not successfully produce and processed a response.
error.exception.mapping.thrown.to.container=An exception mapping did not successfully produce and processed a response. Logging the exception propagated to the container.
error.exception.mapping.thrown.to.container=An exception mapping did not successfully produce and processed a response. Logging the exception propagated to the default exception mapper.
error.marshalling.jaxb=Error marshalling JAXB object of type "{0}".
error.msg=ERROR: {0}
error.monitoring.statistics.generation=Error generating monitoring statistics.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -558,14 +558,12 @@ public void testMapResponseErrorForMbw() throws Exception {
/**
* Test that un-mapped response errors are tried to be processed only once (MBW).
*/
@Test
@Test(expected = ExecutionException.class)
public void testMapCyclicResponseErrorForMbw() throws Exception {
final ApplicationHandler handler = new ApplicationHandler(MapResponseErrorApplication.class);

final ContainerRequest context = RequestContextBuilder.from("/foobar", "GET").build();

final ContainerResponse containerResponse = handler.apply(context).get();
assertEquals(500, containerResponse.getStatus());
assertEquals("Cannot do that!", containerResponse.getEntity());
handler.apply(context).get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@

import jakarta.inject.Singleton;

import org.junit.Ignore;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand Down Expand Up @@ -72,7 +71,6 @@ public void testCompletionCallback() throws ExecutionException, InterruptedExcep
}

@Test
@Ignore("since JAXRS 3.1 failure is not processed by callbacks")
public void testCompletionFail() throws ExecutionException, InterruptedException {
final Flags flags = new Flags();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,11 @@ public Response apply(final ContainerRequestContext request) {
});
resourceConfig.registerResources(rb.build());
final ApplicationHandler application = new ApplicationHandler(resourceConfig);
int status = application.apply(RequestContextBuilder.from("/test", "GET").build()).get().getStatus();
Assert.assertEquals(500, status);
try {
application.apply(RequestContextBuilder.from("/test", "GET").build()).get().getStatus();
Assert.fail("should throw an exception");
} catch (final Exception e) {
// ok
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2021 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -278,8 +278,8 @@ public void test() {
LocalizationMessages.ERROR_EXCEPTION_MAPPING_ORIGINAL_EXCEPTION(),
LocalizationMessages.ERROR_EXCEPTION_MAPPING_THROWN_TO_CONTAINER()}) {

if (logRecord.getMessage().contains(message) && logRecord.getLevel().intValue() > Level.FINE.intValue()) {
fail("Log message should be logged at lower (FINE) level: " + message);
if (logRecord.getMessage().contains(message) && logRecord.getLevel().intValue() > Level.WARNING.intValue()) {
fail("Log message should be logged at lower (WARNING) level: " + message);
}
}
}
Expand Down