use of org.eclipse.jetty.plus.annotation.ContainerInitializer in project jetty.project by eclipse.
the class AnnotationConfiguration method createServletContainerInitializerAnnotationHandlers.
public void createServletContainerInitializerAnnotationHandlers(WebAppContext context, List<ServletContainerInitializer> scis) throws Exception {
if (scis == null || scis.isEmpty())
// nothing to do
return;
List<ContainerInitializer> initializers = new ArrayList<ContainerInitializer>();
context.setAttribute(CONTAINER_INITIALIZERS, initializers);
for (ServletContainerInitializer service : scis) {
HandlesTypes annotation = service.getClass().getAnnotation(HandlesTypes.class);
ContainerInitializer initializer = null;
if (annotation != null) {
//There is a HandlesTypes annotation on the on the ServletContainerInitializer
Class<?>[] classes = annotation.value();
if (classes != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("HandlesTypes {} on initializer {}", Arrays.asList(classes), service.getClass());
}
initializer = new ContainerInitializer(service, classes);
//process the whole class hierarchy to satisfy the ServletContainerInitializer
if (context.getAttribute(CLASS_INHERITANCE_MAP) == null) {
//MultiMap<String> map = new MultiMap<>();
ConcurrentHashMap<String, ConcurrentHashSet<String>> map = new ClassInheritanceMap();
context.setAttribute(CLASS_INHERITANCE_MAP, map);
_classInheritanceHandler = new ClassInheritanceHandler(map);
}
for (Class<?> c : classes) {
//register a handler for it
if (c.isAnnotation()) {
if (LOG.isDebugEnabled())
LOG.debug("Registering annotation handler for " + c.getName());
_containerInitializerAnnotationHandlers.add(new ContainerInitializerAnnotationHandler(initializer, c));
}
}
} else {
initializer = new ContainerInitializer(service, null);
if (LOG.isDebugEnabled())
LOG.debug("No classes in HandlesTypes on initializer " + service.getClass());
}
} else {
initializer = new ContainerInitializer(service, null);
if (LOG.isDebugEnabled())
LOG.debug("No HandlesTypes annotation on initializer " + service.getClass());
}
initializers.add(initializer);
}
//add a bean to the context which will call the servletcontainerinitializers when appropriate
ServletContainerInitializersStarter starter = (ServletContainerInitializersStarter) context.getAttribute(CONTAINER_INITIALIZER_STARTER);
if (starter != null)
throw new IllegalStateException("ServletContainerInitializersStarter already exists");
starter = new ServletContainerInitializersStarter(context);
context.setAttribute(CONTAINER_INITIALIZER_STARTER, starter);
context.addBean(starter, true);
}
use of org.eclipse.jetty.plus.annotation.ContainerInitializer in project jetty.project by eclipse.
the class AnnotationConfiguration method configure.
/**
* @see org.eclipse.jetty.webapp.AbstractConfiguration#configure(org.eclipse.jetty.webapp.WebAppContext)
*/
@Override
public void configure(WebAppContext context) throws Exception {
context.getObjectFactory().addDecorator(new AnnotationDecorator(context));
if (!context.getMetaData().isMetaDataComplete()) {
//If metadata isn't complete, if this is a servlet 3 webapp or isConfigDiscovered is true, we need to search for annotations
if (context.getServletContext().getEffectiveMajorVersion() >= 3 || context.isConfigurationDiscovered()) {
_discoverableAnnotationHandlers.add(new WebServletAnnotationHandler(context));
_discoverableAnnotationHandlers.add(new WebFilterAnnotationHandler(context));
_discoverableAnnotationHandlers.add(new WebListenerAnnotationHandler(context));
}
}
//Regardless of metadata, if there are any ServletContainerInitializers with @HandlesTypes, then we need to scan all the
//classes so we can call their onStartup() methods correctly
createServletContainerInitializerAnnotationHandlers(context, getNonExcludedInitializers(context));
if (!_discoverableAnnotationHandlers.isEmpty() || _classInheritanceHandler != null || !_containerInitializerAnnotationHandlers.isEmpty())
scanForAnnotations(context);
// Resolve container initializers
List<ContainerInitializer> initializers = (List<ContainerInitializer>) context.getAttribute(AnnotationConfiguration.CONTAINER_INITIALIZERS);
if (initializers != null && initializers.size() > 0) {
Map<String, Set<String>> map = (Map<String, Set<String>>) context.getAttribute(AnnotationConfiguration.CLASS_INHERITANCE_MAP);
for (ContainerInitializer i : initializers) i.resolveClasses(context, map);
}
}
use of org.eclipse.jetty.plus.annotation.ContainerInitializer in project jetty.project by eclipse.
the class QuickStartDescriptorProcessor method visitContextParam.
/**
* Process a context-param element
* @param context the webapp
* @param descriptor the xml file to process
* @param node the context-param node in the xml file
* @throws Exception
*/
public void visitContextParam(WebAppContext context, Descriptor descriptor, XmlParser.Node node) throws Exception {
String name = node.getString("param-name", false, true);
String value = node.getString("param-value", false, true);
List<String> values = new ArrayList<>();
// extract values
switch(name) {
case QuickStartDescriptorGenerator.ORIGIN:
{
//value already contains what we need
break;
}
case ServletContext.ORDERED_LIBS:
case AnnotationConfiguration.CONTAINER_INITIALIZERS:
case MetaInfConfiguration.METAINF_TLDS:
case MetaInfConfiguration.METAINF_RESOURCES:
{
context.removeAttribute(name);
QuotedStringTokenizer tok = new QuotedStringTokenizer(value, ",");
while (tok.hasMoreElements()) values.add(tok.nextToken().trim());
break;
}
default:
values.add(value);
}
AttributeNormalizer normalizer = new AttributeNormalizer(context.getBaseResource());
// handle values
switch(name) {
case QuickStartDescriptorGenerator.ORIGIN:
{
context.setAttribute(QuickStartDescriptorGenerator.ORIGIN, value);
break;
}
case ServletContext.ORDERED_LIBS:
{
List<Object> libs = new ArrayList<>();
Object o = context.getAttribute(ServletContext.ORDERED_LIBS);
if (o instanceof Collection<?>)
libs.addAll((Collection<?>) o);
libs.addAll(values);
if (libs.size() > 0)
context.setAttribute(ServletContext.ORDERED_LIBS, libs);
break;
}
case AnnotationConfiguration.CONTAINER_INITIALIZERS:
{
for (String i : values) visitContainerInitializer(context, new ContainerInitializer(Thread.currentThread().getContextClassLoader(), i));
break;
}
case MetaInfConfiguration.METAINF_TLDS:
{
List<Object> tlds = new ArrayList<>();
Object o = context.getAttribute(MetaInfConfiguration.METAINF_TLDS);
if (o instanceof Collection<?>)
tlds.addAll((Collection<?>) o);
for (String i : values) {
Resource r = Resource.newResource(normalizer.expand(i));
if (r.exists())
tlds.add(r.getURI().toURL());
else
throw new IllegalArgumentException("TLD not found: " + r);
}
//empty list signals that tlds were prescanned but none found.
//a missing METAINF_TLDS attribute means that prescanning was not done.
context.setAttribute(MetaInfConfiguration.METAINF_TLDS, tlds);
break;
}
case MetaInfConfiguration.METAINF_RESOURCES:
{
for (String i : values) {
Resource r = Resource.newResource(normalizer.expand(i));
if (r.exists())
visitMetaInfResource(context, r);
else
throw new IllegalArgumentException("Resource not found: " + r);
}
break;
}
default:
}
}
use of org.eclipse.jetty.plus.annotation.ContainerInitializer in project Openfire by igniterealtime.
the class AdminConsolePlugin method createWebAppContext.
private void createWebAppContext() {
WebAppContext context;
// Add web-app. Check to see if we're in development mode. If so, we don't
// add the normal web-app location, but the web-app in the project directory.
boolean developmentMode = Boolean.getBoolean("developmentMode");
if (developmentMode) {
System.out.println(LocaleUtils.getLocalizedString("admin.console.devmode"));
context = new WebAppContext(contexts, pluginDir.getParentFile().getParentFile().getParentFile().getParent() + File.separator + "src" + File.separator + "web", "/");
} else {
context = new WebAppContext(contexts, pluginDir.getAbsoluteFile() + File.separator + "webapp", "/");
}
// Ensure the JSP engine is initialized correctly (in order to be able to cope with Tomcat/Jasper precompiled JSPs).
final List<ContainerInitializer> initializers = new ArrayList<>();
initializers.add(new ContainerInitializer(new JasperInitializer(), null));
context.setAttribute("org.eclipse.jetty.containerInitializers", initializers);
context.setAttribute(InstanceManager.class.getName(), new SimpleInstanceManager());
// The index.html includes a redirect to the index.jsp and doesn't bypass
// the context security when in development mode
context.setWelcomeFiles(new String[] { "index.html" });
// Make sure the context initialization is done when in development mode
if (developmentMode) {
context.addBean(new ServletContainerInitializersStarter(context), true);
}
}
use of org.eclipse.jetty.plus.annotation.ContainerInitializer in project jetty.project by eclipse.
the class QuickStartDescriptorProcessor method visitContainerInitializer.
public void visitContainerInitializer(WebAppContext context, ContainerInitializer containerInitializer) {
if (containerInitializer == null)
return;
//add the ContainerInitializer to the list of container initializers
List<ContainerInitializer> containerInitializers = (List<ContainerInitializer>) context.getAttribute(AnnotationConfiguration.CONTAINER_INITIALIZERS);
if (containerInitializers == null) {
containerInitializers = new ArrayList<ContainerInitializer>();
context.setAttribute(AnnotationConfiguration.CONTAINER_INITIALIZERS, containerInitializers);
}
containerInitializers.add(containerInitializer);
//Ensure a bean is set up on the context that will invoke the ContainerInitializers as the context starts
ServletContainerInitializersStarter starter = (ServletContainerInitializersStarter) context.getAttribute(AnnotationConfiguration.CONTAINER_INITIALIZER_STARTER);
if (starter == null) {
starter = new ServletContainerInitializersStarter(context);
context.setAttribute(AnnotationConfiguration.CONTAINER_INITIALIZER_STARTER, starter);
context.addBean(starter, true);
}
}
Aggregations