Search in sources :

Example 1 with ExchangeAttribute

use of io.undertow.attribute.ExchangeAttribute in project undertow by undertow-io.

the class ExtendedAccessLogParser method parse.

public ExchangeAttribute parse(String pattern) {
    List<ExchangeAttribute> list = new ArrayList<ExchangeAttribute>();
    PatternTokenizer tokenizer = new PatternTokenizer(pattern);
    try {
        // Ignore leading whitespace.
        tokenizer.getWhiteSpaces();
        if (tokenizer.isEnded()) {
            UndertowLogger.ROOT_LOGGER.extendedAccessLogEmptyPattern();
            return null;
        }
        String token = tokenizer.getToken();
        while (token != null) {
            if (UndertowLogger.ROOT_LOGGER.isDebugEnabled()) {
                UndertowLogger.ROOT_LOGGER.debug("token = " + token);
            }
            ExchangeAttribute element = getLogElement(token, tokenizer);
            if (element == null) {
                break;
            }
            list.add(element);
            String whiteSpaces = tokenizer.getWhiteSpaces();
            if (whiteSpaces.length() > 0) {
                list.add(new ConstantExchangeAttribute(whiteSpaces));
            }
            if (tokenizer.isEnded()) {
                break;
            }
            token = tokenizer.getToken();
        }
        if (UndertowLogger.ROOT_LOGGER.isDebugEnabled()) {
            UndertowLogger.ROOT_LOGGER.debug("finished decoding with element size of: " + list.size());
        }
        return new CompositeExchangeAttribute(list.toArray(new ExchangeAttribute[list.size()]));
    } catch (IOException e) {
        UndertowLogger.ROOT_LOGGER.extendedAccessLogPatternParseError(e);
        return null;
    }
}
Also used : ConstantExchangeAttribute(io.undertow.attribute.ConstantExchangeAttribute) CompositeExchangeAttribute(io.undertow.attribute.CompositeExchangeAttribute) SecureExchangeAttribute(io.undertow.attribute.SecureExchangeAttribute) AuthenticationTypeExchangeAttribute(io.undertow.attribute.AuthenticationTypeExchangeAttribute) ConstantExchangeAttribute(io.undertow.attribute.ConstantExchangeAttribute) ExchangeAttribute(io.undertow.attribute.ExchangeAttribute) CompositeExchangeAttribute(io.undertow.attribute.CompositeExchangeAttribute) QuotingExchangeAttribute(io.undertow.attribute.QuotingExchangeAttribute) ArrayList(java.util.ArrayList) HttpString(io.undertow.util.HttpString) IOException(java.io.IOException)

Example 2 with ExchangeAttribute

use of io.undertow.attribute.ExchangeAttribute in project undertow by undertow-io.

the class ExtendedAccessLogParser method getXParameterElement.

protected ExchangeAttribute getXParameterElement(PatternTokenizer tokenizer) throws IOException {
    if (!tokenizer.hasSubToken()) {
        UndertowLogger.ROOT_LOGGER.extendedAccessLogBadXParam();
        return null;
    }
    final String token = tokenizer.getToken();
    if (!tokenizer.hasParameter()) {
        UndertowLogger.ROOT_LOGGER.extendedAccessLogBadXParam();
        return null;
    }
    String parameter = tokenizer.getParameter();
    if (parameter == null) {
        UndertowLogger.ROOT_LOGGER.extendedAccessLogMissingClosing();
        return null;
    }
    if ("A".equals(token)) {
        parser.parse("%{sc," + parameter + "}");
    } else if ("C".equals(token)) {
        return new QuotingExchangeAttribute(new CookieAttribute(parameter));
    } else if ("R".equals(token)) {
        parser.parse("%{r," + parameter + "}");
    } else if ("S".equals(token)) {
        parser.parse("%{s," + parameter + "}");
    } else if ("H".equals(token)) {
        return getServletRequestElement(parameter);
    } else if ("P".equals(token)) {
        parser.parse("%{rp," + parameter + "}");
    } else if ("O".equals(token)) {
        return new QuotingExchangeAttribute(new ExchangeAttribute() {

            @Override
            public String readAttribute(HttpServerExchange exchange) {
                HeaderValues values = exchange.getResponseHeaders().get(token);
                if (values != null && values.size() > 0) {
                    StringBuilder buffer = new StringBuilder();
                    for (int i = 0; i < values.size(); i++) {
                        String string = values.get(i);
                        buffer.append(string);
                        if (i + 1 < values.size())
                            buffer.append(",");
                    }
                    return buffer.toString();
                }
                return null;
            }

            @Override
            public void writeAttribute(HttpServerExchange exchange, String newValue) throws ReadOnlyAttributeException {
                throw new ReadOnlyAttributeException();
            }
        });
    }
    UndertowLogger.ROOT_LOGGER.extendedAccessLogCannotDecodeXParamValue(token);
    return null;
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) SecureExchangeAttribute(io.undertow.attribute.SecureExchangeAttribute) AuthenticationTypeExchangeAttribute(io.undertow.attribute.AuthenticationTypeExchangeAttribute) ConstantExchangeAttribute(io.undertow.attribute.ConstantExchangeAttribute) ExchangeAttribute(io.undertow.attribute.ExchangeAttribute) CompositeExchangeAttribute(io.undertow.attribute.CompositeExchangeAttribute) QuotingExchangeAttribute(io.undertow.attribute.QuotingExchangeAttribute) HeaderValues(io.undertow.util.HeaderValues) ReadOnlyAttributeException(io.undertow.attribute.ReadOnlyAttributeException) HttpString(io.undertow.util.HttpString) QuotingExchangeAttribute(io.undertow.attribute.QuotingExchangeAttribute) CookieAttribute(io.undertow.attribute.CookieAttribute)

Aggregations

AuthenticationTypeExchangeAttribute (io.undertow.attribute.AuthenticationTypeExchangeAttribute)2 CompositeExchangeAttribute (io.undertow.attribute.CompositeExchangeAttribute)2 ConstantExchangeAttribute (io.undertow.attribute.ConstantExchangeAttribute)2 ExchangeAttribute (io.undertow.attribute.ExchangeAttribute)2 QuotingExchangeAttribute (io.undertow.attribute.QuotingExchangeAttribute)2 SecureExchangeAttribute (io.undertow.attribute.SecureExchangeAttribute)2 HttpString (io.undertow.util.HttpString)2 CookieAttribute (io.undertow.attribute.CookieAttribute)1 ReadOnlyAttributeException (io.undertow.attribute.ReadOnlyAttributeException)1 HttpServerExchange (io.undertow.server.HttpServerExchange)1 HeaderValues (io.undertow.util.HeaderValues)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1