diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 1226337a21..616b225e6c 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -116,6 +116,10 @@ Trunk (unreleased changes) HDFS-2441. Remove the Content-Type set by HttpServer.QuotingInputFilter in webhdfs responses. (szetszwo) + HDFS-2428. Convert com.sun.jersey.api.ParamException$QueryParamException + to IllegalArgumentException and response it http BAD_REQUEST in webhdfs. + (szetszwo) + Release 0.23.0 - Unreleased INCOMPATIBLE CHANGES diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/JsonUtil.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/JsonUtil.java index 0efc3d2e8a..9c5774d49b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/JsonUtil.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/JsonUtil.java @@ -98,17 +98,18 @@ private static Token toBlockToken( /** Convert an exception object to a Json string. */ public static String toJsonString(final Exception e) { final Map m = new TreeMap(); - m.put("className", e.getClass().getName()); + m.put("exception", e.getClass().getSimpleName()); m.put("message", e.getMessage()); + m.put("javaClassName", e.getClass().getName()); return toJsonString(RemoteException.class, m); } /** Convert a Json map to a RemoteException. */ public static RemoteException toRemoteException(final Map json) { final Map m = (Map)json.get(RemoteException.class.getSimpleName()); - final String className = (String)m.get("className"); final String message = (String)m.get("message"); - return new RemoteException(className, message); + final String javaClassName = (String)m.get("javaClassName"); + return new RemoteException(javaClassName, message); } private static String toJsonString(final Class clazz, final Object value) { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/resources/ExceptionHandler.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/resources/ExceptionHandler.java index 8a04c4ad91..fdc66f3af2 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/resources/ExceptionHandler.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/resources/ExceptionHandler.java @@ -29,17 +29,28 @@ import org.apache.commons.logging.LogFactory; import org.apache.hadoop.hdfs.web.JsonUtil; +import com.sun.jersey.api.ParamException; + /** Handle exceptions. */ @Provider public class ExceptionHandler implements ExceptionMapper { public static final Log LOG = LogFactory.getLog(ExceptionHandler.class); @Override - public Response toResponse(final Exception e) { + public Response toResponse(Exception e) { if (LOG.isTraceEnabled()) { LOG.trace("GOT EXCEPITION", e); } + //Convert exception + if (e instanceof ParamException) { + final ParamException paramexception = (ParamException)e; + e = new IllegalArgumentException("Invalid value for webhdfs parameter \"" + + paramexception.getParameterName() + "\": " + + e.getCause().getMessage(), e); + } + + //Map response status final Response.Status s; if (e instanceof SecurityException) { s = Response.Status.UNAUTHORIZED; @@ -49,7 +60,10 @@ public Response toResponse(final Exception e) { s = Response.Status.FORBIDDEN; } else if (e instanceof UnsupportedOperationException) { s = Response.Status.BAD_REQUEST; + } else if (e instanceof IllegalArgumentException) { + s = Response.Status.BAD_REQUEST; } else { + LOG.warn("INTERNAL_SERVER_ERROR", e); s = Response.Status.INTERNAL_SERVER_ERROR; }