org.apache.coyote.Request Java Examples

The following examples show how to use org.apache.coyote.Request. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Http2UpgradeHandler.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
void push(Request request, Stream associatedStream) throws IOException {
    if (localSettings.getMaxConcurrentStreams() < activeRemoteStreamCount.incrementAndGet()) {
        // If there are too many open streams, simply ignore the push
        // request.
        setConnectionTimeoutForStreamCount(activeRemoteStreamCount.decrementAndGet());
        return;
    }

    Stream pushStream;

    // Synchronized since PUSH_PROMISE frames have to be sent in order. Once
    // the stream has been created we need to ensure that the PUSH_PROMISE
    // is sent before the next stream is created for a PUSH_PROMISE.
    synchronized (socketWrapper) {
        pushStream = createLocalStream(request);
        writeHeaders(associatedStream, pushStream.getIdAsInt(), request.getMimeHeaders(),
                false, Constants.DEFAULT_HEADERS_FRAME_SIZE);
    }

    pushStream.sentPushPromise();

    processStreamOnContainerThread(pushStream);
}
 
Example #2
Source File: InternalAprInputBuffer.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Alternate constructor.
 */
public InternalAprInputBuffer(Request request, int headerBufferSize) {

    this.request = request;
    headers = request.getMimeHeaders();

    buf = new byte[headerBufferSize];
    if (headerBufferSize < (8 * 1024)) {
        bbuf = ByteBuffer.allocateDirect(6 * 1500);
    } else {
        bbuf = ByteBuffer.allocateDirect((headerBufferSize / 1500 + 1) * 1500);
    }

    inputStreamInputBuffer = new SocketInputBuffer();

    filterLibrary = new InputFilter[0];
    activeFilters = new InputFilter[0];
    lastActiveFilter = -1;

    parsingHeader = true;
    swallowInput = true;
    
}
 
Example #3
Source File: BufferedInputFilter.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Reads the request body and buffers it.
 */
@Override
public void setRequest(Request request) {
    // save off the Request body
    try {
        while (buffer.doRead(this) >= 0) {
            buffered.mark().position(buffered.limit()).limit(buffered.capacity());
            buffered.put(tempRead);
            buffered.limit(buffered.position()).reset();
            tempRead = null;
        }
    } catch(IOException | BufferOverflowException ioe) {
        // No need for i18n - this isn't going to get logged anywhere
        throw new IllegalStateException(
                "Request body too large for buffer");
    }
}
 
Example #4
Source File: InternalAprInputBuffer.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Read bytes into the specified chunk.
 */
@Override
public int doRead(ByteChunk chunk, Request req ) 
    throws IOException {

    if (pos >= lastValid) {
        if (!fill())
            return -1;
    }

    int length = lastValid - pos;
    chunk.setBytes(buf, pos, length);
    pos = lastValid;

    return (length);
}
 
Example #5
Source File: InternalInputBuffer.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Read bytes into the specified chunk.
 */
@Override
public int doRead(ByteChunk chunk, Request req )
    throws IOException {

    if (pos >= lastValid) {
        if (!fill())
            return -1;
    }

    int length = lastValid - pos;
    chunk.setBytes(buf, pos, length);
    pos = lastValid;

    return (length);
}
 
Example #6
Source File: InternalNioInputBuffer.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Alternate constructor.
 */
public InternalNioInputBuffer(Request request, int headerBufferSize) {

    this.request = request;
    headers = request.getMimeHeaders();

    this.headerBufferSize = headerBufferSize;

    inputStreamInputBuffer = new SocketInputBuffer();

    filterLibrary = new InputFilter[0];
    activeFilters = new InputFilter[0];
    lastActiveFilter = -1;

    parsingHeader = true;
    parsingRequestLine = true;
    parsingRequestLinePhase = 0;
    parsingRequestLineEol = false;
    parsingRequestLineStart = 0;
    parsingRequestLineQPos = -1;
    headerParsePos = HeaderParsePosition.HEADER_START;
    headerData.recycle();
    swallowInput = true;

}
 
Example #7
Source File: InternalNioInputBuffer.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Read bytes into the specified chunk.
 */
@Override
public int doRead(ByteChunk chunk, Request req ) 
    throws IOException {

    if (pos >= lastValid) {
        if (!fill(true,true)) //read body, must be blocking, as the thread is inside the app
            return -1;
    }

    int length = lastValid - pos;
    chunk.setBytes(buf, pos, length);
    pos = lastValid;

    return (length);
}
 
Example #8
Source File: InternalAprInputBuffer.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Read bytes into the specified chunk.
 */
