From 94838ee274cbf5c1fa0fa2b621a8535dc11ae504 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Fri, 28 Sep 2012 15:46:17 +0900 Subject: [PATCH] [#441] Provide a better way to handle decoder failures * Rename isPartial() to isPartialFailure() * Add isCompleteFailure() and isFailure() --- .../handler/codec/http/HttpInvalidMessageTest.java | 10 +++++----- .../java/io/netty/handler/codec/DecoderResult.java | 12 ++++++++++-- .../example/http/snoop/HttpSnoopServerHandler.java | 2 +- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/HttpInvalidMessageTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/HttpInvalidMessageTest.java index 77a27f1307..3d67783227 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/HttpInvalidMessageTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/HttpInvalidMessageTest.java @@ -37,7 +37,7 @@ public class HttpInvalidMessageTest { HttpRequest req = (HttpRequest) ch.readInbound(); DecoderResult dr = req.getDecoderResult(); Assert.assertFalse(dr.isSuccess()); - Assert.assertFalse(dr.isPartial()); + Assert.assertFalse(dr.isPartialFailure()); ensureInboundTrafficDiscarded(ch); } @@ -51,7 +51,7 @@ public class HttpInvalidMessageTest { HttpRequest req = (HttpRequest) ch.readInbound(); DecoderResult dr = req.getDecoderResult(); Assert.assertFalse(dr.isSuccess()); - Assert.assertTrue(dr.isPartial()); + Assert.assertTrue(dr.isPartialFailure()); Assert.assertEquals("Good Value", req.getHeader("Good_Name")); Assert.assertEquals("/maybe-something", req.getUri()); ensureInboundTrafficDiscarded(ch); @@ -64,7 +64,7 @@ public class HttpInvalidMessageTest { HttpResponse res = (HttpResponse) ch.readInbound(); DecoderResult dr = res.getDecoderResult(); Assert.assertFalse(dr.isSuccess()); - Assert.assertFalse(dr.isPartial()); + Assert.assertFalse(dr.isPartialFailure()); ensureInboundTrafficDiscarded(ch); } @@ -78,7 +78,7 @@ public class HttpInvalidMessageTest { HttpResponse res = (HttpResponse) ch.readInbound(); DecoderResult dr = res.getDecoderResult(); Assert.assertFalse(dr.isSuccess()); - Assert.assertTrue(dr.isPartial()); + Assert.assertTrue(dr.isPartialFailure()); Assert.assertEquals("Maybe OK", res.getStatus().getReasonPhrase()); Assert.assertEquals("Good Value", res.getHeader("Good_Name")); ensureInboundTrafficDiscarded(ch); @@ -97,7 +97,7 @@ public class HttpInvalidMessageTest { HttpChunk chunk = (HttpChunk) ch.readInbound(); DecoderResult dr = chunk.getDecoderResult(); Assert.assertFalse(dr.isSuccess()); - Assert.assertFalse(dr.isPartial()); + Assert.assertFalse(dr.isPartialFailure()); ensureInboundTrafficDiscarded(ch); } diff --git a/codec/src/main/java/io/netty/handler/codec/DecoderResult.java b/codec/src/main/java/io/netty/handler/codec/DecoderResult.java index 9c12a3c6e1..e621d8baf1 100644 --- a/codec/src/main/java/io/netty/handler/codec/DecoderResult.java +++ b/codec/src/main/java/io/netty/handler/codec/DecoderResult.java @@ -49,7 +49,15 @@ public class DecoderResult { return cause == null; } - public boolean isPartial() { + public boolean isFailure() { + return cause != null; + } + + public boolean isCompleteFailure() { + return cause != null && !partial; + } + + public boolean isPartialFailure() { return partial; } @@ -65,7 +73,7 @@ public class DecoderResult { String cause = cause().toString(); StringBuilder buf = new StringBuilder(cause.length() + 17); - if (isPartial()) { + if (isPartialFailure()) { buf.append("partial_"); } buf.append("failure("); diff --git a/example/src/main/java/io/netty/example/http/snoop/HttpSnoopServerHandler.java b/example/src/main/java/io/netty/example/http/snoop/HttpSnoopServerHandler.java index 7d5793b48f..5ba3073733 100644 --- a/example/src/main/java/io/netty/example/http/snoop/HttpSnoopServerHandler.java +++ b/example/src/main/java/io/netty/example/http/snoop/HttpSnoopServerHandler.java @@ -138,7 +138,7 @@ public class HttpSnoopServerHandler extends ChannelInboundMessageHandlerAdapter< } buf.append(".. WITH A "); - if (result.isPartial()) { + if (result.isPartialFailure()) { buf.append("PARTIAL "); } buf.append("DECODER FAILURE: ");