diff --git a/core/src/main/java/io/confluent/rest/Application.java b/core/src/main/java/io/confluent/rest/Application.java index 72946c1566..c864354d47 100644 --- a/core/src/main/java/io/confluent/rest/Application.java +++ b/core/src/main/java/io/confluent/rest/Application.java @@ -19,6 +19,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.jaxrs.base.JsonParseExceptionMapper; +import io.confluent.rest.exceptions.SuppressedJsonParseExceptionMapper; import org.apache.kafka.common.config.ConfigException; import org.eclipse.jetty.jaas.JAASLoginService; import org.eclipse.jetty.security.ConstraintMapping; @@ -497,7 +498,7 @@ public void configureBaseApplication(Configurable config) { public void configureBaseApplication(Configurable config, Map metricTags) { T restConfig = getConfiguration(); - registerJsonProvider(config, restConfig, true); + registerJsonProvider(config, restConfig, restConfig.getBoolean(RestConfig.DEBUG_CONFIG)); registerFeatures(config, restConfig); registerExceptionMappers(config, restConfig); @@ -526,6 +527,8 @@ protected void registerJsonProvider( config.register(jsonProvider); if (registerExceptionMapper) { config.register(JsonParseExceptionMapper.class); + } else { + config.register(SuppressedJsonParseExceptionMapper.class); } } diff --git a/core/src/main/java/io/confluent/rest/exceptions/SuppressedJsonParseExceptionMapper.java b/core/src/main/java/io/confluent/rest/exceptions/SuppressedJsonParseExceptionMapper.java new file mode 100644 index 0000000000..e351b8723c --- /dev/null +++ b/core/src/main/java/io/confluent/rest/exceptions/SuppressedJsonParseExceptionMapper.java @@ -0,0 +1,33 @@ +/* + * Copyright 2017 Confluent Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.confluent.rest.exceptions; + +import com.fasterxml.jackson.core.JsonParseException; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; +import javax.ws.rs.ext.ExceptionMapper; + +public class SuppressedJsonParseExceptionMapper implements ExceptionMapper { + public SuppressedJsonParseExceptionMapper() {} + + public Response toResponse(JsonParseException exception) { + return Response.status(Status.BAD_REQUEST) + .entity("Error parsing JSON") + .type("text/plain") + .build(); + } +}