@Override
public int doRead(ByteChunk chunk, Request req )
    throws IOException {

    if (pos >= lastValid) {
        if (!fill())
            return -1;
    }

    int length = lastValid - pos;
    chunk.setBytes(buf, pos, length);
    pos = lastValid;

    return (length);
}
 
Example #9
Source File: Http11InputBuffer.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
public Http11InputBuffer(Request request, int headerBufferSize,
        boolean rejectIllegalHeaderName, HttpParser httpParser) {

    this.request = request;
    headers = request.getMimeHeaders();

    this.headerBufferSize = headerBufferSize;
    this.rejectIllegalHeaderName = rejectIllegalHeaderName;
    this.httpParser = httpParser;

    filterLibrary = new InputFilter[0];
    activeFilters = new InputFilter[0];
    lastActiveFilter = -1;

    parsingHeader = true;
    parsingRequestLine = true;
    parsingRequestLinePhase = 0;
    parsingRequestLineEol = false;
    parsingRequestLineStart = 0;
    parsingRequestLineQPos = -1;
    headerParsePos = HeaderParsePosition.HEADER_START;
    swallowInput = true;

    inputStreamInputBuffer = new SocketInputBuffer();
}
 
Example #10
Source File: InternalInputBuffer.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Read bytes into the specified chunk.
 */
@Override
public int doRead(ByteChunk chunk, Request req ) 
    throws IOException {

    if (pos >= lastValid) {
        if (!fill())
            return -1;
    }

    int length = lastValid - pos;
    chunk.setBytes(buf, pos, length);
    pos = lastValid;

    return (length);
}
 
Example #11
Source File: AbstractAjpProcessor.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Read bytes into the specified chunk.
 */
@Override
public int doRead(ByteChunk chunk, Request req)
throws IOException {

    if (endOfStream) {
        return -1;
    }
    if (first && req.getContentLengthLong() > 0) {
        // Handle special first-body-chunk
        if (!receive()) {
            return 0;
        }
    } else if (empty) {
        if (!refillReadBuffer()) {
            return -1;
        }
    }
    ByteChunk bc = bodyBytes.getByteChunk();
    chunk.setBytes(bc.getBuffer(), bc.getStart(), bc.getLength());
    empty = true;
    return chunk.getLength();

}
 
Example #12
Source File: InternalNioInputBuffer.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Read bytes into the specified chunk.
 */
@Override
public int doRead(ByteChunk chunk, Request req )
    throws IOException {

    if (pos >= lastValid) {
        if (!fill(true,true)) //read body, must be blocking, as the thread is inside the app
            return -1;
    }

    int length = lastValid - pos;
    chunk.setBytes(buf, pos, length);
    pos = lastValid;

    return (length);
}
 
Example #13
Source File: InternalAprInputBuffer.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Alternate constructor.
 */
public InternalAprInputBuffer(Request request, int headerBufferSize) {

    this.request = request;
    headers = request.getMimeHeaders();

    buf = new byte[headerBufferSize];
    if (headerBufferSize < (8 * 1024)) {
        bbuf = ByteBuffer.allocateDirect(6 * 1500);
    } else {
        bbuf = ByteBuffer.allocateDirect((headerBufferSize / 1500 + 1) * 1500);
    }

    inputStreamInputBuffer = new SocketInputBuffer();

    filterLibrary = new InputFilter[0];
    activeFilters = new InputFilter[0];
    lastActiveFilter = -1;

    parsingHeader = true;
    swallowInput = true;

}
 
Example #14
Source File: Http2UpgradeHandler.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
public Http2UpgradeHandler(Http2Protocol protocol, Adapter adapter, Request coyoteRequest) {
    super (STREAM_ID_ZERO);
    this.protocol = protocol;
    this.adapter = adapter;
    this.connectionId = Integer.toString(connectionIdGenerator.getAndIncrement());

    lastNonFinalDataPayload = protocol.getOverheadDataThreshold() * 2;
    lastWindowUpdate = protocol.getOverheadWindowUpdateThreshold() * 2;

    remoteSettings = new ConnectionSettingsRemote(connectionId);
    localSettings = new ConnectionSettingsLocal(connectionId);

    // Initial HTTP request becomes stream 1.
    if (coyoteRequest != null) {
        if (log.isDebugEnabled()) {
            log.debug(sm.getString("upgradeHandler.upgrade", connectionId));
        }
        Integer key = Integer.valueOf(1);
        Stream stream = new Stream(key, this, coyoteRequest);
        streams.put(key, stream);
        maxActiveRemoteStreamId = 1;
        activeRemoteStreamCount.set(1);
        maxProcessedStreamId = 1;
    }
}
 
Example #15
Source File: InternalNioInputBuffer.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Alternate constructor.
 */
