use of javax.servlet.ServletContainerInitializer in project wildfly by wildfly.
the class ServletContainerInitializerDeploymentProcessor method loadSci.
private List<ServletContainerInitializer> loadSci(ClassLoader classLoader, VirtualFile sci, String jar, boolean error, Set<Class<? extends ServletContainerInitializer>> sciClasses) throws DeploymentUnitProcessingException {
final List<ServletContainerInitializer> scis = new ArrayList<ServletContainerInitializer>();
InputStream is = null;
try {
// Get the ServletContainerInitializer class name
is = sci.openStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8));
String servletContainerInitializerClassName = reader.readLine();
while (servletContainerInitializerClassName != null) {
try {
int pos = servletContainerInitializerClassName.indexOf('#');
if (pos >= 0) {
servletContainerInitializerClassName = servletContainerInitializerClassName.substring(0, pos);
}
servletContainerInitializerClassName = servletContainerInitializerClassName.trim();
if (!servletContainerInitializerClassName.isEmpty()) {
// Instantiate the ServletContainerInitializer
ServletContainerInitializer service = (ServletContainerInitializer) classLoader.loadClass(servletContainerInitializerClassName).newInstance();
if (service != null && sciClasses.add(service.getClass())) {
scis.add(service);
}
}
servletContainerInitializerClassName = reader.readLine();
} catch (Exception e) {
if (error) {
throw UndertowLogger.ROOT_LOGGER.errorProcessingSCI(jar, e);
} else {
UndertowLogger.ROOT_LOGGER.skippedSCI(jar, e);
}
}
}
} catch (Exception e) {
if (error) {
throw UndertowLogger.ROOT_LOGGER.errorProcessingSCI(jar, e);
} else {
UndertowLogger.ROOT_LOGGER.skippedSCI(jar, e);
}
} finally {
try {
if (is != null)
is.close();
} catch (IOException e) {
// Ignore
}
}
return scis;
}
use of javax.servlet.ServletContainerInitializer in project tomee by apache.
the class OpenEJBContextConfig method webConfig.
@Override
protected void webConfig() {
TomcatHelper.configureJarScanner(context);
// read the real config
super.webConfig();
if (IgnoredStandardContext.class.isInstance(context)) {
// no need of jsf
return;
}
if (AppFinder.findAppContextOrWeb(context.getLoader().getClassLoader(), AppFinder.WebBeansContextTransformer.INSTANCE) != null) {
final FilterDef asyncOwbFilter = new FilterDef();
asyncOwbFilter.setAsyncSupported("true");
asyncOwbFilter.setDescription("OpenEJB CDI Filter - to propagate @RequestScoped in async tasks");
asyncOwbFilter.setDisplayName("OpenEJB CDI");
asyncOwbFilter.setFilterClass(EEFilter.class.getName());
asyncOwbFilter.setFilterName(EEFilter.class.getName());
context.addFilterDef(asyncOwbFilter);
final FilterMap asyncOwbMapping = new FilterMap();
asyncOwbMapping.setFilterName(asyncOwbFilter.getFilterName());
asyncOwbMapping.addURLPattern("/*");
context.addFilterMap(asyncOwbMapping);
}
if ("true".equalsIgnoreCase(SystemInstance.get().getProperty("tomee.jsp-development", "false"))) {
for (final Container c : context.findChildren()) {
if (Wrapper.class.isInstance(c)) {
final Wrapper servlet = Wrapper.class.cast(c);
if ("org.apache.jasper.servlet.JspServlet".equals(servlet.getServletClass())) {
servlet.addInitParameter("development", "true");
}
}
}
}
final ClassLoader classLoader = context.getLoader().getClassLoader();
// add myfaces auto-initializer if mojarra is not present
try {
classLoader.loadClass("com.sun.faces.context.SessionMap");
return;
} catch (final Throwable ignored) {
// no-op
}
try {
final Class<?> myfacesInitializer = Class.forName(MYFACES_TOMEEM_CONTAINER_INITIALIZER, true, classLoader);
final ServletContainerInitializer instance = (ServletContainerInitializer) myfacesInitializer.newInstance();
context.addServletContainerInitializer(instance, getJsfClasses(context));
// cleanup listener
context.addApplicationListener(TOMEE_MYFACES_CONTEXT_LISTENER);
} catch (final Exception | NoClassDefFoundError ignored) {
// no-op
}
}
use of javax.servlet.ServletContainerInitializer in project Payara by payara.
the class StandardContext method callServletContainerInitializers.
protected void callServletContainerInitializers() throws LifecycleException {
// Get the list of ServletContainerInitializers and the classes
// they are interested in
Map<Class<?>, List<Class<? extends ServletContainerInitializer>>> interestList = ServletContainerInitializerUtil.getInterestList(servletContainerInitializers);
Map<Class<? extends ServletContainerInitializer>, Set<Class<?>>> initializerList = ServletContainerInitializerUtil.getInitializerList(servletContainerInitializers, interestList, getTypes(), getClassLoader(), isStandalone());
if (initializerList == null) {
return;
}
// Allow programmatic registration of ServletContextListeners, but
// only within the scope of ServletContainerInitializer#onStartup
isProgrammaticServletContextListenerRegistrationAllowed = true;
// We have the list of initializers and the classes that satisfy the condition.
// Time to call the initializers
ServletContext ctxt = this.getServletContext();
try {
for (Map.Entry<Class<? extends ServletContainerInitializer>, Set<Class<?>>> e : initializerList.entrySet()) {
Class<? extends ServletContainerInitializer> initializer = e.getKey();
try {
if (log.isLoggable(FINE)) {
log.log(FINE, "Calling ServletContainerInitializer [{0}] onStartup with classes {1}", new Object[] { initializer, e.getValue() });
}
ServletContainerInitializer iniInstance = initializer.newInstance();
fireContainerEvent(BEFORE_CONTEXT_INITIALIZER_ON_STARTUP, iniInstance);
iniInstance.onStartup(initializerList.get(initializer), ctxt);
fireContainerEvent(AFTER_CONTEXT_INITIALIZER_ON_STARTUP, iniInstance);
} catch (Throwable t) {
log.log(SEVERE, format(rb.getString(INVOKING_SERVLET_CONTAINER_INIT_EXCEPTION), initializer.getCanonicalName()), t);
throw new LifecycleException(t);
}
}
} finally {
isProgrammaticServletContextListenerRegistrationAllowed = false;
}
}
use of javax.servlet.ServletContainerInitializer in project Payara by payara.
the class DynamicWebServletRegistrationImpl method start.
/**
* Starts this web module.
*/
@Override
public synchronized void start() throws LifecycleException {
// Get interestList of ServletContainerInitializers present, if any.
List<Object> orderingList = null;
boolean hasOthers = false;
Map<String, String> webFragmentMap = Collections.emptyMap();
if (webBundleDescriptor != null) {
AbsoluteOrderingDescriptor aod = ((WebBundleDescriptorImpl) webBundleDescriptor).getAbsoluteOrderingDescriptor();
if (aod != null) {
orderingList = aod.getOrdering();
hasOthers = aod.hasOthers();
}
webFragmentMap = webBundleDescriptor.getJarNameToWebFragmentNameMap();
}
boolean servletInitializersEnabled = true;
if (webBundleDescriptor != null) {
servletInitializersEnabled = webBundleDescriptor.getServletInitializersEnabled();
}
Iterable<ServletContainerInitializer> allInitializers = ServletContainerInitializerUtil.getServletContainerInitializers(webFragmentMap, orderingList, hasOthers, wmInfo.getAppClassLoader(), servletInitializersEnabled);
setServletContainerInitializerInterestList(allInitializers);
DeploymentContext dc = getWebModuleConfig().getDeploymentContext();
if (dc != null) {
directoryDeployed = Boolean.valueOf(dc.getAppProps().getProperty(ServerTags.DIRECTORY_DEPLOYED));
}
if (webBundleDescriptor != null) {
showArchivedRealPathEnabled = webBundleDescriptor.isShowArchivedRealPathEnabled();
servletReloadCheckSecs = webBundleDescriptor.getServletReloadCheckSecs();
String reqEncoding = webBundleDescriptor.getRequestCharacterEncoding();
if (reqEncoding != null) {
setRequestCharacterEncoding(reqEncoding);
}
String resEncoding = webBundleDescriptor.getResponseCharacterEncoding();
if (resEncoding != null) {
setResponseCharacterEncoding(resEncoding);
}
}
// Start and register Tomcat mbeans
super.start();
// Configure catalina listeners and valves. This can only happen
// after this web module has been started, in order to be able to
// load the specified listener and valve classes.
configureValves();
configureCatalinaProperties();
webModuleStartedEvent();
if (directoryListing) {
setDirectoryListing(directoryListing);
}
hasStarted = true;
}
use of javax.servlet.ServletContainerInitializer in project meecrowave by apache.
the class MeecrowaveContextConfig method processServletContainerInitializers.
@Override
protected void processServletContainerInitializers() {
// use our finder
if (!configuration.isTomcatScanning()) {
return;
}
try {
new WebappServiceLoader<ServletContainerInitializer>(context).load(ServletContainerInitializer.class).forEach(sci -> {
final Set<Class<?>> classes = new HashSet<>();
initializerClassMap.put(sci, classes);
final HandlesTypes ht;
try {
ht = sci.getClass().getAnnotation(HandlesTypes.class);
} catch (final Exception | NoClassDefFoundError e) {
return;
}
if (ht == null) {
return;
}
Stream.of(ht.value()).forEach(t -> {
if (t.isAnnotation()) {
final Class<? extends Annotation> annotation = Class.class.cast(t);
classes.addAll(finder.findAnnotatedClasses(annotation));
} else if (t.isInterface()) {
classes.addAll(finder.findImplementations(t));
} else {
classes.addAll(finder.findSubclasses(t));
}
});
});
} catch (final IOException e) {
ok = false;
}
}
Aggregations