/** * {@inhericDoc} * @see org.jboss.modcluster.Engine#findHost(java.lang.String) */ public Host findHost(String name) { org.apache.catalina.Host host = (org.apache.catalina.Host) this.engine.findChild(name); return (host != null) ? new CatalinaHost(host, this) : null; }
protected Context getContext(HttpServletRequest request) { String serverName = request.getServerName(); String contextPath = request.getContextPath(); Host host = (Host)engine.findChild(serverName); if (host == null) { // if it cannot find host, then use the default host. host = (Host)engine.findChild(engine.getDefaultHost()); if (host == null) throw new NullPointerException("Could not find Tomcat host for: " + serverName + " or: " + engine.getDefaultHost()); } Context context = (Context)host.findChild(contextPath); if (context == null) throw new NullPointerException("Could not find Tomcat context for: " + contextPath); return context; }
@Override public Host findHost(String name) { org.apache.catalina.Host host = (org.apache.catalina.Host) this.engine.findChild(name); return (host != null) ? this.registry.getHostFactory().createHost(this.registry, host, this) : null; }
public void addWebService(String contextPath, String[] virtualHosts, WebServiceContainer webServiceContainer, String securityRealmName, String realmName, String transportGuarantee, String authMethod, ClassLoader classLoader) throws Exception { Context webServiceContext = embedded.createEJBWebServiceContext(contextPath, webServiceContainer, securityRealmName, realmName, transportGuarantee, authMethod, classLoader); String virtualServer; if (virtualHosts != null && virtualHosts.length > 0) { virtualServer = virtualHosts[0]; } else { virtualServer = engine.getDefaultHost(); } Container host = engine.findChild(virtualServer); if (host == null) { throw new IllegalArgumentException("Invalid virtual host '" + virtualServer + "'. Do you have a matchiing Host entry in the plan?"); } host.addChild(webServiceContext); webServices.put(contextPath, webServiceContext); }
MBeanServer mBeanServer = MBeanServerFactory.findMBeanServer(null).get(0); ObjectName name = new ObjectName("Catalina", "type", "Server"); Server server = (Server) mBeanServer.getAttribute(name, "managedResource"); Service service = server.findService("Catalina"); Engine engine = (Engine) service.getContainer(); Host host = (Host) engine.findChild(engine.getDefaultHost()); host.getAppBase(); //Got it.
/** * Remove an existing Host. * * @param name MBean Name of the component to remove * * @exception Exception if a component cannot be removed */ public void removeHost(String name) throws Exception { // Acquire a reference to the component to be removed ObjectName oname = new ObjectName(name); String hostName = oname.getKeyProperty("host"); Service service = getService(oname); Engine engine = service.getContainer(); Host host = (Host) engine.findChild(hostName); // Remove this component from its parent component if(host!=null) { engine.removeChild(host); } }
/** * Remove an existing Host. * * @param name MBean Name of the component to remove * * @exception Exception if a component cannot be removed */ public void removeHost(String name) throws Exception { // Acquire a reference to the component to be removed ObjectName oname = new ObjectName(name); String hostName = oname.getKeyProperty("host"); Service service = getService(oname); Engine engine = (Engine) service.getContainer(); Host host = (Host) engine.findChild(hostName); // Remove this component from its parent component if(host!=null) { engine.removeChild(host); } }
/** * Remove an existing Host. * * @param name MBean Name of the component to remove * * @exception Exception if a component cannot be removed */ public void removeHost(String name) throws Exception { // Acquire a reference to the component to be removed ObjectName oname = new ObjectName(name); String hostName = oname.getKeyProperty("host"); Service service = getService(oname); Engine engine = (Engine) service.getContainer(); Host host = (Host) engine.findChild(hostName); // Remove this component from its parent component if(host!=null) { engine.removeChild(host); } }
/** * Remove an existing Host. * * @param name MBean Name of the component to remove * * @exception Exception if a component cannot be removed */ public void removeHost(String name) throws Exception { // Acquire a reference to the component to be removed ObjectName oname = new ObjectName(name); String hostName = oname.getKeyProperty("host"); Service service = getService(oname); Engine engine = (Engine) service.getContainer(); Host host = (Host) engine.findChild(hostName); // Remove this component from its parent component if(host!=null) { engine.removeChild(host); } }
/** * Remove an existing Host. * * @param name MBean Name of the component to remove * * @exception Exception if a component cannot be removed */ public void removeHost(String name) throws Exception { // Acquire a reference to the component to be removed ObjectName oname = new ObjectName(name); String hostName = oname.getKeyProperty("host"); Service service = getService(oname); Engine engine = (Engine) service.getContainer(); Host host = (Host) engine.findChild(hostName); // Remove this component from its parent component if(host!=null) { engine.removeChild(host); } }
/** * Remove an existing Host. * * @param name MBean Name of the component to remove * * @exception Exception if a component cannot be removed */ public void removeHost(String name) throws Exception { // Acquire a reference to the component to be removed ObjectName oname = new ObjectName(name); String hostName = oname.getKeyProperty("host"); Service service = getService(oname); Engine engine = (Engine) service.getContainer(); Host host = (Host) engine.findChild(hostName); // Remove this component from its parent component if(host!=null) { engine.removeChild(host); } }
/** * Remove an existing Host. * * @param name MBean Name of the component to remove * * @exception Exception if a component cannot be removed */ public void removeHost(String name) throws Exception { // Acquire a reference to the component to be removed ObjectName oname = new ObjectName(name); String hostName = oname.getKeyProperty("host"); Service service = getService(oname); Engine engine = service.getContainer(); Host host = (Host) engine.findChild(hostName); // Remove this component from its parent component if(host!=null) { engine.removeChild(host); } }
/** * Remove an existing Host. * * @param name MBean Name of the component to remove * * @exception Exception if a component cannot be removed */ public void removeHost(String name) throws Exception { // Acquire a reference to the component to be removed ObjectName oname = new ObjectName(name); String hostName = oname.getKeyProperty("host"); Service service = getService(oname); Engine engine = (Engine) service.getContainer(); Host host = (Host) engine.findChild(hostName); // Remove this component from its parent component if(host!=null) { engine.removeChild(host); } }
/** * Load a default-web-module on the specified virtual server. */ public void loadDefaultWebModule( com.sun.enterprise.config.serverbeans.VirtualServer vsBean) { VirtualServer virtualServer = (VirtualServer) getEngine().findChild(vsBean.getId()); if (virtualServer != null) { loadDefaultWebModule(virtualServer); } }
private Host prepareVirtualHost(Tomcat tomcat, List<String> virtualHosts) { // assume that the first virtual-host will be the default; additional virtual-hosts will be aliases String hostName = virtualHosts.get(0); Host host; Engine engine = tomcat.getEngine(); org.apache.catalina.Container childContainer = engine.findChild(hostName); if (childContainer instanceof Host) { host = (Host) childContainer; } else { host = new StandardHost(); host.setName(hostName); engine.addChild(host); } virtualHosts.stream() .filter(virtualHost -> virtualHost != hostName) .forEach(virtualHost -> host.addAlias(virtualHost)); return host; }
/** * Remove an existing Host. * * @param name MBean Name of the comonent to remove * * @exception Exception if a component cannot be removed */ public void removeHost(String name) throws Exception { // Acquire a reference to the component to be removed ObjectName oname = new ObjectName(name); String hostName = oname.getKeyProperty("host"); Service service = getService(oname); Engine engine = (Engine) service.getContainer(); Host host = (Host) engine.findChild(hostName); // Remove this component from its parent component if(host!=null) { if(host instanceof StandardHost) ((StandardHost)host).destroy(); else engine.removeChild(host); } }
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); } }
@Test public void findHost() { org.apache.catalina.Host host = mock(org.apache.catalina.Host.class); HostFactory hostFactory = mock(HostFactory.class); Host expected = mock(Host.class); when(this.engine.findChild("host")).thenReturn(host); when(this.registry.getHostFactory()).thenReturn(hostFactory); when(hostFactory.createHost(same(this.registry), same(host), same(this.catalinaEngine))).thenReturn(expected); Host result = this.catalinaEngine.findHost("host"); assertSame(expected, result); }