Java Code Examples for org.apache.catalina.Context#getPath()
The following examples show how to use
org.apache.catalina.Context#getPath() .
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: MapperListener.java From Tomcat8-Source-Read with MIT License | 6 votes |
/** * Unregister wrapper. */ private void unregisterWrapper(Wrapper wrapper) { Context context = ((Context) wrapper.getParent()); String contextPath = context.getPath(); String wrapperName = wrapper.getName(); if ("/".equals(contextPath)) { contextPath = ""; } String version = context.getWebappVersion(); String hostName = context.getParent().getName(); String[] mappings = wrapper.findMappings(); for (String mapping : mappings) { mapper.removeWrapper(hostName, contextPath, version, mapping); } if(log.isDebugEnabled()) { log.debug(sm.getString("mapperListener.unregisterWrapper", wrapperName, contextPath, service)); } }
Example 2
Source File: WebappAuthenticationValve.java From carbon-device-mgt with Apache License 2.0 | 6 votes |
private boolean isContextSkipped(Request request) { Context context = request.getContext(); String ctx = context == null ? null :context.getPath(); if (ctx == null || "".equals(ctx)) { ctx = request.getContextPath(); if (ctx == null || "".equals(ctx)) { String requestUri = request.getRequestURI(); if ("/".equals(requestUri)) { return true; } StringTokenizer tokenizer = new StringTokenizer(request.getRequestURI(), "/"); if (!tokenizer.hasMoreTokens()) { return false; } ctx = tokenizer.nextToken(); } } return ("carbon".equalsIgnoreCase(ctx) || "services".equalsIgnoreCase(ctx)); }
Example 3
Source File: MapperListener.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * Register wrapper. */ private void registerWrapper(Wrapper wrapper) { Context context = (Context) wrapper.getParent(); String contextPath = context.getPath(); if ("/".equals(contextPath)) { contextPath = ""; } String version = context.getWebappVersion(); String hostName = context.getParent().getName(); List<WrapperMappingInfo> wrappers = new ArrayList<WrapperMappingInfo>(); prepareWrapperMappingInfo(context, wrapper, wrappers); mapper.addWrappers(hostName, contextPath, version, wrappers); if(log.isDebugEnabled()) { log.debug(sm.getString("mapperListener.registerWrapper", wrapper.getName(), contextPath, connector)); } }
Example 4
Source File: MapperListener.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * Unregister wrapper. */ private void unregisterWrapper(Wrapper wrapper) { Context context = (Context) wrapper.getParent(); String contextPath = context.getPath(); String wrapperName = wrapper.getName(); if ("/".equals(contextPath)) { contextPath = ""; } String version = context.getWebappVersion(); String hostName = context.getParent().getName(); String[] mappings = wrapper.findMappings(); for (String mapping : mappings) { mapper.removeWrapper(hostName, contextPath, version, mapping); } if(log.isDebugEnabled()) { log.debug(sm.getString("mapperListener.unregisterWrapper", wrapperName, contextPath, connector)); } }
Example 5
Source File: MapperListener.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
/** * Register wrapper. */ private void registerWrapper(Wrapper wrapper) { Context context = (Context) wrapper.getParent(); String contextPath = context.getPath(); if ("/".equals(contextPath)) { contextPath = ""; } String version = context.getWebappVersion(); String hostName = context.getParent().getName(); List<WrapperMappingInfo> wrappers = new ArrayList<WrapperMappingInfo>(); prepareWrapperMappingInfo(context, wrapper, wrappers); mapper.addWrappers(hostName, contextPath, version, wrappers); if(log.isDebugEnabled()) { log.debug(sm.getString("mapperListener.registerWrapper", wrapper.getName(), contextPath, connector)); } }
Example 6
Source File: MapperListener.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
/** * Unregister wrapper. */ private void unregisterWrapper(Wrapper wrapper) { Context context = (Context) wrapper.getParent(); String contextPath = context.getPath(); String wrapperName = wrapper.getName(); if ("/".equals(contextPath)) { contextPath = ""; } String version = context.getWebappVersion(); String hostName = context.getParent().getName(); String[] mappings = wrapper.findMappings(); for (String mapping : mappings) { mapper.removeWrapper(hostName, contextPath, version, mapping); } if(log.isDebugEnabled()) { log.debug(sm.getString("mapperListener.unregisterWrapper", wrapperName, contextPath, connector)); } }
Example 7
Source File: StandardHost.java From Tomcat8-Source-Read with MIT License | 6 votes |
/** * Add a child Container, only if the proposed child is an implementation * of Context. * * @param child Child container to be added */ @Override public void addChild(Container child) { if (!(child instanceof Context)) throw new IllegalArgumentException (sm.getString("standardHost.notContext")); child.addLifecycleListener(new MemoryLeakTrackingListener()); // Avoid NPE for case where Context is defined in server.xml with only a // docBase Context context = (Context) child; if (context.getPath() == null) { ContextName cn = new ContextName(context.getDocBase(), true); context.setPath(cn.getPath()); } super.addChild(child); }
Example 8
Source File: MapperListener.java From Tomcat8-Source-Read with MIT License | 6 votes |
/** * Register wrapper. */ private void registerWrapper(Wrapper wrapper) { Context context = (Context) wrapper.getParent(); String contextPath = context.getPath(); if ("/".equals(contextPath)) { contextPath = ""; } String version = context.getWebappVersion(); String hostName = context.getParent().getName(); List<WrapperMappingInfo> wrappers = new ArrayList<>(); prepareWrapperMappingInfo(context, wrapper, wrappers); mapper.addWrappers(hostName, contextPath, version, wrappers); if(log.isDebugEnabled()) { log.debug(sm.getString("mapperListener.registerWrapper", wrapper.getName(), contextPath, service)); } }
Example 9
Source File: ManagerServlet.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
/** * Render a list of the currently active Contexts in our virtual host. * * @param writer Writer to render to */ protected void list(PrintWriter writer, StringManager smClient) { if (debug >= 1) log("list: Listing contexts for virtual host '" + host.getName() + "'"); writer.println(smClient.getString("managerServlet.listed", host.getName())); Container[] contexts = host.findChildren(); for (int i = 0; i < contexts.length; i++) { Context context = (Context) contexts[i]; if (context != null ) { String displayPath = context.getPath(); if( displayPath.equals("") ) displayPath = "/"; if (context.getState().isAvailable()) { writer.println(smClient.getString("managerServlet.listitem", displayPath, "running", "" + context.getManager().findSessions().length, context.getDocBase())); } else { writer.println(smClient.getString("managerServlet.listitem", displayPath, "stopped", "0", context.getDocBase())); } } } }
Example 10
Source File: MapperListener.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
/** * Register context. */ private void registerContext(Context context) { String contextPath = context.getPath(); if ("/".equals(contextPath)) { contextPath = ""; } Container host = context.getParent(); javax.naming.Context resources = context.getResources(); String[] welcomeFiles = context.findWelcomeFiles(); List<WrapperMappingInfo> wrappers = new ArrayList<WrapperMappingInfo>(); for (Container container : context.findChildren()) { prepareWrapperMappingInfo(context, (Wrapper) container, wrappers); if(log.isDebugEnabled()) { log.debug(sm.getString("mapperListener.registerWrapper", container.getName(), contextPath, connector)); } } mapper.addContextVersion(host.getName(), host, contextPath, context.getWebappVersion(), context, welcomeFiles, resources, wrappers, context.getMapperContextRootRedirectEnabled(), context.getMapperDirectoryRedirectEnabled()); if(log.isDebugEnabled()) { log.debug(sm.getString("mapperListener.registerContext", contextPath, connector)); } }
Example 11
Source File: MapperListener.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
/** * Unregister context. */ private void unregisterContext(Context context) { String contextPath = context.getPath(); if ("/".equals(contextPath)) { contextPath = ""; } String hostName = context.getParent().getName(); if(log.isDebugEnabled()) { log.debug(sm.getString("mapperListener.unregisterContext", contextPath, connector)); } if (context.getPaused()) { if (log.isDebugEnabled()) { log.debug(sm.getString("mapperListener.pauseContext", contextPath, connector)); } mapper.pauseContextVersion(context, hostName, contextPath, context.getWebappVersion()); } else { if (log.isDebugEnabled()) { log.debug(sm.getString("mapperListener.unregisterContext", contextPath, connector)); } mapper.removeContextVersion(hostName, contextPath, context.getWebappVersion()); } }
Example 12
Source File: ManagerServlet.java From tomcatsrc with Apache License 2.0 | 5 votes |
/** * Render a list of the currently active Contexts in our virtual host. * * @param writer Writer to render to */ protected void list(PrintWriter writer, StringManager smClient) { if (debug >= 1) log("list: Listing contexts for virtual host '" + host.getName() + "'"); writer.println(smClient.getString("managerServlet.listed", host.getName())); Container[] contexts = host.findChildren(); for (int i = 0; i < contexts.length; i++) { Context context = (Context) contexts[i]; if (context != null ) { String displayPath = context.getPath(); if( displayPath.equals("") ) displayPath = "/"; if (context.getState().isAvailable()) { writer.println(smClient.getString("managerServlet.listitem", displayPath, "running", "" + context.getManager().findSessions().length, context.getDocBase())); } else { writer.println(smClient.getString("managerServlet.listitem", displayPath, "stopped", "0", context.getDocBase())); } } } }
Example 13
Source File: MapperListener.java From Tomcat8-Source-Read with MIT License | 5 votes |
/** * Unregister context. */ private void unregisterContext(Context context) { String contextPath = context.getPath(); if ("/".equals(contextPath)) { contextPath = ""; } String hostName = context.getParent().getName(); if (context.getPaused()) { if (log.isDebugEnabled()) { log.debug(sm.getString("mapperListener.pauseContext", contextPath, service)); } mapper.pauseContextVersion(context, hostName, contextPath, context.getWebappVersion()); } else { if (log.isDebugEnabled()) { log.debug(sm.getString("mapperListener.unregisterContext", contextPath, service)); } mapper.removeContextVersion(context, hostName, contextPath, context.getWebappVersion()); } }
Example 14
Source File: MapperListener.java From tomcatsrc with Apache License 2.0 | 5 votes |
/** * Register context. */ private void registerContext(Context context) { String contextPath = context.getPath(); if ("/".equals(contextPath)) { contextPath = ""; } Container host = context.getParent(); javax.naming.Context resources = context.getResources(); String[] welcomeFiles = context.findWelcomeFiles(); List<WrapperMappingInfo> wrappers = new ArrayList<WrapperMappingInfo>(); for (Container container : context.findChildren()) { prepareWrapperMappingInfo(context, (Wrapper) container, wrappers); if(log.isDebugEnabled()) { log.debug(sm.getString("mapperListener.registerWrapper", container.getName(), contextPath, connector)); } } mapper.addContextVersion(host.getName(), host, contextPath, context.getWebappVersion(), context, welcomeFiles, resources, wrappers, context.getMapperContextRootRedirectEnabled(), context.getMapperDirectoryRedirectEnabled()); if(log.isDebugEnabled()) { log.debug(sm.getString("mapperListener.registerContext", contextPath, connector)); } }
Example 15
Source File: MapperListener.java From tomcatsrc with Apache License 2.0 | 5 votes |
/** * Unregister context. */ private void unregisterContext(Context context) { String contextPath = context.getPath(); if ("/".equals(contextPath)) { contextPath = ""; } String hostName = context.getParent().getName(); if(log.isDebugEnabled()) { log.debug(sm.getString("mapperListener.unregisterContext", contextPath, connector)); } if (context.getPaused()) { if (log.isDebugEnabled()) { log.debug(sm.getString("mapperListener.pauseContext", contextPath, connector)); } mapper.pauseContextVersion(context, hostName, contextPath, context.getWebappVersion()); } else { if (log.isDebugEnabled()) { log.debug(sm.getString("mapperListener.unregisterContext", contextPath, connector)); } mapper.removeContextVersion(hostName, contextPath, context.getWebappVersion()); } }
Example 16
Source File: MapperListener.java From Tomcat8-Source-Read with MIT License | 5 votes |
/** * Register context. */ private void registerContext(Context context) { String contextPath = context.getPath(); if ("/".equals(contextPath)) { contextPath = ""; } Host host = (Host)context.getParent(); WebResourceRoot resources = context.getResources(); String[] welcomeFiles = context.findWelcomeFiles(); List<WrapperMappingInfo> wrappers = new ArrayList<>(); for (Container container : context.findChildren()) { prepareWrapperMappingInfo(context, (Wrapper) container, wrappers); if(log.isDebugEnabled()) { log.debug(sm.getString("mapperListener.registerWrapper", container.getName(), contextPath, service)); } } mapper.addContextVersion(host.getName(), host, contextPath, context.getWebappVersion(), context, welcomeFiles, resources, wrappers); if(log.isDebugEnabled()) { log.debug(sm.getString("mapperListener.registerContext", contextPath, service)); } }
Example 17
Source File: ManagerServlet.java From Tomcat8-Source-Read with MIT License | 5 votes |
/** * Render a list of the currently active Contexts in our virtual host. * * @param writer Writer to render to * @param smClient i18n support for current client's locale */ protected void list(PrintWriter writer, StringManager smClient) { if (debug >= 1) log("list: Listing contexts for virtual host '" + host.getName() + "'"); writer.println(smClient.getString("managerServlet.listed", host.getName())); Container[] contexts = host.findChildren(); for (int i = 0; i < contexts.length; i++) { Context context = (Context) contexts[i]; if (context != null ) { String displayPath = context.getPath(); if( displayPath.equals("") ) displayPath = "/"; if (context.getState().isAvailable()) { writer.println(smClient.getString("managerServlet.listitem", displayPath, "running", "" + context.getManager().findSessions().length, context.getDocBase())); } else { writer.println(smClient.getString("managerServlet.listitem", displayPath, "stopped", "0", context.getDocBase())); } } } }
Example 18
Source File: CdiEventRealm.java From tomee with Apache License 2.0 | 5 votes |
@Override public SecurityConstraint[] findSecurityConstraints(final Request request, final Context context) { final SecurityConstraint[] sc = super.findSecurityConstraints(request, context); if (beanManager() == null) { return sc; } final FindSecurityConstraintsEvent event = new FindSecurityConstraintsEvent(request.getRequest(), context.getPath()); beanManager().fireEvent(event); if (!event.getRoles().isEmpty()) { final SecurityConstraint s = new SecurityConstraint(); final SecurityCollection collection = new SecurityCollection(); collection.addPattern("/*"); // only for the current request collection.addMethod(request.getMethod()); s.addCollection(collection); if (event.getUserConstraint() != null) { s.setUserConstraint(event.getUserConstraint()); } for(final String r: event.getRoles()) { s.addAuthRole(r); } return new SecurityConstraint[] { s }; } return sc; }
Example 19
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 20
Source File: InfinispanSessionCacheIdMapperUpdater.java From keycloak with Apache License 2.0 | 4 votes |
public static SessionIdMapperUpdater addTokenStoreUpdaters(Context context, SessionIdMapper mapper, SessionIdMapperUpdater previousIdMapperUpdater) { ServletContext servletContext = context.getServletContext(); String containerName = servletContext == null ? null : servletContext.getInitParameter(AdapterConstants.REPLICATION_CONFIG_CONTAINER_PARAM_NAME); String cacheName = servletContext == null ? null : servletContext.getInitParameter(AdapterConstants.REPLICATION_CONFIG_SSO_CACHE_PARAM_NAME); // the following is based on https://github.com/jbossas/jboss-as/blob/7.2.0.Final/clustering/web-infinispan/src/main/java/org/jboss/as/clustering/web/infinispan/DistributedCacheManagerFactory.java#L116-L122 String host = context.getParent() == null ? "" : context.getParent().getName(); String contextPath = context.getPath(); if ("/".equals(contextPath)) { contextPath = "/ROOT"; } String deploymentSessionCacheName = host + contextPath; if (containerName == null || cacheName == null || deploymentSessionCacheName == null) { LOG.warnv("Cannot determine parameters of SSO cache for deployment {0}.", host + contextPath); return previousIdMapperUpdater; } String cacheContainerLookup = DEFAULT_CACHE_CONTAINER_JNDI_NAME + "/" + containerName; try { EmbeddedCacheManager cacheManager = (EmbeddedCacheManager) new InitialContext().lookup(cacheContainerLookup); Configuration ssoCacheConfiguration = cacheManager.getCacheConfiguration(cacheName); if (ssoCacheConfiguration == null) { Configuration cacheConfiguration = cacheManager.getCacheConfiguration(deploymentSessionCacheName); if (cacheConfiguration == null) { LOG.debugv("Using default configuration for SSO cache {0}.{1}.", containerName, cacheName); ssoCacheConfiguration = cacheManager.getDefaultCacheConfiguration(); } else { LOG.debugv("Using distributed HTTP session cache configuration for SSO cache {0}.{1}, configuration taken from cache {2}", containerName, cacheName, deploymentSessionCacheName); ssoCacheConfiguration = cacheConfiguration; cacheManager.defineConfiguration(cacheName, ssoCacheConfiguration); } } else { LOG.debugv("Using custom configuration of SSO cache {0}.{1}.", containerName, cacheName); } CacheMode ssoCacheMode = ssoCacheConfiguration.clustering().cacheMode(); if (ssoCacheMode != CacheMode.REPL_ASYNC && ssoCacheMode != CacheMode.REPL_SYNC) { LOG.warnv("SSO cache mode is {0}, it is recommended to use replicated mode instead.", ssoCacheConfiguration.clustering().cacheModeString()); } Cache<String, String[]> ssoCache = cacheManager.getCache(cacheName, true); final SsoSessionCacheListener listener = new SsoSessionCacheListener(ssoCache, mapper); ssoCache.addListener(listener); // Not possible to add listener for cross-DC support because of too old Infinispan in AS 7 warnIfRemoteStoreIsUsed(ssoCache); LOG.debugv("Added distributed SSO session cache, lookup={0}, cache name={1}", cacheContainerLookup, cacheName); SsoCacheSessionIdMapperUpdater updater = new SsoCacheSessionIdMapperUpdater(ssoCache, previousIdMapperUpdater); return updater; } catch (NamingException ex) { LOG.warnv("Failed to obtain distributed session cache container, lookup={0}", cacheContainerLookup); return previousIdMapperUpdater; } }