Skip to content

Commit

Permalink
Rename to make clear these are exceptions not errors
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1684599 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
markt-asf committed Jun 10, 2015
1 parent cb49fe4 commit a478d3c
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 44 deletions.
Expand Up @@ -16,11 +16,14 @@
*/ */
package org.apache.coyote.http2; package org.apache.coyote.http2;


public class ConnectionError extends Http2Exception { /**
* Thrown when an HTTP/2 connection error occurs.
*/
public class ConnectionException extends Http2Exception {


private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;


public ConnectionError(String msg, Http2Error error) { public ConnectionException(String msg, Http2Error error) {
super(msg, error); super(msg, error);
} }
} }
18 changes: 9 additions & 9 deletions java/org/apache/coyote/http2/ConnectionSettings.java
Expand Up @@ -42,7 +42,7 @@ public class ConnectionSettings {
private volatile int maxFrameSize = DEFAULT_MAX_FRAME_SIZE; private volatile int maxFrameSize = DEFAULT_MAX_FRAME_SIZE;
private volatile long maxHeaderListSize = UNLIMITED; private volatile long maxHeaderListSize = UNLIMITED;


public void set(int parameterId, long value) throws ConnectionError { public void set(int parameterId, long value) throws ConnectionException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug(sm.getString("connectionSettings.debug", log.debug(sm.getString("connectionSettings.debug",
Integer.toString(parameterId), Long.toString(value))); Integer.toString(parameterId), Long.toString(value)));
Expand Down Expand Up @@ -78,10 +78,10 @@ public void set(int parameterId, long value) throws ConnectionError {
public int getHeaderTableSize() { public int getHeaderTableSize() {
return headerTableSize; return headerTableSize;
} }
public void setHeaderTableSize(long headerTableSize) throws ConnectionError { public void setHeaderTableSize(long headerTableSize) throws ConnectionException {
// Need to put a sensible limit on this. Start with 16k (default is 4k) // Need to put a sensible limit on this. Start with 16k (default is 4k)
if (headerTableSize > (16 * 1024)) { if (headerTableSize > (16 * 1024)) {
throw new ConnectionError(sm.getString("connectionSettings.headerTableSizeLimit", throw new ConnectionException(sm.getString("connectionSettings.headerTableSizeLimit",
Long.toString(headerTableSize)), Http2Error.PROTOCOL_ERROR); Long.toString(headerTableSize)), Http2Error.PROTOCOL_ERROR);
} }
this.headerTableSize = (int) headerTableSize; this.headerTableSize = (int) headerTableSize;
Expand All @@ -91,11 +91,11 @@ public void setHeaderTableSize(long headerTableSize) throws ConnectionError {
public boolean getEnablePush() { public boolean getEnablePush() {
return enablePush; return enablePush;
} }
public void setEnablePush(long enablePush) throws ConnectionError { public void setEnablePush(long enablePush) throws ConnectionException {
// Can't be less than zero since the result of the byte->long conversion // Can't be less than zero since the result of the byte->long conversion
// will never be negative // will never be negative
if (enablePush > 1) { if (enablePush > 1) {
throw new ConnectionError(sm.getString("connectionSettings.enablePushInvalid", throw new ConnectionException(sm.getString("connectionSettings.enablePushInvalid",
Long.toString(enablePush)), Http2Error.PROTOCOL_ERROR); Long.toString(enablePush)), Http2Error.PROTOCOL_ERROR);
} }
this.enablePush = (enablePush == 1); this.enablePush = (enablePush == 1);
Expand All @@ -113,9 +113,9 @@ public void setMaxConcurrentStreams(long maxConcurrentStreams) {
public int getInitialWindowSize() { public int getInitialWindowSize() {
return initialWindowSize; return initialWindowSize;
} }
public void setInitialWindowSize(long initialWindowSize) throws ConnectionError { public void setInitialWindowSize(long initialWindowSize) throws ConnectionException {
if (initialWindowSize > MAX_WINDOW_SIZE) { if (initialWindowSize > MAX_WINDOW_SIZE) {
throw new ConnectionError(sm.getString("connectionSettings.windowSizeTooBig", throw new ConnectionException(sm.getString("connectionSettings.windowSizeTooBig",
Long.toString(initialWindowSize), Long.toString(MAX_WINDOW_SIZE)), Long.toString(initialWindowSize), Long.toString(MAX_WINDOW_SIZE)),
Http2Error.PROTOCOL_ERROR); Http2Error.PROTOCOL_ERROR);
} }
Expand All @@ -126,9 +126,9 @@ public void setInitialWindowSize(long initialWindowSize) throws ConnectionError
public int getMaxFrameSize() { public int getMaxFrameSize() {
return maxFrameSize; return maxFrameSize;
} }
public void setMaxFrameSize(long maxFrameSize) throws ConnectionError { public void setMaxFrameSize(long maxFrameSize) throws ConnectionException {
if (maxFrameSize < MIN_MAX_FRAME_SIZE || maxFrameSize > MAX_MAX_FRAME_SIZE) { if (maxFrameSize < MIN_MAX_FRAME_SIZE || maxFrameSize > MAX_MAX_FRAME_SIZE) {
throw new ConnectionError(sm.getString("connectionSettings.maxFrameSizeInvalid", throw new ConnectionException(sm.getString("connectionSettings.maxFrameSizeInvalid",
Long.toString(maxFrameSize), Integer.toString(MIN_MAX_FRAME_SIZE), Long.toString(maxFrameSize), Integer.toString(MIN_MAX_FRAME_SIZE),
Integer.toString(MAX_MAX_FRAME_SIZE)), Http2Error.PROTOCOL_ERROR); Integer.toString(MAX_MAX_FRAME_SIZE)), Http2Error.PROTOCOL_ERROR);
} }
Expand Down
6 changes: 3 additions & 3 deletions java/org/apache/coyote/http2/FrameType.java
Expand Up @@ -61,18 +61,18 @@ public byte getIdByte() {
public void check(int streamId, int payloadSize) throws Http2Exception { public void check(int streamId, int payloadSize) throws Http2Exception {
// Is FrameType valid for the given stream? // Is FrameType valid for the given stream?
if (streamId == 0 && !streamZero || streamId != 0 && !streamNonZero) { if (streamId == 0 && !streamZero || streamId != 0 && !streamNonZero) {
throw new ConnectionError(sm.getString("frameType.checkStream", this), throw new ConnectionException(sm.getString("frameType.checkStream", this),
Http2Error.PROTOCOL_ERROR); Http2Error.PROTOCOL_ERROR);
} }


// Is the payload size valid for the given FrameType // Is the payload size valid for the given FrameType
if (payloadSizeValidator != null && !payloadSizeValidator.test(payloadSize)) { if (payloadSizeValidator != null && !payloadSizeValidator.test(payloadSize)) {
if (payloadErrorFatal || streamId == 0) { if (payloadErrorFatal || streamId == 0) {
throw new ConnectionError(sm.getString("frameType.checkPayloadSize", throw new ConnectionException(sm.getString("frameType.checkPayloadSize",
Integer.toString(payloadSize), this), Integer.toString(payloadSize), this),
Http2Error.FRAME_SIZE_ERROR); Http2Error.FRAME_SIZE_ERROR);
} else { } else {
throw new StreamError(sm.getString("frameType.checkPayloadSize", throw new StreamException(sm.getString("frameType.checkPayloadSize",
Integer.toString(payloadSize), this), Integer.toString(payloadSize), this),
Http2Error.FRAME_SIZE_ERROR, streamId); Http2Error.FRAME_SIZE_ERROR, streamId);
} }
Expand Down
30 changes: 15 additions & 15 deletions java/org/apache/coyote/http2/Http2Parser.java
Expand Up @@ -85,7 +85,7 @@ private boolean readFrame(boolean block, FrameType expected)


try { try {
validateFrame(expected, frameType, streamId, flags, payloadSize); validateFrame(expected, frameType, streamId, flags, payloadSize);
} catch (StreamError se) { } catch (StreamException se) {
swallow(payloadSize); swallow(payloadSize);
throw se; throw se;
} }
Expand Down Expand Up @@ -244,7 +244,7 @@ private void readRstFrame(int streamId) throws Http2Exception, IOException {
private void readSettingsFrame(int flags, int payloadSize) throws Http2Exception, IOException { private void readSettingsFrame(int flags, int payloadSize) throws Http2Exception, IOException {
boolean ack = Flags.isAck(flags); boolean ack = Flags.isAck(flags);
if (payloadSize > 0 && ack) { if (payloadSize > 0 && ack) {
throw new ConnectionError(sm.getString( throw new ConnectionException(sm.getString(
"http2Parser.processFrameSettings.ackWithNonZeroPayload"), "http2Parser.processFrameSettings.ackWithNonZeroPayload"),
Http2Error.FRAME_SIZE_ERROR); Http2Error.FRAME_SIZE_ERROR);
} }
Expand All @@ -264,7 +264,7 @@ private void readSettingsFrame(int flags, int payloadSize) throws Http2Exception




private void readPushPromiseFrame(int streamId) throws Http2Exception { private void readPushPromiseFrame(int streamId) throws Http2Exception {
throw new ConnectionError(sm.getString("http2Parser.processFramePushPromise", throw new ConnectionException(sm.getString("http2Parser.processFramePushPromise",
connectionId, Integer.valueOf(streamId)), Http2Error.PROTOCOL_ERROR); connectionId, Integer.valueOf(streamId)), Http2Error.PROTOCOL_ERROR);
} }


Expand Down Expand Up @@ -308,11 +308,11 @@ private void readWindowUpdateFrame(int streamId) throws Http2Exception, IOExcept
// Validate the data // Validate the data
if (windowSizeIncrement == 0) { if (windowSizeIncrement == 0) {
if (streamId == 0) { if (streamId == 0) {
throw new ConnectionError( throw new ConnectionException(
sm.getString("http2Parser.processFrameWindowUpdate.invalidIncrement"), sm.getString("http2Parser.processFrameWindowUpdate.invalidIncrement"),
Http2Error.PROTOCOL_ERROR); Http2Error.PROTOCOL_ERROR);
} else { } else {
throw new StreamError( throw new StreamException(
sm.getString("http2Parser.processFrameWindowUpdate.invalidIncrement"), sm.getString("http2Parser.processFrameWindowUpdate.invalidIncrement"),
Http2Error.PROTOCOL_ERROR, streamId); Http2Error.PROTOCOL_ERROR, streamId);
} }
Expand All @@ -326,7 +326,7 @@ private void readContinuationFrame(int streamId, int flags, int payloadSize)
throws Http2Exception, IOException { throws Http2Exception, IOException {
if (headersCurrentStream == -1) { if (headersCurrentStream == -1) {
// No headers to continue // No headers to continue
throw new ConnectionError(sm.getString( throw new ConnectionException(sm.getString(
"http2Parser.processFrameContinuation.notExpected", connectionId, "http2Parser.processFrameContinuation.notExpected", connectionId,
Integer.toString(streamId)), Http2Error.PROTOCOL_ERROR); Integer.toString(streamId)), Http2Error.PROTOCOL_ERROR);
} }
Expand Down Expand Up @@ -357,7 +357,7 @@ private void readHeaderBlock(int payloadSize, boolean endOfHeaders)
try { try {
hpackDecoder.decode(headerReadBuffer); hpackDecoder.decode(headerReadBuffer);
} catch (HpackException hpe) { } catch (HpackException hpe) {
throw new ConnectionError( throw new ConnectionException(
sm.getString("http2Parser.processFrameHeaders.decodingFailed"), sm.getString("http2Parser.processFrameHeaders.decodingFailed"),
Http2Error.COMPRESSION_ERROR); Http2Error.COMPRESSION_ERROR);
} }
Expand All @@ -367,7 +367,7 @@ private void readHeaderBlock(int payloadSize, boolean endOfHeaders)
} }


if (headerReadBuffer.position() > 0 && endOfHeaders) { if (headerReadBuffer.position() > 0 && endOfHeaders) {
throw new ConnectionError( throw new ConnectionException(
sm.getString("http2Parser.processFrameHeaders.decodingDataLeft"), sm.getString("http2Parser.processFrameHeaders.decodingDataLeft"),
Http2Error.COMPRESSION_ERROR); Http2Error.COMPRESSION_ERROR);
} }
Expand Down Expand Up @@ -413,26 +413,26 @@ private void validateFrame(FrameType expected, FrameType frameType, int streamId
} }


if (expected != null && frameType != expected) { if (expected != null && frameType != expected) {
throw new StreamError(sm.getString("http2Parser.processFrame.unexpectedType", throw new StreamException(sm.getString("http2Parser.processFrame.unexpectedType",
expected, frameType), Http2Error.PROTOCOL_ERROR, streamId); expected, frameType), Http2Error.PROTOCOL_ERROR, streamId);
} }


if (payloadSize > maxPayloadSize) { if (payloadSize > maxPayloadSize) {
throw new ConnectionError(sm.getString("http2Parser.payloadTooBig", throw new ConnectionException(sm.getString("http2Parser.payloadTooBig",
Integer.toString(payloadSize), Integer.toString(maxPayloadSize)), Integer.toString(payloadSize), Integer.toString(maxPayloadSize)),
Http2Error.FRAME_SIZE_ERROR); Http2Error.FRAME_SIZE_ERROR);
} }


if (headersCurrentStream != -1) { if (headersCurrentStream != -1) {
if (headersCurrentStream != streamId) { if (headersCurrentStream != streamId) {
throw new ConnectionError(sm.getString("http2Parser.headers.wrongStream", throw new ConnectionException(sm.getString("http2Parser.headers.wrongStream",
connectionId, Integer.toString(headersCurrentStream), connectionId, Integer.toString(headersCurrentStream),
Integer.toString(streamId)), Http2Error.COMPRESSION_ERROR); Integer.toString(streamId)), Http2Error.COMPRESSION_ERROR);
} }
if (frameType == FrameType.RST) { if (frameType == FrameType.RST) {
// NO-OP: RST is OK here // NO-OP: RST is OK here
} else if (frameType != FrameType.CONTINUATION) { } else if (frameType != FrameType.CONTINUATION) {
throw new ConnectionError(sm.getString("http2Parser.headers.wrongFrameType", throw new ConnectionException(sm.getString("http2Parser.headers.wrongFrameType",
connectionId, Integer.toString(headersCurrentStream), connectionId, Integer.toString(headersCurrentStream),
frameType), Http2Error.COMPRESSION_ERROR); frameType), Http2Error.COMPRESSION_ERROR);
} }
Expand Down Expand Up @@ -517,11 +517,11 @@ static interface Output {


// Data frames // Data frames
ByteBuffer getInputByteBuffer(int streamId, int payloadSize) throws Http2Exception; ByteBuffer getInputByteBuffer(int streamId, int payloadSize) throws Http2Exception;
void receiveEndOfStream(int streamId) throws ConnectionError; void receiveEndOfStream(int streamId) throws ConnectionException;


// Header frames // Header frames
HeaderEmitter headersStart(int streamId) throws Http2Exception; HeaderEmitter headersStart(int streamId) throws Http2Exception;
void headersEnd(int streamId) throws ConnectionError; void headersEnd(int streamId) throws ConnectionException;


// Priority frames (also headers) // Priority frames (also headers)
void reprioritise(int streamId, int parentStreamId, boolean exclusive, int weight) void reprioritise(int streamId, int parentStreamId, boolean exclusive, int weight)
Expand All @@ -531,7 +531,7 @@ void reprioritise(int streamId, int parentStreamId, boolean exclusive, int weigh
void reset(int streamId, long errorCode) throws Http2Exception; void reset(int streamId, long errorCode) throws Http2Exception;


// Settings frames // Settings frames
void setting(int identifier, long value) throws ConnectionError; void setting(int identifier, long value) throws ConnectionException;
void settingsEnd(boolean ack) throws IOException; void settingsEnd(boolean ack) throws IOException;


// Ping frames // Ping frames
Expand Down
20 changes: 10 additions & 10 deletions java/org/apache/coyote/http2/Http2UpgradeHandler.java
Expand Up @@ -245,7 +245,7 @@ public SocketState upgradeDispatch(SocketStatus status) {
if (!parser.readFrame(false)) { if (!parser.readFrame(false)) {
break; break;
} }
} catch (StreamError se) { } catch (StreamException se) {
// Stream errors are not fatal to the connection so // Stream errors are not fatal to the connection so
// continue reading frames // continue reading frames
closeStream(se); closeStream(se);
Expand Down Expand Up @@ -340,7 +340,7 @@ public void destroy() {
} }




private void closeStream(StreamError se) throws ConnectionError, IOException { private void closeStream(StreamException se) throws ConnectionException, IOException {


if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug(sm.getString("upgradeHandler.rst.debug", connectionId, log.debug(sm.getString("upgradeHandler.rst.debug", connectionId,
Expand Down Expand Up @@ -627,27 +627,27 @@ private int allocate(AbstractStream stream, int allocation) {
} }




private Stream getStream(int streamId, boolean unknownIsError) throws ConnectionError{ private Stream getStream(int streamId, boolean unknownIsError) throws ConnectionException{
Integer key = Integer.valueOf(streamId); Integer key = Integer.valueOf(streamId);
Stream result = streams.get(key); Stream result = streams.get(key);
if (result == null && unknownIsError) { if (result == null && unknownIsError) {
// Stream has been closed and removed from the map // Stream has been closed and removed from the map
throw new ConnectionError(sm.getString("upgradeHandler.stream.closed", key), Http2Error.PROTOCOL_ERROR); throw new ConnectionException(sm.getString("upgradeHandler.stream.closed", key), Http2Error.PROTOCOL_ERROR);
} }
return result; return result;
} }




private Stream createRemoteStream(int streamId) throws ConnectionError { private Stream createRemoteStream(int streamId) throws ConnectionException {
Integer key = Integer.valueOf(streamId); Integer key = Integer.valueOf(streamId);


if (streamId %2 != 1) { if (streamId %2 != 1) {
throw new ConnectionError( throw new ConnectionException(
sm.getString("upgradeHandler.stream.even", key), Http2Error.PROTOCOL_ERROR); sm.getString("upgradeHandler.stream.even", key), Http2Error.PROTOCOL_ERROR);
} }


if (streamId <= maxRemoteStreamId) { if (streamId <= maxRemoteStreamId) {
throw new ConnectionError(sm.getString("upgradeHandler.stream.old", key, throw new ConnectionException(sm.getString("upgradeHandler.stream.old", key,
Integer.valueOf(maxRemoteStreamId)), Http2Error.PROTOCOL_ERROR); Integer.valueOf(maxRemoteStreamId)), Http2Error.PROTOCOL_ERROR);
} }


Expand Down Expand Up @@ -770,7 +770,7 @@ public ByteBuffer getInputByteBuffer(int streamId, int payloadSize) throws Http2




@Override @Override
public void receiveEndOfStream(int streamId) throws ConnectionError { public void receiveEndOfStream(int streamId) throws ConnectionException {
Stream stream = getStream(streamId, true); Stream stream = getStream(streamId, true);
if (stream != null) { if (stream != null) {
stream.receivedEndOfStream(); stream.receivedEndOfStream();
Expand Down Expand Up @@ -807,7 +807,7 @@ public void reprioritise(int streamId, int parentStreamId,




@Override @Override
public void headersEnd(int streamId) throws ConnectionError { public void headersEnd(int streamId) throws ConnectionException {
Stream stream = getStream(streamId, true); Stream stream = getStream(streamId, true);
// Process this stream on a container thread // Process this stream on a container thread
StreamProcessor streamProcessor = new StreamProcessor(stream, adapter, socketWrapper); StreamProcessor streamProcessor = new StreamProcessor(stream, adapter, socketWrapper);
Expand All @@ -828,7 +828,7 @@ public void reset(int streamId, long errorCode) throws Http2Exception {




@Override @Override
public void setting(int identifier, long value) throws ConnectionError { public void setting(int identifier, long value) throws ConnectionException {
remoteSettings.set(identifier, value); remoteSettings.set(identifier, value);
} }


Expand Down
Expand Up @@ -16,13 +16,16 @@
*/ */
package org.apache.coyote.http2; package org.apache.coyote.http2;


public class StreamError extends Http2Exception { /**
* Thrown when an HTTP/2 stream error occurs.
*/
public class StreamException extends Http2Exception {


private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;


private final int streamId; private final int streamId;


public StreamError(String msg, Http2Error error, int streamId) { public StreamException(String msg, Http2Error error, int streamId) {
super(msg, error); super(msg, error);
this.streamId = streamId; this.streamId = streamId;
} }
Expand Down
4 changes: 2 additions & 2 deletions java/org/apache/coyote/http2/StreamStateMachine.java
Expand Up @@ -108,11 +108,11 @@ public synchronized void checkFrameType(FrameType frameType) throws Http2Excepti
// state of this stream. // state of this stream.
if (!isFrameTypePermitted(frameType)) { if (!isFrameTypePermitted(frameType)) {
if (state.connectionErrorForInvalidFrame) { if (state.connectionErrorForInvalidFrame) {
throw new ConnectionError(sm.getString("streamStateMachine.invalidFrame", throw new ConnectionException(sm.getString("streamStateMachine.invalidFrame",
stream.getConnectionId(), stream.getIdentifier(), state, frameType), stream.getConnectionId(), stream.getIdentifier(), state, frameType),
state.errorCodeForInvalidFrame); state.errorCodeForInvalidFrame);
} else { } else {
throw new StreamError(sm.getString("streamStateMachine.invalidFrame", throw new StreamException(sm.getString("streamStateMachine.invalidFrame",
stream.getConnectionId(), stream.getIdentifier(), state, frameType), stream.getConnectionId(), stream.getIdentifier(), state, frameType),
state.errorCodeForInvalidFrame, stream.getIdentifier().intValue()); state.errorCodeForInvalidFrame, stream.getIdentifier().intValue());
} }
Expand Down
2 changes: 1 addition & 1 deletion test/org/apache/coyote/http2/Http2TestBase.java
Expand Up @@ -499,7 +499,7 @@ public void reset(int streamId, long errorCode) {




@Override @Override
public void setting(int identifier, long value) throws ConnectionError { public void setting(int identifier, long value) throws ConnectionException {
trace.append("0-Settings-[" + identifier + "]-[" + value + "]\n"); trace.append("0-Settings-[" + identifier + "]-[" + value + "]\n");
remoteSettings.set(identifier, value); remoteSettings.set(identifier, value);
} }
Expand Down

0 comments on commit a478d3c

Please sign in to comment.