Skip to content

Commit

Permalink
DefaultExceptionMapper made available for compliance check (#4938)
Browse files Browse the repository at this point in the history
Signed-off-by: Maxim Nesen <maxim.nesen@oracle.com>
  • Loading branch information
senivam authored Dec 22, 2021
1 parent 627a1df commit f773633
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 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 All @@ -16,6 +16,7 @@

package org.glassfish.jersey.server;

import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.MessageBodyWriter;
import jakarta.ws.rs.ext.WriterInterceptor;

Expand Down Expand Up @@ -44,5 +45,8 @@ protected void configure() {

// JSONP
bind(JsonWithPaddingInterceptor.class).to(WriterInterceptor.class).in(Singleton.class);

//Default exception mapper
bind(DefaultExceptionMapper.class).to(ExceptionMapper.class).in(Singleton.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,10 @@ private Response mapException(final Throwable originalThrowable) throws Throwabl

final long timestamp = tracingLogger.timestamp(ServerTraceEvent.EXCEPTION_MAPPING);
final ExceptionMapper mapper = runtime.exceptionMappers.findMapping(throwable);
if (mapper != null) {
if (mapper != null
&& !DefaultExceptionMapper.class.getName()
.equals(mapper.getClass().getName())
) {
return processExceptionWithMapper(mapper, throwable, timestamp);
}
if (waeResponse != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 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 @@ -137,6 +137,13 @@ public void testPreventMultipleExceptionMapping() {
assertEquals(500, res.getStatus());
}

@Test
public void testDefaultExceptionMapper() {
Response res = target().path("test/defaultExceptionMapper")
.request("test/test").get();
assertEquals(200, res.getStatus());
}

@Path("test")
public static class Resource {

Expand Down Expand Up @@ -174,6 +181,14 @@ public String throwsThrowable() throws Throwable {
new RuntimeException("runtime-exception",
new ClientErrorException("client-error", 499)));
}

@GET
@Path("defaultExceptionMapper")
public Response isRegisteredDefaultExceptionTest(@Context Providers providers) {
ExceptionMapper<Throwable> em = providers
.getExceptionMapper(Throwable.class);
return Response.status((em == null) ? 500 : 200).build();
}
}

public static class ClientErrorExceptionMapper implements ExceptionMapper<ClientErrorException> {
Expand Down

0 comments on commit f773633

Please sign in to comment.