Search in sources :

Example 1 with QuotingExchangeAttribute

use of io.undertow.attribute.QuotingExchangeAttribute 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)1 CompositeExchangeAttribute (io.undertow.attribute.CompositeExchangeAttribute)1 ConstantExchangeAttribute (io.undertow.attribute.ConstantExchangeAttribute)1 CookieAttribute (io.undertow.attribute.CookieAttribute)1 ExchangeAttribute (io.undertow.attribute.ExchangeAttribute)1 QuotingExchangeAttribute (io.undertow.attribute.QuotingExchangeAttribute)1 ReadOnlyAttributeException (io.undertow.attribute.ReadOnlyAttributeException)1 SecureExchangeAttribute (io.undertow.attribute.SecureExchangeAttribute)1 HttpServerExchange (io.undertow.server.HttpServerExchange)1 HeaderValues (io.undertow.util.HeaderValues)1 HttpString (io.undertow.util.HttpString)1