Skip to content

Commit f773633

Browse files
authored
DefaultExceptionMapper made available for compliance check (#4938)
Signed-off-by: Maxim Nesen <[email protected]>
1 parent 627a1df commit f773633

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2020 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 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
@@ -16,6 +16,7 @@
1616

1717
package org.glassfish.jersey.server;
1818

19+
import jakarta.ws.rs.ext.ExceptionMapper;
1920
import jakarta.ws.rs.ext.MessageBodyWriter;
2021
import jakarta.ws.rs.ext.WriterInterceptor;
2122

@@ -44,5 +45,8 @@ protected void configure() {
4445

4546
// JSONP
4647
bind(JsonWithPaddingInterceptor.class).to(WriterInterceptor.class).in(Singleton.class);
48+
49+
//Default exception mapper
50+
bind(DefaultExceptionMapper.class).to(ExceptionMapper.class).in(Singleton.class);
4751
}
4852
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,10 @@ private Response mapException(final Throwable originalThrowable) throws Throwabl
544544

545545
final long timestamp = tracingLogger.timestamp(ServerTraceEvent.EXCEPTION_MAPPING);
546546
final ExceptionMapper mapper = runtime.exceptionMappers.findMapping(throwable);
547-
if (mapper != null) {
547+
if (mapper != null
548+
&& !DefaultExceptionMapper.class.getName()
549+
.equals(mapper.getClass().getName())
550+
) {
548551
return processExceptionWithMapper(mapper, throwable, timestamp);
549552
}
550553
if (waeResponse != null) {

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2020 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 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
@@ -137,6 +137,13 @@ public void testPreventMultipleExceptionMapping() {
137137
assertEquals(500, res.getStatus());
138138
}
139139

140+
@Test
141+
public void testDefaultExceptionMapper() {
142+
Response res = target().path("test/defaultExceptionMapper")
143+
.request("test/test").get();
144+
assertEquals(200, res.getStatus());
145+
}
146+
140147
@Path("test")
141148
public static class Resource {
142149

@@ -174,6 +181,14 @@ public String throwsThrowable() throws Throwable {
174181
new RuntimeException("runtime-exception",
175182
new ClientErrorException("client-error", 499)));
176183
}
184+
185+
@GET
186+
@Path("defaultExceptionMapper")
187+
public Response isRegisteredDefaultExceptionTest(@Context Providers providers) {
188+
ExceptionMapper<Throwable> em = providers
189+
.getExceptionMapper(Throwable.class);
190+
return Response.status((em == null) ? 500 : 200).build();
191+
}
177192
}
178193

179194
public static class ClientErrorExceptionMapper implements ExceptionMapper<ClientErrorException> {

0 commit comments

Comments
 (0)