io.undertow.predicate.Predicates Java Examples

The following examples show how to use io.undertow.predicate.Predicates. 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: SikulixServer.java    From SikuliX1 with MIT License 6 votes vote down vote up
public ScriptsCommand(TasksCommand tasks) {
  this.taskId = new AtomicInteger();
  this.tasks = tasks;
  this.run.addExceptionHandler(Throwable.class, getExceptionHttpHandler());
  getRouting()
      .add(Methods.GET, "/scripts", 
          getScripts)
      .add(Methods.GET, "/scripts/*",
          Predicates.regex(RelativePathAttribute.INSTANCE, "^/scripts/[^/].*/run$"),
          run)
      .add(Methods.POST, "/scripts/*",
          Predicates.regex(RelativePathAttribute.INSTANCE, "^/scripts/[^/].*/run$"),
          run)
      .add(Methods.POST, "/scripts/*",
          Predicates.regex(RelativePathAttribute.INSTANCE, "^/scripts/[^/].*/task$"),
          task)
      .add(Methods.GET, "/scripts/*",
          Predicates.regex(RelativePathAttribute.INSTANCE, "^/scripts/[^/].*/tasks(/.*)*$"),
          delegate)
      .add(Methods.PUT, "/scripts/*",
          Predicates.regex(RelativePathAttribute.INSTANCE, "^/scripts/[^/].*/tasks(/.*)*$"),
          delegate)
      .add(Methods.GET, "/scripts/*", 
          Predicates.regex(RelativePathAttribute.INSTANCE, "^/scripts/([^/].*)?[^/]$"),
          getScript);
}
 
Example #2
Source File: ErrorContextHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static HttpHandler createErrorContext(final String slot) throws ModuleLoadException {
    final ClassPathResourceManager cpresource = new ClassPathResourceManager(getClassLoader(Module.getCallerModuleLoader(), ERROR_MODULE, slot), "");
    final io.undertow.server.handlers.resource.ResourceHandler handler = new io.undertow.server.handlers.resource.ResourceHandler(cpresource)
            .setAllowed(not(path("META-INF")))
            .setDirectoryListingEnabled(false)
            .setCachable(Predicates.<HttpServerExchange>falsePredicate());

    //we also need to setup the default resource redirect
    return new PredicateHandler(path("/"), new RedirectHandler(ExchangeAttributes.constant(ERROR_CONTEXT + DEFAULT_RESOURCE)), handler);
}
 
Example #3
Source File: ConsoleMode.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static ResourceHandlerDefinition createConsoleHandler(String slot, String resource) throws ModuleLoadException {
    final ClassPathResourceManager cpresource = new ClassPathResourceManager(getClassLoader(Module.getCallerModuleLoader(), ERROR_MODULE, slot), "");
    final io.undertow.server.handlers.resource.ResourceHandler handler = new io.undertow.server.handlers.resource.ResourceHandler(cpresource)
            .setAllowed(not(path("META-INF")))
            .setResourceManager(cpresource)
            .setDirectoryListingEnabled(false)
            .setCachable(Predicates.<HttpServerExchange>falsePredicate());

    //we also need to setup the default resource redirect
    PredicateHandler predicateHandler = new PredicateHandler(path("/"), new RedirectHandler(ExchangeAttributes.constant(CONTEXT + resource)), handler);
    return new ResourceHandlerDefinition(CONTEXT, resource, predicateHandler);
}
 
Example #4
Source File: CustomHandlers.java    From StubbornJava with MIT License 5 votes vote down vote up
public static HttpHandler gzip(HttpHandler next) {
    return new EncodingHandler(new ContentEncodingRepository()
              .addEncodingHandler("gzip",
                  // This 1000 is a priority, not exactly sure what it does.
                  new GzipEncodingProvider(), 1000,
                  // Anything under a content-length of 20 will not be gzipped
                  Predicates.truePredicate()
                  //Predicates.maxContentSize(20) // https://issues.jboss.org/browse/UNDERTOW-1234
                  ))
              .setNext(next);
}
 
