public void registerHandler(String path, HttpHandler handler) { pathHandler.addPrefixPath(path, handler); }
/** * Adds a path prefix and a handler for that path. If the path does not start * with a / then one will be prepended. * <p> * The match is done on a prefix bases, so registering /foo will also match /bar. Exact * path matches are taken into account first. * <p> * If / is specified as the path then it will replace the default handler. * * @param path The path * @param handler The handler * @see #addPrefixPath(String, io.undertow.server.HttpHandler) * @deprecated Superseded by {@link #addPrefixPath(String, io.undertow.server.HttpHandler)}. */ @Deprecated public synchronized PathHandler addPath(final String path, final HttpHandler handler) { return addPrefixPath(path, handler); }
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 void unregisterHandler(String path) { pathHandler.removePrefixPath(path); // if there is registered location for given path, serve it from now on LocationService location = locations.get(path); if (location != null) { pathHandler.addPrefixPath(location.getLocationPath(), location.getLocationHandler()); } // else serve the default response code else if (path.equals("/")) { this.setupDefaultResponseCodeHandler(); } }
@Override public void start(StartContext startContext) throws StartException { final Context namingContext = new NamingContext(namingStore.getValue(), new Hashtable<String, Object>()); HttpRemoteNamingService service = new HttpRemoteNamingService(namingContext); pathHandlerInjectedValue.getValue().addPrefixPath(NAMING, service.createHandler()); }
@Override public void start(StartContext context) throws StartException { pathHandler.clearPaths(); SecureRandomSessionIdGenerator generator = new SecureRandomSessionIdGenerator(); pathHandler.addPrefixPath(AFFINITY_PATH, exchange -> { String resolved = exchange.getResolvedPath(); int index = resolved.lastIndexOf(AFFINITY_PATH); if(index > 0) { resolved = resolved.substring(0, index); } exchange.getResponseCookies().put("JSESSIONID", new CookieImpl("JSESSIONID", generator.createSessionId()).setPath(resolved)); }); }
@Override public void start(StartContext context) throws StartException { EjbHttpService service = new EjbHttpService(associationServiceInjectedValue.getValue().getAssociation(), null, localTransactionContextInjectedValue.getValue()); pathHandlerInjectedValue.getValue().addPrefixPath("/ejb", service.createHttpHandler()); }
@Override public void start(StartContext context) throws StartException { HttpRemoteTransactionService transactionService = new HttpRemoteTransactionService(localTransactionContextInjectedValue.getValue(), (transaction) -> transaction.getProviderInterface(Transaction.class).getTxId()); pathHandlerInjectedValue.getValue().addPrefixPath("/txn", transactionService.createHandler()); }
public HttpHandler createHttpHandler() { PathHandler pathHandler = new PathHandler(); pathHandler.addPrefixPath("/v1/invoke", new AllowedMethodsHandler(new HttpInvocationHandler(association, executorService, localTransactionContext, cancellationFlags), Methods.POST)) .addPrefixPath("/v1/open", new AllowedMethodsHandler(new HttpSessionOpenHandler(association, executorService, localTransactionContext), Methods.POST)) .addPrefixPath("/v1/cancel", new AllowedMethodsHandler(new HttpCancelHandler(association, executorService, localTransactionContext, cancellationFlags), Methods.DELETE)); EncodingHandler encodingHandler = new EncodingHandler(pathHandler, new ContentEncodingRepository().addEncodingHandler(Headers.GZIP.toString(), new GzipEncodingProvider(), 1)); RequestEncodingHandler requestEncodingHandler = new RequestEncodingHandler(encodingHandler); requestEncodingHandler.addEncoding(Headers.GZIP.toString(), GzipStreamSourceConduit.WRAPPER); return requestEncodingHandler; }
.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)) .addPrefixPath("/", new InternalWebInterfaceHandler());
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()))); } }
/** * Maps a path prefix to a resource handler to allow serving resources other than the JAX-RS endpoints. * For example, this can be used for serving static resources like web pages or API documentation that might * be deployed with the REST application server. * * @param path * @param handler */ public void addResourcePrefixPath(String path, ResourceHandler handler) { root.addPrefixPath(path, handler); }
/** * Helper to add given PathResourceProviders to a PathHandler. * * @param pathResourceProviders List of instances of classes implementing PathResourceProvider. * @param pathHandler The handler that will have these handlers added to it. */ public static void addProvidersToPathHandler(PathResourceProvider[] pathResourceProviders, PathHandler pathHandler) { if (pathResourceProviders != null && pathResourceProviders.length > 0) { for (PathResourceProvider pathResourceProvider : pathResourceProviders) { if (pathResourceProvider.isPrefixPath()) { pathHandler.addPrefixPath(pathResourceProvider.getPath(), new ResourceHandler(pathResourceProvider.getResourceManager())); } else { pathHandler.addExactPath(pathResourceProvider.getPath(), new ResourceHandler(pathResourceProvider.getResourceManager())); } } } }
public PathResourceHandler() { PathResourceConfig config = (PathResourceConfig)Config.getInstance().getJsonObjectConfig(PathResourceConfig.CONFIG_NAME, PathResourceConfig.class); if(config.isPrefix()) { pathHandler = new PathHandler() .addPrefixPath(config.getPath(), new ResourceHandler(new PathResourceManager(Paths.get(config.getBase()), config.getTransferMinSize())) .setDirectoryListingEnabled(config.isDirectoryListingEnabled())); } else { pathHandler = new PathHandler() .addExactPath(config.getPath(), new ResourceHandler(new PathResourceManager(Paths.get(config.getBase()), config.getTransferMinSize())) .setDirectoryListingEnabled(config.isDirectoryListingEnabled())); } }
/** * Adds an arbitrary web deployment to underlying Undertow server. This is for your own deployments * * @param builder * @return */ public UndertowJaxrsServer deploy(DeploymentInfo builder) { DeploymentManager manager = container.addDeployment(builder); manager.deploy(); try { root.addPrefixPath(builder.getContextPath(), manager.start()); } catch (ServletException e) { throw new RuntimeException(e); } return this; }
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); }
public void unregisterHandler(String path) { pathHandler.removePrefixPath(path); // if there is registered location for given path, serve it from now on LocationService location = locations.get(path); if (location != null) { pathHandler.addPrefixPath(location.getLocationPath(), location.getLocationHandler()); } // else serve the default response code else if (path.equals("/")) { this.setupDefaultResponseCodeHandler(); } }
@Override public void start(StartContext startContext) throws StartException { final Context namingContext = new NamingContext(namingStore.getValue(), new Hashtable<String, Object>()); HttpRemoteNamingService service = new HttpRemoteNamingService(namingContext); pathHandlerInjectedValue.getValue().addPrefixPath(NAMING, service.createHandler()); }
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); }