ctx = (Context) Class.forName(host.getContextClass(), true, getClass().getClassLoader()) .getDeclaredConstructor().newInstance(); } catch (Exception e) {
/** * Create the configured {@link Context} for the given <code>host</code>. The default constructor of the class that was configured with {@link StandardHost#setContextClass(String)} will be used * * @param host * host for which the {@link Context} should be created, or <code>null</code> if default host should be used * @param url * path of the webapp which should get the {@link Context} * @return newly created {@link Context} */ private Context createContext(Host host, String url) { String contextClass = StandardContext.class.getName(); if (host == null) { host = this.getHost(); } if (host instanceof StandardHost) { contextClass = ((StandardHost) host).getContextClass(); } try { return (Context) Class.forName(contextClass).getConstructor().newInstance(); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException | ClassNotFoundException e) { throw new IllegalArgumentException("Can't instantiate context-class " + contextClass + " for host " + host + " and url " + url, e); } }
/** * Create the configured {@link Context} for the given <code>host</code>. * The default constructor of the class that was configured with * {@link StandardHost#setContextClass(String)} will be used * * @param host * host for which the {@link Context} should be created, or * <code>null</code> if default host should be used * @param url * path of the webapp which should get the {@link Context} * @return newly created {@link Context} */ private Context createContext(Host host, String url) { String contextClass = StandardContext.class.getName(); if (host == null) { host = this.getHost(); } if (host instanceof StandardHost) { contextClass = ((StandardHost) host).getContextClass(); } try { return (Context) Class.forName(contextClass).getConstructor() .newInstance(); } catch (ReflectiveOperationException | IllegalArgumentException | SecurityException e) { throw new IllegalArgumentException( "Can't instantiate context-class " + contextClass + " for host " + host + " and url " + url, e); } }
/** * Create the configured {@link Context} for the given <code>host</code>. * The default constructor of the class that was configured with * {@link StandardHost#setContextClass(String)} will be used * * @param host * host for which the {@link Context} should be created, or * <code>null</code> if default host should be used * @param url * path of the webapp which should get the {@link Context} * @return newly created {@link Context} */ private Context createContext(Host host, String url) { String contextClass = StandardContext.class.getName(); if (host == null) { host = this.getHost(); } if (host instanceof StandardHost) { contextClass = ((StandardHost) host).getContextClass(); } try { return (Context) Class.forName(contextClass).getConstructor() .newInstance(); } catch (ReflectiveOperationException | IllegalArgumentException | SecurityException e) { throw new IllegalArgumentException(sm.getString("tomcat.noContextClass", contextClass, host, url), e); } }
protected Context createContext(Host host, String url) { // similar to super class's private method String contextClass = StandardContext.class.getName(); if (host == null) { host = this.getHost(); } if (host instanceof StandardHost) { contextClass = ((StandardHost) host).getContextClass(); } final Context ctx; try { ctx = (Context) Class.forName(contextClass).getConstructor().newInstance(); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException | ClassNotFoundException e) { String msg = "Can't instantiate context-class " + contextClass + " for host " + host + " and url " + url; throw new IllegalArgumentException(msg, e); } setupAccessLogIfNeeds(ctx); setupYourValveIfNeeds(ctx); if (likeitCatalinaSetupper != null) { likeitCatalinaSetupper.setup(new LikeItCatalinaResource(host, ctx)); } return ctx; }
public void switchContextClass(@Observes final LifecycleEvent le) { for (final Service service : TomcatHelper.getServer().findServices()) { final Container container = service.getContainer(); if (!Engine.class.isInstance(container)) { continue; } for (final Container engineChild : Engine.class.cast(container).findChildren()) { if (!StandardHost.class.isInstance(engineChild)) { LOGGER.warning(ContainerCodes.TELEMETRY_NOT_STANDARDHOST, "{0} is not a StandardHost so can't customize the context class", engineChild); continue; } final String contextClass = StandardHost.class.cast(engineChild).getContextClass(); if (!StandardContext.class.getName().equals(contextClass) && !contextClass.startsWith("com.tomitribe.tribestream.")) { LOGGER.warning(ContainerCodes.TELEMETRY_NOT_USING_STANDARDHOST, "{0} is not using StandardContext so ignoring customization of the context class", engineChild); } StandardHost.class.cast(engineChild).setContextClass(TribestreamStandardContext.class.getName()); } } SystemInstance.get().removeObserver(this); // we don't need to listen LifecycleEvent anymore } }
Class clazz = Class.forName(host.getContextClass()); Context context = (Context) clazz.newInstance(); context.setPath(contextPath);
Class clazz = Class.forName(host.getContextClass()); Context context = (Context) clazz.newInstance(); context.setPath(contextPath);
if (StandardHost.class.isInstance(host) && !StandardContext.class.getName().equals(StandardHost.class.cast(host).getContextClass())) { try { standardContext = StandardContext.class.cast(containerLoader.loadClass(StandardHost.class.cast(host).getContextClass()).newInstance()); } catch (final Throwable th) { logger.warning("Can't use context class specified, using default StandardContext", th);
setDeployXML(((StandardHost) host).isDeployXML()); setUnpackWARs(((StandardHost) host).isUnpackWARs()); setContextClass(((StandardHost) host).getContextClass());
/** * Process the START event for an associated Host. * * @param event The lifecycle event that has occurred */ @Override public void lifecycleEvent(LifecycleEvent event) { // Identify the host we are associated with try { host = (Host) event.getLifecycle(); if (host instanceof StandardHost) { setCopyXML(((StandardHost) host).isCopyXML()); setDeployXML(((StandardHost) host).isDeployXML()); setUnpackWARs(((StandardHost) host).isUnpackWARs()); setContextClass(((StandardHost) host).getContextClass()); } } catch (ClassCastException e) { log.error(sm.getString("hostConfig.cce", event.getLifecycle()), e); return; } // Process the event that has occurred if (event.getType().equals(Lifecycle.PERIODIC_EVENT)) { check(); } else if (event.getType().equals(Lifecycle.START_EVENT)) { start(); } else if (event.getType().equals(Lifecycle.STOP_EVENT)) { stop(); } }
setDeployXML(((StandardHost) host).isDeployXML()); setUnpackWARs(((StandardHost) host).isUnpackWARs()); setContextClass(((StandardHost) host).getContextClass());