@Override final void throwException(String msg, Http2Error error) throws ConnectionException { throw new ConnectionException(msg, error); } }
final void close(Http2Exception http2Exception) { if (http2Exception instanceof StreamException) { try { StreamException se = (StreamException) http2Exception; if (log.isDebugEnabled()) { log.debug(sm.getString("stream.reset.send", getConnectionId(), getIdentifier(), se.getError())); } state.sendReset(); handler.sendStreamReset(se); } catch (IOException ioe) { ConnectionException ce = new ConnectionException( sm.getString("stream.reset.fail"), Http2Error.PROTOCOL_ERROR); ce.initCause(ioe); handler.closeConnection(ce); } } else { handler.closeConnection(http2Exception); } }
ConnectionException ce = new ConnectionException(sm.getString( "streamProcessor.error.connection", stream.getConnectionId(), stream.getIdentifier()), Http2Error.INTERNAL_ERROR); log.debug(msg, e); ConnectionException ce = new ConnectionException(msg, Http2Error.INTERNAL_ERROR); ce.initCause(e); stream.close(ce); } finally {
private Stream getStream(int streamId, boolean unknownIsError) throws ConnectionException { Integer key = Integer.valueOf(streamId); Stream result = streams.get(key); if (result == null && unknownIsError) { // Stream has been closed and removed from the map throw new ConnectionException(sm.getString("upgradeHandler.stream.closed", key), Http2Error.PROTOCOL_ERROR); } return result; }
/** * This default server side implementation always throws an exception. If * re-used for client side parsing, this method should be overridden with an * appropriate implementation. * * @param streamId The pushed stream * @param buffer The payload, if available * * @throws Http2Exception */ protected void readPushPromiseFrame(int streamId, ByteBuffer buffer) throws Http2Exception { throw new ConnectionException(sm.getString("http2Parser.processFramePushPromise", connectionId, Integer.valueOf(streamId)), Http2Error.PROTOCOL_ERROR); }
private Stream createRemoteStream(int streamId) throws ConnectionException { Integer key = Integer.valueOf(streamId); if (streamId %2 != 1) { throw new ConnectionException( sm.getString("upgradeHandler.stream.even", key), Http2Error.PROTOCOL_ERROR); } pruneClosedStreams(); Stream result = new Stream(key, this); streams.put(key, result); return result; }
final void receivedData(int payloadSize) throws ConnectionException { contentLengthReceived += payloadSize; long contentLengthHeader = coyoteRequest.getContentLengthLong(); if (contentLengthHeader > -1 && contentLengthReceived > contentLengthHeader) { throw new ConnectionException(sm.getString("stream.header.contentLength", getConnectionId(), getIdentifier(), Long.valueOf(contentLengthHeader), Long.valueOf(contentLengthReceived)), Http2Error.PROTOCOL_ERROR); } }
void check(int streamId, int payloadSize) throws Http2Exception { // Is FrameType valid for the given stream? if (streamId == 0 && !streamZero || streamId != 0 && !streamNonZero) { throw new ConnectionException(sm.getString("frameType.checkStream", this), Http2Error.PROTOCOL_ERROR); } // Is the payload size valid for the given FrameType if (payloadSizeValidator != null && !payloadSizeValidator.test(payloadSize)) { if (payloadErrorFatal || streamId == 0) { throw new ConnectionException(sm.getString("frameType.checkPayloadSize", Integer.toString(payloadSize), this), Http2Error.FRAME_SIZE_ERROR); } else { throw new StreamException(sm.getString("frameType.checkPayloadSize", Integer.toString(payloadSize), this), Http2Error.FRAME_SIZE_ERROR, streamId); } } }
protected void readContinuationFrame(int streamId, int flags, int payloadSize, ByteBuffer buffer) throws Http2Exception, IOException { if (headersCurrentStream == -1) { // No headers to continue throw new ConnectionException(sm.getString( "http2Parser.processFrameContinuation.notExpected", connectionId, Integer.toString(streamId)), Http2Error.PROTOCOL_ERROR); } readHeaderPayload(streamId, payloadSize, buffer); if (Flags.isEndOfHeaders(flags)) { headersCurrentStream = -1; onHeadersComplete(streamId); } }
final void receivedEndOfStream() throws ConnectionException { long contentLengthHeader = coyoteRequest.getContentLengthLong(); if (contentLengthHeader > -1 && contentLengthReceived != contentLengthHeader) { throw new ConnectionException(sm.getString("stream.header.contentLength", getConnectionId(), getIdentifier(), Long.valueOf(contentLengthHeader), Long.valueOf(contentLengthReceived)), Http2Error.PROTOCOL_ERROR); } state.receivedEndOfStream(); if (inputBuffer != null) { inputBuffer.notifyEof(); } }
throw new ConnectionException(sm.getString("http2Parser.payloadTooBig", Integer.toString(payloadSize), Integer.toString(maxFrameSize)), Http2Error.FRAME_SIZE_ERROR); throw new ConnectionException(sm.getString("http2Parser.headers.wrongStream", connectionId, Integer.toString(headersCurrentStream), Integer.toString(streamId)), Http2Error.COMPRESSION_ERROR); throw new ConnectionException(sm.getString("http2Parser.headers.wrongFrameType", connectionId, Integer.toString(headersCurrentStream), frameType), Http2Error.COMPRESSION_ERROR);
protected void onHeadersComplete(int streamId) throws Http2Exception { // Any left over data is a compression error if (headerReadBuffer.position() > 0) { throw new ConnectionException( sm.getString("http2Parser.processFrameHeaders.decodingDataLeft"), Http2Error.COMPRESSION_ERROR); } // Delay validation (and triggering any exception) until this point // since all the headers still have to be read if a StreamException is // going to be thrown. hpackDecoder.getHeaderEmitter().validateHeaders(); output.headersEnd(streamId); if (headersEndStream) { output.receivedEndOfStream(streamId); headersEndStream = false; } // Reset size for new request if the buffer was previously expanded if (headerReadBuffer.capacity() > Constants.DEFAULT_HEADER_READ_BUFFER_SIZE) { headerReadBuffer = ByteBuffer.allocate(Constants.DEFAULT_HEADER_READ_BUFFER_SIZE); } }
throw new ConnectionException(sm.getString("http2Parser.nonZeroPadding", connectionId, Integer.toString(streamId)), Http2Error.PROTOCOL_ERROR);
/** * Increment window size. * @param increment The amount by which the window size should be increased * @throws Http2Exception If the window size is now higher than * the maximum allowed */ synchronized void incrementWindowSize(int increment) throws Http2Exception { // No need for overflow protection here. // Increment can't be more than Integer.MAX_VALUE and once windowSize // goes beyond 2^31-1 an error is triggered. windowSize += increment; if (log.isDebugEnabled()) { log.debug(sm.getString("abstractStream.windowSizeInc", getConnectionId(), getIdentifier(), Integer.toString(increment), Long.toString(windowSize))); } if (windowSize > ConnectionSettingsBase.MAX_WINDOW_SIZE) { String msg = sm.getString("abstractStream.windowSizeTooBig", getConnectionId(), identifier, Integer.toString(increment), Long.toString(windowSize)); if (identifier.intValue() == 0) { throw new ConnectionException(msg, Http2Error.FLOW_CONTROL_ERROR); } else { throw new StreamException( msg, Http2Error.FLOW_CONTROL_ERROR, identifier.intValue()); } } }
hpackDecoder.decode(headerReadBuffer); } catch (HpackException hpe) { throw new ConnectionException( sm.getString("http2Parser.processFrameHeaders.decodingFailed"), Http2Error.COMPRESSION_ERROR, hpe); throw new ConnectionException(sm.getString("http2Parser.headerLimitSize", connectionId, Integer.valueOf(streamId)), Http2Error.ENHANCE_YOUR_CALM);
protected void readWindowUpdateFrame(int streamId, ByteBuffer buffer) throws Http2Exception, IOException { byte[] payload = new byte[4]; if (buffer == null) { input.fill(true, payload); } else { buffer.get(payload); } int windowSizeIncrement = ByteUtil.get31Bits(payload, 0); if (log.isDebugEnabled()) { log.debug(sm.getString("http2Parser.processFrameWindowUpdate.debug", connectionId, Integer.toString(streamId), Integer.toString(windowSizeIncrement))); } // Validate the data if (windowSizeIncrement == 0) { if (streamId == 0) { throw new ConnectionException( sm.getString("http2Parser.processFrameWindowUpdate.invalidIncrement"), Http2Error.PROTOCOL_ERROR); } else { throw new StreamException( sm.getString("http2Parser.processFrameWindowUpdate.invalidIncrement"), Http2Error.PROTOCOL_ERROR, streamId); } } output.incrementWindowSize(streamId, windowSizeIncrement); }
@Override public void reprioritise(int streamId, int parentStreamId, boolean exclusive, int weight) throws Http2Exception { if (streamId == parentStreamId) { throw new ConnectionException(sm.getString("upgradeHandler.dependency.invalid", getConnectionId(), Integer.valueOf(streamId)), Http2Error.PROTOCOL_ERROR); } Stream stream = getStream(streamId, false); if (stream == null) { stream = createRemoteStream(streamId); } stream.checkState(FrameType.PRIORITY); AbstractStream parentStream = getStream(parentStreamId, false); if (parentStream == null) { parentStream = this; } stream.rePrioritise(parentStream, exclusive, weight); }
final synchronized void checkFrameType(FrameType frameType) throws Http2Exception { // No state change. Checks that receiving the frame type is valid for // the current state of this stream. if (!isFrameTypePermitted(frameType)) { if (state.connectionErrorForInvalidFrame) { throw new ConnectionException(sm.getString("streamStateMachine.invalidFrame", stream.getConnectionId(), stream.getIdentifier(), state, frameType), state.errorCodeForInvalidFrame); } else { throw new StreamException(sm.getString("streamStateMachine.invalidFrame", stream.getConnectionId(), stream.getIdentifier(), state, frameType), state.errorCodeForInvalidFrame, stream.getIdentifier().intValue()); } } }
throw new ConnectionException(sm.getString("upgradeHandler.stream.old", Integer.valueOf(streamId), Integer.valueOf(maxActiveRemoteStreamId)), Http2Error.PROTOCOL_ERROR);
throw new ConnectionException( sm.getString("http2Parser.processFrame.tooMuchPadding", connectionId, Integer.toString(streamId), Integer.toString(padLength),