io.undertow.attribute.ExchangeAttribute Java Examples

The following examples show how to use io.undertow.attribute.ExchangeAttribute. 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: ExtendedAccessLogParser.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
protected ExchangeAttribute getServerToClientElement(
        PatternTokenizer tokenizer) throws IOException {
    if (tokenizer.hasSubToken()) {
        String token = tokenizer.getToken();
        if ("status".equals(token)) {
            return ResponseCodeAttribute.INSTANCE;
        } else if ("comment".equals(token)) {
            return new ConstantExchangeAttribute("?");
        }
    } else if (tokenizer.hasParameter()) {
        String parameter = tokenizer.getParameter();
        if (parameter == null) {
            UndertowLogger.ROOT_LOGGER.extendedAccessLogMissingClosing();
            return null;
        }
        return new QuotingExchangeAttribute(new ResponseHeaderAttribute(new HttpString(parameter)));
    }
    UndertowLogger.ROOT_LOGGER.extendedAccessLogCannotDecode(tokenizer.getRemains());
    return null;
}
 
Example #2
Source File: SetHeaderHandler.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@Override
public HandlerWrapper build(final Map<String, Object> config) {
    final ExchangeAttribute value = (ExchangeAttribute) config.get("value");
    final String header = (String) config.get("header");

    return new HandlerWrapper() {
        @Override
        public HttpHandler wrap(HttpHandler handler) {
            return new SetHeaderHandler(handler, header, value);
        }
    };
}
 
Example #3
Source File: ServletRequestLineAttribute.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public ExchangeAttribute build(final String token) {
    if (token.equals(REQUEST_LINE) || token.equals(REQUEST_LINE_SHORT)) {
        return ServletRequestLineAttribute.INSTANCE;
    }
    return null;
}
 
Example #4
Source File: DirectoryPredicate.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@Override
public Predicate build(final Map<String, Object> config) {
    ExchangeAttribute value = (ExchangeAttribute) config.get("value");
    if(value == null) {
        value = ExchangeAttributes.relativePath();
    }
    return new DirectoryPredicate(value);
}
 
Example #5
Source File: ServletContextAttribute.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@Override
public ExchangeAttribute build(final String token) {
    if (token.startsWith("%{sc,") && token.endsWith("}")) {
        final String attributeName = token.substring(5, token.length() - 1);
        return new ServletContextAttribute(attributeName);
    }
    return null;
}
 
Example #6
Source File: ServletSessionAttribute.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public ExchangeAttribute build(final String token) {
    if (token.startsWith("%{s,") && token.endsWith("}")) {
        final String attributeName = token.substring(4, token.length() - 1);
        return new ServletSessionAttribute(attributeName);
    }
    return null;
}
 
Example #7
Source File: PathTemplatePredicate.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Predicate build(final Map<String, Object> config) {
    ExchangeAttribute match = (ExchangeAttribute) config.get("match");
    if (match == null) {
        match = ExchangeAttributes.relativePath();
    }
    String value = (String) config.get("value");
    return new PathTemplatePredicate(value, match);
}
 
Example #8
Source File: FilePredicate.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Map<String, Class<?>> parameters() {
    final Map<String, Class<?>> params = new HashMap<>();
    params.put("value", ExchangeAttribute.class);
    params.put("require-content", Boolean.class);
    return params;
}
 
Example #9
Source File: ContainsPredicate.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Map<String, Class<?>> parameters() {
    final Map<String, Class<?>> params = new HashMap<>();
    params.put("value", ExchangeAttribute.class);
    params.put("search", String[].class);
    return params;
}
 
Example #10
Source File: ExtendedAccessLogParser.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected ExchangeAttribute getProxyElement(PatternTokenizer tokenizer)
        throws IOException {
    String token = null;
    if (tokenizer.hasSubToken()) {
        tokenizer.getToken();
        return new ConstantExchangeAttribute("-");
    } else if (tokenizer.hasParameter()) {
        tokenizer.getParameter();
        return new ConstantExchangeAttribute("-");
    }
    UndertowLogger.ROOT_LOGGER.extendedAccessLogCannotDecode(token);
    return null;
}
 
