private String getDeployedContextPath(DeploymentInfo deploymentInfo) { return "".equals(deploymentInfo.getContextPath()) ? "/" : deploymentInfo.getContextPath(); }
/** * 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; }
@Override public String getContextPath() { String contextPath = deploymentInfo.getContextPath(); if (contextPath.equals("/")) { return ""; } return contextPath; }
private String getDeployedContextPath(DeploymentInfo deploymentInfo) { return "".equals(deploymentInfo.getContextPath()) ? "/" : deploymentInfo.getContextPath(); }
private String getDeployedContextPath(DeploymentInfo deploymentInfo) { return "".equals(deploymentInfo.getContextPath()) ? "/" : deploymentInfo.getContextPath(); }
@Override public String getPath() { String path = this.deployment.getDeploymentInfo().getContextPath(); return "/".equals(path) ? "" : path; }
@Override public DeploymentManager addDeployment(final DeploymentInfo deployment) { final DeploymentInfo dep = deployment.clone(); DeploymentManager deploymentManager = new DeploymentManagerImpl(dep, this); deployments.put(dep.getDeploymentName(), deploymentManager); deploymentsByPath.put(dep.getContextPath(), deploymentManager); return deploymentManager; }
@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() { try { undertow.start(); baseURI = new URI("http", null, deploymentInfo.getHostName(), getPorts().get(0), deploymentInfo.getContextPath(), null, null); } catch (Exception e) { throw new IllegalStateException(e); } }
@Override public void start() { try { undertow.start(); baseURI = new URI("http", null, deploymentInfo.getHostName(), getPorts().get(0), deploymentInfo.getContextPath(), null, null); } catch (Exception e) { throw new IllegalStateException(e); } }
private void checkForOverlappingContextPath(Deployment dep) { final DeploymentInfo depInfo = dep.getDeploymentInfo(); if (dep.getHandler() != null) { final String contextPath = depInfo.getContextPath(); final Boolean exists = existingContextPaths.putIfAbsent(contextPath, Boolean.TRUE); IllegalStateAssertion.assertFalse(Boolean.TRUE == exists, "Cannot overwrite context path " + contextPath + " owned by camel-undertow" + contextPath); } } }
@Override public void removeDeployment(final DeploymentInfo deploymentInfo) { final DeploymentManager deploymentManager = deployments.get(deploymentInfo.getDeploymentName()); if (deploymentManager.getState() != DeploymentManager.State.UNDEPLOYED) { throw UndertowServletMessages.MESSAGES.canOnlyRemoveDeploymentsWhenUndeployed(deploymentManager.getState()); } deployments.remove(deploymentInfo.getDeploymentName()); deploymentsByPath.remove(deploymentInfo.getContextPath()); }
@Override public DeploymentManager addDeployment(final DeploymentInfo deployment) { final DeploymentInfo dep = deployment.clone(); DeploymentManager deploymentManager = null; if (isConvergedDeployment(dep.getDeploymentName())) { deploymentManager = new ConvergedDeploymentManagerImpl(dep, this); // accessing parent fields using reflection: try { Field deploymentsField = ServletContainerImpl.class.getDeclaredField("deployments"); deploymentsField.setAccessible(true); Map<String, DeploymentManager> deployments = (Map<String, DeploymentManager>) deploymentsField.get(this); deployments.put(dep.getDeploymentName(), deploymentManager); deploymentsField.setAccessible(false); Field deploymentsByPathField = ServletContainerImpl.class.getDeclaredField("deploymentsByPath"); deploymentsByPathField.setAccessible(true); Map<String, DeploymentManager> deploymentsByPath = (Map<String, DeploymentManager>) deploymentsByPathField .get(this); deploymentsByPath.put(dep.getContextPath(), deploymentManager); deploymentsByPathField.setAccessible(false); } catch (NoSuchFieldException | IllegalAccessException e) { throw new RuntimeException(e); } } else { deploymentManager = super.addDeployment(deployment); } return deploymentManager; }
@Override public void onDeploymentStop(Deployment dep, Host host) { runtimeState.removeHttpContext(dep.getServletContext().getContextPath()); final DeploymentInfo depInfo = dep.getDeploymentInfo(); if (dep.getHandler() != null) { final String contextPath = depInfo.getContextPath(); existingContextPaths.remove(contextPath); } }
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()); } } } }
@Override public ServerInstance init(ServerDescriptor descriptor, DeploymentInfo deploymentInfo) { try { DeploymentManager manager = Servlets.defaultContainer() .addDeployment(deploymentInfo); manager.deploy(); HttpHandler httpHandler = manager.start(); RedirectHandler defaultHandler = Handlers.redirect(deploymentInfo.getContextPath()); PathHandler pathHandler = Handlers.path(defaultHandler); pathHandler.addPrefixPath(deploymentInfo.getContextPath(), httpHandler); Undertow undertow = Undertow.builder() .addHttpListener(0, deploymentInfo.getHostName(), pathHandler) .build(); return new UndertowServerInstance(undertow, deploymentInfo); } catch (Exception e) { throw new IllegalStateException(e); } }
@Override public ServerInstance init(ServerDescriptor descriptor, DeploymentInfo deploymentInfo) { try { DeploymentManager manager = Servlets.defaultContainer() .addDeployment(deploymentInfo); manager.deploy(); HttpHandler httpHandler = manager.start(); RedirectHandler defaultHandler = Handlers.redirect(deploymentInfo.getContextPath()); PathHandler pathHandler = Handlers.path(defaultHandler); pathHandler.addPrefixPath(deploymentInfo.getContextPath(), httpHandler); Undertow undertow = Undertow.builder() .addHttpListener(0, deploymentInfo.getHostName(), pathHandler) .build(); return new UndertowServerInstance(undertow, deploymentInfo); } catch (Exception e) { throw new IllegalStateException(e); } }
public ServletContextImpl(final ServletContainer servletContainer, final Deployment deployment) { this.servletContainer = servletContainer; this.deployment = deployment; this.deploymentInfo = deployment.getDeploymentInfo(); sessionCookieConfig = new SessionCookieConfigImpl(this); sessionCookieConfig.setPath(deploymentInfo.getContextPath()); if (deploymentInfo.getServletContextAttributeBackingMap() == null) { this.attributes = new ConcurrentHashMap<>(); } else { this.attributes = deploymentInfo.getServletContextAttributeBackingMap(); } attributes.putAll(deployment.getDeploymentInfo().getServletContextAttributes()); this.contentTypeCache = new LRUCache<>(deployment.getDeploymentInfo().getContentTypeCacheSize(), -1, true); this.defaultSessionTimeout = deploymentInfo.getDefaultSessionTimeout() / 60; }
private HTTPContext registerDeploymentInfo(Archive<?> archive) { UndertowWebArchive servletBuilder = (UndertowWebArchive) archive; final DeploymentInfo deploymentInfo = servletBuilder .getDeploymentInfo(); deploymentManager = defaultContainer().addDeployment( deploymentInfo); deploymentManager.deploy(); try { this.undertow = createUndertow(deploymentManager.start()); this.undertow.start(); } catch (ServletException e) { throw new IllegalArgumentException(e); } HTTPContext httpContext = new HTTPContext( configuration.getBindAddress(), configuration.getBindHttpPort()); final Map<String, ServletInfo> servlets = deploymentInfo.getServlets(); final Collection<ServletInfo> servletsInfo = servlets.values(); for (ServletInfo servletInfo : servletsInfo) { httpContext.add(new Servlet(servletInfo.getName(), deploymentManager.getDeployment().getDeploymentInfo() .getContextPath())); } return httpContext; }
public void handleDeploymentSessionConfig(DeploymentInfo deploymentInfo, ServletContextImpl servletContext) { SessionCookieConfigImpl sessionCookieConfig = servletContext.getSessionCookieConfig(); ServletSessionConfig sc = deploymentInfo.getServletSessionConfig(); if (sc != null) { sessionCookieConfig.setName(sc.getName()); sessionCookieConfig.setComment(sc.getComment()); sessionCookieConfig.setDomain(sc.getDomain()); sessionCookieConfig.setHttpOnly(sc.isHttpOnly()); sessionCookieConfig.setMaxAge(sc.getMaxAge()); if(sc.getPath() != null) { sessionCookieConfig.setPath(sc.getPath()); } else { sessionCookieConfig.setPath(deploymentInfo.getContextPath()); } sessionCookieConfig.setSecure(sc.isSecure()); if (sc.getSessionTrackingModes() != null) { servletContext.setDefaultSessionTrackingModes(new HashSet<>(sc.getSessionTrackingModes())); } } }