Author: max_shaposhnik
Date: 2009-12-29 07:26:31 -0500 (Tue, 29 Dec 2009)
New Revision: 1232
Added:
ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/WebApplicationExceptionTest.java
Modified:
ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/RequestHandlerImpl.java
ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/MethodExceptionTest.java
Log:
EXOJCR-353 added message & header when WebApplicationexception occurs
Modified:
ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/RequestHandlerImpl.java
===================================================================
---
ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/RequestHandlerImpl.java 2009-12-29
12:18:42 UTC (rev 1231)
+++
ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/RequestHandlerImpl.java 2009-12-29
12:26:31 UTC (rev 1232)
@@ -147,7 +147,7 @@
{
if (LOG.isDebugEnabled() && e.getCause() != null)
{
- LOG.warn("WedApplication exception occurs.",
e.getCause());
+ LOG.warn("WebApplication exception occurs.",
e.getCause());
}
if (errorResponse.getEntity() == null)
{
@@ -156,6 +156,12 @@
errorResponse = excmap.toResponse(e);
}
}
+
+ if (e.getMessage() != null)
+ errorResponse =
+ Response.status(errorResponse.getStatus()).entity(new
String(e.getMessage())).type(
+
MediaType.TEXT_PLAIN).header("JAXRS-Message-Provided",
"true").build();
+
response.setResponse(errorResponse);
}
else
@@ -168,7 +174,7 @@
if (LOG.isDebugEnabled() && e.getCause() != null)
{
// Hide error message if exception mapper exists.
- LOG.warn("WedApplication exception occurs.",
e.getCause());
+ LOG.warn("WebApplication exception occurs.",
e.getCause());
}
errorResponse = excmap.toResponse(e);
@@ -177,13 +183,20 @@
{
if (e.getCause() != null)
{
- LOG.warn("WedApplication exception occurs.",
e.getCause());
+ LOG.warn("WebApplication exception occurs.",
e.getCause());
}
- // add stack trace as message body
- errorResponse =
- Response.status(errorResponse.getStatus()).entity(new
ErrorStreaming(e)).type(
- MediaType.TEXT_PLAIN).build();
+ // print stack trace & adding ex message into body
+ if (LOG.isDebugEnabled())
+ {
+ e.printStackTrace();
+ }
+ if (e.getMessage() != null)
+ errorResponse =
+ Response.status(errorResponse.getStatus()).entity(new
String(e.getMessage())).type(
+
MediaType.TEXT_PLAIN).header("JAXRS-Message-Provided",
"true").build();
+ else
+ errorResponse =
Response.status(errorResponse.getStatus()).header("JAXRS-Message-Provided",
"false").build();
}
}
response.setResponse(errorResponse);
Modified:
ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/MethodExceptionTest.java
===================================================================
---
ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/MethodExceptionTest.java 2009-12-29
12:18:42 UTC (rev 1231)
+++
ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/MethodExceptionTest.java 2009-12-29
12:26:31 UTC (rev 1232)
@@ -31,7 +31,7 @@
* Date: 21 Jan 2009
*
* @author <a href="mailto:dmitry.kataev@exoplatform.com.ua">Dmytro
Katayev</a>
- * @version $Id: TestMethodException.java
+ * @version $Id: MethodExceptionTest.java
*/
public class MethodExceptionTest extends AbstractResourceTest
{
Added:
ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/WebApplicationExceptionTest.java
===================================================================
---
ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/WebApplicationExceptionTest.java
(rev 0)
+++
ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/WebApplicationExceptionTest.java 2009-12-29
12:26:31 UTC (rev 1232)
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.services.rest.impl.method;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+
+import org.exoplatform.services.rest.AbstractResourceTest;
+import org.exoplatform.services.rest.impl.method.MethodExceptionTest.UncheckedException;
+
+/**
+ * Created by The eXo Platform SAS. <br/>
+ * Date: 24 Dec 2009
+ *
+ * @author <a href="mailto:max.shaposhnik@exoplatform.com">Max
Shaposhnik</a>
+ * @version $Id: WebApplicationExceptionTest.java
+ */
+public class WebApplicationExceptionTest extends AbstractResourceTest
+{
+
+ @Path("/a")
+ public static class Resource1
+ {
+
+ @GET
+ @Path("/0")
+ public void m0() throws WebApplicationException
+ {
+ Exception e = new Exception("testmsg");
+ throw new WebApplicationException(e, 500);
+ }
+
+ @GET
+ @Path("/1")
+ public Response m1() throws WebApplicationException
+ {
+ throw new WebApplicationException(500);
+ }
+
+ @GET
+ @Path("/2")
+ public void m2() throws Exception
+ {
+ throw new UncheckedException("Unchecked exception");
+ }
+
+ }
+
+ public void testExceptionMessage() throws Exception
+ {
+ Resource1 resource = new Resource1();
+ registry(resource);
+
+ assertEquals(500, service("GET", "/a/0", "", null,
null).getStatus());
+ String entity = (String)service("GET", "/a/0", "",
null, null).getEntity();
+ assertTrue(entity.indexOf("testmsg") > 0);
+
+ assertEquals(500, service("GET", "/a/1", "", null,
null).getStatus());
+ assertEquals(null, service("GET", "/a/1", "", null,
null).getEntity());
+ unregistry(resource);
+ }
+
+}
Property changes on:
ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/WebApplicationExceptionTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native