Example #5
Source File: PredicatedHandlersParser.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
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 #6
Source File: FormAuthTestCase.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@Override
protected void setRootHandler(HttpHandler current) {
    final PredicateHandler handler = new PredicateHandler(Predicates.path("/login"), new HttpHandler() {
        @Override
        public void handleRequest(HttpServerExchange exchange) throws Exception {
            exchange.writeAsync("Login Page");
        }
    }, current);
    super.setRootHandler(new SessionAttachmentHandler(handler, new InMemorySessionManager("test"), new SessionCookieConfig()));
}
 
Example #7
Source File: RedirectTestCase.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setup() {
    DefaultServer.setRootHandler(new PathHandler()
            .addPrefixPath("/target", new HttpHandler() {
                @Override
                public void handleRequest(HttpServerExchange exchange) throws Exception {
                    message = exchange.getRequestURI();
                }
            })
            .addPrefixPath("/", predicateContext(predicate(Predicates.regex("%{REQUEST_URL}", "/(aa.*?)c", RedirectTestCase.class.getClassLoader(), false),
                    Handlers.redirect("/target/matched/${1}"), Handlers.redirect("/target%U"))))
    );
}
 
Example #8
Source File: CustomHandlers.java    From StubbornJava with MIT License 5 votes vote down vote up
public static HttpHandler gzip(HttpHandler next) {
    return new EncodingHandler(new ContentEncodingRepository()
              .addEncodingHandler("gzip",
                  // This 1000 is a priority, not exactly sure what it does.
                  new GzipEncodingProvider(), 1000,
                  // Anything under a content-length of 20 will not be gzipped
                  Predicates.truePredicate()
                  //Predicates.maxContentSize(20) // https://issues.jboss.org/browse/UNDERTOW-1234
                  ))
              .setNext(next);
}
 
Example #9
Source File: PredicatedHandlersParser.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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 #10
Source File: AccessLogHandler.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public AccessLogHandler(final HttpHandler next, final AccessLogReceiver accessLogReceiver, String formatString, final ExchangeAttribute attribute) {
    this(next, accessLogReceiver, formatString, attribute, Predicates.truePredicate());
}
 
Example #11
Source File: ContentEncodingRepository.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public synchronized ContentEncodingRepository addEncodingHandler(final String encoding, final ContentEncodingProvider encoder, int priority) {
    addEncodingHandler(encoding, encoder, priority, Predicates.truePredicate());
    return this;
}
 
Example #12
Source File: ConnectHandler.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public ConnectHandler(HttpHandler next) {
    this(next, Predicates.truePredicate());
}
 
Example #13
Source File: HttpContinueAcceptingHandler.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public HandlerWrapper build(Map<String, Object> config) {
    return new Wrapper(Predicates.truePredicate());
}
 
Example #14
Source File: HttpContinueAcceptingHandler.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public HttpContinueAcceptingHandler(HttpHandler next) {
    this(next, Predicates.truePredicate());
}
 
Example #15
Source File: AccessLogHandler.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
public AccessLogHandler(final HttpHandler next, final AccessLogReceiver accessLogReceiver, final String formatString, ClassLoader classLoader) {
    this(next, accessLogReceiver, formatString, classLoader, Predicates.truePredicate());
}
 
Example #16
Source File: AccessLogHandler.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public AccessLogHandler(final HttpHandler next, final AccessLogReceiver accessLogReceiver, final String formatString, ClassLoader classLoader) {
    this(next, accessLogReceiver, formatString, classLoader, Predicates.truePredicate());
}
 
Example #17
Source File: HttpContinueAcceptingHandler.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
@Override
public HandlerWrapper build(Map<String, Object> config) {
    return new Wrapper(Predicates.truePredicate());
}
 
Example #18
Source File: HttpContinueAcceptingHandler.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
public HttpContinueAcceptingHandler(HttpHandler next) {
    this(next, Predicates.truePredicate());
}
 
Example #19
Source File: AccessLogHandler.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
public AccessLogHandler(final HttpHandler next, final AccessLogReceiver accessLogReceiver, String formatString, final ExchangeAttribute attribute) {
    this(next, accessLogReceiver, formatString, attribute, Predicates.truePredicate());
}