Skip to content

Commit b7a3946

Browse files
authored
Default Exception Mapper re-worked (#4908)
Signed-off-by: Maxim Nesen <[email protected]>
1 parent fee1c32 commit b7a3946

File tree

8 files changed

+121
-87
lines changed

8 files changed

+121
-87
lines changed

core-common/src/main/java/org/glassfish/jersey/internal/ExceptionMapperFactory.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ public class ExceptionMapperFactory implements ExceptionMappers {
5858

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

61-
private static final ExceptionMapper<Throwable> DEFAULT_EXCEPTION_MAPPER = new DefaultExceptionMapper();
62-
6361
/**
6462
* Configurator which initializes and register {@link ExceptionMappers} instance into {@link InjectionManager} and
6563
* {@link BootstrapBag}.
@@ -129,7 +127,7 @@ private <T extends Throwable> ExceptionMapper<T> find(final Class<T> type, final
129127
}
130128
}
131129
}
132-
return mapper == null ? (ExceptionMapper<T>) DEFAULT_EXCEPTION_MAPPER : mapper;
130+
return mapper;
133131
}
134132

135133
/**

core-common/src/main/java/org/glassfish/jersey/internal/DefaultExceptionMapper.java renamed to core-server/src/main/java/org/glassfish/jersey/server/DefaultExceptionMapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
1515
*/
1616

17-
package org.glassfish.jersey.internal;
17+
package org.glassfish.jersey.server;
1818

1919
import jakarta.ws.rs.WebApplicationException;
2020
import jakarta.ws.rs.core.Response;
2121
import jakarta.ws.rs.ext.ExceptionMapper;
2222

23-
public class DefaultExceptionMapper implements ExceptionMapper<Throwable> {
23+
class DefaultExceptionMapper implements ExceptionMapper<Throwable> {
2424
@Override
2525
public Response toResponse(Throwable exception) {
2626
return (exception instanceof WebApplicationException)

core-server/src/main/java/org/glassfish/jersey/server/ServerRuntime.java

Lines changed: 106 additions & 70 deletions
Large diffs are not rendered by default.

core-server/src/main/resources/org/glassfish/jersey/server/internal/localization.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ error.closing.commit.output.stream=Error while closing the output stream in orde
4040
error.closing.finder=Error while closing {0} resource finder.
4141
error.exception.mapping.original.exception=An exception mapping did not successfully produce and processed a response. Logging the original error.
4242
error.exception.mapping.processed.response.error=A response error mapping did not successfully produce and processed a response.
43-
error.exception.mapping.thrown.to.container=An exception mapping did not successfully produce and processed a response. Logging the exception propagated to the container.
43+
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.
4444
error.marshalling.jaxb=Error marshalling JAXB object of type "{0}".
4545
error.msg=ERROR: {0}
4646
error.monitoring.statistics.generation=Error generating monitoring statistics.

core-server/src/test/java/org/glassfish/jersey/server/ApplicationHandlerTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -558,14 +558,12 @@ public void testMapResponseErrorForMbw() throws Exception {
558558
/**
559559
* Test that un-mapped response errors are tried to be processed only once (MBW).
560560
*/
561-
@Test
561+
@Test(expected = ExecutionException.class)
562562
public void testMapCyclicResponseErrorForMbw() throws Exception {
563563
final ApplicationHandler handler = new ApplicationHandler(MapResponseErrorApplication.class);
564564

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

567-
final ContainerResponse containerResponse = handler.apply(context).get();
568-
assertEquals(500, containerResponse.getStatus());
569-
assertEquals("Cannot do that!", containerResponse.getEntity());
567+
handler.apply(context).get();
570568
}
571569
}

core-server/src/test/java/org/glassfish/jersey/server/AsyncCallbackServerTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535

3636
import jakarta.inject.Singleton;
3737

38-
import org.junit.Ignore;
3938
import org.junit.Test;
4039
import static org.junit.Assert.assertEquals;
4140
import static org.junit.Assert.assertFalse;
@@ -72,7 +71,6 @@ public void testCompletionCallback() throws ExecutionException, InterruptedExcep
7271
}
7372

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

core-server/src/test/java/org/glassfish/jersey/server/filter/ApplicationFilterTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,11 @@ public Response apply(final ContainerRequestContext request) {
318318
});
319319
resourceConfig.registerResources(rb.build());
320320
final ApplicationHandler application = new ApplicationHandler(resourceConfig);
321-
int status = application.apply(RequestContextBuilder.from("/test", "GET").build()).get().getStatus();
322-
Assert.assertEquals(500, status);
321+
try {
322+
application.apply(RequestContextBuilder.from("/test", "GET").build()).get().getStatus();
323+
Assert.fail("should throw an exception");
324+
} catch (final Exception e) {
325+
// ok
326+
}
323327
}
324328
}

tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/ExtendedExceptionMapperTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2021 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -278,8 +278,8 @@ public void test() {
278278
LocalizationMessages.ERROR_EXCEPTION_MAPPING_ORIGINAL_EXCEPTION(),
279279
LocalizationMessages.ERROR_EXCEPTION_MAPPING_THROWN_TO_CONTAINER()}) {
280280

281-
if (logRecord.getMessage().contains(message) && logRecord.getLevel().intValue() > Level.FINE.intValue()) {
282-
fail("Log message should be logged at lower (FINE) level: " + message);
281+
if (logRecord.getMessage().contains(message) && logRecord.getLevel().intValue() > Level.WARNING.intValue()) {
282+
fail("Log message should be logged at lower (WARNING) level: " + message);
283283
}
284284
}
285285
}

0 commit comments

Comments
 (0)