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;
}
}
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;
}
Aggregations