Author: aparfonov
Date: 2009-09-03 02:34:16 -0400 (Thu, 03 Sep 2009)
New Revision: 131
Modified:
ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/ConstructorDescriptorImpl.java
ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/FieldInjectorImpl.java
ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/RequestHandlerImpl.java
ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/DefaultMethodInvoker.java
Log:
EXOJCR-130 : Add media type and log.error for exceptions
Modified:
ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/ConstructorDescriptorImpl.java
===================================================================
---
ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/ConstructorDescriptorImpl.java 2009-09-03
05:21:20 UTC (rev 130)
+++
ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/ConstructorDescriptorImpl.java 2009-09-03
06:34:16 UTC (rev 131)
@@ -44,6 +44,7 @@
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.Provider;
@@ -232,15 +233,11 @@
}
catch (Exception e)
{
-
- if (LOG.isDebugEnabled())
- e.printStackTrace();
-
Class<?> ac = a.annotationType();
if (ac == MatrixParam.class || ac == QueryParam.class || ac ==
PathParam.class)
- throw new
WebApplicationException(Response.status(Response.Status.NOT_FOUND).build());
+ throw new WebApplicationException(e,
Response.status(Response.Status.NOT_FOUND).build());
- throw new
WebApplicationException(Response.status(Response.Status.BAD_REQUEST).build());
+ throw new WebApplicationException(e,
Response.status(Response.Status.BAD_REQUEST).build());
}
}
else
@@ -255,7 +252,7 @@
"Can't instantiate resource " + resourceClass + " by
using constructor " + this
+ ". Not found parameter " + cp;
throw new
WebApplicationException(Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg)
- .build());
+ .type(MediaType.TEXT_PLAIN).build());
}
p[i] = tmp;
@@ -286,8 +283,6 @@
catch (InvocationTargetException invExc)
{
// constructor may produce exceptions
- if (LOG.isDebugEnabled())
- invExc.printStackTrace();
// get cause of exception that method produces
Throwable cause = invExc.getCause();
// if WebApplicationException than it may contain response
Modified:
ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/FieldInjectorImpl.java
===================================================================
---
ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/FieldInjectorImpl.java 2009-09-03
05:21:20 UTC (rev 130)
+++
ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/FieldInjectorImpl.java 2009-09-03
06:34:16 UTC (rev 131)
@@ -218,13 +218,11 @@
catch (Throwable e)
{
- LOG.error("Failed initialize field. ", e);
-
Class<?> ac = annotation.annotationType();
if (ac == MatrixParam.class || ac == QueryParam.class || ac ==
PathParam.class)
- throw new
WebApplicationException(Response.status(Response.Status.NOT_FOUND).build());
+ throw new WebApplicationException(e,
Response.status(Response.Status.NOT_FOUND).build());
- throw new
WebApplicationException(Response.status(Response.Status.BAD_REQUEST).build());
+ throw new WebApplicationException(e,
Response.status(Response.Status.BAD_REQUEST).build());
}
}
Modified:
ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/RequestHandlerImpl.java
===================================================================
---
ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/RequestHandlerImpl.java 2009-09-03
05:21:20 UTC (rev 130)
+++
ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/RequestHandlerImpl.java 2009-09-03
06:34:16 UTC (rev 131)
@@ -144,6 +144,10 @@
// should be some of 4xx status
if (errorResponse.getStatus() < 500)
{
+ if (LOG.isDebugEnabled() && e.getCause() != null)
+ {
+ LOG.warn("WedApplication exception occurs.",
e.getCause());
+ }
if (errorResponse.getEntity() == null)
{
if (excmap != null)
@@ -155,17 +159,26 @@
}
else
{
- if (LOG.isDebugEnabled())
- e.printStackTrace();
if (errorResponse.getEntity() == null)
{
if (excmap != null)
{
+ if (LOG.isDebugEnabled() && e.getCause() != null)
+ {
+ // Hide error message if exception mapper exists.
+ LOG.warn("WedApplication exception occurs.",
e.getCause());
+ }
+
errorResponse = excmap.toResponse(e);
}
else
{
+ if (e.getCause() != null)
+ {
+ LOG.warn("WedApplication exception occurs.",
e.getCause());
+ }
+
// add stack trace as message body
errorResponse =
Response.status(errorResponse.getStatus()).entity(new
ErrorStreaming(e)).type(
@@ -177,20 +190,27 @@
}
else if (e instanceof InternalException)
{
- Class cause = e.getCause().getClass();
- ExceptionMapper excmap =
ProviderBinder.getInstance().getExceptionMapper(cause);
- while (cause != null && excmap == null)
+ Throwable cause = e.getCause();
+ Class causeClazz = cause.getClass();
+ ExceptionMapper excmap =
ProviderBinder.getInstance().getExceptionMapper(causeClazz);
+ while (causeClazz != null && excmap == null)
{
- excmap = ProviderBinder.getInstance().getExceptionMapper(cause);
+ excmap = ProviderBinder.getInstance().getExceptionMapper(causeClazz);
if (excmap == null)
- cause = cause.getSuperclass();
+ causeClazz = causeClazz.getSuperclass();
}
if (excmap != null)
{
+ if (LOG.isDebugEnabled())
+ {
+ // Hide error message if exception mapper exists.
+ LOG.warn("Internal error occurs.", cause);
+ }
response.setResponse(excmap.toResponse(e.getCause()));
}
else
{
+ LOG.error("Internal error occurs.", cause);
throw new UnhandledException(e.getCause());
}
}
Modified:
ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/DefaultMethodInvoker.java
===================================================================
---
ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/DefaultMethodInvoker.java 2009-09-03
05:21:20 UTC (rev 130)
+++
ws/trunk/rest/core/src/main/java/org/exoplatform/services/rest/impl/method/DefaultMethodInvoker.java 2009-09-03
06:34:16 UTC (rev 131)
@@ -84,14 +84,11 @@
catch (Exception e)
{
- if (LOG.isDebugEnabled())
- e.printStackTrace();
-
Class<?> ac = a.annotationType();
if (ac == MatrixParam.class || ac == QueryParam.class || ac ==
PathParam.class)
- throw new
WebApplicationException(Response.status(Response.Status.NOT_FOUND).build());
+ throw new WebApplicationException(e,
Response.status(Response.Status.NOT_FOUND).build());
- throw new
WebApplicationException(Response.status(Response.Status.BAD_REQUEST).build());
+ throw new WebApplicationException(e,
Response.status(Response.Status.BAD_REQUEST).build());
}
Show replies by date