1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.eclipse.jetty.annotations;
15
16 import javax.servlet.MultipartConfigElement;
17 import javax.servlet.Servlet;
18 import javax.servlet.annotation.MultipartConfig;
19
20 import org.eclipse.jetty.annotations.AnnotationIntrospector.AbstractIntrospectableAnnotationHandler;
21 import org.eclipse.jetty.servlet.ServletHolder;
22 import org.eclipse.jetty.webapp.Descriptor;
23 import org.eclipse.jetty.webapp.MetaData;
24 import org.eclipse.jetty.webapp.WebAppContext;
25
26
27
28
29
30
31 public class MultiPartConfigAnnotationHandler extends AbstractIntrospectableAnnotationHandler
32 {
33 protected WebAppContext _context;
34
35 public MultiPartConfigAnnotationHandler(WebAppContext context)
36 {
37
38 super(false);
39 _context = context;
40 }
41
42
43
44 public void doHandle(Class clazz)
45 {
46 if (!Servlet.class.isAssignableFrom(clazz))
47 return;
48
49 MultipartConfig multi = (MultipartConfig) clazz.getAnnotation(MultipartConfig.class);
50 if (multi == null)
51 return;
52
53 MetaData metaData = _context.getMetaData();
54
55
56
57
58
59
60 ServletHolder holder = getServletHolderForClass(clazz);
61 if (holder != null)
62 {
63 Descriptor d = metaData.getOriginDescriptor(holder.getName()+".servlet.multipart-config");
64
65
66 if (d == null)
67 {
68 metaData.setOrigin(holder.getName()+".servlet.multipart-config");
69 holder.getRegistration().setMultipartConfig(new MultipartConfigElement(multi));
70 }
71 }
72 }
73
74 private ServletHolder getServletHolderForClass (Class clazz)
75 {
76 ServletHolder holder = null;
77 ServletHolder[] holders = _context.getServletHandler().getServlets();
78 if (holders != null)
79 {
80 for (ServletHolder h : holders)
81 {
82 if (h.getClassName().equals(clazz.getName()))
83 {
84 holder = h;
85 }
86 }
87 }
88 return holder;
89 }
90 }