View Javadoc

1   /* ------------------------------------
2    * © Kaamelot - 2006
3    * ------------------------------------
4    * Projet  : KaamelotAddOn
5    * Fichier : BogusDwrPluginServlet.java
6    * Servlet similar as BogusDwrPluginServlet but using 
7    * com.atlassian.jira.servlet.DWRServlet instead of uk.ltd.getahead.dwr.DWRServlet 
8    */
9   package com.atlassian.cache.servlet.resolver;
10  
11  import java.io.IOException;
12  import java.lang.reflect.InvocationTargetException;
13  import java.lang.reflect.Method;
14  
15  import javax.servlet.ServletConfig;
16  import javax.servlet.ServletException;
17  import javax.servlet.http.HttpServlet;
18  import javax.servlet.http.HttpServletRequest;
19  import javax.servlet.http.HttpServletResponse;
20  
21  import com.atlassian.jira.servlet.DWRServlet;
22  
23  import uk.ltd.getahead.dwr.AbstractDWRServlet;
24  
25  public class BogusDwrPluginServlet extends HttpServlet {
26  
27  	/** */
28  	private static final long serialVersionUID = 1L;
29  
30  	protected DWRServlet dwrServlet = new DWRServlet();
31  
32  	public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
33  		try {
34  			Method method = findMethod();
35  			if (method == null) {
36  				throw new ServletException("Could not find doGet");
37  			}
38  			method.invoke(getDwrServlet(), new Object[] { req, resp });
39  		} catch (IllegalAccessException e) {
40  			throw new ServletException("Failed to fake DWR servlet", e);
41  		} catch (InvocationTargetException e) {
42  			throw new ServletException("Failed to fake DWR servlet", e);
43  		}
44  	}
45  
46  	private Method findMethod() {
47  		Method method = null;
48  
49  		Method[] methods = AbstractDWRServlet.class.getDeclaredMethods();
50  		// Method[] methods = DWRServlet.class.getDeclaredMethods(); DWR 1.0
51  		for (int i = 0; i < methods.length; i++) {
52  			Method aMethod = methods[i];
53  			if (aMethod.getName().equals("doGet")) {
54  				aMethod.setAccessible(true);
55  				method = aMethod;
56  				break;
57  			}
58  		}
59  		return method;
60  	}
61  
62  	public void init(ServletConfig config) throws ServletException {
63  		getDwrServlet().init(config);
64  	}
65  
66  	protected DWRServlet getDwrServlet() {
67  		return dwrServlet;
68  	}
69  
70  }