public InternalNioInputBuffer(Request request, int headerBufferSize) {

    this.request = request;
    headers = request.getMimeHeaders();

    this.headerBufferSize = headerBufferSize;

    inputStreamInputBuffer = new SocketInputBuffer();

    filterLibrary = new InputFilter[0];
    activeFilters = new InputFilter[0];
    lastActiveFilter = -1;

    parsingHeader = true;
    parsingRequestLine = true;
    parsingRequestLinePhase = 0;
    parsingRequestLineEol = false;
    parsingRequestLineStart = 0;
    parsingRequestLineQPos = -1;
    headerParsePos = HeaderParsePosition.HEADER_START;
    headerData.recycle();
    swallowInput = true;

}
 
Example #16
Source File: Http2Protocol.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public boolean accept(Request request) {
    // Should only be one HTTP2-Settings header
    Enumeration<String> settings = request.getMimeHeaders().values("HTTP2-Settings");
    int count = 0;
    while (settings.hasMoreElements()) {
        count++;
        settings.nextElement();
    }
    if (count != 1) {
        return false;
    }

    Enumeration<String> connection = request.getMimeHeaders().values("Connection");
    boolean found = false;
    while (connection.hasMoreElements() && !found) {
        found = connection.nextElement().contains("HTTP2-Settings");
    }
    return found;
}
 
Example #17
Source File: Http2Protocol.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public InternalHttpUpgradeHandler getInternalUpgradeHandler(Adapter adapter,
        Request coyoteRequest) {
    Http2UpgradeHandler result = new Http2UpgradeHandler(this, adapter, coyoteRequest);

    result.setReadTimeout(getReadTimeout());
    result.setKeepAliveTimeout(getKeepAliveTimeout());
    result.setWriteTimeout(getWriteTimeout());
    result.setMaxConcurrentStreams(getMaxConcurrentStreams());
    result.setMaxConcurrentStreamExecution(getMaxConcurrentStreamExecution());
    result.setInitialWindowSize(getInitialWindowSize());
    result.setAllowedTrailerHeaders(allowedTrailerHeaders);
    result.setMaxHeaderCount(getMaxHeaderCount());
    result.setMaxHeaderSize(getMaxHeaderSize());
    result.setMaxTrailerCount(getMaxTrailerCount());
    result.setMaxTrailerSize(getMaxTrailerSize());
    result.setInitiatePingDisabled(initiatePingDisabled);
    return result;
}
 
Example #18
Source File: AbstractAjpProcessor.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Read bytes into the specified chunk.
 */
@Override
public int doRead(ByteChunk chunk, Request req)
throws IOException {

    if (endOfStream) {
        return -1;
    }
    if (first && req.getContentLengthLong() > 0) {
        // Handle special first-body-chunk
        if (!receive()) {
            return 0;
        }
    } else if (empty) {
        if (!refillReadBuffer()) {
            return -1;
        }
    }
    ByteChunk bc = bodyBytes.getByteChunk();
    chunk.setBytes(bc.getBuffer(), bc.getStart(), bc.getLength());
    empty = true;
    return chunk.getLength();

}
 
Example #19
Source File: Stream.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
private static void push(final Http2UpgradeHandler handler, final Request request,
        final Stream stream) throws IOException {
    if (org.apache.coyote.Constants.IS_SECURITY_ENABLED) {
        try {
            AccessController.doPrivileged(new PrivilegedPush(handler, request, stream));
        } catch (PrivilegedActionException ex) {
            Exception e = ex.getException();
            if (e instanceof IOException) {
                throw (IOException) e;
            } else {
                throw new IOException(ex);
            }
        }

    } else {
        handler.push(request, stream);
    }
}
 
Example #20
Source File: Stream.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
final void push(Request request) throws IOException {
    // Can only push when supported and from a peer initiated stream
    if (!isPushSupported() || getIdAsInt() % 2 == 0) {
        return;
    }
    // Set the special HTTP/2 headers
    request.getMimeHeaders().addValue(":method").duplicate(request.method());
    request.getMimeHeaders().addValue(":scheme").duplicate(request.scheme());
    StringBuilder path = new StringBuilder(request.requestURI().toString());
    if (!request.queryString().isNull()) {
        path.append('?');
        path.append(request.queryString().toString());
    }
    request.getMimeHeaders().addValue(":path").setString(path.toString());

    // Authority needs to include the port only if a non-standard port is
    // being used.
    if (!(request.scheme().equals("http") && request.getServerPort() == 80) &&
            !(request.scheme().equals("https") && request.getServerPort() == 443)) {
        request.getMimeHeaders().addValue(":authority").setString(
                request.serverName().getString() + ":" + request.getServerPort());
    } else {
        request.getMimeHeaders().addValue(":authority").duplicate(request.serverName());
    }

    push(handler, request, this);
}
 