Example #11
Source File: PredicatedHandlersParser.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private static Object coerceToType(final String string, final Token token, final Class<?> type, final ExchangeAttributeParser attributeParser) {
    if (type.isArray()) {
        Object array = Array.newInstance(type.getComponentType(), 1);
        Array.set(array, 0, coerceToType(string, token, type.getComponentType(), attributeParser));
        return array;
    }

    if (type == String.class) {
        return token.getToken();
    } else if (type.equals(Boolean.class) || type.equals(boolean.class)) {
        return Boolean.valueOf(token.getToken());
    } else if (type.equals(Byte.class) || type.equals(byte.class)) {
        return Byte.valueOf(token.getToken());
    } else if (type.equals(Character.class) || type.equals(char.class)) {
        if (token.getToken().length() != 1) {
            throw error(string, token.getPosition(), "Cannot coerce " + token.getToken() + " to a Character");
        }
        return Character.valueOf(token.getToken().charAt(0));
    } else if (type.equals(Short.class) || type.equals(short.class)) {
        return Short.valueOf(token.getToken());
    } else if (type.equals(Integer.class) || type.equals(int.class)) {
        return Integer.valueOf(token.getToken());
    } else if (type.equals(Long.class) || type.equals(long.class)) {
        return Long.valueOf(token.getToken());
    } else if (type.equals(Float.class) || type.equals(float.class)) {
        return Float.valueOf(token.getToken());
    } else if (type.equals(Double.class) || type.equals(double.class)) {
        return Double.valueOf(token.getToken());
    } else if (type.equals(ExchangeAttribute.class)) {
        return attributeParser.parse(token.getToken());
    }

    return token.getToken();
}
 
Example #12
Source File: ServletRequestAttribute.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public ExchangeAttribute build(final String token) {
    if (token.startsWith("%{r,") && token.endsWith("}")) {
        final String attributeName = token.substring(4, token.length() - 1);
        return new ServletRequestAttribute(attributeName);
    }
    return null;
}
 
Example #13
Source File: RedirectHandler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Map<String, Class<?>> parameters() {
    Map<String, Class<?>> params = new HashMap<>();
    params.put("value", ExchangeAttribute.class);

    return params;
}
 
Example #14
Source File: AccessControlListHandler.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, Class<?>> parameters() {
    Map<String, Class<?>> params = new HashMap<>();
    params.put("acl", String[].class);
    params.put("default-allow", boolean.class);
    params.put("attribute", ExchangeAttribute.class);
    return params;
}
 
Example #15
Source File: FilePredicate.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Predicate build(final Map<String, Object> config) {
    ExchangeAttribute value = (ExchangeAttribute) config.get("value");
    Boolean requireContent = (Boolean)config.get("require-content");
    if(value == null) {
        value = ExchangeAttributes.relativePath();
    }
    return new FilePredicate(value, requireContent == null ? false : requireContent);
}
 
Example #16
Source File: ServletSessionIdAttribute.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public ExchangeAttribute build(final String token) {
    if (token.equals(SESSION_ID) || token.equals(SESSION_ID_SHORT)) {
        return INSTANCE;
    }
    return null;
}
 
Example #17
Source File: ServletRequestLocaleAttribute.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public ExchangeAttribute build(final String token) {
    if (token.equals(REQUEST_LOCALE)) {
        return INSTANCE;
    }
    return null;
}
 
Example #18
Source File: ProxyHandler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
ProxyAction(final ProxyConnection clientConnection, final HttpServerExchange exchange, Map<HttpString, ExchangeAttribute> requestHeaders,
            boolean rewriteHostHeader, boolean reuseXForwarded, ProxyClientHandler proxyClientHandler, Predicate idempotentPredicate) {
    this.clientConnection = clientConnection;
    this.exchange = exchange;
    this.requestHeaders = requestHeaders;
    this.rewriteHostHeader = rewriteHostHeader;
    this.reuseXForwarded = reuseXForwarded;
    this.proxyClientHandler = proxyClientHandler;
    this.idempotentPredicate = idempotentPredicate;
}
 
