Java Code Examples for io.undertow.server.handlers.builder.PredicatedHandlersParser

The following examples show how to use io.undertow.server.handlers.builder.PredicatedHandlersParser. These examples are extracted from open source projects. 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
@Override
public void handleDeployment(DeploymentInfo deploymentInfo, ServletContext servletContext) {
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    try (InputStream handlers = classLoader.getResourceAsStream(META_INF_UNDERTOW_HANDLERS_CONF)) {
        if (handlers != null) {
            // From Stuart Douglas: Ideally these would be parsed at deployment time and passed into a recorder,
            // however they are likely not bytecode serialisable. Even though this approach
            // does not 100% align with the Quarkus ethos I think it is ok in this case as
            // the gains would be marginal compared to the cost of attempting to make
            // every predicate bytecode serialisable.
            List<PredicatedHandler> handlerList = PredicatedHandlersParser.parse(handlers, classLoader);
            if (!handlerList.isEmpty()) {
                deploymentInfo.addOuterHandlerChainWrapper(new RewriteCorrectingHandlerWrappers.PostWrapper());
                deploymentInfo.addOuterHandlerChainWrapper(new HandlerWrapper() {
                    @Override
                    public HttpHandler wrap(HttpHandler handler) {
                        return Handlers.predicates(handlerList, handler);
                    }
                });
                deploymentInfo.addOuterHandlerChainWrapper(new RewriteCorrectingHandlerWrappers.PreWrapper());
            }
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example 2
Source Project: quarkus-http   Source File: PredicateParser.java    License: Apache License 2.0 4 votes vote down vote up
public static Predicate parse(String string, final ClassLoader classLoader) {
    return PredicatedHandlersParser.parsePredicate(string, classLoader);
}
 
Example 3
Source Project: lams   Source File: PredicateParser.java    License: GNU General Public License v2.0 4 votes vote down vote up
public static final Predicate parse(String string, final ClassLoader classLoader) {
    return PredicatedHandlersParser.parsePredicate(string, classLoader);
}
 
Example 4
Source Project: light   Source File: LightServer.java    License: Apache License 2.0 4 votes vote down vote up
static public void start() {
    // hosts and server configuration
    Map<String, Object> hostConfigMap = ServiceLocator.getInstance().getJsonMapConfig(ServiceLocator.HOST_CONFIG);
    Map<String, Object> serverConfigMap = ServiceLocator.getInstance().getJsonMapConfig(ServiceLocator.SERVER_CONFIG);

    OrientGraphFactory factory = ServiceLocator.getInstance().getFactory();
    // check if database exists, if not create it and init it.
    if(!factory.exists()) {
        try {
            OrientBaseGraph g = new OrientGraph(ServiceLocator.getInstance().getDbUrl());
            // database is auto created
            g.command(new OCommandSQL("alter database custom useLightweightEdges=true")).execute();
            g.command(new OCommandSQL("alter database DATETIMEFORMAT yyyy-MM-dd'T'HH:mm:ss.SSS")).execute();
            g.command(new OCommandSQL("alter database TIMEZONE UTC")).execute();
            OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.setValue(-1);
        } finally {
            // this also closes the OrientGraph instances created by the factory
            // Note that OrientGraphFactory does not implement Closeable
            factory.close();
        }
        InitDatabase.initDb();
        // load rule compileCache here
        AbstractRuleRule.loadCompileCache();
        // replay all the event to create database image.
        // TODO need to rethink replay as orientdb is used instead of Memory Image.
        replayEvent();
    } else {
        // load rule compileCache here
        AbstractRuleRule.loadCompileCache();
    }

    NameVirtualHostHandler virtualHostHandler = new NameVirtualHostHandler();
    Iterator<String> it = hostConfigMap.keySet().iterator();
    while (it.hasNext()) {
        String host = it.next();
        Map<String, String> hostPropMap = (Map<String, String>)hostConfigMap.get(host);
        String base = hostPropMap.get("base");
        String transferMinSize = hostPropMap.get("transferMinSize");
        virtualHostHandler
                .addHost(
                        host,
                        Handlers.predicates(
                            PredicatedHandlersParser.parse("not path-prefix('/images', '/assets', '/api') -> rewrite('/index.html')"
                            //PredicatedHandlersParser.parse("not path-suffix['.js', '.html', '.css'] -> rewrite['/index.html']"
                            //PredicatedHandlersParser.parse("path-prefix['/home', '/page', '/form'] -> rewrite['/index.html']"
                            , LightServer.class.getClassLoader()),
                                new PathHandler(resource(new FileResourceManager(
                                        new File(base), Integer
                                        .valueOf(transferMinSize))))
                                        .addPrefixPath("/api/rs",
                                                new EagerFormParsingHandler().setNext(
                                                        new RestHandler()))
                                        .addPrefixPath("/api/ws",
                                                websocket(new WebSocketHandler()))
                        ));
    }
    String ip = (String)serverConfigMap.get("ip");
    String port = (String)serverConfigMap.get("port");
    server = Undertow
            .builder()
            .addHttpListener(Integer.valueOf(port), ip)
            .setBufferSize(1024 * 16)
            .setServerOption(UndertowOptions.ALWAYS_SET_KEEP_ALIVE, false)
            .setHandler(
                    Handlers.header(virtualHostHandler,
                            Headers.SERVER_STRING, "LIGHT"))
            .setWorkerThreads(200).build();
    server.start();

}