private static Context findContext(final Container host, final String webContext) { Context webapp = Context.class.cast(host.findChild(webContext)); if (webapp == null && "/".equals(webContext)) { // ROOT webapp = Context.class.cast(host.findChild("")); } else if (webapp == null && webContext.length() > 0 && !webContext.startsWith("/")) { webapp = Context.class.cast(host.findChild("/" + webContext)); } return webapp; }
public void deactivate(URI uri) throws WebApplicationActivationException { String contextPath = mappings.remove(uri); if (contextPath == null) { throw new WebApplicationActivationException("Context not registered for component: " + uri); } StandardContext context = null; try { for (Container container : connector.getContainer().findChildren()) { if (container instanceof StandardHost) { context = (StandardContext) container.findChild(contextPath); container.removeChild(context); try { context.destroy(); } catch (Exception e) { throw new WebApplicationActivationException(e); } break; } } if (context == null) { throw new WebApplicationActivationException("Context not found for: " + contextPath); } context.stop(); monitor.deactivated(contextPath); } catch (LifecycleException e) { throw new WebApplicationActivationException(e); } }
private static Context findContext(final Container host, final String appId, final String webContext) { if (appId != null) { // when using versioning appId is like context#1235 but not the context itself so ensure to test appId first final Context ctx = Context.class.cast(host.findChild('/' + appId)); if (ctx != null) { return ctx; } } Context webapp = Context.class.cast(host.findChild(webContext)); if (webapp == null && "/".equals(webContext)) { // ROOT webapp = Context.class.cast(host.findChild("")); } else if (webapp == null && webContext.length() > 0 && !webContext.startsWith("/")) { webapp = Context.class.cast(host.findChild("/" + webContext)); } return webapp; }
@Init public void init() throws ServletHostException { connector = connectorService.getConnector(); dispatchingServlet = new Fabric3DispatchingServlet(); Fabric3ServletWrapper wrapper = new Fabric3ServletWrapper(dispatchingServlet); wrapper.setName("Fabric3Servlet"); for (Container container : connector.getContainer().findChildren()) { if (container instanceof StandardHost) { Container child = container.findChild(""); if (child != null) { container.removeChild(child); } StandardContext context = createContext("", "."); context.addChild(wrapper); context.addServletMapping("/*", "Fabric3Servlet"); container.addChild(context); try { dispatchingServlet.init(wrapper); } catch (ServletException e) { throw new AssertionError(e); } } } }
/** * Get Parent ContainerBase to add its child component * from child component's ObjectName as a String */ private Container getParentContainerFromChild(ObjectName oname) throws Exception { String hostName = oname.getKeyProperty("host"); String path = oname.getKeyProperty("path"); Service service = getService(oname); Container engine = service.getContainer(); if (hostName == null) { // child's container is Engine return engine; } else if (path == null) { // child's container is Host Container host = engine.findChild(hostName); return host; } else { // child's container is Context Container host = engine.findChild(hostName); path = getPathStr(path); Container context = host.findChild(path); return context; } }
/** * Get Parent ContainerBase to add its child component * from child component's ObjectName as a String */ private Container getParentContainerFromChild(ObjectName oname) throws Exception { String hostName = oname.getKeyProperty("host"); String path = oname.getKeyProperty("path"); Service service = getService(oname); Container engine = service.getContainer(); if (hostName == null) { // child's container is Engine return engine; } else if (path == null) { // child's container is Host Container host = engine.findChild(hostName); return host; } else { // child's container is Context Container host = engine.findChild(hostName); path = getPathStr(path); Container context = host.findChild(path); return context; } }
/** * Get Parent ContainerBase to add its child component * from child component's ObjectName as a String */ private Container getParentContainerFromChild(ObjectName oname) throws Exception { String hostName = oname.getKeyProperty("host"); String path = oname.getKeyProperty("path"); Service service = getService(oname); Container engine = service.getContainer(); if (hostName == null) { // child's container is Engine return engine; } else if (path == null) { // child's container is Host Container host = engine.findChild(hostName); return host; } else { // child's container is Context Container host = engine.findChild(hostName); path = getPathStr(path); Container context = host.findChild(path); return context; } }
/** * Remove an existing child Container from association with this parent * Container. * * @param name Name of the existing child Container to be removed * @throws MBeanException if the child cannot be removed */ public void removeChild(String name) throws MBeanException{ if (name != null) { Container container = doGetManagedResource(); Container contained = container.findChild(name); container.removeChild(contained); } }
/** * Remove an existing child Container from association with this parent * Container. * * @param name Name of the existing child Container to be removed * @throws MBeanException if the child cannot be removed */ public void removeChild(String name) throws MBeanException{ if (name != null) { Container container = doGetManagedResource(); Container contained = container.findChild(name); container.removeChild(contained); } }
Container host = engine.findChild(hostName); String pathStr = getPathStr(path); Container context = host.findChild(pathStr); return context; } else if (type != null) {
private static boolean undeploy(final StandardContext standardContext, final Container host) { final Container child = host.findChild(standardContext.getName()); // skip undeployment if redeploying (StandardContext.redeploy()) if (child instanceof org.apache.catalina.Context && org.apache.catalina.Context.class.cast(child).getPaused()) { return true; } // skip undeployment if restarting final TomEEWebappClassLoader tomEEWebappClassLoader = lazyClassLoader( org.apache.catalina.Context.class.isInstance(child) ? org.apache.catalina.Context.class.cast(child) : null); if (tomEEWebappClassLoader != null && tomEEWebappClassLoader.isRestarting()) { return true; } if (child != null) { host.removeChild(standardContext); return true; } return false; }
public List<String> setWsContainer(String virtualHost, String contextRoot, String servletName, HttpListener wsContainer) throws Exception { if (virtualHost == null) virtualHost = engine.getDefaultHost(); Container host = engine.findChild(virtualHost); if (host == null) { throw new IllegalArgumentException("Invalid virtual host '" + virtualHost + "'. Do you have a matchiing Host entry in the server.xml?"); } Context context = (Context) host.findChild("/" + contextRoot); if (context == null) { throw new IllegalArgumentException("Could not find web application context " + contextRoot + " in host " + host.getName()); } Wrapper wrapper = (Wrapper) context.findChild(servletName); if (wrapper == null) { throw new IllegalArgumentException("Could not find servlet " + contextRoot + " in web application context " + context.getName()); } setWsContainer(context, wrapper, wsContainer); // add service locations List<String> addresses = new ArrayList<String>(); for (Connector connector : connectors) { for (String mapping : wrapper.findMappings()) { URI address = new URI(connector.getScheme(), null, host.getName(), connector.getPort(), "/" + contextRoot + mapping, null, null); addresses.add(address.toString()); } } return addresses; }
public void clearWsContainer(String virtualHost, String contextRoot, String servletName) { if (virtualHost == null) virtualHost = engine.getDefaultHost(); Container host = engine.findChild(virtualHost); if (host == null) { throw new IllegalArgumentException("Invalid virtual host '" + virtualHost + "'. Do you have a matchiing Host entry in the server.xml?"); } Context context = (Context) host.findChild("/" + contextRoot); if (context == null) { throw new IllegalArgumentException("Could not find web application context " + contextRoot + " in host " + host.getName()); } Wrapper wrapper = (Wrapper) context.findChild(servletName); if (wrapper == null) { throw new IllegalArgumentException("Could not find servlet " + contextRoot + " in web application context " + context.getName()); } // clear the webservice ref in the servlet context String webServicecontainerId = wrapper.findInitParameter(WsServlet.WEBSERVICE_CONTAINER); if (webServicecontainerId != null) { context.getServletContext().removeAttribute(webServicecontainerId); wrapper.removeInitParameter(WsServlet.WEBSERVICE_CONTAINER); } }
public void clearWsContainer(String virtualHost, String contextRoot, String servletName) { if (virtualHost == null) virtualHost = engine.getDefaultHost(); Container host = engine.findChild(virtualHost); if (host == null) { throw new IllegalArgumentException("Invalid virtual host '" + virtualHost + "'. Do you have a matchiing Host entry in the server.xml?"); } Context context = (Context) host.findChild("/" + contextRoot); if (context == null) { throw new IllegalArgumentException("Could not find web application context " + contextRoot + " in host " + host.getName()); } Wrapper wrapper = (Wrapper) context.findChild(servletName); if (wrapper == null) { throw new IllegalArgumentException("Could not find servlet " + servletName + " in web application context " + context.getName()); } // clear the webservice ref in the servlet context String webServicecontainerId = wrapper.findInitParameter(WsServlet.WEBSERVICE_CONTAINER); if (webServicecontainerId != null) { context.getServletContext().removeAttribute(webServicecontainerId); wrapper.removeInitParameter(WsServlet.WEBSERVICE_CONTAINER); } }
/** * Remove an existing child Container from association with this parent * Container. * * @param name Name of the existing child Container to be removed */ public void removeChild(String name) throws MBeanException{ if(name != null){ try { Container container = (Container)getManagedResource(); Container contained = container.findChild(name); container.removeChild(contained); } catch (InstanceNotFoundException e) { throw new MBeanException(e); } catch (RuntimeOperationsException e) { throw new MBeanException(e); } catch (InvalidTargetObjectTypeException e) { throw new MBeanException(e); } } }
/** * Remove an existing child Container from association with this parent * Container. * * @param name Name of the existing child Container to be removed */ public void removeChild(String name) throws MBeanException{ if(name != null){ try { Container container = (Container)getManagedResource(); Container contained = container.findChild(name); container.removeChild(contained); } catch (InstanceNotFoundException e) { throw new MBeanException(e); } catch (RuntimeOperationsException e) { throw new MBeanException(e); } catch (InvalidTargetObjectTypeException e) { throw new MBeanException(e); } } }
/** * Remove an existing child Container from association with this parent * Container. * * @param name Name of the existing child Container to be removed */ public void removeChild(String name) throws MBeanException{ if(name != null){ try { Container container = (Container)getManagedResource(); Container contained = container.findChild(name); container.removeChild(contained); } catch (InstanceNotFoundException e) { throw new MBeanException(e); } catch (RuntimeOperationsException e) { throw new MBeanException(e); } catch (InvalidTargetObjectTypeException e) { throw new MBeanException(e); } } }
/** * Remove an existing child Container from association with this parent * Container. * * @param name Name of the existing child Container to be removed */ public void removeChild(String name) throws MBeanException{ if(name != null){ try { Container container = (Container)getManagedResource(); Container contained = container.findChild(name); container.removeChild(contained); } catch (InstanceNotFoundException e) { throw new MBeanException(e); } catch (RuntimeOperationsException e) { throw new MBeanException(e); } catch (InvalidTargetObjectTypeException e) { throw new MBeanException(e); } } }
/** * Remove an existing child Container from association with this parent * Container. * * @param name Name of the existing child Container to be removed */ public void removeChild(String name) throws MBeanException{ if(name != null){ try { Container container = (Container)getManagedResource(); Container contained = container.findChild(name); container.removeChild(contained); } catch (InstanceNotFoundException e) { throw new MBeanException(e); } catch (RuntimeOperationsException e) { throw new MBeanException(e); } catch (InvalidTargetObjectTypeException e) { throw new MBeanException(e); } } }
/** * Remove an existing child Container from association with this parent * Container. * * @param name Name of the existing child Container to be removed */ public void removeChild(String name) throws MBeanException{ if(name != null){ try { Container container = (Container)getManagedResource(); Container contained = container.findChild(name); container.removeChild(contained); } catch (InstanceNotFoundException e) { throw new MBeanException(e); } catch (RuntimeOperationsException e) { throw new MBeanException(e); } catch (InvalidTargetObjectTypeException e) { throw new MBeanException(e); } } }