[#441] Provide a better way to handle decoder failures

* Rename isPartial() to isPartialFailure()
* Add isCompleteFailure() and isFailure()
This commit is contained in:
Trustin Lee 2012-09-28 15:46:17 +09:00
parent 045b621b3f
commit 94838ee274
3 changed files with 16 additions and 8 deletions

View File

@ -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);
}

View File

@ -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(");

View File

@ -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: ");