org.apache.tomcat.util.log.UserDataHelper Java Examples

The following examples show how to use org.apache.tomcat.util.log.UserDataHelper. 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: Cookie.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
private static void logInvalidHeader(ByteBuffer bb) {
    UserDataHelper.Mode logMode = invalidCookieLog.getNextMode();
    if (logMode != null) {
        String headerValue = new String(bb.array(), bb.position(), bb.limit() - bb.position(),
                    StandardCharsets.UTF_8);
        String message = sm.getString("cookie.invalidCookieValue", headerValue);
        switch (logMode) {
            case INFO_THEN_DEBUG:
                message += sm.getString("cookie.fallToDebug");
                //$FALL-THROUGH$
            case INFO:
                log.info(message);
                break;
            case DEBUG:
                log.debug(message);
        }
    }
}
 
Example #2
Source File: Cookie.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
private static void logInvalidVersion(ByteBuffer value) {
    UserDataHelper.Mode logMode = invalidCookieVersionLog.getNextMode();
    if (logMode != null) {
        String version;
        if (value == null) {
            version = sm.getString("cookie.valueNotPresent");
        } else {
            version = new String(value.bytes, value.position(),
                    value.limit() - value.position(), StandardCharsets.UTF_8);
        }
        String message = sm.getString("cookie.invalidCookieVersion", version);
        switch (logMode) {
            case INFO_THEN_DEBUG:
                message += sm.getString("cookie.fallToDebug");
                //$FALL-THROUGH$
            case INFO:
                log.info(message);
                break;
            case DEBUG:
                log.debug(message);
        }
    }
}
 
Example #3
Source File: AbstractProcessor.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
protected AbstractProcessor(AbstractEndpoint<?> endpoint, Request coyoteRequest,
        Response coyoteResponse) {
    this.endpoint = endpoint;
    asyncStateMachine = new AsyncStateMachine(this);
    request = coyoteRequest;
    response = coyoteResponse;
    response.setHook(this);
    request.setResponse(response);
    request.setHook(this);
    userDataHelper = new UserDataHelper(getLog());
}
 
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);
    }
}
 
Example #5
Source File: AbstractHttp11Processor.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
public AbstractHttp11Processor(AbstractEndpoint<S> endpoint) {
    super(endpoint);
    userDataHelper = new UserDataHelper(getLog());
}
 
Example #6
Source File: AbstractHttp11Processor.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
public AbstractHttp11Processor(AbstractEndpoint<S> endpoint) {
    super(endpoint);
    userDataHelper = new UserDataHelper(getLog());
}