spring-webmvc

org.springframework.web.servlet.mvc
Class ServletWrappingController

java.lang.Object
  extended by org.springframework.context.support.ApplicationObjectSupport
      extended by org.springframework.web.context.support.WebApplicationObjectSupport
          extended by org.springframework.web.servlet.support.WebContentGenerator
              extended by org.springframework.web.servlet.mvc.AbstractController
                  extended by org.springframework.web.servlet.mvc.ServletWrappingController
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware, org.springframework.web.context.ServletContextAware, Controller

public class ServletWrappingController
extends AbstractController
implements org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean

Spring Controller implementation that wraps a servlet instance which it manages internally. Such a wrapped servlet is not known outside of this controller; its entire lifecycle is covered here (in contrast to ServletForwardingController).

Useful to invoke an existing servlet via Spring's dispatching infrastructure, for example to apply Spring HandlerInterceptors to its requests.

Note that Struts has a special requirement in that it parses web.xml to find its servlet mapping. Therefore, you need to specify the DispatcherServlet's servlet name as "servletName" on this controller, so that Struts finds the DispatcherServlet's mapping (thinking that it refers to the ActionServlet).

Example: a DispatcherServlet XML context, forwarding "*.do" to the Struts ActionServlet wrapped by a ServletWrappingController. All such requests will go through the configured HandlerInterceptor chain (e.g. an OpenSessionInViewInterceptor). From the Struts point of view, everything will work as usual.

 <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
   <property name="interceptors">
     <list>
       <ref bean="openSessionInViewInterceptor"/>
     </list>
   </property>
   <property name="mappings">
     <props>
       <prop key="*.do">strutsWrappingController</prop>
     </props>
   </property>
 </bean>

 <bean id="strutsWrappingController" class="org.springframework.web.servlet.mvc.ServletWrappingController">
   <property name="servletClass">
     <value>org.apache.struts.action.ActionServlet</value>
   </property>
   <property name="servletName">
     <value>action</value>
   </property>
   <property name="initParameters">
     <props>
       <prop key="config">/WEB-INF/struts-config.xml</prop>
     </props>
   </property>
 </bean>

Since:
1.1.1
Author:
Juergen Hoeller
See Also:
ServletForwardingController, org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor, org.springframework.orm.hibernate3.support.OpenSessionInViewFilter, org.springframework.orm.jdo.support.OpenPersistenceManagerInViewInterceptor, org.springframework.orm.jdo.support.OpenPersistenceManagerInViewFilter

Field Summary
 
Fields inherited from class org.springframework.web.servlet.support.WebContentGenerator
METHOD_GET, METHOD_HEAD, METHOD_POST
 
Fields inherited from class org.springframework.context.support.ApplicationObjectSupport
logger
 
Constructor Summary
ServletWrappingController()
           
 
Method Summary
 void afterPropertiesSet()
          Initialize the wrapped Servlet instance.
 void destroy()
          Destroy the wrapped Servlet instance.
protected  ModelAndView handleRequestInternal(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Invoke the the wrapped Servlet instance.
 void setBeanName(java.lang.String name)
           
 void setInitParameters(java.util.Properties initParameters)
          Specify init parameters for the servlet to wrap, as name-value pairs.
 void setServletClass(java.lang.Class servletClass)
          Set the class of the servlet to wrap.
 void setServletName(java.lang.String servletName)
          Set the name of the servlet to wrap.
 
Methods inherited from class org.springframework.web.servlet.mvc.AbstractController
handleRequest, isSynchronizeOnSession, setSynchronizeOnSession
 
Methods inherited from class org.springframework.web.servlet.support.WebContentGenerator
applyCacheSeconds, applyCacheSeconds, cacheForSeconds, cacheForSeconds, checkAndPrepare, checkAndPrepare, getCacheSeconds, getSupportedMethods, isRequireSession, isUseCacheControlHeader, isUseCacheControlNoStore, isUseExpiresHeader, preventCaching, setCacheSeconds, setRequireSession, setSupportedMethods, setUseCacheControlHeader, setUseCacheControlNoStore, setUseExpiresHeader
 
Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext
 
Methods inherited from class org.springframework.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, initApplicationContext, requiredContextClass, setApplicationContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServletWrappingController

public ServletWrappingController()
Method Detail

setServletClass

public void setServletClass(java.lang.Class servletClass)
Set the class of the servlet to wrap. Needs to implement javax.servlet.Servlet.

See Also:
Servlet

setServletName

public void setServletName(java.lang.String servletName)
Set the name of the servlet to wrap. Default is the bean name of this controller.


setInitParameters

public void setInitParameters(java.util.Properties initParameters)
Specify init parameters for the servlet to wrap, as name-value pairs.


setBeanName

public void setBeanName(java.lang.String name)
Specified by:
setBeanName in interface org.springframework.beans.factory.BeanNameAware

afterPropertiesSet

public void afterPropertiesSet()
                        throws java.lang.Exception
Initialize the wrapped Servlet instance.

Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
Throws:
java.lang.Exception
See Also:
Servlet.init(javax.servlet.ServletConfig)

handleRequestInternal

protected ModelAndView handleRequestInternal(javax.servlet.http.HttpServletRequest request,
                                             javax.servlet.http.HttpServletResponse response)
                                      throws java.lang.Exception
Invoke the the wrapped Servlet instance.

Specified by:
handleRequestInternal in class AbstractController
Throws:
java.lang.Exception
See Also:
Servlet.service(javax.servlet.ServletRequest, javax.servlet.ServletResponse)

destroy

public void destroy()
Destroy the wrapped Servlet instance.

Specified by:
destroy in interface org.springframework.beans.factory.DisposableBean
See Also:
Servlet.destroy()

spring-webmvc