protected MemcachedNodesManager createMemcachedNodesManager(final String memcachedNodes, final String failoverNodes) { final Context context = _manager.getContext(); final String webappVersion = Reflections.invoke(context, "getWebappVersion", null); final StorageKeyFormat storageKeyFormat = StorageKeyFormat.of(_storageKeyPrefix, context.getParent().getName(), context.getName(), webappVersion); return MemcachedNodesManager.createFor( memcachedNodes, failoverNodes, storageKeyFormat, _storageClientCallback); }
@Override public String getConfigBase() { File configBase = new File(System.getProperty("catalina.base"), "conf"); Container baseHost = null; Container thisContainer = host; while (thisContainer != null) { if (thisContainer instanceof Host) { baseHost = thisContainer; } thisContainer = thisContainer.getParent(); } if (baseHost != null) { configBase = new File(configBase, baseHost.getName()); } return configBase.getAbsolutePath(); }
public void shutdown() { _log.info( "Stopping services." ); _manager.getContext().getParent().getPipeline().removeValve(_trackingHostValve); _manager.getContext().getPipeline().removeValve(_trackingContextValve); _backupSessionService.shutdown(); if ( _lockingStrategy != null ) { _lockingStrategy.shutdown(); } if ( _storage != null ) { _storage.shutdown(); _storage = null; } _transcoderFactory = null; _invalidSessionsCache.clear(); }
/** * Unregister context. */ private void unregisterContext(Context context) { // Don't un-map a context that is paused if (context.getPaused()){ return; } String contextPath = context.getPath(); if ("/".equals(contextPath)) { contextPath = ""; } String hostName = context.getParent().getName(); if(log.isDebugEnabled()) log.debug(sm.getString("mapperListener.unregisterContext", contextPath, connector)); mapper.removeContextVersion(hostName, contextPath, context.getWebappVersion()); }
ErrorPage errorPage) { if (container.getLogger().isDebugEnabled()) { container.getLogger().debug("Processing " + errorPage); request.getContext().getServletContext(); RequestDispatcher rd = servletContext.getRequestDispatcher(errorPage.getLocation()); container.getLogger().error( sm.getString("standardHostValue.customStatusFailed", errorPage.getLocation())); return false; rd.include(request.getRequest(), response.getResponse()); } else { response.setContentLength(-1); rd.forward(request.getRequest(), response.getResponse()); ExceptionUtils.handleThrowable(t); container.getLogger().error("Exception Processing " + errorPage, t); return false;
/** * Perform the internal processing required to passivate * this session. */ public void passivate() { // Notify interested session event listeners fireSessionEvent(Session.SESSION_PASSIVATED_EVENT, null); // Notify ActivationListeners HttpSessionEvent event = null; String keys[] = keys(); for (int i = 0; i < keys.length; i++) { Object attribute = attributes.get(keys[i]); if (attribute instanceof HttpSessionActivationListener) { if (event == null) event = new HttpSessionEvent(getSession()); try { ((HttpSessionActivationListener)attribute) .sessionWillPassivate(event); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); manager.getContainer().getLogger().error (sm.getString("standardSession.attributeEvent"), t); } } } }
@Override public void sessionDestroyed(HttpSessionEvent se) { // Close all Comet connections associated with this session Request[] reqs = (Request[]) se.getSession().getAttribute(cometRequestsAttribute); if (reqs != null) { for (int i = 0; i < reqs.length; i++) { Request req = reqs[i]; try { CometEventImpl event = req.getEvent(); event.setEventType(CometEvent.EventType.END); event.setEventSubType(CometEvent.EventSubType.SESSION_END); ((CometProcessor) req.getWrapper().getServlet()).event(event); event.close(); } catch (Exception e) { req.getWrapper().getParent().getLogger().warn(sm.getString( "cometConnectionManagerValve.listenerEvent"), e); } } } }
/** * Unregister wrapper. */ private void unregisterWrapper(Wrapper wrapper) { String contextPath = ((Context) wrapper.getParent()).getPath(); String wrapperName = wrapper.getName(); if ("/".equals(contextPath)) { contextPath = ""; } String version = ((Context) wrapper.getParent()).getWebappVersion(); String hostName = wrapper.getParent().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)); } }
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); } }
@Override public synchronized void removeContext(Context context) { if( log.isDebugEnabled() ) log.debug("Removing context[" + context.getPath() + "]"); boolean isContextExists = isContextExists(context); if(!isContextExists) return; // Remove this Context from the associated Host if( log.isDebugEnabled() ) log.debug(" Removing this Context"); context.getParent().removeChild(context); }
/** * Reset DeltaRequest from session * @param session HttpSession from current request or cross context session */ protected void resetDeltaRequest(Session session) { if(log.isDebugEnabled()) { log.debug(sm.getString("ReplicationValve.resetDeltaRequest" , session.getManager().getContainer().getName() )); } ((DeltaSession)session).resetDeltaRequest(); }
protected void processChildren(Container container) { ClassLoader originalClassLoader = null; try { if (container instanceof Context) { Loader loader = ((Context) container).getLoader(); // Loader will be null for FailedContext instances if (loader == null) { return; } // Ensure background processing for Contexts and Wrappers // is performed under the web app's class loader originalClassLoader = ((Context) container).bind(false, null); } container.backgroundProcess(); Container[] children = container.findChildren(); for (int i = 0; i < children.length; i++) { if (children[i].getBackgroundProcessorDelay() <= 0) { processChildren(children[i]); } } } catch (Throwable t) { ExceptionUtils.handleThrowable(t); log.error(sm.getString("containerBase.backgroundProcess.error"), t); } finally { if (container instanceof Context) { ((Context) container).unbind(false, originalClassLoader); } } } }
/** * Close the specified database connection. */ protected void close() { // Do nothing if the database connection is already closed if (conn == null) { return; } // Close our prepared statements (if any) try { ps.close(); } catch (Throwable f) { ExceptionUtils.handleThrowable(f); } this.ps = null; // Close this database connection, and log any errors try { conn.close(); } catch (SQLException e) { container.getLogger().error(sm.getString("jdbcAccessLogValve.close"), e); // Just log it here } finally { this.conn = null; } }
public SingleSignOnSessionKey(Session session) { this.sessionId = session.getId(); Context context = session.getManager().getContext(); this.contextName = context.getName(); this.hostName = context.getParent().getName(); }
@Override public void lifecycleEvent(LifecycleEvent event) { if (Lifecycle.BEFORE_STOP_EVENT.equals(event.getType())) { // The container is getting stopped, close all current connections Iterator<Request> iterator = cometRequests.iterator(); while (iterator.hasNext()) { Request request = iterator.next(); // Remove the session tracking attribute as it isn't // serializable or required. HttpSession session = request.getSession(false); if (session != null) { session.removeAttribute(cometRequestsAttribute); } // Close the comet connection try { CometEventImpl cometEvent = request.getEvent(); cometEvent.setEventType(CometEvent.EventType.END); cometEvent.setEventSubType( CometEvent.EventSubType.WEBAPP_RELOAD); getNext().event(request, request.getResponse(), cometEvent); cometEvent.close(); } catch (Exception e) { container.getLogger().warn( sm.getString("cometConnectionManagerValve.event"), e); } } cometRequests.clear(); } }
/** * Send the changed Sessionid to all clusternodes. * * @see JvmRouteSessionIDBinderListener#messageReceived( * org.apache.catalina.ha.ClusterMessage) * @param sessionId * current failed sessionid * @param newSessionID * new session id, bind to the new cluster node */ protected void sendSessionIDClusterBackup(Request request, String sessionId, String newSessionID) { CatalinaCluster c = getCluster(); if (c != null && !(getManager(request) instanceof BackupManager)) { SessionIDMessage msg = new SessionIDMessage(); msg.setOrignalSessionID(sessionId); msg.setBackupSessionID(newSessionID); Context context = request.getContext(); msg.setContextName(context.getName()); msg.setHost(context.getParent().getName()); c.send(msg); } }
/** * Set the JNDI name of a DataSource-factory to use for db access * * @param dataSourceName The JNDI name of the DataSource-factory */ public void setDataSourceName(String dataSourceName) { if (dataSourceName == null || "".equals(dataSourceName.trim())) { manager.getContainer().getLogger().warn( sm.getString(getStoreName() + ".missingDataSourceName")); return; } this.dataSourceName = dataSourceName; }
this.context = context; if (context != null) { this.servletContext = context.getServletContext(); Pipeline p = context.getParent().getPipeline(); if (p != null) { hostValve = p.getBasic(); String reqEncoding = this.servletContext.getRequestCharacterEncoding(); if (reqEncoding != null) { setCharacterEncoding(reqEncoding); getResponse().getResponse().setCharacterEncoding(resEncoding); initSessionTracker();
/** * Attempt to load a class using the given Container's class loader. If the * class cannot be loaded, a debug level log message will be written to the * Container's log and null will be returned. */ public static Class<?> loadClass(Container container, String className) { ClassLoader cl = container.getLoader().getClassLoader(); Log log = container.getLogger(); Class<?> clazz = null; try { clazz = cl.loadClass(className); } catch (ClassNotFoundException e) { log.debug(sm.getString("introspection.classLoadFailed"), e); } catch (NoClassDefFoundError e) { log.debug(sm.getString("introspection.classLoadFailed"), e); } catch (ClassFormatError e) { log.debug(sm.getString("introspection.classLoadFailed"), e); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); log.debug(sm.getString("introspection.classLoadFailed"), t); } return clazz; }