io.undertow.attribute.ExchangeAttributeParser Java Examples
The following examples show how to use
io.undertow.attribute.ExchangeAttributeParser.
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: JsonLogFormatter.java From digdag with Apache License 2.0 | 6 votes |
public static ExchangeAttribute buildExchangeAttribute(String pattern, ClassLoader classLoader) { if (pattern.equals("json")) { pattern = DEFAULT_PATTERN; } String body = pattern.substring("json{".length(), pattern.length() - "}".length()); Map<String, ExchangeAttribute> map = new LinkedHashMap<>(); ExchangeAttributeParser parser = ExchangeAttributes.parser(classLoader); String[] kvs = body.split(" "); for (String kv : kvs) { String[] fragments = kv.split(":", 2); if (fragments.length != 2) { throw new IllegalArgumentException("JSON access log pattern includes an invalid fragment: " + kv); } String key = fragments[0]; String value = fragments[1]; map.put(key, parser.parse(value)); } return new JsonExchangeAttribute(map); }
Example #2
Source File: PredicatedHandlersParser.java From lams with GNU General Public License v2.0 | 6 votes |
private static Object readArrayType(final String string, String paramName, ArrayNode value, ExchangeAttributeParser parser, Class type) { if (!type.isArray()) { throw error(string, value.getToken().getPosition(), "parameter is not an array type " + paramName); } Class<?> componentType = type.getComponentType(); final List<Object> values = new ArrayList<>(); for(Token token : value.getValues()) { values.add(coerceToType(string, token, componentType, parser)); } Object array = Array.newInstance(componentType, values.size()); for (int i = 0; i < values.size(); ++i) { Array.set(array, i, values.get(i)); } return array; }
Example #3
Source File: PredicatedHandlersParser.java From quarkus-http with Apache License 2.0 | 6 votes |
private static Object readArrayType(final String string, String paramName, ArrayNode value, ExchangeAttributeParser parser, Class type) { if (!type.isArray()) { throw error(string, value.getToken().getPosition(), "parameter is not an array type " + paramName); } Class<?> componentType = type.getComponentType(); final List<Object> values = new ArrayList<>(); for(Token token : value.getValues()) { values.add(coerceToType(string, token, componentType, parser)); } Object array = Array.newInstance(componentType, values.size()); for (int i = 0; i < values.size(); ++i) { Array.set(array, i, values.get(i)); } return array; }
Example #4
Source File: SetAttributeHandler.java From lams with GNU General Public License v2.0 | 5 votes |
public SetAttributeHandler(HttpHandler next, final String attribute, final String value, final ClassLoader classLoader) { this.next = next; ExchangeAttributeParser parser = ExchangeAttributes.parser(classLoader); this.attribute = parser.parseSingleToken(attribute); this.value = parser.parse(value); this.preCommit = false; }
Example #5
Source File: SetAttributeHandler.java From lams with GNU General Public License v2.0 | 5 votes |
public SetAttributeHandler(HttpHandler next, final String attribute, final String value) { this.next = next; ExchangeAttributeParser parser = ExchangeAttributes.parser(getClass().getClassLoader()); this.attribute = parser.parseSingleToken(attribute); this.value = parser.parse(value); this.preCommit = false; }
Example #6
Source File: SetAttributeHandler.java From lams with GNU General Public License v2.0 | 5 votes |
public SetAttributeHandler(HttpHandler next, final String attribute, final String value, boolean preCommit) { this.next = next; this.preCommit = preCommit; ExchangeAttributeParser parser = ExchangeAttributes.parser(getClass().getClassLoader()); this.attribute = parser.parseSingleToken(attribute); this.value = parser.parse(value); }
Example #7
Source File: SetAttributeHandler.java From lams with GNU General Public License v2.0 | 5 votes |
public SetAttributeHandler(HttpHandler next, final String attribute, final String value, final ClassLoader classLoader, boolean preCommit) { this.next = next; this.preCommit = preCommit; ExchangeAttributeParser parser = ExchangeAttributes.parser(classLoader); this.attribute = parser.parseSingleToken(attribute); this.value = parser.parse(value); }
Example #8
Source File: PredicatedHandlersParser.java From lams with GNU General Public License v2.0 | 5 votes |
public static List<PredicatedHandler> parse(final String contents, final ClassLoader classLoader) { Deque<Token> tokens = tokenize(contents); Node node = parse(contents, tokens); Map<String, PredicateBuilder> predicateBuilders = loadPredicateBuilders(classLoader); Map<String, HandlerBuilder> handlerBuilders = loadHandlerBuilders(classLoader); final ExchangeAttributeParser attributeParser = ExchangeAttributes.parser(classLoader); return handleNode(contents, node, predicateBuilders, handlerBuilders, attributeParser); }
Example #9
Source File: PredicatedHandlersParser.java From lams with GNU General Public License v2.0 | 5 votes |
public static Predicate parsePredicate(String string, ClassLoader classLoader) { Deque<Token> tokens = tokenize(string); Node node = parse(string, tokens); Map<String, PredicateBuilder> predicateBuilders = loadPredicateBuilders(classLoader); final ExchangeAttributeParser attributeParser = ExchangeAttributes.parser(classLoader); return handlePredicateNode(string, node, predicateBuilders, attributeParser); }
Example #10
Source File: PredicatedHandlersParser.java From lams with GNU General Public License v2.0 | 5 votes |
public static HandlerWrapper parseHandler(String string, ClassLoader classLoader) { Deque<Token> tokens = tokenize(string); Node node = parse(string, tokens); Map<String, HandlerBuilder> handlerBuilders = loadHandlerBuilders(classLoader); final ExchangeAttributeParser attributeParser = ExchangeAttributes.parser(classLoader); return handleHandlerNode(string, (ExpressionNode)node, handlerBuilders, attributeParser); }
Example #11
Source File: PredicatedHandlersParser.java From lams with GNU General Public License v2.0 | 5 votes |
private static List<PredicatedHandler> handleNode(String contents, Node node, Map<String, PredicateBuilder> predicateBuilders, Map<String, HandlerBuilder> handlerBuilders, ExchangeAttributeParser attributeParser) { if(node instanceof BlockNode) { return handleBlockNode(contents, (BlockNode) node, predicateBuilders, handlerBuilders, attributeParser); } else if(node instanceof ExpressionNode) { HandlerWrapper handler = handleHandlerNode(contents, (ExpressionNode) node, handlerBuilders, attributeParser); return Collections.singletonList(new PredicatedHandler(Predicates.truePredicate(), handler)); } else if(node instanceof PredicateOperatorNode) { return Collections.singletonList(handlePredicateOperatorNode(contents, (PredicateOperatorNode)node, predicateBuilders, handlerBuilders, attributeParser)); } else { throw error(contents, node.getToken().getPosition(), "unexpected token " + node.getToken()); } }
Example #12
Source File: PredicatedHandlersParser.java From lams with GNU General Public License v2.0 | 5 votes |
private static PredicatedHandler handlePredicateOperatorNode(String contents, PredicateOperatorNode node, Map<String, PredicateBuilder> predicateBuilders, Map<String, HandlerBuilder> handlerBuilders, ExchangeAttributeParser parser) { Predicate predicate = handlePredicateNode(contents, node.getLeft(), predicateBuilders, parser); HandlerWrapper ret = handlePredicatedAction(contents, node.getRight(), predicateBuilders, handlerBuilders, parser); HandlerWrapper elseBranch = null; if(node.getElseBranch() != null) { elseBranch = handlePredicatedAction(contents, node.getElseBranch(), predicateBuilders, handlerBuilders, parser); } return new PredicatedHandler(predicate, ret, elseBranch); }
Example #13
Source File: PredicatedHandlersParser.java From lams with GNU General Public License v2.0 | 5 votes |
private static HandlerWrapper handlePredicatedAction(String contents, Node node, Map<String, PredicateBuilder> predicateBuilders, Map<String, HandlerBuilder> handlerBuilders, ExchangeAttributeParser parser) { if(node instanceof ExpressionNode) { return handleHandlerNode(contents, (ExpressionNode) node, handlerBuilders, parser); } else if(node instanceof BlockNode) { List<PredicatedHandler> handlers = handleBlockNode(contents, (BlockNode) node, predicateBuilders, handlerBuilders, parser); return new PredicatesHandler.Wrapper(handlers, false); } else { throw error(contents, node.getToken().getPosition(), "unexpected token " + node.getToken()); } }
Example #14
Source File: PredicatedHandlersParser.java From lams with GNU General Public License v2.0 | 5 votes |
private static List<PredicatedHandler> handleBlockNode(String contents, BlockNode node, Map<String, PredicateBuilder> predicateBuilders, Map<String, HandlerBuilder> handlerBuilders, ExchangeAttributeParser parser) { List<PredicatedHandler> ret = new ArrayList<>(); for(Node line : node.getBlock()) { ret.addAll(handleNode(contents, line, predicateBuilders, handlerBuilders, parser)); } return ret; }
Example #15
Source File: PredicatedHandlersParser.java From lams with GNU General Public License v2.0 | 5 votes |
private static HandlerWrapper handleHandlerNode(String contents, ExpressionNode node, Map<String, HandlerBuilder> handlerBuilders, ExchangeAttributeParser parser) { Token token = node.getToken(); HandlerBuilder builder = handlerBuilders.get(token.getToken()); if (builder == null) { throw error(contents, token.getPosition(), "no handler named " + token.getToken() + " known handlers are " + handlerBuilders.keySet()); } Map<String, Object> parameters = new HashMap<>(); for(Map.Entry<String, Node> val : node.getValues().entrySet()) { String name = val.getKey(); if(name == null) { if(builder.defaultParameter() == null) { throw error(contents, token.getPosition(), "default parameter not supported"); } name = builder.defaultParameter(); } Class<?> type = builder.parameters().get(name); if(type == null) { throw error(contents, val.getValue().getToken().getPosition(), "unknown parameter " + name); } if(val.getValue() instanceof ValueNode) { parameters.put(name, coerceToType(contents, val.getValue().getToken(), type, parser)); } else if(val.getValue() instanceof ArrayNode) { parameters.put(name, readArrayType(contents, name, (ArrayNode)val.getValue(), parser, type)); } else { throw error(contents, val.getValue().getToken().getPosition(), "unexpected node " + val.getValue()); } } return builder.build(parameters); }
Example #16
Source File: PredicatedHandlersParser.java From lams with GNU General Public License v2.0 | 5 votes |
private static Predicate handlePredicateExpressionNode(String contents, ExpressionNode node, Map<String, PredicateBuilder> handlerBuilders, ExchangeAttributeParser parser) { Token token = node.getToken(); PredicateBuilder builder = handlerBuilders.get(token.getToken()); if (builder == null) { throw error(contents, token.getPosition(), "no predicate named " + token.getToken() + " known predicates are " + handlerBuilders.keySet()); } Map<String, Object> parameters = new HashMap<>(); for(Map.Entry<String, Node> val : node.getValues().entrySet()) { String name = val.getKey(); if(name == null) { if(builder.defaultParameter() == null) { throw error(contents, token.getPosition(), "default parameter not supported"); } name = builder.defaultParameter(); } Class<?> type = builder.parameters().get(name); if(type == null) { throw error(contents, val.getValue().getToken().getPosition(), "unknown parameter " + name); } if(val.getValue() instanceof ValueNode) { parameters.put(name, coerceToType(contents, val.getValue().getToken(), type, parser)); } else if(val.getValue() instanceof ArrayNode) { parameters.put(name, readArrayType(contents, name, (ArrayNode)val.getValue(), parser, type)); } else { throw error(contents, val.getValue().getToken().getPosition(), "unexpected node " + val.getValue()); } } return builder.build(parameters); }
Example #17
Source File: PredicatedHandlersParser.java From lams with GNU General Public License v2.0 | 5 votes |
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 #18
Source File: PredicatedHandlersParser.java From quarkus-http with Apache License 2.0 | 5 votes |
private static List<PredicatedHandler> handleNode(String contents, Node node, Map<String, PredicateBuilder> predicateBuilders, Map<String, HandlerBuilder> handlerBuilders, ExchangeAttributeParser attributeParser) { if(node instanceof BlockNode) { return handleBlockNode(contents, (BlockNode) node, predicateBuilders, handlerBuilders, attributeParser); } else if(node instanceof ExpressionNode) { HandlerWrapper handler = handleHandlerNode(contents, (ExpressionNode) node, handlerBuilders, attributeParser); return Collections.singletonList(new PredicatedHandler(Predicates.truePredicate(), handler)); } else if(node instanceof PredicateOperatorNode) { return Collections.singletonList(handlePredicateOperatorNode(contents, (PredicateOperatorNode)node, predicateBuilders, handlerBuilders, attributeParser)); } else { throw error(contents, node.getToken().getPosition(), "unexpected token " + node.getToken()); } }
Example #19
Source File: SetAttributeHandler.java From quarkus-http with Apache License 2.0 | 5 votes |
public SetAttributeHandler(HttpHandler next, final String attribute, final String value, final ClassLoader classLoader) { this.next = next; ExchangeAttributeParser parser = ExchangeAttributes.parser(classLoader); this.attribute = parser.parseSingleToken(attribute); this.value = parser.parse(value); this.preCommit = false; }
Example #20
Source File: SetAttributeHandler.java From quarkus-http with Apache License 2.0 | 5 votes |
public SetAttributeHandler(HttpHandler next, final String attribute, final String value, boolean preCommit) { this.next = next; this.preCommit = preCommit; ExchangeAttributeParser parser = ExchangeAttributes.parser(getClass().getClassLoader()); this.attribute = parser.parseSingleToken(attribute); this.value = parser.parse(value); }
Example #21
Source File: SetAttributeHandler.java From quarkus-http with Apache License 2.0 | 5 votes |
public SetAttributeHandler(HttpHandler next, final String attribute, final String value, final ClassLoader classLoader, boolean preCommit) { this.next = next; this.preCommit = preCommit; ExchangeAttributeParser parser = ExchangeAttributes.parser(classLoader); this.attribute = parser.parseSingleToken(attribute); this.value = parser.parse(value); }
Example #22
Source File: PredicatedHandlersParser.java From quarkus-http with Apache License 2.0 | 5 votes |
public static List<PredicatedHandler> parse(final String contents, final ClassLoader classLoader) { Deque<Token> tokens = tokenize(contents); Node node = parse(contents, tokens); Map<String, PredicateBuilder> predicateBuilders = loadPredicateBuilders(classLoader); Map<String, HandlerBuilder> handlerBuilders = loadHandlerBuilders(classLoader); final ExchangeAttributeParser attributeParser = ExchangeAttributes.parser(classLoader); return handleNode(contents, node, predicateBuilders, handlerBuilders, attributeParser); }
Example #23
Source File: PredicatedHandlersParser.java From quarkus-http with Apache License 2.0 | 5 votes |
public static Predicate parsePredicate(String string, ClassLoader classLoader) { Deque<Token> tokens = tokenize(string); Node node = parse(string, tokens); Map<String, PredicateBuilder> predicateBuilders = loadPredicateBuilders(classLoader); final ExchangeAttributeParser attributeParser = ExchangeAttributes.parser(classLoader); return handlePredicateNode(string, node, predicateBuilders, attributeParser); }
Example #24
Source File: PredicatedHandlersParser.java From quarkus-http with Apache License 2.0 | 5 votes |
public static HandlerWrapper parseHandler(String string, ClassLoader classLoader) { Deque<Token> tokens = tokenize(string); Node node = parse(string, tokens); Map<String, HandlerBuilder> handlerBuilders = loadHandlerBuilders(classLoader); final ExchangeAttributeParser attributeParser = ExchangeAttributes.parser(classLoader); return handleHandlerNode(string, (ExpressionNode)node, handlerBuilders, attributeParser); }
Example #25
Source File: SetAttributeHandler.java From quarkus-http with Apache License 2.0 | 5 votes |
public SetAttributeHandler(HttpHandler next, final String attribute, final String value) { this.next = next; ExchangeAttributeParser parser = ExchangeAttributes.parser(getClass().getClassLoader()); this.attribute = parser.parseSingleToken(attribute); this.value = parser.parse(value); this.preCommit = false; }
Example #26
Source File: PredicatedHandlersParser.java From quarkus-http with Apache License 2.0 | 5 votes |
private static PredicatedHandler handlePredicateOperatorNode(String contents, PredicateOperatorNode node, Map<String, PredicateBuilder> predicateBuilders, Map<String, HandlerBuilder> handlerBuilders, ExchangeAttributeParser parser) { Predicate predicate = handlePredicateNode(contents, node.getLeft(), predicateBuilders, parser); HandlerWrapper ret = handlePredicatedAction(contents, node.getRight(), predicateBuilders, handlerBuilders, parser); HandlerWrapper elseBranch = null; if(node.getElseBranch() != null) { elseBranch = handlePredicatedAction(contents, node.getElseBranch(), predicateBuilders, handlerBuilders, parser); } return new PredicatedHandler(predicate, ret, elseBranch); }
Example #27
Source File: PredicatedHandlersParser.java From quarkus-http with Apache License 2.0 | 5 votes |
private static HandlerWrapper handlePredicatedAction(String contents, Node node, Map<String, PredicateBuilder> predicateBuilders, Map<String, HandlerBuilder> handlerBuilders, ExchangeAttributeParser parser) { if(node instanceof ExpressionNode) { return handleHandlerNode(contents, (ExpressionNode) node, handlerBuilders, parser); } else if(node instanceof BlockNode) { List<PredicatedHandler> handlers = handleBlockNode(contents, (BlockNode) node, predicateBuilders, handlerBuilders, parser); return new PredicatesHandler.Wrapper(handlers, false); } else { throw error(contents, node.getToken().getPosition(), "unexpected token " + node.getToken()); } }
Example #28
Source File: PredicatedHandlersParser.java From quarkus-http with Apache License 2.0 | 5 votes |
private static List<PredicatedHandler> handleBlockNode(String contents, BlockNode node, Map<String, PredicateBuilder> predicateBuilders, Map<String, HandlerBuilder> handlerBuilders, ExchangeAttributeParser parser) { List<PredicatedHandler> ret = new ArrayList<>(); for(Node line : node.getBlock()) { ret.addAll(handleNode(contents, line, predicateBuilders, handlerBuilders, parser)); } return ret; }
Example #29
Source File: PredicatedHandlersParser.java From quarkus-http with Apache License 2.0 | 5 votes |
private static HandlerWrapper handleHandlerNode(String contents, ExpressionNode node, Map<String, HandlerBuilder> handlerBuilders, ExchangeAttributeParser parser) { Token token = node.getToken(); HandlerBuilder builder = handlerBuilders.get(token.getToken()); if (builder == null) { throw error(contents, token.getPosition(), "no handler named " + token.getToken() + " known handlers are " + handlerBuilders.keySet()); } Map<String, Object> parameters = new HashMap<>(); for(Map.Entry<String, Node> val : node.getValues().entrySet()) { String name = val.getKey(); if(name == null) { if(builder.defaultParameter() == null) { throw error(contents, token.getPosition(), "default parameter not supported"); } name = builder.defaultParameter(); } Class<?> type = builder.parameters().get(name); if(type == null) { throw error(contents, val.getValue().getToken().getPosition(), "unknown parameter " + name); } if(val.getValue() instanceof ValueNode) { parameters.put(name, coerceToType(contents, val.getValue().getToken(), type, parser)); } else if(val.getValue() instanceof ArrayNode) { parameters.put(name, readArrayType(contents, name, (ArrayNode)val.getValue(), parser, type)); } else { throw error(contents, val.getValue().getToken().getPosition(), "unexpected node " + val.getValue()); } } return builder.build(parameters); }
Example #30
Source File: PredicatedHandlersParser.java From quarkus-http with Apache License 2.0 | 5 votes |
private static Predicate handlePredicateExpressionNode(String contents, ExpressionNode node, Map<String, PredicateBuilder> handlerBuilders, ExchangeAttributeParser parser) { Token token = node.getToken(); PredicateBuilder builder = handlerBuilders.get(token.getToken()); if (builder == null) { throw error(contents, token.getPosition(), "no predicate named " + token.getToken() + " known predicates are " + handlerBuilders.keySet()); } Map<String, Object> parameters = new HashMap<>(); for(Map.Entry<String, Node> val : node.getValues().entrySet()) { String name = val.getKey(); if(name == null) { if(builder.defaultParameter() == null) { throw error(contents, token.getPosition(), "default parameter not supported"); } name = builder.defaultParameter(); } Class<?> type = builder.parameters().get(name); if(type == null) { throw error(contents, val.getValue().getToken().getPosition(), "unknown parameter " + name); } if(val.getValue() instanceof ValueNode) { parameters.put(name, coerceToType(contents, val.getValue().getToken(), type, parser)); } else if(val.getValue() instanceof ArrayNode) { parameters.put(name, readArrayType(contents, name, (ArrayNode)val.getValue(), parser, type)); } else { throw error(contents, val.getValue().getToken().getPosition(), "unexpected node " + val.getValue()); } } return builder.build(parameters); }