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