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

DefaultExceptionMapper made available for compliance check #4938

Merged
merged 3 commits into from
Dec 22, 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
@@ -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