private HttpHandler getContextHandler(HttpHandler httpHandler) { HttpHandler contextHandler = UndertowCompressionConfigurer .configureCompression(this.compression, httpHandler); if (StringUtils.isEmpty(this.contextPath)) { return contextHandler; } return Handlers.path().addPrefixPath(this.contextPath, contextHandler); }
public CacheHandler setNext(final HttpHandler next) { Handlers.handlerNotNull(next); this.next = next; return this; } }
@Override public HttpHandler createHttpHandler(Predicate predicate, ModelNode model, HttpHandler next) { int code = model.get(CODE.getName()).asInt(); String path = model.get(PATH.getName()).asString(); FileErrorPageHandler handler = new FileErrorPageHandler(Paths.get(path), code); handler.setNext(next); if(predicate == null) { return handler; } else { return Handlers.predicate(predicate, handler, next); } }
/** * Creates the set of handlers that are required to perform a simple rewrite. * @param condition The rewrite condition * @param target The rewrite target if the condition matches * @param next The next handler * @return */ public static HttpHandler rewrite(final String condition, final String target, final ClassLoader classLoader, final HttpHandler next) { return predicateContext(predicate(PredicateParser.parse(condition, classLoader), setAttribute(next, "%R", target, classLoader), next)); }
protected HttpHandler createContextHandler(HttpHandler pippoHandler) { String contextPath = getSettings().getContextPath(); // create a handler than redirects non-contact requests to the context PathHandler contextHandler = Handlers.path(Handlers.redirect(contextPath)); // add the handler with the context prefix contextHandler.addPrefixPath(contextPath, pippoHandler); return contextHandler; }
public static MappedEndpoint staticFiles(String url, String docPath) { url = resolveUrl(url); url = url.isEmpty() ? BASE_PATH : url; docPath = docPath.startsWith(BASE_PATH) ? docPath.replaceFirst(BASE_PATH, "") : docPath; HttpHandler handler = Handlers.path() .addPrefixPath(url, Handlers.resource(new ClassPathResourceManager(Thread.currentThread().getContextClassLoader(), docPath)) .addWelcomeFiles(INDEX_HTML)); return new MappedEndpoint(Methods.GET_STRING, url, MappedEndpoint.Type.STATIC, handler); }
@Override public void end() { NativeWebSocket ws = exchange.getAttachment(UndertowRequest.SOCKET); if (ws != null) { try { Handlers.websocket((wsExchange, channel) -> ((UndertowWebSocket) ws).connect(channel)).handleRequest(exchange); } catch (Exception ex) { LoggerFactory.getLogger(NativeResponse.class).error("Upgrade result in exception", ex); } finally { exchange.removeAttachment(UndertowRequest.SOCKET); } } if (endExchange) { exchange.endExchange(); } }
HttpHandler pathHttpHandler = path() .addPrefixPath(API_ENDPOINT_WS_XML, websocket(new InternalWebSocketHandler(this, certificateCommonName, RequestFormatType.XML))) .addPrefixPath(API_ENDPOINT_WS_JSON, websocket(new InternalWebSocketHandler(this, certificateCommonName, RequestFormatType.JSON))) .addPrefixPath(API_ENDPOINT_REST_XML, new InternalRestHandler(this, RequestFormatType.XML)) .addPrefixPath(API_ENDPOINT_REST_JSON, new InternalRestHandler(this, RequestFormatType.JSON))
HttpHandler handler = Handlers.path(Handlers.redirect("/")) .addPrefixPath("/", deployment.start()); if (config.getAccessLogPath().isPresent()) { handler = buildAccessLogHandler(config, handler); appHandler = Handlers.trace(handler); GracefulShutdownHandler httpHandler = Handlers.gracefulShutdown(appHandler); httpHandlers.put(httpHandler, addr); control.addHandler(httpHandler);
private Undertow createServer(URL url, UndertowHTTPHandler undertowHTTPHandler) throws Exception { Undertow.Builder result = Undertow.builder(); result.setServerOption(UndertowOptions.IDLE_TIMEOUT, getMaxIdleTime()); if (tlsServerParameters != null) { if (this.sslContext == null) { this.sslContext = createSSLContext(); } result = result.addHttpsListener(getPort(), getHost(), this.sslContext); } else { result = result.addHttpListener(getPort(), getHost()); } path = Handlers.path(new NotFoundHandler()); if (url.getPath().length() == 0) { result = result.setHandler(Handlers.trace(undertowHTTPHandler)); } else { if (undertowHTTPHandler.isContextMatchExact()) { path.addExactPath(url.getPath(), undertowHTTPHandler); } else { path.addPrefixPath(url.getPath(), undertowHTTPHandler); } result = result.setHandler(wrapHandler(new HttpContinueReadHandler(path))); } result = decorateUndertowSocketConnection(result); result = disableSSLv3(result); result = configureThreads(result); return result.build(); }
.addHost( host, Handlers.predicates( PredicatedHandlersParser.parse("not path-prefix('/images', '/assets', '/api') -> rewrite('/index.html')" new PathHandler(resource(new FileResourceManager( new File(base), Integer .valueOf(transferMinSize)))) new RestHandler())) .addPrefixPath("/api/ws", websocket(new WebSocketHandler())) )); .setServerOption(UndertowOptions.ALWAYS_SET_KEEP_ALIVE, false) .setHandler( Handlers.header(virtualHostHandler, Headers.SERVER_STRING, "LIGHT")) .setWorkerThreads(200).build();
@Override public HttpHandler createHttpHandler(Predicate predicate, ModelNode model, HttpHandler next) { String expression = model.get(EXPRESSION.getName()).asString(); String moduleName = null; if (model.hasDefined(MODULE.getName())) { moduleName = model.get(MODULE.getName()).asString(); } ClassLoader classLoader; if (moduleName == null) { classLoader = getClass().getClassLoader(); } else { try { ModuleLoader moduleLoader = Module.getBootModuleLoader(); Module filterModule = moduleLoader.loadModule(ModuleIdentifier.fromString(moduleName)); classLoader = filterModule.getClassLoader(); } catch (ModuleLoadException e) { throw UndertowLogger.ROOT_LOGGER.couldNotLoadHandlerFromModule(expression, moduleName, e); } } List<PredicatedHandler> handlers = PredicatedHandlersParser.parse(expression, classLoader); UndertowLogger.ROOT_LOGGER.debugf("Creating http handler %s from module %s", expression, moduleName); if (predicate != null) { return Handlers.predicate(predicate, Handlers.predicates(handlers, next), next); } else { return Handlers.predicates(handlers, next); } }
private static ResourceHandler resourceHandler() { return resource( new ClassPathResourceManager( StandaloneTestingService.class.getClassLoader())); }
static void deployServlets(final Builder builder , final DeploymentInfo deploymentInfo) throws ServletException { final ServletContainer servletContainer = defaultContainer(); final DeploymentManager manager = servletContainer.addDeployment(deploymentInfo); manager.deploy(); final HttpHandler servletHandler = manager.start(); final PathHandler pathServlet = Handlers .path(Handlers.redirect(MYAPP)) .addPrefixPath(MYAPP , servletHandler); final String realServletPort = System.getProperty(SERVLET_PORT_PROPERTY , DEFAULT_SERVLET_PORT + ""); final String realServletHost = System.getProperty(SERVLET_HOST_PROPERTY , Main.DEFAULT_HOST); builder.addHttpListener(Integer.parseInt(realServletPort) , realServletHost , pathServlet); }
public static MappedEndpoint staticFiles(String url, String docPath, List<Interceptor> interceptors) { Objects.requireNonNull(url, Messages.INVALID_URL); url = resolveUrl(url); docPath = docPath.startsWith(BASE_PATH) ? docPath.replaceFirst(BASE_PATH, "") : docPath; HttpHandler handler = Handlers.path() .addPrefixPath(url, Handlers.resource(new ClassPathResourceManager(Thread.currentThread().getContextClassLoader(), docPath)) .addWelcomeFiles("index.html")); InterceptorHandler interceptorHandler = new InterceptorHandler(interceptors); interceptorHandler.setNext(handler); return new MappedEndpoint(Methods.GET_STRING, url, MappedEndpoint.Type.STATIC, interceptorHandler); }
public WebsocketHandler(WebSocketConnectionCallback connectionCallback) { websocket = Handlers.websocket(connectionCallback); }
/** * Creates the set of handlers that are required to perform a simple rewrite. * @param condition The rewrite condition * @param target The rewrite target if the condition matches * @param next The next handler * @return */ public static HttpHandler rewrite(final String condition, final String target, final ClassLoader classLoader, final HttpHandler next) { return predicateContext(predicate(PredicateParser.parse(condition, classLoader), setAttribute(next, "%R", target, classLoader), next)); }
ResourceHandler handler = resource(new FileResourceManager(file, 3)) .addWelcomeFiles(welcomeFile) .setDirectoryListingEnabled(false);
protected void startImpl() { try { fathomDeploymentManager = createFathomDeploymentManager(); HttpHandler fathomHandler = fathomDeploymentManager.start(); String contextPath = settings.getContextPath(); // create a handler than redirects non-context requests to the context PathHandler contextHandler = Handlers.path(Handlers.redirect(contextPath)); // add the handler with the context prefix contextHandler.addPrefixPath(contextPath, fathomHandler); GracefulShutdownHandler rootHandler = new GracefulShutdownHandler(contextHandler); server = createServer(rootHandler); String version = server.getClass().getPackage().getImplementationVersion(); log.info("Starting Undertow {}", version); server.start(); } catch (Exception e) { throw new FathomException(e); } }
public OriginHandler setOriginFailedHandler(HttpHandler originFailedHandler) { Handlers.handlerNotNull(originFailedHandler); this.originFailedHandler = originFailedHandler; return this; } }