Java Code Examples for org.apache.catalina.Context#getName()
The following examples show how to use
org.apache.catalina.Context#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: WebappLoader.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
@Override protected String getObjectNameKeyProperties() { StringBuilder name = new StringBuilder("type=Loader"); if (container instanceof Context) { name.append(",context="); Context context = (Context) container; String contextName = context.getName(); if (!contextName.startsWith("/")) { name.append("/"); } name.append(contextName); name.append(",host="); name.append(context.getParent().getName()); } else { // Unlikely / impossible? Handle it to be safe name.append(",container="); name.append(container.getName()); } return name.toString(); }
Example 2
Source File: WebappLoader.java From tomcatsrc with Apache License 2.0 | 6 votes |
@Override protected String getObjectNameKeyProperties() { StringBuilder name = new StringBuilder("type=Loader"); if (container instanceof Context) { name.append(",context="); Context context = (Context) container; String contextName = context.getName(); if (!contextName.startsWith("/")) { name.append("/"); } name.append(contextName); name.append(",host="); name.append(context.getParent().getName()); } else { // Unlikely / impossible? Handle it to be safe name.append(",container="); name.append(container.getName()); } return name.toString(); }
Example 3
Source File: WebappLoaderStartInterceptor.java From pinpoint with Apache License 2.0 | 6 votes |
private String extractContextKey(WebappLoader webappLoader) { final String defaultContextName = ""; try { Container container = extractContext(webappLoader); // WebappLoader's associated Container should be a Context. if (container instanceof Context) { Context context = (Context)container; String contextName = context.getName(); Host host = (Host)container.getParent(); Engine engine = (Engine)host.getParent(); StringBuilder sb = new StringBuilder(); sb.append(engine.getName()).append("/").append(host.getName()); if (!contextName.startsWith("/")) { sb.append('/'); } sb.append(contextName); return sb.toString(); } } catch (Exception e) { // Same action for any and all exceptions. logger.warn("Error extracting context name.", e); } return defaultContextName; }
Example 4
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 5
Source File: TomcatWsRegistry.java From tomee with Apache License 2.0 | 5 votes |
@Override public void removeWsContainer(String path, final String moduleId) { if (path == null) { return; } // assure context root with a leading slash if (!path.startsWith("/")) { path = "/" + path; } if (TomcatHelper.isStopping()) { return; } Context context = webserviceContexts.remove(new Key(path, moduleId)); if (context == null) { // fake context = webserviceContexts.remove(new Key(path, null)); } Integer refs = 1; // > 0 to avoid to destroy the context if not mandatory if (context != null) { final String name = context.getName(); refs = fakeContextReferences.remove(name); if (refs != null && refs > 0) { fakeContextReferences.put(name, refs - 1); } } if ((WEBSERVICE_OLDCONTEXT_ACTIVE || (refs != null && refs == 0)) && context != null) { try { context.stop(); context.destroy(); } catch (final Exception e) { throw new TomEERuntimeException(e); } final Host host = (Host) context.getParent(); host.removeChild(context); } // else let tomcat manages its context }
Example 6
Source File: SingleSignOnSessionKey.java From Tomcat8-Source-Read with MIT License | 4 votes |
public SingleSignOnSessionKey(Session session) { this.sessionId = session.getId(); Context context = session.getManager().getContext(); this.contextName = context.getName(); this.hostName = context.getParent().getName(); }
Example 7
Source File: StandardContextSF.java From Tomcat8-Source-Read with MIT License | 4 votes |
/** * Store a Context as Separate file as configFile value from context exists. * filename can be relative to catalina.base. * * @see org.apache.catalina.storeconfig.IStoreFactory#store(java.io.PrintWriter, * int, java.lang.Object) */ @Override public void store(PrintWriter aWriter, int indent, Object aContext) throws Exception { if (aContext instanceof StandardContext) { StoreDescription desc = getRegistry().findDescription( aContext.getClass()); if (desc.isStoreSeparate()) { URL configFile = ((StandardContext) aContext) .getConfigFile(); if (configFile != null) { if (desc.isExternalAllowed()) { if (desc.isBackup()) storeWithBackup((StandardContext) aContext); else storeContextSeparate(aWriter, indent, (StandardContext) aContext); return; } } else if (desc.isExternalOnly()) { // Set a configFile so that the configuration is actually saved Context context = ((StandardContext) aContext); Host host = (Host) context.getParent(); File configBase = host.getConfigBaseFile(); ContextName cn = new ContextName(context.getName(), false); String baseName = cn.getBaseName(); File xml = new File(configBase, baseName + ".xml"); context.setConfigFile(xml.toURI().toURL()); if (desc.isBackup()) storeWithBackup((StandardContext) aContext); else storeContextSeparate(aWriter, indent, (StandardContext) aContext); return; } } } super.store(aWriter, indent, aContext); }
Example 8
Source File: SingleSignOnSessionKey.java From Tomcat7.0.67 with Apache License 2.0 | 4 votes |
public SingleSignOnSessionKey(Session session) { this.sessionId = session.getId(); Context context = (Context) session.getManager().getContainer(); this.contextName = context.getName(); this.hostName = context.getParent().getName(); }
Example 9
Source File: SingleSignOnSessionKey.java From tomcatsrc with Apache License 2.0 | 4 votes |
public SingleSignOnSessionKey(Session session) { this.sessionId = session.getId(); Context context = (Context) session.getManager().getContainer(); this.contextName = context.getName(); this.hostName = context.getParent().getName(); }
Example 10
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 11
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); }