io.undertow.server.handlers.NameVirtualHostHandler Java Examples
The following examples show how to use
io.undertow.server.handlers.NameVirtualHostHandler.
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: NameVirtualHostDefaultHandler.java From galeb with Apache License 2.0 | 6 votes |
@Override public synchronized void handleRequest(HttpServerExchange exchange) throws Exception { final String hostName = exchange.getHostName(); final NameVirtualHostHandler nameVirtualHostHandler = context.getBean(NameVirtualHostHandler.class); if (existHostname(hostName)) { if (!nameVirtualHostHandler.getHosts().containsKey(hostName)) { logger.info("adding " + hostName); final VirtualHost virtualHost = cache.get(hostName); nameVirtualHostHandler.addHost(hostName, defineNextHandler(virtualHost)); } nameVirtualHostHandler.handleRequest(exchange); } else { ResponseCodeOnError.VIRTUALHOST_NOT_FOUND.getHandler().handleRequest(exchange); } }
Example #2
Source File: Handlers.java From quarkus-http with Apache License 2.0 | 5 votes |
/** * Creates a new virtual host handler that uses the provided handler as the root handler for the given hostnames. * * @param hostHandler The host handler * @param hostnames The host names * @return A new virtual host handler */ public static NameVirtualHostHandler virtualHost(final HttpHandler hostHandler, String... hostnames) { NameVirtualHostHandler handler = new NameVirtualHostHandler(); for (String host : hostnames) { handler.addHost(host, hostHandler); } return handler; }
Example #3
Source File: RootHandlerConfiguration.java From galeb with Apache License 2.0 | 5 votes |
@Autowired public RootHandlerConfiguration(final NameVirtualHostHandler nameVirtualHostHandler, final AccessLogCompletionListener accessLogCompletionListener, final StatsdCompletionListener statsdCompletionListener) { this.nameVirtualHostHandler = nameVirtualHostHandler; this.accessLogCompletionListener = accessLogCompletionListener; this.statsdCompletionListener = statsdCompletionListener; }
Example #4
Source File: UpdaterService.java From galeb with Apache License 2.0 | 5 votes |
@Autowired public UpdaterService(final ManagerClient managerClient, final ManagerClientCache cache, final NameVirtualHostHandler nameVirtualHostHandler) { this.managerClient = managerClient; this.cache = cache; this.nameVirtualHostHandler = nameVirtualHostHandler; }
Example #5
Source File: RootHandler.java From galeb with Apache License 2.0 | 5 votes |
public RootHandler(final NameVirtualHostHandler nameVirtualHostHandler, final AccessLogCompletionListener accessLogCompletionListener, final StatsdCompletionListener statsdCompletionListener) { this.nameVirtualHostHandler = nameVirtualHostHandler; this.accessLogCompletionListener = accessLogCompletionListener; this.statsdCompletionListener = statsdCompletionListener; }
Example #6
Source File: Handlers.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Creates a new virtual host handler that uses the provided handler as the root handler for the given hostnames. * * @param hostHandler The host handler * @param hostnames The host names * @return A new virtual host handler */ public static NameVirtualHostHandler virtualHost(final HttpHandler hostHandler, String... hostnames) { NameVirtualHostHandler handler = new NameVirtualHostHandler(); for (String host : hostnames) { handler.addHost(host, hostHandler); } return handler; }
Example #7
Source File: VirtualHostServer.java From StubbornJava with MIT License | 5 votes |
public static void main(String[] args) { NameVirtualHostHandler handler = Handlers.virtualHost() .addHost("localhost", VirtualHostServer.redirectToHost("www.localhost")) .addHost("www.localhost", ROUTES); SimpleServer server = SimpleServer.simpleServer(handler); server.start(); }
Example #8
Source File: VirtualHostHandler.java From light-4j with Apache License 2.0 | 5 votes |
public VirtualHostHandler() { VirtualHostConfig config = (VirtualHostConfig)Config.getInstance().getJsonObjectConfig(VirtualHostConfig.CONFIG_NAME, VirtualHostConfig.class); virtualHostHandler = new NameVirtualHostHandler(); for(VirtualHost host: config.hosts) { virtualHostHandler.addHost(host.domain, new PathHandler().addPrefixPath(host.getPath(), new ResourceHandler((new PathResourceManager(Paths.get(host.getBase()), host.getTransferMinSize()))).setDirectoryListingEnabled(host.isDirectoryListingEnabled()))); } }
Example #9
Source File: VirtualHostServer.java From StubbornJava with MIT License | 5 votes |
public static void main(String[] args) { NameVirtualHostHandler handler = Handlers.virtualHost() .addHost("localhost", VirtualHostServer.redirectToHost("www.localhost")) .addHost("www.localhost", ROUTES); SimpleServer server = SimpleServer.simpleServer(handler); server.start(); }
Example #10
Source File: LightServer.java From light with Apache License 2.0 | 4 votes |
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(); }
Example #11
Source File: Handlers.java From quarkus-http with Apache License 2.0 | 2 votes |
/** * Creates a new virtual host handler * * @return A new virtual host handler */ public static NameVirtualHostHandler virtualHost() { return new NameVirtualHostHandler(); }
Example #12
Source File: Handlers.java From quarkus-http with Apache License 2.0 | 2 votes |
/** * Creates a new virtual host handler using the provided default handler * * @return A new virtual host handler */ public static NameVirtualHostHandler virtualHost(final HttpHandler defaultHandler) { return new NameVirtualHostHandler().setDefaultHandler(defaultHandler); }
Example #13
Source File: Handlers.java From quarkus-http with Apache License 2.0 | 2 votes |
/** * Creates a new virtual host handler that uses the provided handler as the root handler for the given hostnames. * * @param defaultHandler The default handler * @param hostHandler The host handler * @param hostnames The host names * @return A new virtual host handler */ public static NameVirtualHostHandler virtualHost(final HttpHandler defaultHandler, final HttpHandler hostHandler, String... hostnames) { return virtualHost(hostHandler, hostnames).setDefaultHandler(defaultHandler); }
Example #14
Source File: Handlers.java From lams with GNU General Public License v2.0 | 2 votes |
/** * Creates a new virtual host handler * * @return A new virtual host handler */ public static NameVirtualHostHandler virtualHost() { return new NameVirtualHostHandler(); }
Example #15
Source File: Handlers.java From lams with GNU General Public License v2.0 | 2 votes |
/** * Creates a new virtual host handler using the provided default handler * * @return A new virtual host handler */ public static NameVirtualHostHandler virtualHost(final HttpHandler defaultHandler) { return new NameVirtualHostHandler().setDefaultHandler(defaultHandler); }
Example #16
Source File: Handlers.java From lams with GNU General Public License v2.0 | 2 votes |
/** * Creates a new virtual host handler that uses the provided handler as the root handler for the given hostnames. * * @param defaultHandler The default handler * @param hostHandler The host handler * @param hostnames The host names * @return A new virtual host handler */ public static NameVirtualHostHandler virtualHost(final HttpHandler defaultHandler, final HttpHandler hostHandler, String... hostnames) { return virtualHost(hostHandler, hostnames).setDefaultHandler(defaultHandler); }