2 Replies Latest reply on Feb 28, 2013 6:28 AM by jmnarloch

    Improving Warp Spring MVC

    jmnarloch

      Lately, I had been thinking about bringing some functionalitites of Spring 3 into the Warp Spring MVC extension.

       

      Current the extension is being compiled against Spring 2.5.6. In order not to brake the it's compatiblity with older Spring versions I have been thinking about creating new seperate artifact that could target new Spring versions or doing a little hack in the implemntationm so that it could detect which Spring version has been registered in classpath and package appropiate classes.

       

      Either way I was thinking about introducing fallowing changes.

       

      • Idea 1. Programmatically configuring the ApplicationContext in WarpDispatcherServlet, so that it could be used with together with WebApplicationInitializer in no descriptor deployments scenarios. i.e.

                        Note: Current version always loads the [name]-servlet.xml from WEB-INF directory.

       

      {code}

      public class EmployeeWebInitializer implements WebApplicationInitializer {

       

          public void onStartup(ServletContext servletContext) throws ServletException {

       

              // creates the web app context

              AnnotationConfigWebApplicationContext webContext = new AnnotationConfigWebApplicationContext();

              webContext.register(WebAppConfig.class);

       

              // registers a warp dispatcher servlet

              ServletRegistration.Dynamic servletConfig = servletContext.addServlet("warp-servlet", new WarpDispatcherServlet(webContext));

              servletConfig.setLoadOnStartup(1);

              servletConfig.addMapping("*.htm");

          }

      }

       

      {code}

       

      • Idea 2. The issue could also approached a little bit differently. We could introduce a implementation of HandlerInterceptor that could be registered within Spring context directly. This way we would have solution that works with any Spring version and also brings alternative way for capturing the execution context. Although the interceptor has it's limitations, it's being registered within the execution chain and there is no guarantee that the interceptor will be always invoked.

       

      The intercetor would be configured in the xml file.

       

      {code}

      <beans>

          <mvc:annotation-driven/>

       

          <mvc:interceptors>

              <bean class="org.jboss.arquillian.warp.extension.spring.interceptor.WarpHandlerInterceptor"/>

          </mvc:interceptors>

      </beans>

      {code}

       

      • Idea 2. A) As an extension to this idea we could include nice little shortcut in a form of schema based configuration:

       

      {code}

      <beans>

          <mvc:annotation-driven/>

       

          <warp:enable-interception />

      </beans>

      {code}

       

       

      • Idea 2. B) Or in caase we would also target Spring 3 and it's java based configuration, additional handy annotation could be introduced.

       

      {code}

      @EnableWarp

      @EnableWebMvc

      @Configuration

      public class ContextConfiguration {

        ...

      }

      {code}

       

      All of that would enalbe to resgister the Warp extension, without modyfing the web.xml settings, and running the tests in plain Spring DispatcherServlet.

      Potentialy in Spring 3.1 one could use profiles to prepare test configuration in which Warp will be enabled.

        • 1. Re: Improving Warp Spring MVC
          meetoblivion

          Jakub,

           

          Is it possible to provide Spring3 support in a separate JAR, so that people who may be on Spring 2.5 or higher don't have to upgrade, but if they want to use the new spring 3 features they simply bring in an extra dependency?

          • 2. Re: Improving Warp Spring MVC
            jmnarloch

            Hi John,

             

            Yes, that was exactly I was thinking about. The current spring-warp could maintain it's compabilitity with Spring 2.5. For all of the new features that targets Spring 3 and above we could introduce new artificat.