Java Code Examples for org.eclipse.jetty.webapp.MetaData

Following code examples demonstrate how to use org.eclipse.jetty.webapp.MetaData from jetty. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.eclipse.jetty.webapp.MetaData and various code implementation of this class.
Example 1
Project : jetty Source File : MultiPartConfigAnnotationHandler.java View Source Code on GitHub

    
    public void doHandle(Class clazz)
    {
        if (!Servlet.class.isAssignableFrom(clazz))
            return;
        
        MultipartConfig multi = (MultipartConfig) clazz.getAnnotation(MultipartConfig.class);
        if (multi == null)
            return;
        
        MetaData metaData = _context.getMetaData();
              

        ServletHolder holder = getServletHolderForClass(clazz);
        if (holder != null)
        {
            Descriptor d = metaData.getOriginDescriptor(holder.getName()+".servlet.multipart-config");
            if (d == null)
            {
                metaData.setOrigin(holder.getName()+".servlet.multipart-config",multi,clazz);
                holder.getRegistration().setMultipartConfig(new MultipartConfigElement(multi));
            }
        }
    }
			
Example 2
Project : jetty Source File : WebListenerAnnotation.java View Source Code on GitHub

    
    public void apply()
    {
        Class<? extends java.util.EventListener> clazz = (Class<? extends EventListener>)getTargetClass();

        if (clazz == null)
        {
            LOG.warn(_className+" cannot be loaded");
            return;
        }

        try
        {
            if (ServletContextListener.class.isAssignableFrom(clazz) ||
                    ServletContextAttributeListener.class.isAssignableFrom(clazz) ||
                    ServletRequestListener.class.isAssignableFrom(clazz) ||
                    ServletRequestAttributeListener.class.isAssignableFrom(clazz) ||
                    HttpSessionListener.class.isAssignableFrom(clazz) ||
                    HttpSessionAttributeListener.class.isAssignableFrom(clazz) ||
                    HttpSessionIdListener.class.isAssignableFrom(clazz))
            {
                java.util.EventListener listener = (java.util.EventListener)_context.getServletContext().createInstance(clazz);      
                MetaData metaData = _context.getMetaData();
                if (metaData.getOrigin(clazz.getName()+".listener") == Origin.NotSet)
                {
                    ListenerHolder h = _context.getServletHandler().newListenerHolder(new Source(Source.Origin.ANNOTATION, clazz.getName()));
                    h.setListener(listener);
                    _context.getServletHandler().addListener(h);
                    _context.addEventListener(listener);
                }
            }
            else
                LOG.warn(clazz.getName()+" does not implement one of the servlet listener interfaces");
        }
        catch (Exception e)
        {
            LOG.warn(e);
        }
    }
			
Example 3
Project : jetty Source File : PreDestroyAnnotationHandler.java View Source Code on GitHub

    }

    public void doHandle(Class clazz)
    {
        if (Util.supportsPostConstructPreDestroy(clazz))
        {
            Method[] methods = clazz.getDeclaredMethods();
            for (int i=0; i<methods.length; i++)
            {
                Method m = (Method)methods[i];
                if (m.isAnnotationPresent(PreDestroy.class))
                {
                    if (m.getParameterTypes().length != 0)
                        throw new IllegalStateException(m+" has parameters");
                    if (m.getReturnType() != Void.TYPE)
                        throw new IllegalStateException(m+" is not void");
                    if (m.getExceptionTypes().length != 0)
                        throw new IllegalStateException(m+" throws checked exceptions");
                    if (Modifier.isStatic(m.getModifiers()))
                        throw new IllegalStateException(m+" is static");

                    MetaData metaData = _context.getMetaData();
                    Origin origin = metaData.getOrigin("pre-destroy");
                    if (origin != null &&
                            (origin == Origin.WebXml ||
                             origin == Origin.WebDefaults ||
                             origin == Origin.WebOverride))
                            return;

                    PreDestroyCallback callback = new PreDestroyCallback();
                    callback.setTarget(clazz.getName(), m.getName());

                    LifeCycleCallbackCollection lifecycles = (LifeCycleCallbackCollection)_context.getAttribute(LifeCycleCallbackCollection.LIFECYCLE_CALLBACK_COLLECTION);
                    if (lifecycles == null)
                    {
                        lifecycles = new LifeCycleCallbackCollection();
                        _context.setAttribute(LifeCycleCallbackCollection.LIFECYCLE_CALLBACK_COLLECTION, lifecycles);
                    }

                    lifecycles.add(callback);
                }
            }
        }
    }
			
