@Override public Iterable<Context> getContexts() { List<Context> contexts = new ArrayList<>(); for (Deployment deployment : this.host.getDeployments()) { contexts.add(new UndertowContext(deployment, this)); } for (String path : this.host.getLocations()) { contexts.add(new LocationContext(path, this)); } return contexts; }
@Override public Context findContext(String path) { String findPath = "".equals(path) ? "/" : path; for (Deployment deployment : this.host.getDeployments()) { if (deployment.getDeploymentInfo().getContextPath().equals(findPath)) { return new UndertowContext(deployment, this); } } return null; }
@Override public void start(StartContext context) { this.service.get().registerListener(this); for (Deployment deployment : this.host.get().getDeployments()) { this.addDeployment(deployment); } this.registry.accept(this); }
@Override public void stop(StopContext context) { for (Deployment deployment : this.host.get().getDeployments()) { this.removeDeployment(deployment); } this.service.get().unregisterListener(this); }
private void validateEndpointContextPath(URI httpURI) { String undertowEndpointPath = getContextPath(httpURI); Set<Deployment> deployments = defaultHost.getDeployments(); for (Deployment deployment : deployments) { DeploymentInfo depInfo = deployment.getDeploymentInfo(); String contextPath = depInfo.getContextPath(); if (contextPath.equals(undertowEndpointPath)) { final HttpHandler handler = deployment.getHandler(); if (handler instanceof CamelEndpointDeployerHandler && ((CamelEndpointDeployerHandler)handler).getRoutingHandler() instanceof DelegatingRoutingHandler) { final ModuleClassLoader oldCl = ((DelegatingRoutingHandler)((CamelEndpointDeployerHandler)handler).getRoutingHandler()).classLoader; final ModuleClassLoader tccl = checkTccl(); if (tccl != oldCl) { /* Avoid allowing handlers from distict apps to handle the same path */ throw new IllegalStateException("Cannot add "+ HttpHandler.class.getName() +" for path " + contextPath + " defined in " + tccl.getName() + " because that path is already served by "+ oldCl.getName()); } } else { /* Another application already serves this path */ throw new IllegalStateException("Cannot overwrite context path " + contextPath + " owned by " + depInfo.getDeploymentName()); } } } }
/** * Exposes an HTTP endpoint that will be served by the given {@link HttpHandler} under the given {@link URI}'s path. * * @param uri determines the path and protocol under which the HTTP endpoint should be exposed * @param routingHandler an {@link HttpHandler} to use for handling HTTP requests sent to the given * {@link URI}'s path */ public void deploy(URI uri, final HttpHandler routingHandler) { final Set<Deployment> availableDeployments = hostSupplier.getValue().getDeployments(); if (!availableDeployments.stream().anyMatch( deployment -> deployment.getHandler() instanceof CamelEndpointDeployerHandler && ((CamelEndpointDeployerHandler) deployment.getHandler()).getRoutingHandler() == routingHandler)) { /* deploy only if the routing handler is not there already */ doDeploy( uri, servletInstance -> servletInstance.setEndpointHttpHandler(new DelegatingEndpointHttpHandler(routingHandler)), // plug the endpointHttpHandler into the servlet deploymentInfo -> deploymentInfo.addInnerHandlerChainWrapper(exchangeStoringHandlerWrapper), // add the handler to the chain deployment -> { // wrap the initial handler with our custom class so that we can recognize it at other places final HttpHandler servletHandler = new CamelEndpointDeployerHandler(deployment.getHandler(), routingHandler); deployment.setInitialHandler(servletHandler); }); } }
/** * Exposes an HTTP endpoint that will be served by the given {@link HttpHandler} under the given {@link URI}'s path. * * @param uri determines the path and protocol under which the HTTP endpoint should be exposed * @param routingHandler an {@link HttpHandler} to use for handling HTTP requests sent to the given * {@link URI}'s path */ public void deploy(URI uri, final HttpHandler routingHandler) { final Set<Deployment> availableDeployments = hostSupplier.getValue().getDeployments(); if (!availableDeployments.stream().anyMatch( deployment -> deployment.getHandler() instanceof CamelEndpointDeployerHandler && ((CamelEndpointDeployerHandler) deployment.getHandler()).getRoutingHandler() == routingHandler)) { /* deploy only if the routing handler is not there already */ doDeploy( uri, servletInstance -> servletInstance.setEndpointHttpHandler(new DelegatingEndpointHttpHandler(routingHandler)), // plug the endpointHttpHandler into the servlet deploymentInfo -> deploymentInfo.addInnerHandlerChainWrapper(exchangeStoringHandlerWrapper), // add the handler to the chain deployment -> { // wrap the initial handler with our custom class so that we can recognize it at other places final HttpHandler servletHandler = new CamelEndpointDeployerHandler(deployment.getHandler(), routingHandler); deployment.setInitialHandler(servletHandler); }); } }