svn merge -c 1183098 from trunk for HDFS-2428.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.23@1189486 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Tsz-wo Sze 2011-10-26 21:35:52 +00:00
parent 23cb6497d0
commit cb8ab18033
3 changed files with 23 additions and 4 deletions

View File

@ -1100,6 +1100,10 @@ Release 0.23.0 - Unreleased
HDFS-2441. Remove the Content-Type set by HttpServer.QuotingInputFilter in HDFS-2441. Remove the Content-Type set by HttpServer.QuotingInputFilter in
webhdfs responses. (szetszwo) webhdfs responses. (szetszwo)
HDFS-2428. Convert com.sun.jersey.api.ParamException$QueryParamException
to IllegalArgumentException and response it http BAD_REQUEST in webhdfs.
(szetszwo)
BREAKDOWN OF HDFS-1073 SUBTASKS BREAKDOWN OF HDFS-1073 SUBTASKS
HDFS-1521. Persist transaction ID on disk between NN restarts. HDFS-1521. Persist transaction ID on disk between NN restarts.

View File

@ -98,17 +98,18 @@ public class JsonUtil {
/** Convert an exception object to a Json string. */ /** Convert an exception object to a Json string. */
public static String toJsonString(final Exception e) { public static String toJsonString(final Exception e) {
final Map<String, Object> m = new TreeMap<String, Object>(); final Map<String, Object> m = new TreeMap<String, Object>();
m.put("className", e.getClass().getName()); m.put("exception", e.getClass().getSimpleName());
m.put("message", e.getMessage()); m.put("message", e.getMessage());
m.put("javaClassName", e.getClass().getName());
return toJsonString(RemoteException.class, m); return toJsonString(RemoteException.class, m);
} }
/** Convert a Json map to a RemoteException. */ /** Convert a Json map to a RemoteException. */
public static RemoteException toRemoteException(final Map<?, ?> json) { public static RemoteException toRemoteException(final Map<?, ?> json) {
final Map<?, ?> m = (Map<?, ?>)json.get(RemoteException.class.getSimpleName()); final Map<?, ?> m = (Map<?, ?>)json.get(RemoteException.class.getSimpleName());
final String className = (String)m.get("className");
final String message = (String)m.get("message"); 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) { private static String toJsonString(final Class<?> clazz, final Object value) {

View File

@ -29,17 +29,28 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hdfs.web.JsonUtil; import org.apache.hadoop.hdfs.web.JsonUtil;
import com.sun.jersey.api.ParamException;
/** Handle exceptions. */ /** Handle exceptions. */
@Provider @Provider
public class ExceptionHandler implements ExceptionMapper<Exception> { public class ExceptionHandler implements ExceptionMapper<Exception> {
public static final Log LOG = LogFactory.getLog(ExceptionHandler.class); public static final Log LOG = LogFactory.getLog(ExceptionHandler.class);
@Override @Override
public Response toResponse(final Exception e) { public Response toResponse(Exception e) {
if (LOG.isTraceEnabled()) { if (LOG.isTraceEnabled()) {
LOG.trace("GOT EXCEPITION", e); 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; final Response.Status s;
if (e instanceof SecurityException) { if (e instanceof SecurityException) {
s = Response.Status.UNAUTHORIZED; s = Response.Status.UNAUTHORIZED;
@ -49,7 +60,10 @@ public class ExceptionHandler implements ExceptionMapper<Exception> {
s = Response.Status.FORBIDDEN; s = Response.Status.FORBIDDEN;
} else if (e instanceof UnsupportedOperationException) { } else if (e instanceof UnsupportedOperationException) {
s = Response.Status.BAD_REQUEST; s = Response.Status.BAD_REQUEST;
} else if (e instanceof IllegalArgumentException) {
s = Response.Status.BAD_REQUEST;
} else { } else {
LOG.warn("INTERNAL_SERVER_ERROR", e);
s = Response.Status.INTERNAL_SERVER_ERROR; s = Response.Status.INTERNAL_SERVER_ERROR;
} }