CS520 Web Programming Bits and Pieces of Web Programming (I) Chengyu Sun California State University, Los Angeles.

Slides:



Advertisements
Similar presentations
Debugging tutorial. Outline Brief refresher on debugging using Eclipse Logging with log4j – Logging levels – log4j.properties Debugging strategically.
Advertisements

1 Generic logging layer for the distributed computing by Gene Van Buren Valeri Fine Jerome Lauret.
Browsers and Servers CGI Processing Model ( Common Gateway Interface ) © Norman White, 2013.
CS320 Web and Internet Programming Generating HTTP Responses
Slide 1 of 9 Presenting 24x7 Scheduler The art of computer automation Press PageDown key or click to advance.
SEEM4570: XAMPP, Eclipse, Summary of Html Kangfei Zhao Room 711,ERB
Struts 2.0 an Overview ( )
Unit Testing & Defensive Programming. F-22 Raptor Fighter.
WaveMaker Visual AJAX Studio 4.0 Training Troubleshooting.
Logging Best Practices Dubna 2012 Benedicto Fernandez Software Engineer CERN / GS-AIS.
Christopher Jeffers August 2012
AIT 616 Fall 2002 PHP. AIT 616 Fall 2002 PHP  Special scripting language used to dynamically generate web documents  Open source – Free!!!  Performs.
Logging with Log4j. Introduction Logging - chronological and systematic record of data processing events in a program. Possible goals: Create an audit.
ProCol~ A jEdit Plugin for Remote Project Collaboration Justin Dieters Spring 2004 CS470 Final Presentation.
Designing For Testability. Incorporate design features that facilitate testing Include features to: –Support test automation at all levels (unit, integration,
LogBox Enterprise Logging Brad Wood
Dyalog’09. Overview of MildServer Morten Kromberg Dyalog’09 – Princeton, NJ.
Running Kuali: A Technical Perspective Ailish Byrne - Indiana University Jay Sissom - Indiana University Foundation.
Chapter 3 Servlet Basics. 1.Recall the Servlet Role 2.Basic Servlet Structure 3.A simple servlet that generates plain text 4.A servlet that generates.
Unit Testing with JUnit and Clover Based on material from: Daniel Amyot JUnit Web site.
Running Kuali: A Technical Perspective Ailish Byrne (Indiana University) Jonathan Keller (University of California, Davis)
The Log4E logging plug-in David Gallardo. What is logging good for? Tracing program execution during development Debugging Providing an audit trail for.
Web Server Design Week 13 Old Dominion University Department of Computer Science CS 495/595 Spring 2010 Martin Klein 4/7/10.
Enterprise Java v090125Dev Env Overview1 Enterprise Java ( ) Development Environment Overview.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, written in Java code, that.
® IBM Software Group © 2006 IBM Corporation How to utilize logging in EGL This Learning Module shows how to utilize the open source log4j project from.
CSC 2720 Building Web Applications File Upload using Apache Commons – FileUpload.
Lecture XI: Logging and Monitoring CS 4593 Cloud-Oriented Big Data and Software Engineering.
Selenium server By, Kartikeya Rastogi Mayur Sapre Mosheca. R
Google Code Libraries Dima Ionut Daniel. Contents What is Google Code? LDAPBeans Object-ldap-mapping Ldap-ODM Bug4j jOOR Rapa jongo Conclusion Bibliography.
CS520 Web Programming Bits and Pieces of Web Programming (II) Chengyu Sun California State University, Los Angeles.
CS520 Web Programming Introduction to Maven Chengyu Sun California State University, Los Angeles.
Web Programming Week 1 Old Dominion University Department of Computer Science CS 418/518 Fall 2007 Michael L. Nelson 8/27/07.
CS422 Principles of Database Systems Stored Procedures and Triggers Chengyu Sun California State University, Los Angeles.
Copyright © 2010 Accenture All Rights Reserved. Accenture, its logo, and High Performance Delivered are trademarks of Accenture. ODS Tools – Fannie Mae.
Development of the EDEX plug-in Ingest overview Manual Endpoint LDM DistributionSrv Plugin decoder Plugin Data Object PersistIndexSrv NotificationSrv.
Fermilab Scientific Computing Division Fermi National Accelerator Laboratory, Batavia, Illinois, USA. Off-the-Shelf Hardware and Software DAQ Performance.
CS320 Web and Internet Programming Introduction to Java Servlets Chengyu Sun California State University, Los Angeles.
CS520 Web Programming Spring – Web MVC Chengyu Sun California State University, Los Angeles.
CS520 Web Programming Bits and Pieces of Web Programming (I) Chengyu Sun California State University, Los Angeles.
1 RIC 2009 Symbolic Nuclear Analysis Package - SNAP version 1.0: Features and Applications Chester Gingrich RES/DSA/CDB 3/12/09.
CS520 Web Programming Spring – Web MVC Chengyu Sun California State University, Los Angeles.
SWE 434 SOFTWARE TESTING AND VALIDATION LAB2 – INTRODUCTION TO JUNIT 1 SWE 434 Lab.
Chengyu Sun California State University, Los Angeles
CS3220 Web and Internet Programming RESTful Web Service
CS520 Web Programming Introduction to Maven
CS320 Web and Internet Programming Generating HTTP Responses
CS520 Web Programming Bits and Pieces of Web Programming (II)
Data Bridge Solving diverse data access in scientific applications
Understanding SOAP and REST calls The types of web service requests
Introduction to JUnit CS 4501 / 6501 Software Testing
Chengyu Sun California State University, Los Angeles
Designing For Testability
CS3220 Web and Internet Programming Generating HTTP Responses
Testing and Debugging.
Software Engineering 1, CS 355 Unit Testing with JUnit
Chapter 12: Automated data collection methods
CS5220 Advanced Topics in Web Programming Spring – Web MVC
CS5220 Advanced Topics in Web Programming Spring – Web MVC
Introduction to JUnit IT323 – Software Engineering II
CS 240 – Advanced Programming Concepts
The Most Popular Android UI Automation Testing Tool Andrii Voitenko
Chengyu Sun California State University, Los Angeles
CS4961 Software Design Laboratory Understand Aquila Backend
Chengyu Sun California State University, Los Angeles
OpenURL: Pointing a Loaded Resolver
Chengyu Sun California State University, Los Angeles
Java Code Review with CheckStyle
Chengyu Sun California State University, Los Angeles
Plug-In Architecture Pattern
Presentation transcript:

CS520 Web Programming Bits and Pieces of Web Programming (I) Chengyu Sun California State University, Los Angeles

Roadmap Logging Testing File upload and download Exception Handling

Logging Recording events happened during software execution, e.g. using print statements to assist debugging Why do we want to do that when we have GUI debugger?? public void foo() { System.out.println( “loop started” ); // some code that might get into infinite loop … System.out.println( “loop finished” ); }

Requirements of Good Logging Tools Minimize performance penalty Support different log output Console, file, database, … Support different message levels Fatal, error, warn, info, debug, trace Easy configuration

Java Logging Libraries Logging implementations Log4j - java.util.logging in JDK Logging API Apache Commons Logging (JCL) Simple Logging Façade for Java (SLF4J) -

Choose Your Logging Libraries Log4j Widely used Good performance Rich features Easy configuration java.util.logging Part of JDK, i.e. no extra library dependency Commons Logging Determines logging implementation at runtime SLF4j Statically linked to a logging implementation  Cleaner design  Better performance  Less problem

Using Log4j and SLF4j Library dependencies Coding Creating a Logger Logging statements Configuration Output format

Log4j Configuration File log4j.xml or log4j.properties Appender Output type Output format Logger Package or class selection Message level

Log4j PatternLayout docs/org/apache/log4j/PatternLayout.ht ml

Logging in CSNS2 src/main/resources/log4j.xml build.properties app.log.dir app.log.level Use of Log Viewer plugin in Eclipse

Software Testing Unit Testing Integration Testing System Testing User Acceptance Testing (Beta Testing)

Java Testing Frameworks JUnit Widely used and supported TestNG Technically superior to JUnit (for a while) but not as widely used or supported

What We Want From a Testing Framework Automation Including setup and tear-down Grouping and selection Test Dependency Skip tests that depend on tests that already failed Run independent test in parallel Report Other, e.g. tool support, API, dependency injection, and so on

Maven Support for JUnit/TestNG Library dependency Directory structure src/test/java src/test/resources The surefire plugin

Basic TestNG Method Class Annotations for various before/after methods

Group and groups dependsOnMethods dependsOnGroups

Test Suite A test suite is represented by an XML file and contains one or more tests. Select tests by method, class, package, and group Include and exclude

Test Suite Example testng.xml

TestNG in CSNS2 Configuration Test classes inherit from Spring TestNG support BeforeSuite and AfterSuite methods

More About TestNG TestNG Documenation – main.html main.html Next Generation Java Testing by Cédric Beust and Hani Suleiman

File Upload and Download in Web Applications Pictures on online albums and social networking sites Attachments in web forum posts and web s Resumes on job search sites Student homework submissions in learning management systems (LMS) …

File Upload – The Form <form action="FileUploadHandler" method="post" enctype="multipart/form-data"> First file: Second file:

File Upload – The Request POST / HTTP/1.1 Host: cs.calstatela.edu:4040 […] Cookie: SITESERVER=ID=289f7e a2d7d1e6e44f Content-Type: multipart/form-data; boundary= Content-Length: Content-Disposition: form-data; name="file1"; filename="test.txt" Content-Type: text/plain this is a test file Content-Disposition: form-data; name="file2"; filename="test2.txt.gz" Content-Type: application/x-gzip ?????????UC

Apache commons-fileupload d/using.html Maven dependency: commons-fileupload:commons-fileupload FileItemFactory fileItemFactory = DiskFileItemFactory(); ServletFileUpload fileUpload = new ServletFileUpload( fileItemFactory ); List items = fileUpload.parseRequest( request ); for( Object o : items ) { FileItem item = (FileItem) items; if( ! item.isFormFiled() ) {...} }

Handle File Upload in Spring multipartResolver bean Support multiple request parser libraries See CSNS2 for example Add argument of type MultipartFile to the controller method api/org/springframework/web/multipart/MultipartF ile.html api/org/springframework/web/multipart/MultipartF ile.html

Store Uploaded Files In database BLOB, CLOB BINARY VARCAR, VARCHAR On disk Pros and Cons??

File Download Generate an HTTP response directly Add an HttpServletResponse argument to the controller method Return null for view Understand Java IO Reader and Writer InputStream and OutputStream Use of the Content-Disposition header

Problem with Java Exceptions Too many checked exceptions Checked vs. Runtime exceptions Require lots of boilerplate exception handling code

Spring’s Solution to the Exception Problem Use primarily runtime exceptions Separate exception handling code into exception handlers

Controller Exception Handing in Spring An Exception Resolver handles all runtime exceptions thrown by controllers SimpleMappingExceptionResolverSimpleMappingExceptionResolver maps different exceptions to different views

ExceptionResolver in CSNS2 <bean id="exceptionResolver“ class="csns.web.resolver.ExceptionResolver"> exception/access exception/mail A SimpleMappingExceptionResolver with additional logging.