Add DecoderResult.UNFINISHED to represent the case where a decoder generated a message that was not decoded completely / Remove partial failure in DecoderResult which is not very useful but confusing
This commit is contained in:
parent
acde9a3f8e
commit
c660002b4e
@ -175,7 +175,7 @@ public class HttpObjectAggregator extends MessageToMessageDecoder<HttpObject> {
|
||||
final boolean last;
|
||||
if (!chunk.getDecoderResult().isSuccess()) {
|
||||
currentMessage.setDecoderResult(
|
||||
DecoderResult.partialFailure(chunk.getDecoderResult().cause()));
|
||||
DecoderResult.failure(chunk.getDecoderResult().cause()));
|
||||
last = true;
|
||||
} else {
|
||||
last = chunk instanceof LastHttpContent;
|
||||
|
@ -447,7 +447,7 @@ public abstract class HttpObjectDecoder extends ReplayingDecoder<HttpObjectDecod
|
||||
private HttpMessage invalidMessage(Exception cause) {
|
||||
checkpoint(State.BAD_MESSAGE);
|
||||
if (message != null) {
|
||||
message.setDecoderResult(DecoderResult.partialFailure(cause));
|
||||
message.setDecoderResult(DecoderResult.failure(cause));
|
||||
} else {
|
||||
message = createInvalidMessage();
|
||||
message.setDecoderResult(DecoderResult.failure(cause));
|
||||
|
@ -37,7 +37,7 @@ public class HttpInvalidMessageTest {
|
||||
HttpRequest req = (HttpRequest) ch.readInbound();
|
||||
DecoderResult dr = req.getDecoderResult();
|
||||
assertFalse(dr.isSuccess());
|
||||
assertFalse(dr.isPartialFailure());
|
||||
assertFalse(dr.isFailure());
|
||||
ensureInboundTrafficDiscarded(ch);
|
||||
}
|
||||
|
||||
@ -51,7 +51,7 @@ public class HttpInvalidMessageTest {
|
||||
HttpRequest req = (HttpRequest) ch.readInbound();
|
||||
DecoderResult dr = req.getDecoderResult();
|
||||
assertFalse(dr.isSuccess());
|
||||
assertTrue(dr.isPartialFailure());
|
||||
assertTrue(dr.isFailure());
|
||||
assertEquals("Good Value", req.headers().get("Good_Name"));
|
||||
assertEquals("/maybe-something", req.getUri());
|
||||
ensureInboundTrafficDiscarded(ch);
|
||||
@ -64,7 +64,7 @@ public class HttpInvalidMessageTest {
|
||||
HttpResponse res = (HttpResponse) ch.readInbound();
|
||||
DecoderResult dr = res.getDecoderResult();
|
||||
assertFalse(dr.isSuccess());
|
||||
assertFalse(dr.isPartialFailure());
|
||||
assertFalse(dr.isFailure());
|
||||
ensureInboundTrafficDiscarded(ch);
|
||||
}
|
||||
|
||||
@ -78,7 +78,7 @@ public class HttpInvalidMessageTest {
|
||||
HttpResponse res = (HttpResponse) ch.readInbound();
|
||||
DecoderResult dr = res.getDecoderResult();
|
||||
assertFalse(dr.isSuccess());
|
||||
assertTrue(dr.isPartialFailure());
|
||||
assertTrue(dr.isFailure());
|
||||
assertEquals("Maybe OK", res.getStatus().reasonPhrase());
|
||||
assertEquals("Good Value", res.headers().get("Good_Name"));
|
||||
ensureInboundTrafficDiscarded(ch);
|
||||
@ -97,7 +97,7 @@ public class HttpInvalidMessageTest {
|
||||
HttpContent chunk = (HttpContent) ch.readInbound();
|
||||
DecoderResult dr = chunk.getDecoderResult();
|
||||
assertFalse(dr.isSuccess());
|
||||
assertFalse(dr.isPartialFailure());
|
||||
assertFalse(dr.isFailure());
|
||||
ensureInboundTrafficDiscarded(ch);
|
||||
}
|
||||
|
||||
|
@ -15,71 +15,68 @@
|
||||
*/
|
||||
package io.netty.handler.codec;
|
||||
|
||||
import io.netty.util.Signal;
|
||||
|
||||
public class DecoderResult {
|
||||
|
||||
public static final DecoderResult SUCCESS = new DecoderResult(false, null);
|
||||
protected static final Signal SIGNAL_UNFINISHED = new Signal(DecoderResult.class.getName() + ".UNFINISHED");
|
||||
protected static final Signal SIGNAL_SUCCESS = new Signal(DecoderResult.class.getName() + ".SUCCESS");
|
||||
|
||||
public static final DecoderResult UNFINISHED = new DecoderResult(SIGNAL_UNFINISHED);
|
||||
public static final DecoderResult SUCCESS = new DecoderResult(SIGNAL_SUCCESS);
|
||||
|
||||
public static DecoderResult failure(Throwable cause) {
|
||||
if (cause == null) {
|
||||
throw new NullPointerException("cause");
|
||||
}
|
||||
return new DecoderResult(false, cause);
|
||||
return new DecoderResult(cause);
|
||||
}
|
||||
|
||||
public static DecoderResult partialFailure(Throwable cause) {
|
||||
private final Throwable cause;
|
||||
|
||||
protected DecoderResult(Throwable cause) {
|
||||
if (cause == null) {
|
||||
throw new NullPointerException("cause");
|
||||
}
|
||||
return new DecoderResult(true, cause);
|
||||
}
|
||||
|
||||
private final boolean partial;
|
||||
private final Throwable cause;
|
||||
|
||||
protected DecoderResult(boolean partial, Throwable cause) {
|
||||
if (partial && cause == null) {
|
||||
throw new IllegalArgumentException("successful result cannot be partial.");
|
||||
}
|
||||
|
||||
this.partial = partial;
|
||||
this.cause = cause;
|
||||
}
|
||||
|
||||
public boolean isFinished() {
|
||||
return cause != SIGNAL_UNFINISHED;
|
||||
}
|
||||
|
||||
public boolean isSuccess() {
|
||||
return cause == null;
|
||||
return cause == SIGNAL_SUCCESS;
|
||||
}
|
||||
|
||||
public boolean isFailure() {
|
||||
return cause != null;
|
||||
}
|
||||
|
||||
public boolean isCompleteFailure() {
|
||||
return cause != null && !partial;
|
||||
}
|
||||
|
||||
public boolean isPartialFailure() {
|
||||
return partial;
|
||||
return cause != SIGNAL_SUCCESS && cause != SIGNAL_UNFINISHED;
|
||||
}
|
||||
|
||||
public Throwable cause() {
|
||||
if (isFailure()) {
|
||||
return cause;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (isFinished()) {
|
||||
if (isSuccess()) {
|
||||
return "success";
|
||||
}
|
||||
|
||||
String cause = cause().toString();
|
||||
StringBuilder buf = new StringBuilder(cause.length() + 17);
|
||||
if (isPartialFailure()) {
|
||||
buf.append("partial_");
|
||||
}
|
||||
buf.append("failure(");
|
||||
buf.append(cause);
|
||||
buf.append(')');
|
||||
|
||||
return buf.toString();
|
||||
} else {
|
||||
return "unfinished";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -132,11 +132,7 @@ public class HttpSnoopServerHandler extends ChannelInboundMessageHandlerAdapter<
|
||||
return;
|
||||
}
|
||||
|
||||
buf.append(".. WITH A ");
|
||||
if (result.isPartialFailure()) {
|
||||
buf.append("PARTIAL ");
|
||||
}
|
||||
buf.append("DECODER FAILURE: ");
|
||||
buf.append(".. WITH DECODER FAILURE: ");
|
||||
buf.append(result.cause());
|
||||
buf.append("\r\n");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user