Professional Documents
Culture Documents
Page 1 of 16
Table of Content
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. Introduction..................................................................................................................... 3 IOC Design Pattern ......................................................................................................... 3 How Multipart HTTP requests are resolved. .................................................................. 4 File Upload Using Spring Frame work........................................................................... 4 File Validations:.............................................................................................................. 8 Data Validations: ............................................................................................................ 8 Handling Referential Data .............................................................................................. 9 Performance Considerations: ........................................................................................ 10 All or None processing/Grouping of Data .................................................................... 10 Batch States............................................................................................................... 10 Delegate Discovery Using Type 2 Dependency Injection........................................ 10 Setting up Spring (Detailed) ..................................................................................... 11 Testing File Upload Controller ................................................................................. 15 Sequence Diagram .................................................................................................... 16
Page 2 of 16
1 Introduction
Enterprise Application Integration (EAI) is a rapidly growing segment in enterprise computing. Multiple forces are driving this trend. Many of them center on rapidly changing business needs and opportunities driven by the Internet, merger/acquisitions, competition, regulation, and deregulation. Increased attention on Customer Relationship Management (CRM) and supply chain integration in many industries is driving the demand for intra- and inters enterprise system integration. Rapidly integrating applications across an enterprise is becoming more and more imperative to staying competitive in todays marketplace. A large portion of IT budgets is spent on integrating applications: bridging heterogeneous computing environments, connecting new and legacy applications, and linking internal and external resources. Information systems in most companies are a mixture of computing platforms, software applications, data schemas, and business processes. The mainframe in one location cant communicate instantaneously with workstations in another. The Accounts Receivable system may not have the same data schema as the CRM system. For example, when customer service representatives need to access customer information, they must access separate data stored in a CRM database and then open a financial application that is completely disconnected.
The classess are more resuable It easier to test the classes It's easier to assemble systems and configure.
The problem with small working applications that become large is that static-method entanglement does not scale. One part of a system that's otherwise fairly self-contained statically accesses another part of the system and cannot be instantiated without invoking methods in the latter. Thus it can't easily be isolated for unit testing. What's more, it can't be developed as an independent component. Components that are developed separately can have their own development teams and may well be part of a larger design. These components will have their own source control directory and can be developed against mock implementations of their dependent components. All this will help overall development become faster, in terms of both the team's efficiency and the build time.
File processing handling will not handled as part of this design. That would be handled separately. The scope is to cover the client side design in as de-coupled a fashion as possible.
Page 3 of 16
type of "multipart/form-data", then FileUpload can parse that request, and make the results available in a manner easily used by the caller. Generally, there are following components in a spring based web application 1) Multipart resolver configuration: There would be three resolver a. CommonsMultipartResolver: This will be used for handling files via the Jakarta commons framework. This has a max size limit of 1 MB.
b. CosMultipartResolver: This will be used for handling files OReilly (COS) package.. This has no documented max size limit. The max size limit would need to be tested.
c. epCabViewResolver: This will be developed by the epcab development. This would not have any size limitations. This configuration will be done in the action-servlet.xml file, as follows Page 5 of 16
<!-- Configure the multipart resolver for Jakarata Commons: Jan 25 2006 > <bean class="org.spfw.web.servlet.multipart.commons.CommonsMultipartResolver"> <!-- maximum file size is 1 Megabyte --> <property name="maxUploadSize"><value>1048576</value></property> </bean>
2) Controller for uploading the file: The controller will be part of a package called com.epcab.controllers.fileupload named FileUploadController. This controller will extend from org.springframework.web.servlet.mvc.AbstractController.
3) The actual form to upload the file (fileupload.jsp): On the client side, the client's browser must support form-based upload. Most modern browsers do, but there's no guarantee. For example, <FORM ENCTYPE='multipart/form-data' method='POST' action='/myservlet'> <INPUT TYPE='file' NAME='mptest'> <INPUT TYPE='submit' VALUE='upload'> </FORM> The input type <INPUT TYPE='file' brings up a button for a file select box on the browser together with a text field that takes the file name once selected. The servlet can use the GET method parameters to decide what to do with the upload while the POST body of the request contains the file data to parse. When the user clicks the "Upload" button, the client browser locates the local file and sends it using HTTP POST, encoded using the MIME-type multipart/form-data. When it reaches the
Page 6 of 16
servlet, the servlet must process the POST data in order to extract the encoded file. This is in format RFC 1867. The fileUploadBean will be used for handling the uploaded files. The fileType parameter of the fileUploadedBean will be used for determining the type of a particular type for example EOJ files will be determined by say fileType of EOJ_FILE_TYPE. A fileType needs to be added to system to support a new file Type. 4) Upload Lifecycle of a File: Following are the stages in the lifecycle of an Upload. Most of the states are self-explanatory.
Lifecycle States
Upload File
Preview File
Edit File
Submit File
View Errors
View Success
5) Lifecycle Views: An abstract class AbstractFinder will resolve the lifecycle view. There would a concrete implementation for each of the lifecycle state views. As shown below.
Page 7 of 16
If a new file state is needed based on new business requirements then this design can be easily extended by adding a new ViewFinder class.
3. File Validations:
There are following two aspects to file validations 1) Identifying the error: There would be two components of the design. A custom parser for each application context (file type), there would be one-to-one mapping between the application context and file types and similarly one custom validator for each file type. 2) Displaying this error: The errors will be displayed using custom jstl tags for each type or context in which the file is uploading. A tag library will be created for the epcab project.
Activity Diagram
File File Upload Controller Parse File
Client
4. Data Validations:
There are two types of data. Self Contained Data: In this case, you have a set of self-contained data with respect to a specific rule. By self contained I mean that all the data elements refer to the data with in that set as an example take the case, when a cab driver is uploading the data about the services it performed, into the system of the cab company using a file. This file has one row for each service performed. Let's say you have rule that would say the trip charges couldnt exceed, the service fee plus tolls. Now the data with respect to this rule is self contained. I would call these rules as Self Contained Rules Page 8 of 16
Referential Data: When in order to apply a rule more data is needed from an external system or a database, such rules are called Non- Self Contained Rules. Taking the previous example if the rule says that the service needs to have been performed against a valid reservation number, then in order to execute the rule a lookup needs to be made into the database to get the list of valid reservation numbers. In this case the data in the file itself is not sufficient to execute the rule. While executing such rules we need to take extreme care, as these rules can be very performance extensive. For each record, there could be multiple data base calls going back and forth.
Page 9 of 16
6. Performance Considerations:
The files can sometimes be very big, for example a file may contains say 10,000 records and if each records processing takes even a fraction of a second the overall processing time can be a few minutes or may be more than that. In that case the user would need to be notified of the incremental status and should have the option of canceling the processing. The possible options for incrementally displaying the data to the user are - Use HTML refreshes: This option works and can give the incremental status updates to the user, but has bandwidth overhead. Every time entire page is re-rendered on the server side taking - Use xmtHTTPObject: using this object the data from the server can be obtained incrementally and rendered in the browser.
8. Batch States
Each file submitted to the system will be accepted as a batch by the system. A unique batch number identify each batch will. Each batch will go through the following states Validating: After the submission of a batch the batch data will first be validated. All errors will be incrementally notified to the user. Submitting: During processing the data will be sent to the appropriate service for processing. The incremental progress will be retrieved and sent back to the client. Any errors. User will have the option of canceling the submission at any stage; any uncommitted transaction will be rolled back.
Following are the steps involved injecting the business delegate into the controller Page 10 of 16
1. Identify the business delegate class, in this case the business delegate class is com.epcab.delegates.StagingDelegate. 2. Modify the action-servlet class to add a property to the fileUploadForm bean.
<bean id="fileUploadForm" class="com.epcab.controllers.FileUploadController"> <property name="sessionForm"><value>true</value></property> <property name="commandName"><value>fileUpload</value></property> <property name="commandClass"><value>com.epcab.commands.FileUpload</value></property> <property name="validator"><ref bean="fileUploadValidator"/></property> <property name="formView"><value>fileupload</value></property> <property name="successView"><value>hello.htm</value></property> <property name="delegateClass"><value>com.epcab.delegates.StagingDelegate</value></property> </bean>
Page 11 of 16
/** * @return Returns the file. */ public byte[] getFile() { return file; } /** * @param file The file to set. */ public void setFile(byte[] file) { this.file = file; } }
Page 12 of 16
return maxPercentage; } }
Page 13 of 16
return priceIncrease; } public void setProductManager(ProductManager pm) { prodMan = pm; } public ProductManager getProductManager() { return prodMan; } } 1) Modify the supports method in the validator class
import com.epcab.commands.fileUpload; public class FileUploadValidator implements Validator { private int DEFAULT_MIN_PERCENTAGE = 0; private int DEFAULT_MAX_PERCENTAGE = 50; private int minPercentage = DEFAULT_MIN_PERCENTAGE; private int maxPercentage = DEFAULT_MAX_PERCENTAGE; /** Logger for this class and subclasses */ protected final Log logger = LogFactory.getLog(getClass()); public boolean supports(Class clazz) { return clazz.equals(fileUpload.class); }
7) Override formBackingObject Method: This function is used to return and object that can be used by the View form. This is not needed in the case of a File Upload operation. But this can be used for populating a value object with some contextual information Say as follows
PriceIncrease priceIncrease = new PriceIncrease(); priceIncrease.setPercentage(20); // For file upload just return a new object. protected Object formBackingObject(HttpServletRequest request) throws ServletException { return new Object(); }
2) Write the JSP page corresponding to the submission. Add a title using fmt tag.
<html> <head> <title><fmt:message key="title"/></title> </head> <body> <h1>Please upload a file</h1> <form method="post" action="upload.form" enctype="multipart/form-data"> <input type="file" name="file"/> <input type="submit"/> </form> </body> </html>
Page 14 of 16
Page 15 of 16
12.Sequence Diagram
Page 16 of 16