Clover Coverage Report - KS Common Util 1.2.1-SNAPSHOT
Coverage timestamp: Wed Nov 2 2011 05:02:05 EST
../../../../../img/srcFileCovDistChart0.png 40% of files have more coverage
30   128   16   2.5
6   87   0.53   6
12     1.33  
2    
 
  ServletWrappingController       Line # 40 26 0% 12 40 0% 0.0
  ServletWrappingController.DelegatingServletConfig       Line # 110 4 0% 4 8 0% 0.0
 
No Tests
 
1    /**
2    * Copyright 2010 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10    * software distributed under the License is distributed on an "AS IS"
11    * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12    * or implied. See the License for the specific language governing
13    * permissions and limitations under the License.
14    */
15   
16    package org.kuali.student.common.ws;
17   
18    import java.util.Enumeration;
19    import java.util.Properties;
20   
21    import javax.servlet.Servlet;
22    import javax.servlet.ServletConfig;
23    import javax.servlet.ServletContext;
24    import javax.servlet.http.HttpServletRequest;
25    import javax.servlet.http.HttpServletResponse;
26   
27    import org.apache.log4j.Logger;
28    import org.springframework.beans.factory.BeanNameAware;
29    import org.springframework.beans.factory.DisposableBean;
30    import org.springframework.beans.factory.InitializingBean;
31    import org.springframework.web.servlet.ModelAndView;
32    import org.springframework.web.servlet.mvc.AbstractController;
33   
34    /**
35    * Spring Controller implementation that mimics standard
36    * ServletWrappingController behaviour (see its documentation), but with the
37    * important difference that it doesn't instantiate the Servlet instance
38    * directly but delegate for this the BeanContext, so that we can also use IoC.*
39    */
 
40    public class ServletWrappingController extends AbstractController implements
41    BeanNameAware, InitializingBean, DisposableBean {
42    private Class<? extends Servlet> servletClass;
43    private String servletName;
44    private Properties initParameters = new Properties();
45    private String beanName;
46    private Servlet servletInstance;
47   
48    private static org.apache.log4j.Logger log = Logger.getLogger(ServletWrappingController.class);
49   
50   
 
51  0 toggle public void setServletClass(Class<? extends Servlet> servletClass) {
52  0 log.info("setServletClass : " + servletClass);
53  0 this.servletClass = servletClass;
54    }
55   
 
56  0 toggle public void setServletName(String servletName) {
57  0 log.info("setServletName : " + servletName);
58  0 this.servletName = servletName;
59    }
60   
 
61  0 toggle public void setInitParameters(Properties initParameters) {
62  0 log.info("setInitParameters : " + initParameters);
63  0 this.initParameters = initParameters;
64    }
65   
 
66  0 toggle public void setBeanName(String name) {
67  0 log.info("setBeanName : " + name);
68  0 this.beanName = name;
69    }
70   
 
71  0 toggle public void setServletInstance(Servlet servletInstance) {
72  0 log.info("setServletInstance : " + servletInstance);
73  0 this.servletInstance = servletInstance;
74    }
75   
 
76  0 toggle public void afterPropertiesSet() throws Exception {
77  0 log.info("afterPropertiesSet");
78  0 if (this.servletInstance == null) {
79  0 throw new IllegalArgumentException("servletInstance is required");
80    }
81  0 if (!Servlet.class.isAssignableFrom(servletInstance.getClass())) {
82  0 throw new IllegalArgumentException("servletInstance ["
83    + this.servletClass.getName()
84    + "] needs to implement interface [javax.servlet.Servlet]");
85    }
86  0 if (this.servletName == null) {
87  0 this.servletName = this.beanName;
88    }
89  0 this.servletInstance.init(new DelegatingServletConfig());
90    }
91   
 
92  0 toggle protected ModelAndView handleRequestInternal(HttpServletRequest request,
93    HttpServletResponse response) throws Exception {
94  0 log.info("handleRequestInternal : " + servletName);
95  0 try{
96  0 this.servletInstance.service(request, response);
97    }catch(Exception e){
98  0 log.error(e.getMessage());
99  0 throw e;
100    }
101   
102  0 return null;
103    }
104   
 
105  0 toggle public void destroy() {
106  0 log.info("destroy : " + servletName);
107  0 this.servletInstance.destroy();
108    }
109   
 
110    private class DelegatingServletConfig implements ServletConfig {
 
111  0 toggle public String getServletName() {
112  0 return servletName;
113    }
114   
 
115  0 toggle public ServletContext getServletContext() {
116  0 return getWebApplicationContext().getServletContext();
117    }
118   
 
119  0 toggle public String getInitParameter(String paramName) {
120  0 return initParameters.getProperty(paramName);
121   
122    }
123   
 
124  0 toggle public Enumeration<?> getInitParameterNames() {
125  0 return initParameters.keys();
126    }
127    }
128    }