Java Code Examples for org.apache.tomcat.util.buf.MessageBytes#getLength()

The following examples show how to use org.apache.tomcat.util.buf.MessageBytes#getLength() . 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: Parameters.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
public void processParameters(MessageBytes data, Charset charset) {
    if( data==null || data.isNull() || data.getLength() <= 0 ) {
        return;
    }

    if( data.getType() != MessageBytes.T_BYTES ) {
        data.toBytes();
    }
    ByteChunk bc=data.getByteChunk();
    processParameters(bc.getBytes(), bc.getOffset(), bc.getLength(), charset);
}
 
Example 2
Source File: Parameters.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
public void processParameters( MessageBytes data, String encoding ) {
    if( data==null || data.isNull() || data.getLength() <= 0 ) {
        return;
    }

    if( data.getType() != MessageBytes.T_BYTES ) {
        data.toBytes();
    }
    ByteChunk bc=data.getByteChunk();
    processParameters( bc.getBytes(), bc.getOffset(),
                       bc.getLength(), getCharset(encoding));
}
 
Example 3
Source File: Parameters.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
public void processParameters( MessageBytes data, String encoding ) {
    if( data==null || data.isNull() || data.getLength() <= 0 ) {
        return;
    }

    if( data.getType() != MessageBytes.T_BYTES ) {
        data.toBytes();
    }
    ByteChunk bc=data.getByteChunk();
    processParameters( bc.getBytes(), bc.getOffset(),
                       bc.getLength(), getCharset(encoding));
}
 
Example 4
Source File: AbstractProcessor.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
protected void parseHost(MessageBytes valueMB) {
    if (valueMB == null || valueMB.isNull()) {
        populateHost();
        populatePort();
        return;
    } else if (valueMB.getLength() == 0) {
        // Empty Host header so set sever name to empty string
        request.serverName().setString("");
        populatePort();
        return;
    }

    ByteChunk valueBC = valueMB.getByteChunk();
    byte[] valueB = valueBC.getBytes();
    int valueL = valueBC.getLength();
    int valueS = valueBC.getStart();
    if (hostNameC.length < valueL) {
        hostNameC = new char[valueL];
    }

    try {
        // Validates the host name
        int colonPos = Host.parse(valueMB);

        // Extract the port information first, if any
        if (colonPos != -1) {
            int port = 0;
            for (int i = colonPos + 1; i < valueL; i++) {
                char c = (char) valueB[i + valueS];
                if (c < '0' || c > '9') {
                    response.setStatus(400);
                    setErrorState(ErrorState.CLOSE_CLEAN, null);
                    return;
                }
                port = port * 10 + c - '0';
            }
            request.setServerPort(port);

            // Only need to copy the host name up to the :
            valueL = colonPos;
        }

        // Extract the host name
        for (int i = 0; i < valueL; i++) {
            hostNameC[i] = (char) valueB[i + valueS];
        }
        request.serverName().setChars(hostNameC, 0, valueL);

    } catch (IllegalArgumentException e) {
        // IllegalArgumentException indicates that the host name is invalid
        UserDataHelper.Mode logMode = userDataHelper.getNextMode();
        if (logMode != null) {
            String message = sm.getString("abstractProcessor.hostInvalid", valueMB.toString());
            switch (logMode) {
                case INFO_THEN_DEBUG:
                    message += sm.getString("abstractProcessor.fallToDebug");
                    //$FALL-THROUGH$
                case INFO:
                    getLog().info(message, e);
                    break;
                case DEBUG:
                    getLog().debug(message, e);
            }
        }

        response.setStatus(400);
        setErrorState(ErrorState.CLOSE_CLEAN, e);
    }
}