@Override public boolean getAvailable(Context context) { return context.getState().isAvailable(); }
@Override protected ModelAndView handleContext(String contextName, Context context, HttpServletRequest request, HttpServletResponse response) throws Exception { if (context != null && !request.getContextPath().equals(contextName)) { try { // Logging action Authentication auth = SecurityContextHolder.getContext().getAuthentication(); // get username logger String name = auth.getName(); if (context.getState().isAvailable()) { logger.info("{} requested STOP of {}", request.getRemoteAddr(), contextName); getContainerWrapper().getTomcatContainer().stop(contextName); logger.info(getMessageSourceAccessor().getMessage("probe.src.log.stop"), name, contextName); } else { logger.info("{} requested START of {}", request.getRemoteAddr(), contextName); getContainerWrapper().getTomcatContainer().start(contextName); logger.info(getMessageSourceAccessor().getMessage("probe.src.log.start"), name, contextName); } } catch (Exception e) { logger.error("Error during ajax request to START/STOP of '{}'", contextName, e); } } return new ModelAndView(getViewName(), "available", context != null && getContainerWrapper().getTomcatContainer().getAvailable(context)); }
@Override public boolean isStarted() { return LifecycleState.STARTED.equals(this.context.getState()); }
private void destroy(Context context) throws LifecycleException, InterruptedException { context.destroy(); long deadline = System.currentTimeMillis() + 10000; do { switch(context.getState()) { case DESTROYED: case FAILED: return; default : { } } Thread.sleep(10); } while(deadline > System.currentTimeMillis()); } }
private void stop(Context context) throws LifecycleException, InterruptedException { context.stop(); long deadline = System.currentTimeMillis() + 10000; do { switch(context.getState()) { case STOPPED: case DESTROYING: case DESTROYED: case FAILED: return; default : { } } Thread.sleep(10); } while(deadline > System.currentTimeMillis()); }
private Stream<Context> findContexts(final Host host) { return Stream.of(host.findChildren()) .filter(Context.class::isInstance) .map(Context.class::cast) .filter(ctx -> ctx.getState().isAvailable()); }
private Stream<Context> findContexts(final Host host) { return Stream.of(host.findChildren()) .filter(Context.class::isInstance) .map(Context.class::cast) .filter(ctx -> ctx.getState().isAvailable()); }
private void writeDeployResult(PrintWriter writer, StringManager smClient, String name, String displayPath) { Context deployed = (Context) host.findChild(name); if (deployed != null && deployed.getConfigured() && deployed.getState().isAvailable()) { writer.println(smClient.getString( "managerServlet.deployed", displayPath)); } else if (deployed!=null && !deployed.getState().isAvailable()) { writer.println(smClient.getString( "managerServlet.deployedButNotStarted", displayPath)); } else { // Something failed writer.println(smClient.getString( "managerServlet.deployFailed", displayPath)); } }
private void writeDeployResult(PrintWriter writer, StringManager smClient, String name, String displayPath) { Context deployed = (Context) host.findChild(name); if (deployed != null && deployed.getConfigured() && deployed.getState().isAvailable()) { writer.println(smClient.getString( "managerServlet.deployed", displayPath)); } else if (deployed!=null && !deployed.getState().isAvailable()) { writer.println(smClient.getString( "managerServlet.deployedButNotStarted", displayPath)); } else { // Something failed writer.println(smClient.getString( "managerServlet.deployFailed", displayPath)); } }
@Test public void isStarted() { when(this.context.getState()).thenReturn(LifecycleState.STOPPED); boolean result = this.catalinaContext.isStarted(); assertFalse(result); when(this.context.getState()).thenReturn(LifecycleState.STARTED); result = this.catalinaContext.isStarted(); assertTrue(result); }
@Override public Set<String> setServletSecurity(ServletSecurityElement constraint) { if (constraint == null) { throw new IllegalArgumentException(sm.getString( "applicationServletRegistration.setServletSecurity.iae", getName(), context.getName())); } if (!context.getState().equals(LifecycleState.STARTING_PREP)) { throw new IllegalStateException(sm.getString( "applicationServletRegistration.setServletSecurity.ise", getName(), context.getName())); } return context.addServletSecurity(this, constraint); }
@Override public Set<String> setServletSecurity(ServletSecurityElement constraint) { if (constraint == null) { throw new IllegalArgumentException(sm.getString( "applicationServletRegistration.setServletSecurity.iae", getName(), context.getName())); } if (!context.getState().equals(LifecycleState.STARTING_PREP)) { throw new IllegalStateException(sm.getString( "applicationServletRegistration.setServletSecurity.ise", getName(), context.getName())); } return context.addServletSecurity(this, constraint); }
@Override public Set<String> setServletSecurity(ServletSecurityElement constraint) { if (constraint == null) { throw new IllegalArgumentException(sm.getString( "applicationServletRegistration.setServletSecurity.iae", getName(), context.getName())); } if (!context.getState().equals(LifecycleState.STARTING_PREP)) { throw new IllegalStateException(sm.getString( "applicationServletRegistration.setServletSecurity.ise", getName(), context.getName())); } this.constraint = constraint; return context.addServletSecurity(this, constraint); }
@Override public Set<String> setServletSecurity(ServletSecurityElement constraint) { if (constraint == null) { throw new IllegalArgumentException(sm.getString( "applicationServletRegistration.setServletSecurity.iae", getName(), context.getName())); } if (!context.getState().equals(LifecycleState.STARTING_PREP)) { throw new IllegalStateException(sm.getString( "applicationServletRegistration.setServletSecurity.ise", getName(), context.getName())); } return context.addServletSecurity(this, constraint); }
@Override public Set<String> setServletSecurity(ServletSecurityElement constraint) { if (constraint == null) { throw new IllegalArgumentException(sm.getString( "applicationServletRegistration.setServletSecurity.iae", getName(), context.getName())); } if (!context.getState().equals(LifecycleState.STARTING_PREP)) { throw new IllegalStateException(sm.getString( "applicationServletRegistration.setServletSecurity.ise", getName(), context.getName())); } return context.addServletSecurity(this, constraint); }
@Override public Set<String> setServletSecurity(ServletSecurityElement constraint) { if (constraint == null) { throw new IllegalArgumentException(sm.getString( "applicationServletRegistration.setServletSecurity.iae", getName(), context.getName())); } if (!context.getState().equals(LifecycleState.STARTING_PREP)) { throw new IllegalStateException(sm.getString( "applicationServletRegistration.setServletSecurity.ise", getName(), context.getName())); } return context.addServletSecurity(this, constraint); }
@Override public Set<String> setServletSecurity(ServletSecurityElement constraint) { if (constraint == null) { throw new IllegalArgumentException(sm.getString( "applicationServletRegistration.setServletSecurity.iae", getName(), context.getName())); } if (!context.getState().equals(LifecycleState.STARTING_PREP)) { throw new IllegalStateException(sm.getString( "applicationServletRegistration.setServletSecurity.ise", getName(), context.getName())); } return context.addServletSecurity(this, constraint); }
@Override public Set<String> setServletSecurity(ServletSecurityElement constraint) { if (constraint == null) { throw new IllegalArgumentException(sm.getString( "applicationServletRegistration.setServletSecurity.iae", getName(), context.getName())); } if (!context.getState().equals(LifecycleState.STARTING_PREP)) { throw new IllegalStateException(sm.getString( "applicationServletRegistration.setServletSecurity.ise", getName(), context.getName())); } this.constraint = constraint; return context.addServletSecurity(this, constraint); }
private void reload(DeployedApplication app) { if(log.isInfoEnabled()) log.info(sm.getString("hostConfig.reload", app.name)); Context context = (Context) host.findChild(app.name); if (context.getState().isAvailable()) { // Reload catches and logs exceptions context.reload(); } else { // If the context was not started (for example an error // in web.xml) we'll still get to try to start try { context.start(); } catch (Exception e) { log.warn(sm.getString ("hostConfig.context.restart", app.name), e); } } }
private void reload(DeployedApplication app, File fileToRemove, String newDocBase) { if(log.isInfoEnabled()) log.info(sm.getString("hostConfig.reload", app.name)); Context context = (Context) host.findChild(app.name); if (context.getState().isAvailable()) { if (fileToRemove != null && newDocBase != null) { context.addLifecycleListener( new ExpandedDirectoryRemovalListener(fileToRemove, newDocBase)); } // Reload catches and logs exceptions context.reload(); } else { // If the context was not started (for example an error // in web.xml) we'll still get to try to start if (fileToRemove != null && newDocBase != null) { ExpandWar.delete(fileToRemove); context.setDocBase(newDocBase); } try { context.start(); } catch (Exception e) { log.warn(sm.getString ("hostConfig.context.restart", app.name), e); } } }