Migrating from Struts 1.x to Spring MVC

Similar documents
MVC pattern in java web programming

DTS Web Developers Guide

Tutorial: Building a Web Application with Struts

In this chapter, we lay the foundation for all our further discussions. We start

Complete Java Web Development

Course Name: Course in JSP Course Code: P5

WEB APPLICATION DEVELOPMENT. UNIT I J2EE Platform 9

Development. with NetBeans 5.0. A Quick Start in Basic Web and Struts Applications. Geertjan Wielenga

Research Article. ISSN (Print) *Corresponding author Lili Wang

CrownPeak Java Web Hosting. Version 0.20

Model-View-Controller. and. Struts 2

SSC - Web development Model-View-Controller for Java web application development

Struts Tools Tutorial. Version: M5

Enterprise Application Development In Java with AJAX and ORM

Converting Java EE Applications into OSGi Applications

Web Container Components Servlet JSP Tag Libraries

Web Frameworks and WebWork

How To Understand The Architecture Of Java 2Ee, J2Ee, And J2E (Java) In A Wordpress Blog Post

SPRING INTERVIEW QUESTIONS

Framework Adoption for Java Enterprise Application Development

OUR COURSES 19 November All prices are per person in Swedish Krona. Solid Beans AB Kungsgatan Göteborg Sweden

Portals, Portlets & Liferay Platform

A Comparative Study of Web Development Technologies Using Open Source and Proprietary Software

Design Approaches of Web Application with Efficient Performance in JAVA

Core Java+ J2EE+Struts+Hibernate+Spring

Server-Side Web Development JSP. Today. Web Servers. Static HTML Directives. Actions Comments Tag Libraries Implicit Objects. Apache.

Oracle WebLogic Foundation of Oracle Fusion Middleware. Lawrence Manickam Toyork Systems Inc

HPC Portal Development Platform with E-Business and HPC Portlets

Expert Spring MVC and Web Flow

JBoss SOAP Web Services User Guide. Version: M5

Case Studies of Running the Platform. NetBeans UML Servlet JSP GlassFish EJB

Developing Java Web Applications with Jakarta Struts Framework

An Architecture for Web-based DSS

BIRT Application and BIRT Report Deployment Functional Specification

A Guide to Understanding Web Application Development Corey Benson, SAS Institute, Inc., Cary, NC Robert Girardin, SAS Institute, Inc.

An introduction to creating JSF applications in Rational Application Developer Version 8.0

Client-Server Architecture & J2EE Platform Technologies Overview Ahmed K. Ezzat

Enterprise Applications

Customer Bank Account Management System Technical Specification Document

Japan Communication India Skill Development Center

Simplify Your Web App Development Using the Spring MVC Framework

Core J2EE Patterns, Frameworks and Micro Architectures

JBoss Portlet Container. User Guide. Release 2.0

Beginning POJOs. From Novice to Professional. Brian Sam-Bodden

<Insert Picture Here> Betting Big on JavaServer Faces: Components, Tools, and Tricks

Developing Java Web Services

HPC PORTAL DEVELOPMENT PLATFORM

Web Applications and Struts 2

How to Build an E-Commerce Application using J2EE. Carol McDonald Code Camp Engineer

Glassfish, JAVA EE, Servlets, JSP, EJB

Programma corso di formazione J2EE

Evaluating Presentation Layer Development Frameworks for EJB Applications in J2EE Architecture

New Web Application Development Tool and Its MDA-Based Support Methodology

Performance Comparison of Persistence Frameworks

Developing XML Solutions with JavaServer Pages Technology

Model-View-Controller: A Design Pattern for Software. June 2004

IBM WebSphere Server Administration

Getting Started with Web Applications

A Comparison of Open Source Application Development Frameworks for the Enterprise

WebSphere v5 Administration, Network Deployment Edition

Java EE 7: Back-End Server Application Development

Java technológiák 7. előadás A Struts keretrendszer