Example #21
Source File: StreamProcessor.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
protected final void doPush(Request pushTarget) {
    try {
        stream.push(pushTarget);
    } catch (IOException ioe) {
        setErrorState(ErrorState.CLOSE_CONNECTION_NOW, ioe);
        response.setErrorException(ioe);
    }
}
 
Example #22
Source File: Http2UpgradeHandler.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
private Stream createLocalStream(Request request) {
    int streamId = nextLocalStreamId.getAndAdd(2);

    Integer key = Integer.valueOf(streamId);

    Stream result = new Stream(key, this, request);
    streams.put(key, result);
    return result;
}
 
Example #23
Source File: TomcatHttpHandlerAdapter.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private static HttpHeaders createTomcatHttpHeaders(HttpServletRequest request) {
	RequestFacade requestFacade = getRequestFacade(request);
	org.apache.catalina.connector.Request connectorRequest = (org.apache.catalina.connector.Request)
			ReflectionUtils.getField(COYOTE_REQUEST_FIELD, requestFacade);
	Assert.state(connectorRequest != null, "No Tomcat connector request");
	Request tomcatRequest = connectorRequest.getCoyoteRequest();
	TomcatHeadersAdapter headers = new TomcatHeadersAdapter(tomcatRequest.getMimeHeaders());
	return new HttpHeaders(headers);
}
 
Example #24
Source File: InternalAprInputBuffer.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Read some bytes.
 */
@Override
public int doRead(ByteChunk chunk, Request req) 
    throws IOException {

    if (lastActiveFilter == -1)
        return inputStreamInputBuffer.doRead(chunk, req);
    else
        return activeFilters[lastActiveFilter].doRead(chunk,req);

}
 
Example #25
Source File: AbstractInputBuffer.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Read some bytes.
 */
@Override
public int doRead(ByteChunk chunk, Request req) 
    throws IOException {

    if (lastActiveFilter == -1)
        return inputStreamInputBuffer.doRead(chunk, req);
    else
        return activeFilters[lastActiveFilter].doRead(chunk,req);

}
 
Example #26
Source File: InternalAprInputBuffer.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Read some bytes.
 */
@Override
public int doRead(ByteChunk chunk, Request req)
    throws IOException {

    if (lastActiveFilter == -1)
        return inputStreamInputBuffer.doRead(chunk, req);
    else
        return activeFilters[lastActiveFilter].doRead(chunk,req);

}
 
Example #27
Source File: IdentityInputFilter.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Read bytes.
 * 
 * @return If the filter does request length control, this value is
 * significant; it should be the number of bytes consumed from the buffer,
 * up until the end of the current request body, or the buffer length, 
 * whichever is greater. If the filter does not do request body length
 * control, the returned value should be -1.
 */
@Override
public int doRead(ByteChunk chunk, Request req)
    throws IOException {

    int result = -1;

    if (contentLength >= 0) {
        if (remaining > 0) {
            int nRead = buffer.doRead(chunk, req);
            if (nRead > remaining) {
                // The chunk is longer than the number of bytes remaining
                // in the body; changing the chunk length to the number
                // of bytes remaining
                chunk.setBytes(chunk.getBytes(), chunk.getStart(), 
                               (int) remaining);
                result = (int) remaining;
            } else {
                result = nRead;
            }
            if (nRead > 0) {
                remaining = remaining - nRead;
            }
        } else {
            // No more bytes left to be read : return -1 and clear the 
            // buffer
            chunk.recycle();
            result = -1;
        }
    }

    return result;

}
 
Example #28
Source File: VoidInputFilter.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Write some bytes.
 * 
 * @return number of bytes written by the filter
 */
@Override
public int doRead(ByteChunk chunk, Request req)
    throws IOException {

    return -1;

}
 
Example #29
Source File: BufferedInputFilter.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Fills the given ByteChunk with the buffered request body.
 */
@Override
public int doRead(ByteChunk chunk, Request request) throws IOException {
    if (hasRead || buffered.getLength() <= 0) {
        return -1;
    }

    chunk.setBytes(buffered.getBytes(), buffered.getStart(),
            buffered.getLength());
    hasRead = true;
    return chunk.getLength();
}
 
Example #30
Source File: BufferedInputFilter.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Reads the request body and buffers it.
 */
@Override
public void setRequest(Request request) {
    // save off the Request body
    try {
        while (buffer.doRead(tempRead, request) >= 0) {
            buffered.append(tempRead);
            tempRead.recycle();
        }
    } catch(IOException ioe) {
        // No need for i18n - this isn't going to get logged anywhere
        throw new IllegalStateException(
                "Request body too large for buffer");
    }
}