CS520 Web Programming Bits and Pieces of Web Programming (II)

Slides:



Advertisements
Similar presentations
Developing in CAS. Why? As distributed you edit CAS 3 with Eclipse and build with Maven 2 – Best Practice for Release Engineering – Difficult edit-debug.
Advertisements

An introduction to Java Servlet Programming
CS320 Web and Internet Programming Generating HTTP Responses
Chapter 2: Application layer  2.1 Web and HTTP  2.2 FTP 2-1 Lecture 5 Application Layer.
Building and Deploying a Simple Web Application. Tomcat and JSP Tomcat is an application server, commonly used to host JSP applications Applications are.
Web Applications Basics. Introduction to Web Web features Clent/Server HTTP HyperText Markup Language URL addresses Web server - a computer program that.
Julien Thibault / Phil Brewster / Kristina Doing-Harris
JAVA MAIL API. High level representation of the basic components of any mail system. The components are represented by abstract classes in the javax.mail.
Java Servlets and JSP.
Java Enterprise Edition Java Web Development Structure of a web project Introduction to Web Applications The first project Introduction to Java Web Development.
ENTERPRISE JOB SCHEDULER SAJEEV RAMAKRISHNAN 29 AUG 2014.
Computer Networking From LANs to WANs: Hardware, Software, and Security Chapter 12 Electronic Mail.
CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES LECTURE 5_1 George Koutsogiannakis/ Summer
AN OVERVIEW OF SERVLET TECHNOLOGY SERVER SETUP AND CONFIGURATION WEB APPLICATION STRUCTURE BASIC SERVLET EXAMPLE Java Servlets - Compiled By Nitin Pai.
|Tecnologie Web L-A Anno Accademico Laboratorio di Tecnologie Web Introduzione ad Eclipse e Tomcat
Web Applications - Basics. Introduction to Web Web features Clent/Server HyperText Transfer Protocol HyperText Markup Language URL addresses Web server.
Standalone Java Application vs. Java Web Application
CS4273: Distributed System Technologies and Programming Lecture 13: Review.
Running Kuali: A Technical Perspective Ailish Byrne - Indiana University Jay Sissom - Indiana University Foundation.
J2EE Overview Web Programming CSCI J2EE multi-tier architecture Servlet: Java class loaded into Web server JSP page: enhanced HTML page that is.
CaDSR Freestyle Search June 11, caDSR Freestyle Search Overview Architecture Implementation Dependencies Futures 2.
Module 6: Managing Client Access. Overview Implementing Client Access Servers Implementing Client Access Features Implementing Outlook Web Access Introduction.
Running Kuali: A Technical Perspective Ailish Byrne (Indiana University) Jonathan Keller (University of California, Davis)
HTTP protocol Java Servlets. HTTP protocol Web system communicates with end-user via HTTP protocol HTTP protocol methods: GET, POST, HEAD, PUT, OPTIONS,
CS440 Computer Networks 1 Neil Tang 12/01/2008.
CSC 2720 Building Web Applications File Upload using Apache Commons – FileUpload.
JAVA, JEE Training Introduction to Web Harinath Mallepally
Apache Struts Technology A MVC Framework for Java Web Applications.
CS520 Web Programming Bits and Pieces of Web Programming (II) Chengyu Sun California State University, Los Angeles.
1 Web Programming with Servlets & JSPs WEB APPLICATIONS – AN OVERVIEW.
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 Spring – Web MVC Chengyu Sun California State University, Los Angeles.
Deploying Web Applications to Tomcat Server Chun Guo
CS520 Web Programming Bits and Pieces of Web Programming (I) Chengyu Sun California State University, Los Angeles.
Chengyu Sun California State University, Los Angeles
CS3220 Web and Internet Programming Introduction to Java Servlets
Platform as a Service (PaaS)
CS3220 Web and Internet Programming RESTful Web Service
Platform as a Service (PaaS)
SMTP SMTP stands for Simple Mail Transfer Protocol. SMTP is used when is delivered from an client, such as Outlook Express, to an server.
CS520 Web Programming Introduction to Maven
CS320 Web and Internet Programming Generating HTTP Responses
Data Bridge Solving diverse data access in scientific applications
SMTP SMTP stands for Simple Mail Transfer Protocol. SMTP is used when is delivered from an client, such as Outlook Express, to an server.
Chapter 9 Periodic Processes
Chengyu Sun California State University, Los Angeles
Course Outcomes of Advanced Java Programming AJP (17625, C603)
Test Driven Development
CS3220 Web and Internet Programming Generating HTTP Responses
J2EE Lecture 7: Spring – Spring MVC
CS5220 Advanced Topics in Web Programming Course Overview
CompTIA Server+ Certification (Exam SK0-004)
April Webinar: Advanced Configuration of Order Forms in Workflow
CS5220 Advanced Topics in Web Programming Spring – Web MVC
CS320 Web and Internet Programming Cookies and Session Tracking
Web Server Design Week 15 Old Dominion University
CS3220 Web and Internet Programming Cookies and Session Tracking
CS5220 Advanced Topics in Web Programming Spring – Web MVC
Java Servlets and JSP.
CS3220 Web and Internet Programming Introduction to Java Servlets
Chengyu Sun California State University, Los Angeles
CS3220 Web and Internet Programming Cookies and Session Tracking
CS5220 Advanced Topics in Web Programming Secure REST API
Enterprise Java Beans.
CS4961 Software Design Laboratory Understand Aquila Backend
Chengyu Sun California State University, Los Angeles
CS5220 Advanced Topics in Web Programming Course Overview
Web Server Design Week 14 Old Dominion University
Web Programming Week 1 Old Dominion University
Presentation transcript:

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