Example 4
Project : jetty Source File : MavenAnnotationConfiguration.java View Source Code on GitHub

    @Override
    public void parseWebInfClasses(final WebAppContext context, final AnnotationParser parser) throws Exception
    {
        JettyWebAppContext jwac = (JettyWebAppContext)context;
        if (jwac.getClassPathFiles() == null)
            super.parseWebInfClasses (context, parser);
        else
        {
            Log.debug("Scanning classes ");
            
            MetaData metaData = context.getMetaData();
            if (metaData == null)
               throw new IllegalStateException ("No metadata");

            clearAnnotationList(parser.getAnnotationHandlers());    

            for (File f:jwac.getClassPathFiles())
            {
                if (f.isDirectory() && f.exists())
                {
                    parser.parse(Resource.newResource(f.toURL()), 
                                new ClassNameResolver()
                    {
                        public boolean isExcluded (String name)
                        {
                            if (context.isSystemClass(name)) return true;
                            if (context.isServerClass(name)) return false;
                            return false;
                        }

                        public boolean shouldOverride (String name)
                        {
                            if (context.isParentLoaderPriority())
                                return false;
                            return true;
                        }
                    });
                }
            }
            List<DiscoveredAnnotation> annotations = new ArrayList<DiscoveredAnnotation>();
            gatherAnnotations(annotations, parser.getAnnotationHandlers());
            metaData.addDiscoveredAnnotations (annotations);
        }
    }
			
Example 5
Project : jetty Source File : FragmentFolderConfiguration.java View Source Code on GitHub

    public void findWebFragments(WebAppContext context, MetaData metaData) throws Exception {
        final List<Resource> frags = (List<Resource>) context.getAttribute(FRAGMENT_RESOURCES);
        if (frags != null) {
            for (final Resource frag : frags) {
                final Resource parentResource = Util.chop(frag.getURL(), "/META-INF/web-fragment.xml");
                metaData.addFragment(parentResource, frag);
            }
        }
    }
			
Example 6
Project : jetty Source File : NonWarConfiguration.java View Source Code on GitHub

    public void preConfigure(WebAppContext context) throws Exception {
        
        MetaData meta = context.getMetaData();
        
        Resource baseResource = context.getBaseResource();
        
        addFiles(baseResource, meta);
        
    }
			
Example 7
Project : jetty Source File : NonWarConfiguration.java View Source Code on GitHub

    private void addFiles(Resource dir, MetaData meta) {
        for(String filePath : dir.list()) {
            try {
                Resource file = dir.addPath(filePath);
                
                if(file.getName().endsWith(".jar")) {
                    if(webInfJarsToInclude == null || webInfJarsToInclude.contains(file.getFile().getName())) {
                        System.out.println("Adding: "+file);
                        meta.addWebInfJar(file);
                    }
                } else if(file.isDirectory()) {
                    addFiles(file, meta);
                }
            } catch(Exception e) {
                System.out.println(""+e);
            }
        }
    }
			
Example 8
Project : jetty Source File : PostConstructAnnotationHandler.java View Source Code on GitHub

    }


    public void doHandle(Class clazz)
    {
        if (Util.supportsPostConstructPreDestroy(clazz))
        {
            Method[] methods = clazz.getDeclaredMethods();
            for (int i=0; i<methods.length; i++)
            {
                Method m = (Method)methods[i];
                if (m.isAnnotationPresent(PostConstruct.class))
                {
                    if (m.getParameterTypes().length != 0)
                        throw new IllegalStateException(m+" has parameters");
                    if (m.getReturnType() != Void.TYPE)
                        throw new IllegalStateException(m+" is not void");
                    if (m.getExceptionTypes().length != 0)
                        throw new IllegalStateException(m+" throws checked exceptions");
                    if (Modifier.isStatic(m.getModifiers()))
                        throw new IllegalStateException(m+" is static");

                    MetaData metaData = _context.getMetaData();
                    Origin origin = metaData.getOrigin("post-construct");
                    if (origin != null &&
                        (origin == Origin.WebXml ||
                         origin == Origin.WebDefaults ||
                         origin == Origin.WebOverride))
                        return;

                    PostConstructCallback callback = new PostConstructCallback();
                    callback.setTarget(clazz.getName(), m.getName());
                    LifeCycleCallbackCollection lifecycles = (LifeCycleCallbackCollection)_context.getAttribute(LifeCycleCallbackCollection.LIFECYCLE_CALLBACK_COLLECTION);
                    if (lifecycles == null)
                    {
                        lifecycles = new LifeCycleCallbackCollection();
                        _context.setAttribute(LifeCycleCallbackCollection.LIFECYCLE_CALLBACK_COLLECTION,lifecycles);
                    }
                    lifecycles.add(callback);
                }
            }
        }
    }