Search in sources :

Example 6 with Descriptor

use of org.eclipse.jetty.webapp.Descriptor in project jetty.project by eclipse.

the class PlusDescriptorProcessorTest method testMismatchedFragmentResourceDeclarations.

@Test
public void testMismatchedFragmentResourceDeclarations() throws Exception {
    //if declared in more than 1 fragment, declarations must be the same
    ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(context.getClassLoader());
    try {
        PlusDescriptorProcessor pdp = new PlusDescriptorProcessor();
        pdp.process(context, fragDescriptor1);
        Descriptor d = context.getMetaData().getOriginDescriptor("resource-ref.jdbc/mydatasource");
        assertNotNull(d);
        assertTrue(d == fragDescriptor1);
        assertEquals(Origin.WebFragment, context.getMetaData().getOrigin("resource-ref.jdbc/mydatasource"));
        pdp.process(context, fragDescriptor2);
        fail("Expected conflicting resource-ref declaration");
    } catch (Exception e) {
    //expected
    } finally {
        Thread.currentThread().setContextClassLoader(oldLoader);
    }
}
Also used : WebAppClassLoader(org.eclipse.jetty.webapp.WebAppClassLoader) Descriptor(org.eclipse.jetty.webapp.Descriptor) FragmentDescriptor(org.eclipse.jetty.webapp.FragmentDescriptor) WebDescriptor(org.eclipse.jetty.webapp.WebDescriptor) InvocationTargetException(java.lang.reflect.InvocationTargetException) Test(org.junit.Test)

Example 7 with Descriptor

use of org.eclipse.jetty.webapp.Descriptor in project jetty.project by eclipse.

the class RunAsAnnotationHandler method doHandle.

public void doHandle(Class clazz) {
    if (!Servlet.class.isAssignableFrom(clazz))
        return;
    javax.annotation.security.RunAs runAs = (javax.annotation.security.RunAs) clazz.getAnnotation(javax.annotation.security.RunAs.class);
    if (runAs != null) {
        String role = runAs.value();
        if (role != null) {
            ServletHolder holder = getServletHolderForClass(clazz);
            if (holder != null) {
                MetaData metaData = _context.getMetaData();
                Descriptor d = metaData.getOriginDescriptor(holder.getName() + ".servlet.run-as");
                //let the annotation override it
                if (d == null) {
                    metaData.setOrigin(holder.getName() + ".servlet.run-as", runAs, clazz);
                    org.eclipse.jetty.plus.annotation.RunAs ra = new org.eclipse.jetty.plus.annotation.RunAs();
                    ra.setTargetClassName(clazz.getCanonicalName());
                    ra.setRoleName(role);
                    RunAsCollection raCollection = (RunAsCollection) _context.getAttribute(RunAsCollection.RUNAS_COLLECTION);
                    if (raCollection == null) {
                        raCollection = new RunAsCollection();
                        _context.setAttribute(RunAsCollection.RUNAS_COLLECTION, raCollection);
                    }
                    raCollection.add(ra);
                }
            }
        } else
            LOG.warn("Bad value for @RunAs annotation on class " + clazz.getName());
    }
}
Also used : ServletHolder(org.eclipse.jetty.servlet.ServletHolder) RunAsCollection(org.eclipse.jetty.plus.annotation.RunAsCollection) MetaData(org.eclipse.jetty.webapp.MetaData) Servlet(javax.servlet.Servlet) Descriptor(org.eclipse.jetty.webapp.Descriptor)

Example 8 with Descriptor

use of org.eclipse.jetty.webapp.Descriptor in project jetty.project by eclipse.

the class MultiPartConfigAnnotationHandler method doHandle.

/** 
     * @see org.eclipse.jetty.annotations.AnnotationIntrospector.AbstractIntrospectableAnnotationHandler#doHandle(java.lang.Class)
     */
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();
    //TODO: The MultipartConfigElement needs to be set on the ServletHolder's Registration.
    //How to identify the correct Servlet?  If the Servlet has no WebServlet annotation on it, does it mean that this MultipartConfig
    //annotation applies to all declared instances in web.xml/programmatically?
    //Assuming TRUE for now.
    ServletHolder holder = getServletHolderForClass(clazz);
    if (holder != null) {
        Descriptor d = metaData.getOriginDescriptor(holder.getName() + ".servlet.multipart-config");
        //let the annotation override it
        if (d == null) {
            metaData.setOrigin(holder.getName() + ".servlet.multipart-config", multi, clazz);
            holder.getRegistration().setMultipartConfig(new MultipartConfigElement(multi));
        }
    }
}
Also used : MultipartConfigElement(javax.servlet.MultipartConfigElement) MultipartConfig(javax.servlet.annotation.MultipartConfig) MetaData(org.eclipse.jetty.webapp.MetaData) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) Servlet(javax.servlet.Servlet) Descriptor(org.eclipse.jetty.webapp.Descriptor)

Example 9 with Descriptor

use of org.eclipse.jetty.webapp.Descriptor in project jetty.project by eclipse.

the class PlusDescriptorProcessorTest method testMatchingFragmentResourceDeclarations.

@Test
public void testMatchingFragmentResourceDeclarations() throws Exception {
    //if declared in more than 1 fragment, declarations must be the same
    ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(context.getClassLoader());
    try {
        PlusDescriptorProcessor pdp = new PlusDescriptorProcessor();
        pdp.process(context, fragDescriptor1);
        Descriptor d = context.getMetaData().getOriginDescriptor("resource-ref.jdbc/mydatasource");
        assertNotNull(d);
        assertTrue(d == fragDescriptor1);
        assertEquals(Origin.WebFragment, context.getMetaData().getOrigin("resource-ref.jdbc/mydatasource"));
        pdp.process(context, fragDescriptor3);
    } finally {
        Thread.currentThread().setContextClassLoader(oldLoader);
    }
}
Also used : WebAppClassLoader(org.eclipse.jetty.webapp.WebAppClassLoader) Descriptor(org.eclipse.jetty.webapp.Descriptor) FragmentDescriptor(org.eclipse.jetty.webapp.FragmentDescriptor) WebDescriptor(org.eclipse.jetty.webapp.WebDescriptor) Test(org.junit.Test)

Aggregations

Descriptor (org.eclipse.jetty.webapp.Descriptor)9 FragmentDescriptor (org.eclipse.jetty.webapp.FragmentDescriptor)7 Origin (org.eclipse.jetty.webapp.Origin)4 Iterator (java.util.Iterator)3 WebAppClassLoader (org.eclipse.jetty.webapp.WebAppClassLoader)3 WebDescriptor (org.eclipse.jetty.webapp.WebDescriptor)3 XmlParser (org.eclipse.jetty.xml.XmlParser)3 Test (org.junit.Test)3 Servlet (javax.servlet.Servlet)2 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)2 MetaData (org.eclipse.jetty.webapp.MetaData)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MultipartConfigElement (javax.servlet.MultipartConfigElement)1 MultipartConfig (javax.servlet.annotation.MultipartConfig)1 RunAsCollection (org.eclipse.jetty.plus.annotation.RunAsCollection)1