Example #19
Source File: RegularExpressionPredicate.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Predicate build(final Map<String, Object> config) {
    ExchangeAttribute value = (ExchangeAttribute) config.get("value");
    if(value == null) {
        value = ExchangeAttributes.relativePath();
    }
    Boolean fullMatch = (Boolean) config.get("full-match");
    Boolean caseSensitive = (Boolean) config.get("case-sensitive");
    String pattern = (String) config.get("pattern");
    return new RegularExpressionPredicate(pattern, value, fullMatch == null ? false : fullMatch, caseSensitive == null ? true : caseSensitive);
}
 
Example #20
Source File: ProxyHandler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
ProxyHandler(Builder builder) {
    this.proxyClient = builder.proxyClient;
    this.maxRequestTime = builder.maxRequestTime;
    this.next = builder.next;
    this.rewriteHostHeader = builder.rewriteHostHeader;
    this.reuseXForwarded = builder.reuseXForwarded;
    this.maxConnectionRetries = builder.maxConnectionRetries;
    this.idempotentRequestPredicate = builder.idempotentRequestPredicate;
    for(Map.Entry<HttpString, ExchangeAttribute> e : builder.requestHeaders.entrySet()) {
        requestHeaders.put(e.getKey(), e.getValue());
    }
}
 
Example #21
Source File: RegularExpressionPredicate.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, Class<?>> parameters() {
    final Map<String, Class<?>> params = new HashMap<>();
    params.put("pattern", String.class);
    params.put("value", ExchangeAttribute.class);
    params.put("full-match", Boolean.class);
    params.put("case-sensitive", Boolean.class);
    return params;
}
 
Example #22
Source File: RegularExpressionPredicate.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@Override
public Predicate build(final Map<String, Object> config) {
    ExchangeAttribute value = (ExchangeAttribute) config.get("value");
    if(value == null) {
        value = ExchangeAttributes.relativePath();
    }
    Boolean fullMatch = (Boolean) config.get("full-match");
    Boolean caseSensitive = (Boolean) config.get("case-sensitive");
    String pattern = (String) config.get("pattern");
    return new RegularExpressionPredicate(pattern, value, fullMatch == null ? false : fullMatch, caseSensitive == null ? true : caseSensitive);
}
 
Example #23
Source File: PathTemplatePredicate.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Map<String, Class<?>> parameters() {
    final Map<String, Class<?>> params = new HashMap<>();
    params.put("value", String.class);
    params.put("match", ExchangeAttribute.class);
    return params;
}
 
Example #24
Source File: RewriteHandlerBuilder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public HandlerWrapper build(final Map<String, Object> config) {
    final ExchangeAttribute value = (ExchangeAttribute) config.get("value");

    return new HandlerWrapper() {
        @Override
        public HttpHandler wrap(HttpHandler handler) {
            return new SetAttributeHandler(handler, ExchangeAttributes.relativePath(), value);
        }
    };
}
 
Example #25
Source File: ServletRequestedSessionIdValidAttribute.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public ExchangeAttribute build(final String token) {
    if (token.equals(REQUESTED_SESSION_ID_VALID)) {
        return INSTANCE;
    }
    return null;
}
 
Example #26
Source File: AccessLogHandler.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
public AccessLogHandler(final HttpHandler next, final AccessLogReceiver accessLogReceiver, String formatString, final ExchangeAttribute attribute, Predicate predicate) {
    this.next = next;
    this.accessLogReceiver = accessLogReceiver;
    this.predicate = predicate;
    this.formatString = handleCommonNames(formatString);
    this.tokens = attribute;
}
 
