Skip to content
Browse files

[RESTEASY-1006] Fix unhandled exception handling in Netty and Netty 4

  • Loading branch information...
1 parent 3ddbc5b commit 18bc8d770e23141c7e895f43f6104277e246c17b @tbroyer tbroyer committed
View
6 jaxrs/server-adapters/resteasy-netty/pom.xml
@@ -28,6 +28,12 @@
<artifactId>junit</artifactId>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.jboss.resteasy</groupId>
+ <artifactId>resteasy-client</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
<plugins>
View
2 .../resteasy-netty/src/main/java/org/jboss/resteasy/plugins/server/netty/RequestHandler.java
@@ -59,14 +59,12 @@ public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Ex
{
response.reset();
response.setStatus(e1.getErrorCode());
- return;
}
catch (Exception ex)
{
response.reset();
response.setStatus(500);
logger.error("Unexpected", ex);
- return;
}
// Write the response.
View
72 jaxrs/server-adapters/resteasy-netty/src/test/java/org/jboss/resteasy/test/NettyTest.java
@@ -0,0 +1,72 @@
+package org.jboss.resteasy.test;
+
+import org.jboss.resteasy.client.jaxrs.ResteasyClient;
+import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;
+import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Response;
+
+import static org.jboss.resteasy.test.TestPortProvider.generateURL;
+
+/**
+ * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
+ * @version $Revision: 1 $
+ */
+public class NettyTest
+{
+ @Path("/")
+ public static class Resource
+ {
+ @GET
+ @Path("/test")
+ @Produces("text/plain")
+ public String hello()
+ {
+ return "hello world";
+ }
+
+ @GET
+ @Path("/exception")
+ @Produces("text/plain")
+ public String exception() {
+ throw new RuntimeException();
+ }
+ }
+
+ @BeforeClass
+ public static void setup() throws Exception
+ {
+ NettyContainer.start().getRegistry().addPerRequestResource(Resource.class);
+ }
+
+ @AfterClass
+ public static void end() throws Exception
+ {
+ NettyContainer.stop();
+ }
+
+ @Test
+ public void testBasic() throws Exception
+ {
+ ResteasyClient client = new ResteasyClientBuilder().build();
+ ResteasyWebTarget target = client.target(generateURL("/test"));
+ String val = target.request().get(String.class);
+ Assert.assertEquals("hello world", val);
+ }
+
+ @Test
+ public void testUnhandledException() throws Exception
+ {
+ ResteasyClient client = new ResteasyClientBuilder().build();
+ ResteasyWebTarget target = client.target(generateURL("/exception"));
+ Response resp = target.request().get();
+ Assert.assertEquals(500, resp.getStatus());
+ }
+}
View
22 jaxrs/server-adapters/resteasy-netty4/src/test/java/org/jboss/resteasy/test/NettyTest.java
@@ -11,6 +11,7 @@
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
+import javax.ws.rs.core.Response;
import static org.jboss.resteasy.test.TestPortProvider.generateURL;
@@ -20,17 +21,23 @@
*/
public class NettyTest
{
- @Path("/test")
+ @Path("/")
public static class Resource
{
@GET
+ @Path("/test")
@Produces("text/plain")
public String hello()
{
return "hello world";
}
-
+ @GET
+ @Path("/exception")
+ @Produces("text/plain")
+ public String exception() {
+ throw new RuntimeException();
+ }
}
@BeforeClass
@@ -51,6 +58,15 @@ public void testBasic() throws Exception
ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target(generateURL("/test"));
String val = target.request().get(String.class);
- Assert.assertEquals(val, "hello world");
+ Assert.assertEquals("hello world", val);
+ }
+
+ @Test
+ public void testUnhandledException() throws Exception
+ {
+ ResteasyClient client = new ResteasyClientBuilder().build();
+ ResteasyWebTarget target = client.target(generateURL("/exception"));
+ Response resp = target.request().get();
+ Assert.assertEquals(500, resp.getStatus());
}
}

0 comments on commit 18bc8d7

Please sign in to comment.
Something went wrong with that request. Please try again.