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);
}
}
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());
}
}
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));
}
}
}
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);
}
}
Aggregations