Example #27
Source File: ExtendedAccessLogParser.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected ExchangeAttribute getServletRequestElement(String parameter) {
    if ("authType".equals(parameter)) {
        return new SubstituteEmptyWrapper.SubstituteEmptyAttribute(AuthenticationTypeExchangeAttribute.INSTANCE,"-");
    } else if ("remoteUser".equals(parameter)) {
        return new SubstituteEmptyWrapper.SubstituteEmptyAttribute(RemoteUserAttribute.INSTANCE,"-");
    } else if ("requestedSessionId".equals(parameter)) {
        return parser.parse("%{REQUESTED_SESSION_ID}");
    } else if ("requestedSessionIdFromCookie".equals(parameter)) {
        return parser.parse("%{REQUESTED_SESSION_ID_FROM_COOKIE}");
    } else if ("requestedSessionIdValid".equals(parameter)) {
        return parser.parse("%{REQUESTED_SESSION_ID_VALID}");
    } else if ("contentLength".equals(parameter)) {
        return new QuotingExchangeAttribute(new RequestHeaderAttribute(Headers.CONTENT_LENGTH));
    } else if ("characterEncoding".equals(parameter)) {
        return parser.parse("%{REQUEST_CHARACTER_ENCODING}");
    } else if ("locale".equals(parameter)) {
        return parser.parse("%{REQUEST_LOCALE}");
    } else if ("protocol".equals(parameter)) {
        return RequestProtocolAttribute.INSTANCE;
    } else if ("scheme".equals(parameter)) {
        return RequestSchemeAttribute.INSTANCE;
    } else if ("secure".equals(parameter)) {
        return SecureExchangeAttribute.INSTANCE;
    }
    UndertowLogger.ROOT_LOGGER.extendedAccessLogCannotDecodeXParamValue(parameter);
    return null;
}
 
Example #28
Source File: ExtendedAccessLogParser.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
protected ExchangeAttribute getProxyElement(PatternTokenizer tokenizer)
        throws IOException {
    String token = null;
    if (tokenizer.hasSubToken()) {
        tokenizer.getToken();
        return new ConstantExchangeAttribute("-");
    } else if (tokenizer.hasParameter()) {
        tokenizer.getParameter();
        return new ConstantExchangeAttribute("-");
    }
    UndertowLogger.ROOT_LOGGER.extendedAccessLogCannotDecode(token);
    return null;
}
 
Example #29
Source File: ExtendedAccessLogParser.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
protected ExchangeAttribute getServletRequestElement(String parameter) {
    if ("authType".equals(parameter)) {
        return new SubstituteEmptyWrapper.SubstituteEmptyAttribute(AuthenticationTypeExchangeAttribute.INSTANCE,"-");
    } else if ("remoteUser".equals(parameter)) {
        return new SubstituteEmptyWrapper.SubstituteEmptyAttribute(RemoteUserAttribute.INSTANCE,"-");
    } else if ("requestedSessionId".equals(parameter)) {
        return parser.parse("%{REQUESTED_SESSION_ID}");
    } else if ("requestedSessionIdFromCookie".equals(parameter)) {
        return parser.parse("%{REQUESTED_SESSION_ID_FROM_COOKIE}");
    } else if ("requestedSessionIdValid".equals(parameter)) {
        return parser.parse("%{REQUESTED_SESSION_ID_VALID}");
    } else if ("contentLength".equals(parameter)) {
        return new QuotingExchangeAttribute(new RequestHeaderAttribute(HttpHeaderNames.CONTENT_LENGTH));
    } else if ("characterEncoding".equals(parameter)) {
        return parser.parse("%{REQUEST_CHARACTER_ENCODING}");
    } else if ("locale".equals(parameter)) {
        return parser.parse("%{REQUEST_LOCALE}");
    } else if ("getProtocol".equals(parameter)) {
        return RequestProtocolAttribute.INSTANCE;
    } else if ("scheme".equals(parameter)) {
        return RequestSchemeAttribute.INSTANCE;
    } else if ("secure".equals(parameter)) {
        return SecureExchangeAttribute.INSTANCE;
    }
    UndertowLogger.ROOT_LOGGER.extendedAccessLogCannotDecodeXParamValue(parameter);
    return null;
}
 
Example #30
Source File: ServletRequestParameterAttribute.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public ExchangeAttribute build(final String token) {
    if (token.startsWith("%{rp,") && token.endsWith("}")) {
        final String attributeName = token.substring(5, token.length() - 1);
        return new ServletRequestParameterAttribute(attributeName);
    }
    return null;
}