Web Frameworks. web development done right. Course of Web Technologies A.A. 2010/2011 Valerio Maggio, PhD Student Prof.

PowerTier Web Development Tools 4

Course Number: IAC-SOFT-WDAD Web Design and Application Development

Web Application Developer s Guide

Parsing Technology and its role in Legacy Modernization. A Metaware White Paper

Operations and Monitoring with Spring

Decomposition into Parts. Software Engineering, Lecture 4. Data and Function Cohesion. Allocation of Functions and Data. Component Interfaces

2012 LABVANTAGE Solutions, Inc. All Rights Reserved.

WebSphere Server Administration Course

Install guide for Websphere 7.0

Understanding class paths in Java EE projects with Rational Application Developer Version 8.0

White Paper: 1) Architecture Objectives: The primary objective of this architecture is to meet the. 2) Architecture Explanation

Course Description. Course Audience. Course Outline. Course Page - Page 1 of 5

The Spring Framework: An Open Source Java Platform for Developing Robust Java Applications

Chapter 1 - Web Server Management and Cluster Topology

zen Platform technical white paper

Java EE Introduction, Content. Component Architecture: Why and How Java EE: Enterprise Java

Pentesting Web Frameworks (preview of next year's SEC642 update)

Web Application Architectures

CS506 Web Design and Development Solved Online Quiz No. 01

Introduction to Apache Roller. Matt Raible Apache Roller Committer June 2007

Web and Enterprise Applications Developer Track

FUSE-ESB4 An open-source OSGi based platform for EAI and SOA

Terms and Definitions for CMS Administrators, Architects, and Developers

NetBeans IDE Field Guide

Java Technology in the Design and Implementation of Web Applications

WEB SERVICES. Revised 9/29/2015

COMPARISON BETWEEN SPRING AND ASP.NET FRAMEWORKS

SOA REFERENCE ARCHITECTURE: WEB TIER

LearningOnWeb development of a SCORM compliant Learning Management System

Commercial software development with the help of J2EE architecture and MVC

Apache Sling A REST-based Web Application Framework Carsten Ziegeler cziegeler@apache.org ApacheCon NA 2014

Automating Rich Internet Application Development for Enterprise Web 2.0 and SOA

Developing Web Applications using JavaServer Pages and Servlets

UBS Training Course Catalog

Transcription:

Migrating from Struts 1.x to Spring MVC Hundekar MohammedJunaid 1, Chavan Santosh 2, Gondikar Shreyas 3, Shah Vaibhav 4 and Dr. Prof. Prasanna Joeg 5 1,2,3,4 Pune University, MIT College of Engineering, MIT Campus, Rambaug Colony, Pune-38, India 5 Professor, MIT College of Engineering, MIT Campus, Rambaug Colony, Pune-38, India Abstract: In the last couple of decades web development is becoming more easier and simpler due to introduction of powerful web application development frameworks. Most of the web application development frameworks offers wide variety of services and features for developers to develop the applications with ease and simplicity. Popular web frameworks include ASP.NET, J2EE, Struts, Spring MVC etc. Every framework has some pros and cons. Developers often migrate from one framework to other according to their requirements for application development. In this paper we included our analysis about the two currently most popular frameworks namely Struts and Spring MVC. As Spring is becoming the choice of developers, we presents several approaches to migrate from Struts applications to Spring MVC. It will be useful to understand the logical mapping between the two frameworks and how to transform Struts applications into Spring MVC applications. The technology direction going forward is to use spring MVC as the basis for the client layer of application. This paper is divided into four sections. First section gives the overview of Struts and Spring frameworks, merits and demerits of these frameworks. Second section briefly concentrates on why it has become essential to migrate from Struts to Spring and the benefits that this migration will offer. Different approaches can be followed to do such migration in framework. In Third Section we discuss about the approaches that can be used for migration in framework. Manually converting any application from one framework to other is always tedious and time consuming task. Manual conversion requires the developer to be expert at both the frameworks, understand the logical mapping between the components of the two different framework, identify project flow and working by going through code. Developers have to invest lot of effort in manual process. To ease the process of migration a Struts application to Spring MVC, we implemented a solution, a tool Framework migrator which will automate the task of migration. Our tool Framework Migrator yields better results in terms of time and cost investment in the process of automation. In final section we focus on framework migrator architecture, analysis about its efficiency and percentage completeness of automation. To fully appreciate the subjects discussed, readers should have a working knowledge of the Struts framework. Keywords: Struts 1.x, Spring MVC, Framework Migrator, Automation in Migration 1. INTRODUCTION Struts: - Apache Struts is an open-source web application framework for developing Java EE web. It uses and extends the Java Servlet API to encourage developers to adopt a Model View Controller (MVC) architecture. Model-View-Controller Architecture:- Figure 1-Model-View-Controller Architecture Model View Controller (MVC) is an architecture that separates the representation of information from the user's interaction with it. The model consists of application data and business rules, and the controller mediates input, converting it to commands for the model or view. A view can be any output representation of data, such as a chart or a diagram. Multiple views of the same data are possible, such as a pie chart for management and a tabular view for accountants. The central idea behind MVC is code reusability and separation of concern [8] [9].Struts component includes ActionForms, Tag libraries, Resource management and Configuration. Struts also provide developers Front controller servlet, Tag libraries for logic and Form binding [10], [13]. However Struts 1.x has some limitations such as: 1. Struts has very rigid inheritance structure, so it limits the reusability of code. This limits the usefulness of struts in complex systems where reusability of code is must. 2. Struts 1.x form the beans and duplicate the existing objects, hence memory requirement is heavy and it introduces redundancy in objects. 3. Struts does not support built in error handling, so errors may occur at inconvenient time. Programmer or Developer has to deal with the tedious task of error Volume 2, Issue 2 March April 2013 Page 156

handling and validation. 4. Testing is the difficult process when working with struts as compared to other alternative technologies available. 5. Struts has confusing naming scheme which makes developers job more complex if developer are working in teams and in distributed environment.[11]. (Note- Some of these limitations are resolved in struts 2 but still application needs to be migrated from struts 1.0 to struts 2.0) Spring MVC:- Spring Framework is an open source application framework and Inversion of Control container for the Java platform. The core features of the Spring Framework can be used by any Java application, but there are extensions for building web applications on top of the Java EE platform. Although the Spring Framework does not impose any specific programming model, it has become popular in the Java community as an alternative to, replacement for, or even addition to the Enterprise JavaBean (EJB) model.[3][12]. Benefits of Spring MVC over Struts:- 1. Spring MVC provides business objects instead of form beans. 2. Spring MVC Supports built in validation and error handling very well, thereby reduces the job of the developer. 3. Flexible mapping to controllers (not just to URL patterns). 4. It allows you to build application on top of spring letting you use one framework/configuration scheme in all tiers. 5. It is easy to use Aspect Oriented Programming (AOP) and other spring features in web tier. 6. It is Compatible with newer technologies and tools [12]. 2. WHY TO MIGRATE Experts in the web frameworks field suggest that the Struts framework has reached the point where its innovation and adoption will start declining. In fact, the Craig McClanahan, chief architect and author of Struts, has left the project for good, and he is actively urging current Struts users to migrate to newer Web frameworks. [14].Meanwhile, in the J2EE Web space, Spring MVC has gained steady adoption and Java developer attention. The highly popular Spring framework (with Spring MVC as its core component) is nicely designed, productive, and innovative, so many Struts users undoubtedly will find Spring MVC as a replacement framework for Struts more useful. Some of the main reasons to migrate from struts to spring:- 1. Better Inheritance Structure: - The Struts design is based on concrete inheritance, meaning that each custom action has to be in an inheritance hierarchy of the Struts Action component. Because Spring controllers are interfaces, any component can play the role of the controller. This gives application designers more flexibility in the design of components. [4] 2. Flexible:- At the framework component level, Struts requires use of Struts-specific objects, such as Form Beans (static or dynamic), Actions, Action Mappings, Action Forwards, and Request Processors. Spring MVC is more flexible, as all its major components are defined as interfaces. 3. Struts Is a Web Framework Only: - Struts addresses only the presentation aspects of application development. On the other hand, Spring MVC is an integral part of the Spring framework, which fully integrates Spring with the rest of the frameworks that manage business components as well as other aspects of Spring enterprise development. 4. No action Forms: - One of the biggest and the most positive differences in the Spring framework is that it has no specialized ActionForm objects. The framework supports binding of HTTP form values directly into POJOs (Plain Old Java Objects). This feature greatly simplifies application maintenance by limiting the number of classes to create and maintain. 5. Future scope: - Spring MVC is compatible with more tools and software and it has bright future, whereas popularity of struts has been steadily declining, while on the other hand Spring MVC is steadily attracting the attention of Java developers. Many large organizations (like IBM), which were working on Struts earlier are migrating to Spring MVC.[12] 3. APPROACHES There are two approaches for migrating struts applications to spring MVC. 1. Integrating struts with spring 2. Complete migration 1. Integrating struts with springs:- This approach focuses on how our current Struts assets can be reused in Spring MVC configuration. Areas to consider are struts implementation classes and configurations, struts tag libraries, struts tiles (used primarily for static content). By learning the existing Struts application and Spring MVC, identify the minimal set of changes required to successfully migrate the functionalities[15]. Both frameworks have their merits and drawbacks. Many development teams have learned to rely on Struts as the foundation for building quality software under strict deadlines. With so much momentum behind Struts, even development teams that would like to integrate features of the Spring framework don't want to switch to Spring MVC. The Spring architecture allows you to connect Struts as your Web framework to Springbased business and persistence layers [15]. One of the major advantages of combining Struts and Spring, and doing it by delegating Struts actions to Volume 2, Issue 2 March April 2013 Page 157

the Spring framework, is that you can apply Spring's AOP interceptors to your Struts actions. By applying Spring interceptors to Struts actions, you can tackle crosscutting concerns with minimal effort. One major disadvantage of this approach is as both frameworks are used, cost and efforts increases. 2. Complete Migration: - Complete migration means total replacement of all the components of the Struts framework with Spring MVC. At the end of the process, no Struts-specific components would remain in the application. A simple struts application can be divided into six different categories of files. JSP (ex. Login.jsp) Action classes (ex.loginaction.java) FormBeans (ex. LoginForm.java) TagLibs (ex. Struts-html. tld) Config Files (ex. StrutsConfig.xml) Library files (ex. Struts.jar) To migrate from Struts to Spring we have to change the source code of above mentioned files so that they canl work on spring MVC. Following Flowchart shows the algorithm that we follow for the migration. with <input type = text name = username /> Similarly Struts tag library tags can be replaced by their corresponding JSTL tags [4]. Ex. Replace <bean:define> with <c:set> Step 2: Changing Struts Form Beans to Spring Command Classes Struts provide FormBeans as interface between the JSP and the controller servlet. In Spring these are replaced by POJO (Plain Old Java Objects) Command Classes. Form beans extend the ActionForm class of struts framework. POJO (Plain Old Java Object) Command Classes do not extend any class. Step 3: Changing Struts Action classes to Spring Controller classes Struts provide ActionServlet by default as the controller where as in Spring the default controller is DispatcherServlet. Spring has different controllers which handle individual modules. These can be seen as replacement for Action Classes. Annotations can be used within the class definition to make them act as controller. Ex. public xxxclass extends Action {.} Will change to public xxxclass { @controller.. } In Struts ActionMapping, objects are pointers into presentation resources (Actions, JSPs, Tiles, HTML files, etc.). The closest component in Spring MVC to ActionMapping is the ModelAndView interface. Spring Controllers return implementations of the ModelAndView interface, which like a Controller can be custom implemented. Or, if appropriate, you can use the ModelAndView implementation supplied by Spring MVC[3]. Ex. Figure 2-Flowchart for migration process We will do this conversion in 5 steps. Let s see all the steps in detail: - 1. Converting struts specific tags to HTML tags JSP s in a Struts application can contain Struts specific tags where as JSP s in a Spring application contains simple HTML tags. We have to replace Struts specific tags with the equivalent or most suitable simple HTML tags so that they will fit in spring application. Ex. Replace <html: text property= username /> public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request,httpservletresponse response) { } Will be written as Protected ModelAndView onsubmit( HttpServletRequest request, HttpServletResponse response, Object cmd,bindexception exp) throws Exception { } As the name implies, ModelAndView objects have Model and View components. Model components contain the business object to be displayed via the View component. Depending on the scenario, ModelAndView implementations may not have any Model components Volume 2, Issue 2 March April 2013 Page 158

included. They may simply forward into some form of an actual View component (JSP, XSLT, Tiles, HTML, XML, etc.). Ex. Replace return mapping.findforward( success ); With Return new ModelAndView(getSuccessView()); Step 4: Changing Struts Configuration files to Spring Configuration files Struts use web.xml & struts-config.xml to direct the flow of the application In struts we have at least one struts-config.xml file (or more if we are using modules) that holds all the forwards, action mappings, form definitions, and plug-in declarations. In Spring MVC, all the Web application-related controller declarations are configured as Spring Beans. One or more Dispatcher Controllers dispatch all requests for the Web resources to the appropriate Controllers. For instance, if you want to remap your ".do" application into a Spring MVC application, you register the following servlet mapping in the web.xml of your application. step 5: Replacing Struts jar files with Spring jar files Removing the struts specific jars (struts.jar, struts-legacy.jar etc) Adding Spring specific jars (standard.jar, spring.jar etc) into lib folder of the application All *.tld remain same. Updating classpath entries. Validation and Error messages:- If Commons Validator is used in Struts, it can be completely reuse it in Spring. Spring 1.2 does not officially support the Commons-based validation framework, but the "sandbox" version of Spring MVC supports the reuse of validation definitions written in Commons Validator markup (validator.xml and validation-rules.xml). In any case, do not throw away your XML files with validation declarations. They could be reusable in Spring. Spring recognizes Struts message bundles in an identical format. In order to reuse your existing Message resources within Spring MVC, you just configure it as message Source in the Spring MVC configuration file. process needs the developer to be the expert in both the frameworks. Developer has to invest lots of efforts and time to do this. Even after completing the migration, this conversion process cannot be reused in other similar projects, developer has to follow the same series of action for next set of similar projects. The solution to this is building a tool that will automate the task of migration from one framework to other, in our case Struts to Spring. The approach discussed for the migration of Struts application to Spring, in above section can be automated. We present an architecture for a tool Framework Migrator. Existing Struts application will be provided as input to the tool. Depending on the application content, the tool will generate equivalent Spring application using the algorithm mentioned in last section. Benefits of Framework Migrator:- 1. As we are building the tool for conversion, conversion process will be automated. Tedious task of manually converting the Struts application to Spring application will be eliminated. 2. As the tool will be used for migration, efforts needed to migrate will be reduced; hence cost of conversion will also be reduced. There are five major components in the architecture of Framework Migrator. 1. File Locator:- It Checks the input folders structure and file types. It also Stores input and output project folder path in mapping database. 2. File Converter:- Converter Checks the file types and calls appropriate file parsers. 3. File Parsers:- Individual parsers are designed for individual file types like XML parser, JSP parser, JAVA parser. These Parsers will convert Struts specific code, tags to Spring equivalent one. 4. File Creator:- File Creator creates Spring project Folder and copies the files to appropriate directory. 5. Mapping database:- Database will store the mapping of the tags required for the Struts-Spring migration. 4. AUTOMATION Why Automation:- Converting any application from one framework to other is a tedious task. Developer who has to convert the application, need to study the existing application, understand the working, flow, characteristics, expected outcome of the application by going through the code of application line by line. After analyzing the application he has to map every component of that application to its equivalent component in the other framework. This Figure 3- Architecture of framework migrator Volume 2, Issue 2 March April 2013 Page 159

Analysis about Framework Migrator:- Cost-effort reduction analysis: - Let us take an example, Suppose for migration of a Struts application having average complexity level, and size of 10,000 LOC (lines of code) or 200 function points, a team of 4 person needs 10 days, then same Struts application can be migrated to spring in few hours by using the tool.( Few hours because even after automation some of the components must be set up manually such as configuration files, plugins ). Framework migrator cannot achieve 100% migration in all cases. Success of automated migration of application in percentage depends on complexity level of application, software tools we are using to run the application, their version differences and other execution environmental factors. After the changes done by the framework migrator tool, some of the configuration files may need to be changed, libraries may need to be added as framework differences exist. Library files need to be imported as some of the libraries that are inbuilt in Struts may be missing in Spring. Overall we can say framework migrator achieves the automated migration of application about 85-90 percent, remaining amount of work we need to do manually. 5. CONCLUSION Web application development has become simpler due to the web application development frameworks. Many web frameworks are being designed and released for the use of developers to develop application with ease. Developer often needs to migrate from one framework to other. In this paper we highlighted the differences between the two frameworks. Spring MVC Framework offers more advantages over Struts framework. Most of the industries which worked on Struts earlier are now undergoing the process of migrating to Spring framework; as they believe that the Struts framework has reached the point where its innovation and adoption has started to decline. Whereas the highly popular Spring framework (with Spring MVC as its core component) is nicely designed, productive and innovative. We presented the different approaches which can be followed for migrating existing Struts applications to Spring MVC. Finally we discussed a solution Framework Migrator that we have implemented, which simplifies the process of migration and minimizes the efforts needed for migration. As all the web developers are highly likely to migrate from Struts to Spring, our solution framework migrator will be useful for them to convert their existing applications to spring MVC with relative ease and less time. REFERENCES [1] The Struts Framework: Subtitle Practical Guide for Java Programmers by Sue Spielman. Elsevier Science & Technology Books: October 2002. [2] A Guide to Migrating Enterprise Applications to Spring Prepared by: Colin Sampaleanu, Co- Founder, SpringSource dated :October 14, 2008. [3] Spring in Action by Craig Walls and Ryan Breidenbach. [4]http://www07.ibm.com/shared_downloads2/software/rs dc2006/dc_day_2/radplugin-strutstospring.pdf [5]http://forum.springsource.org/forum.php [6] http://strutscr.uw.hu/0067.html [7]http://www.ibm.com/developerworks/library/jsr2/index.html [8]http://www.tutorialspoint.com/struts_2/basicmvcarchit ecture.htm [9]http://www.ibm.com/developerworks/library/j-struts/ [10]http://struts.apache.org/development/1.x/userGuide/in troduction.html [11]http://r4r.co.in/java/struts/basic/tutorial/strutsbasictut orials.php?id=249&option=struts%20basic [12]http://orangeslate.com/2006/11/10/12-benefits-ofspring-mvc-over-struts/ [13]http://publib.boulder.ibm.com/infocenter/wsadhelp/v5 r1m2/index.jsp?topic=%2fcom.ibm.etools.struts.doc %2Ftopics%2Fcstrdoc001.html [14] http://www.devx.com/java/article/29208 [15]http://www.ibm.com/developerworks/library/jsr2/index.html [16]http://www.javabeat.net/2007/05/integrating-strutswith-spring/ Volume 2, Issue 2 March April 2013 Page 160