Roadmap File upload and download Sending email Task scheduling and execution Application deployment

File Upload – The Form <form action="FileUploadHandler" method="post" enctype="multipart/form-data"> First file: <input type="file" name="file1" /> <br /> Second file: <input type="file" name="file2" /> <br /> <input type="submit" name="upload" value="Upload" /> </form>

File Upload – The Request POST / HTTP/1.1 Host: cs.calstatela.edu:4040 […] Cookie: SITESERVER=ID=289f7e73912343a2d7d1e6e44f931195 Content-Type: multipart/form-data; boundary=---------------------------146043902153 Content-Length: 509 -----------------------------146043902153 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 http://jakarta.apache.org/commons/fileupload/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 an @RequestParam argument of type MultipartFile to the controller method http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/multipart/MultipartFile.html

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

File Download Generate an HTTP response directly Understand Java IO 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

How Email Works SMTP, IMAP, POP Email Server A Email Server B ?? ?? ?? Client A Client B

JavaMail http://www.oracle.com/technetwork/java/javamail/index.html Maven dependency: javax.mail:mail Properties props = System.getProperties(); props.put("mail.smtp.host", mailhost); Session session = Session.getInstance( props ); Message msg = new MimeMessage(session); ... Transport.send( msg );

Spring Email Support Mail message classes Need spring-context-support dependency Declare a mailSender bean JavaMailSender interface See CSNS2 for example Mail message classes SimpleMailMessage No attachment, no special character encoding MimeMailMessage

Set Up a Local Email Server for Testing hMailServer on Windows - http://csns.calstatela.edu/wiki/content/cysun/course_materials/hmailserver postfix on Linux - http://csns.calstatela.edu/wiki/content/cysun/notes/ubuntu_server#email

Examples of Scheduled Tasks Periodic email notifications Weekly sales Member interests Payment reminders Batch data processing

Concepts in Task Scheduling and Execution … Executor Use one thread for each task Use one thread for all tasks Use a thread pool Schedule (a.k.a. Trigger) E.g. every 5 minutes, every day at midnight, every first Sunday of each month at 8am …

… Concepts in Task Scheduling and Execution Scheduler Task Schedule/Trigger Executor

Spring Configuration <task> namespace <task:scheduler id="scheduler" /> <task:executor id="executor" pool-size="5"/> <task:annotation-driven scheduler="scheduler" executor="executor" /> Creates a scheduler Creates a thread pool Based executor Enables annotations @Scheduled and @Async

@Scheduled http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/scheduling/annotation/Scheduled.html

Cron Expression Six field separated by space Seconds (0-59) Minutes (0-59) Hours (0-23) Day of month (1-31) Month (1-12 or JAN-DEC) Day of week (1-7 or MON-SUN)

Cron Field Values Single value, e.g. 12 Set of values, e.g. 0,15,30,45 Range, e.g. 1-12,MON-FRI,* (first-last) Range with step, e.g. 1-12/3

Cron Expression Examples Every hour at the beginning of the hour 0 0 * * * * 0 */10 * * * * 0 0 8 * * MON-FRI 0 0 1 1,15 * * Every 10 minutes Every weekday at 8AM Every 1st and 15th of each month at 1AM

Application Deployment Deploy Application Computer for Development Server Hosting the Web Application

Directory Structure of a Java Web Application Application Root Directory JSPs and static resources WEB-INF web.xml classes Compiled Java classes lib Additional Java libraries

WAR Files Web application ARchive A JAR file for packaging, distributing, and deploying Java web applications Create WAR files The command line tool jar Eclipse Export -> Web -> WAR file mvn package

Deploy WAR Files to a Tomcat Server Copy the WAR file to the webapps folder Use the Manager App Need a user with the manager-gui role More options at http://tomcat.apache.org/tomcat-7.0-doc/deployer-howto.html