Java Code Examples for org.apache.catalina.Container#getName()
The following examples show how to use
org.apache.catalina.Container#getName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JAASRealm.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
@Override public void setContainer(Container container) { super.setContainer(container); if( appName==null ) { String name = container.getName(); if (!name.startsWith("/")) { name = "/" + name; } name = makeLegalForJAAS(name); appName=name; log.info("Set JAAS app name " + appName); } }
Example 2
Source File: JAASRealm.java From tomcatsrc with Apache License 2.0 | 6 votes |
@Override public void setContainer(Container container) { super.setContainer(container); if( appName==null ) { String name = container.getName(); if (!name.startsWith("/")) { name = "/" + name; } name = makeLegalForJAAS(name); appName=name; log.info("Set JAAS app name " + appName); } }
Example 3
Source File: JDBCStore.java From Tomcat8-Source-Read with MIT License | 6 votes |
/** * @return the name for this instance (built from container name) */ public String getName() { if (name == null) { Container container = manager.getContext(); String contextName = container.getName(); if (!contextName.startsWith("/")) { contextName = "/" + contextName; } String hostName = ""; String engineName = ""; if (container.getParent() != null) { Container host = container.getParent(); hostName = host.getName(); if (host.getParent() != null) { engineName = host.getParent().getName(); } } name = "/" + engineName + "/" + hostName + contextName; } return name; }
Example 4
Source File: MBeanUtils.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
/** * Determine the name of the domain to register MBeans for from a given * Service. * * @param service * * @deprecated To be removed since to creates a circular dependency. Will * be replaced in Tomcat 8 by a new method on {@link * Service}. */ @Deprecated public static String getDomain(Service service) { // Null service -> return null if (service == null) { return null; } String domain = null; Container engine = service.getContainer(); // Use the engine name first if (engine != null) { domain = engine.getName(); } // No engine or no engine name, use the service name if (domain == null) { domain = service.getName(); } // No service name, use null return domain; }
Example 5
Source File: ContainerBase.java From Tomcat8-Source-Read with MIT License | 6 votes |
/** * @return the abbreviated name of this container for logging messages */ @Override public String getLogName() { if (logName != null) { return logName; } String loggerName = null; Container current = this; while (current != null) { String name = current.getName(); if ((name == null) || (name.equals(""))) { name = "/"; } else if (name.startsWith("##")) { name = "/" + name; } loggerName = "[" + name + "]" + ((loggerName != null) ? ("." + loggerName) : ""); current = current.getParent(); } logName = ContainerBase.class.getName() + "." + loggerName; return logName; }
Example 6
Source File: ContainerBase.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
/** * Return the abbreviated name of this container for logging messages */ protected String logName() { if (logName != null) { return logName; } String loggerName = null; Container current = this; while (current != null) { String name = current.getName(); if ((name == null) || (name.equals(""))) { name = "/"; } else if (name.startsWith("##")) { name = "/" + name; } loggerName = "[" + name + "]" + ((loggerName != null) ? ("." + loggerName) : ""); current = current.getParent(); } logName = ContainerBase.class.getName() + "." + loggerName; return logName; }
Example 7
Source File: MBeanUtils.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * Determine the name of the domain to register MBeans for from a given * Container. * * @param container * * @deprecated To be removed since to creates a circular dependency. Will * be replaced in Tomcat 8 by a new method on {@link * Container}. */ @Deprecated public static String getDomain(Container container) { String domain = null; Container c = container; while (!(c instanceof Engine) && c != null) { c = c.getParent(); } if (c != null) { domain = c.getName(); } return domain; }
Example 8
Source File: StandardService.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Override protected String getDomainInternal() { String domain = null; Container engine = getContainer(); // Use the engine name first if (engine != null) { domain = engine.getName(); } // No engine or no engine name, use the service name if (domain == null) { domain = getName(); } // No service name, return null which will trigger the use of the // default return domain; }
Example 9
Source File: MBeanUtils.java From tomcatsrc with Apache License 2.0 | 5 votes |
/** * Calculate the key properties string to be added to an object's * {@link ObjectName} to indicate that it is associated with that container. * * @param container The container the object is associated with * @return A string suitable for appending to the ObjectName * @deprecated To be removed since to creates a circular dependency. Will * be replaced in Tomcat 8 by a new method on {@link * Container}. */ @Deprecated public static String getContainerKeyProperties(Container container) { Container c = container; StringBuilder keyProperties = new StringBuilder(); int containerCount = 0; // Work up container hierarchy, add a component to the name for // each container while (!(c instanceof Engine)) { if (c instanceof Wrapper) { keyProperties.append(",servlet="); keyProperties.append(c.getName()); } else if (c instanceof Context) { keyProperties.append(",context="); ContextName cn = new ContextName(c.getName(), false); keyProperties.append(cn.getDisplayName()); } else if (c instanceof Host) { keyProperties.append(",host="); keyProperties.append(c.getName()); } else if (c == null) { // May happen in unit testing and/or some embedding scenarios keyProperties.append(",container"); keyProperties.append(containerCount++); keyProperties.append("=null"); break; } else { // Should never happen... keyProperties.append(",container"); keyProperties.append(containerCount++); keyProperties.append('='); keyProperties.append(c.getName()); } c = c.getParent(); } return keyProperties.toString(); }
Example 10
Source File: Contexts.java From tomee with Apache License 2.0 | 5 votes |
public static String getHostname(final StandardContext ctx) { String hostName = null; final Container parentHost = ctx.getParent(); if (parentHost != null) { hostName = parentHost.getName(); } if ((hostName == null) || (hostName.length() < 1)) { hostName = "_"; } return hostName; }
Example 11
Source File: SimpleTcpCluster.java From tomcatsrc with Apache License 2.0 | 5 votes |
/** * @param name * @param manager * @return TODO */ @Override public String getManagerName(String name, Manager manager) { String clusterName = name ; if (clusterName == null) clusterName = manager.getContainer().getName(); if (getContainer() instanceof Engine) { Context context = (Context) manager.getContainer() ; Container host = context.getParent(); if (host instanceof Host && clusterName != null && !(clusterName.startsWith(host.getName() +"#"))) { clusterName = host.getName() +"#" + clusterName ; } } return clusterName; }
Example 12
Source File: SimpleTcpCluster.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Override public String getManagerName(String name, Manager manager) { String clusterName = name ; if (clusterName == null) clusterName = manager.getContext().getName(); if (getContainer() instanceof Engine) { Context context = manager.getContext(); Container host = context.getParent(); if (host instanceof Host && clusterName != null && !(clusterName.startsWith(host.getName() +"#"))) { clusterName = host.getName() +"#" + clusterName ; } } return clusterName; }
Example 13
Source File: ApplicationContext.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Override public String getVirtualServerName() { // Constructor will fail if context or its parent is null Container host = context.getParent(); Container engine = host.getParent(); return engine.getName() + "/" + host.getName(); }
Example 14
Source File: TomcatWsRegistry.java From tomee with Apache License 2.0 | 5 votes |
@Override public void clearWsContainer(final String contextRoot, String virtualHost, final ServletInfo servletInfo, final String moduleId) { if (virtualHost == null) { virtualHost = engine.getDefaultHost(); } final 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?"); } final Context context = (Context) host.findChild("/" + contextRoot); if (context == null) { throw new IllegalArgumentException("Could not find web application context " + contextRoot + " in host " + host.getName()); } final Wrapper wrapper = (Wrapper) context.findChild(servletInfo.servletName); if (wrapper == null) { throw new IllegalArgumentException("Could not find servlet " + servletInfo.servletName + " in web application context " + context.getName()); } // clear the webservice ref in the servlet context final String webServicecontainerId = wrapper.findInitParameter(WsServlet.WEBSERVICE_CONTAINER); if (webServicecontainerId != null) { context.getServletContext().removeAttribute(webServicecontainerId); wrapper.removeInitParameter(WsServlet.WEBSERVICE_CONTAINER); } }
Example 15
Source File: WebappClassLoaderBase.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Override public String getServiceName() { if (resources != null) { Container host = resources.getContext().getParent(); if (host != null) { Container engine = host.getParent(); if (engine != null) { return engine.getName(); } } } return null; }
Example 16
Source File: WebappClassLoaderBase.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Override public String getHostName() { if (resources != null) { Container host = resources.getContext().getParent(); if (host != null) { return host.getName(); } } return null; }
Example 17
Source File: TomcatWsRegistry.java From tomee with Apache License 2.0 | 4 votes |
@Override public List<String> setWsContainer(final HttpListener httpListener, final ClassLoader classLoader, String contextRoot, String virtualHost, final ServletInfo servletInfo, final String realmName, final String transportGuarantee, final String authMethod, final String moduleId) throws Exception { if (virtualHost == null) { virtualHost = engine.getDefaultHost(); } final 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?"); } if ("ROOT".equals(contextRoot)) { // doesn't happen in tomee itself but with all our tooling around contextRoot = ""; } if (!contextRoot.startsWith("/") && !contextRoot.isEmpty()) { contextRoot = "/" + contextRoot; } final Context context = (Context) host.findChild(contextRoot); if (context == null) { throw new IllegalArgumentException("Could not find web application context " + contextRoot + " in host " + host.getName()); } final Wrapper wrapper = (Wrapper) context.findChild(servletInfo.servletName); if (wrapper == null) { throw new IllegalArgumentException("Could not find servlet " + servletInfo.servletName + " in web application context " + context.getName()); } // for Pojo web services, we need to change the servlet class which is the service implementation // by the WsServler class wrapper.setServletClass(WsServlet.class.getName()); if (wrapper.getServlet() != null) { wrapper.unload(); // deallocate previous one wrapper.load(); // reload this one withuot unloading it to keep the instance - unload is called during stop() // boolean controlling this method call can't be set to false through API so let do it ourself wrapper.getServlet().init(StandardWrapper.class.cast(wrapper)); // or Reflections.set(wrapper, "instanceInitialized", false); } setWsContainer(context, wrapper, httpListener); // add service locations final List<String> addresses = new ArrayList<>(); for (final Connector connector : connectors) { for (final String mapping : wrapper.findMappings()) { final URI address = new URI(connector.getScheme(), null, host.getName(), connector.getPort(), (contextRoot.startsWith("/") ? "" : "/") + contextRoot + mapping, null, null); addresses.add(address.toString()); } } return addresses; }
Example 18
Source File: TomcatWsRegistry.java From tomee with Apache License 2.0 | 4 votes |
private void addServlet(final Container host, final Context context, final String mapping, final HttpListener httpListener, final String path, final List<String> addresses, final boolean fakeDeployment, final String moduleId) { // build the servlet final Wrapper wrapper = context.createWrapper(); wrapper.setName("webservice" + path.substring(1)); wrapper.setServletClass(WsServlet.class.getName()); // add servlet to context context.addChild(wrapper); context.addServletMappingDecoded(mapping, wrapper.getName()); final String webServicecontainerID = wrapper.getName() + WsServlet.WEBSERVICE_CONTAINER + httpListener.hashCode(); wrapper.addInitParameter(WsServlet.WEBSERVICE_CONTAINER, webServicecontainerID); setWsContainer(context, wrapper, httpListener); webserviceContexts.put(new Key(path, moduleId), context); // register wsdl locations for service-ref resolution for (final Connector connector : connectors) { final StringBuilder fullContextpath; if (!WEBSERVICE_OLDCONTEXT_ACTIVE && !fakeDeployment) { String contextPath = context.getPath(); if (contextPath == null || !contextPath.isEmpty()) { if (contextPath != null && !contextPath.startsWith("/")) { contextPath = "/" + contextPath; } else if (contextPath == null) { contextPath = "/"; } } fullContextpath = new StringBuilder(contextPath); if (!WEBSERVICE_SUB_CONTEXT.equals("/")) { fullContextpath.append(WEBSERVICE_SUB_CONTEXT); } fullContextpath.append(path); } else { fullContextpath = new StringBuilder(context.getPath()).append(path); } try { final URI address = new URI(connector.getScheme(), null, host.getName(), connector.getPort(), fullContextpath.toString(), null, null); addresses.add(address.toString()); } catch (final URISyntaxException ignored) { // no-op } } }
Example 19
Source File: TomcatHessianRegistry.java From tomee with Apache License 2.0 | 4 votes |
@Override public String deploy(final ClassLoader loader, final HessianServer listener, final String hostname, final String app, final String authMethod, final String transportGuarantee, final String realmName, final String name) throws URISyntaxException { Container host = engine.findChild(hostname); if (host == null) { host = engine.findChild(engine.getDefaultHost()); if (host == null) { throw new IllegalArgumentException("Invalid virtual host '" + engine.getDefaultHost() + "'. Do you have a matchiing Host entry in the server.xml?"); } } final String contextRoot = contextName(app); Context context = Context.class.cast(host.findChild(contextRoot)); if (context == null) { Pair<Context, Integer> fakeContext = fakeContexts.get(contextRoot); if (fakeContext != null) { context = fakeContext.getLeft(); fakeContext.setValue(fakeContext.getValue() + 1); } else { context = Context.class.cast(host.findChild(contextRoot)); if (context == null) { fakeContext = fakeContexts.get(contextRoot); if (fakeContext == null) { context = createNewContext(loader, authMethod, transportGuarantee, realmName, app); fakeContext = new MutablePair<>(context, 1); fakeContexts.put(contextRoot, fakeContext); } else { context = fakeContext.getLeft(); fakeContext.setValue(fakeContext.getValue() + 1); } } } } final String servletMapping = generateServletPath(name); Wrapper wrapper = Wrapper.class.cast(context.findChild(servletMapping)); if (wrapper != null) { throw new IllegalArgumentException("Servlet " + servletMapping + " in web application context " + context.getName() + " already exists"); } wrapper = context.createWrapper(); wrapper.setName(HESSIAN.replace("/", "") + "_" + name); wrapper.setServlet(new OpenEJBHessianServlet(listener)); context.addChild(wrapper); context.addServletMappingDecoded(servletMapping, wrapper.getName()); if ("BASIC".equals(authMethod) && StandardContext.class.isInstance(context)) { final StandardContext standardContext = StandardContext.class.cast(context); boolean found = false; for (final Valve v : standardContext.getPipeline().getValves()) { if (LimitedBasicValve.class.isInstance(v) || BasicAuthenticator.class.isInstance(v)) { found = true; break; } } if (!found) { standardContext.addValve(new LimitedBasicValve()); } } final List<String> addresses = new ArrayList<>(); for (final Connector connector : connectors) { for (final String mapping : wrapper.findMappings()) { final URI address = new URI(connector.getScheme(), null, host.getName(), connector.getPort(), contextRoot + mapping, null, null); addresses.add(address.toString()); } } return HttpUtil.selectSingleAddress(addresses); }
Example 20
Source File: TomcatRsRegistry.java From tomee with Apache License 2.0 | 4 votes |
@Override public AddressInfo createRsHttpListener(final String appId, final String webContext, final HttpListener listener, final ClassLoader classLoader, final String completePath, final String virtualHost, final String auth, final String realm) { String path = webContext; if (path == null) { throw new NullPointerException("contextRoot is null"); } if (listener == null) { throw new NullPointerException("listener is null"); } // find the existing host (we do not auto-create hosts) Container host; Context context = null; if (virtualHost == null) { host = hosts.getDefault(); } else { host = hosts.get(virtualHost); } if (host == null) { for (final Host h : hosts) { context = findContext(h, webContext); if (context != null) { host = h; if (classLoader != null && classLoader.equals(context.getLoader().getClassLoader())) { break; } // else try next to find something better } } if (host == null) { throw new IllegalArgumentException("Invalid virtual host '" + virtualHost + "'. Do you have a matching Host entry in the server.xml?"); } } else { context = findContext(host, webContext); } if (context == null) { throw new IllegalStateException("Invalid context '" + webContext + "'. Cannot find context in host " + host.getName()); } final CxfRsHttpListener cxfRsHttpListener = findCxfRsHttpListener(listener); final String description = "tomee-jaxrs-" + listener; String mapping = completePath; if (!completePath.endsWith("/*")) { // respect servlet spec (!= from our embedded listeners) if (completePath.endsWith("*")) { mapping = completePath.substring(0, completePath.length() - 1); } mapping = mapping + "/*"; } final String urlPattern = removeWebContext(webContext, mapping); cxfRsHttpListener.setUrlPattern(urlPattern.substring(0, urlPattern.length() - 1)); final FilterDef filterDef = new FilterDef(); filterDef.setAsyncSupported("true"); filterDef.setDescription(description); filterDef.setFilterName(description); filterDef.setDisplayName(description); filterDef.setFilter(new CXFJAXRSFilter(cxfRsHttpListener, context.findWelcomeFiles())); filterDef.setFilterClass(CXFJAXRSFilter.class.getName()); filterDef.addInitParameter("mapping", urlPattern.substring(0, urlPattern.length() - "/*".length())); // just keep base path context.addFilterDef(filterDef); final FilterMap filterMap = new FilterMap(); filterMap.addURLPattern(urlPattern); for (final DispatcherType type : DispatcherType.values()) { filterMap.setDispatcher(type.name()); } filterMap.setFilterName(filterDef.getFilterName()); context.addFilterMap(filterMap); Registrations.addFilterConfig(context, filterDef); path = address(connectors, host.getName(), webContext); final String key = address(connectors, host.getName(), completePath); listeners.put(new Key(appId, key), listener); return new AddressInfo(path, key); }