Using Applets as Front Ends to Server-Side Programs

Similar documents
Using Applets as Front Ends to

Servlet and JSP. Quick Reference

Selected Sections of Applied Informatics Lab 3

Generating the Server Response: HTTP Status Codes

Generating the Server Response:

Applets as front-ends to server-side programming

Network Programming: Servers

Network Programming. Powered by Pentalog. by Vlad Costel Ungureanu for Learn Stuff

Steps for Implementing a Server

GENERATING THE SERVER RESPONSE: HTTP STATUS CODES

Distributed Systems COMP 212. Lecture 8 Othon Michail

IT6503 WEB PROGRAMMING. Unit-I

Backend. (Very) Simple server examples

JAVA. Duration: 2 Months

Sophos Mobile Control Network Access Control interface guide

CS193j, Stanford Handout #26. Files and Streams

URL Kullanımı Get URL

I/O Streams. Object-oriented programming

Generating the Server Response: HTTP Response Headers

Networking Basics. network communication.

Today. cisc3120-fall2012-parsons-lectiv.2 2

PART1: Choose the correct answer and write it on the answer sheet:

REST Web Services Objektumorientált szoftvertervezés Object-oriented software design

Java.net Package and Classes(Url, UrlConnection, HttpUrlConnection)

Distributed Multitiered Application

Outline of Lecture 5. Course Content. Objectives of Lecture 6 CGI and HTML Forms

CS 11 java track: lecture 6

Networking. Lecture 25 ish? COP 3252 Summer July 11, 2017

Modern web applications and web sites are not "islands". They need to communicate with each other and share information.

In servlet, form parsing is handled automatically. You call request.getparameter to get the value of a form parameter.

Java - Applications. The following code sets up an application with a drop down menu, as yet the menu does not do anything.

Controller/server communication

HTTP Protocol and Server-Side Basics

Core Java SYLLABUS COVERAGE SYLLABUS IN DETAILS

CH -7 RESPONSE HEADERS

WA2018 Programming REST Web Services with JAX-RS WebLogic 12c / Eclipse. Student Labs. Web Age Solutions Inc.

Input from Files. Buffered Reader

CS 2113 Software Engineering

Web. Remote Method Invocation. core. programming. Training Courses: Java, JSP, Servlets, Struts, & JSF:

THE CONTEXTUAL DATA SUPPLIER. API Integration Guide

The Future of the Web: HTML 5, WebSockets, Comet and Server Sent Events

Previous lecture: threads G51PRG: Introduction to Programming Second semester Lecture 12 URL

Advanced Java Programming. Networking

Computer Networks - A Simple HTTP proxy -

CS2 Advanced Programming in Java note 8

Controller/server communication

CS 10: Problem solving via Object Oriented Programming. Web Services

COMSC-030 Web Site Development- Part 1. Part-Time Instructor: Joenil Mistal

LESSON LEARNING TARGETS

CSCI 136: Fundamentals of Computer Science II Keith Vertanen Copyright 2012

HTTP Request Handling

IMY 110 Theme 11 HTML Frames

1.00 Lecture 30. Sending information to a Java program

COMP 213. Advanced Object-oriented Programming. Lecture 20. Network Programming

CS 251 Intermediate Programming Java I/O Streams

09-1. CSE 143 Java GREAT IDEAS IN COMPUTER SCIENCE. Overview. Data Representation. Representation of Primitive Java Types. Input and Output.

Using OAuth 2.0 to Access ionbiz APIs

Using the Visualization API with GWT and Other Advanced Topics. Itai Raz May 27, 2009

CS 5010: PDP. Lecture 11: Networks CS 5010 Fall 2017 Seattle. Adrienne Slaughter, Ph.D.

Forms, CGI. Cristian Bogdan 2D2052 / 2D1335 F5 1

Network. Dr. Jens Bennedsen, Aarhus University, School of Engineering Aarhus, Denmark

13. Databases on the Web

Chapter 10 Web-based Information Systems

SNS COLLEGE OF ENGINEERING, Coimbatore

Reading from URL. Intent - open URL get an input stream on the connection, and read from the input stream.

Basic Java IO Decorator pattern Advanced Java IO. Java IO - part 2 BIU OOP. BIU OOP Java IO - part 2

UNIT -I PART-A Q.No Question Competence BTL

Composer Help. Web Request Common Block

Integrating Servlets and JavaServer Pages Lecture 13

Forms, CGI. HTML forms. Form example. Form example...

Kaazing Gateway: An Open Source

Module 3 Web Component

Session 8. JavaBeans. Reading & Reference. Reading. Reference. Session 8 Java Beans. 2/27/2013 Robert Kelly, Head First Chapter 3 (MVC)

protocols September 15,

WEB TECHNOLOGIES CHAPTER 1

Distributed Programming - Sockets

********************************************************************

Files and Streams

This document is published by Appiyo Technologies Pte., Ltd., without any warranty.

Session 13. RESTful Services Part 2. Lecture Objectives

1Z Java SE 5 and 6, Certified Associate Exam Summary Syllabus Questions

Special error return Constructors do not have a return value What if method uses the full range of the return type?

Chapter 12. File Input and Output. CS180-Recitation

Repository In a Box (RIB)

KINGS COLLEGE OF ENGINEERING 1

Java Programming Course Overview. Duration: 35 hours. Price: $900

For live Java EE training, please see training courses at

Assignment, part 2. Statement and concepts INFO-0010

Software 1 with Java. Recitation No. 7 (Java IO) May 29,

Seminar. Migrating Lotus Domino/Notes application to WebSphere architecture

Web Application Security GVSAGE Theater

Sockets and RMI. CS151 Chris Pollett Dec. 5, 2005.

Advanced Java Programming

Getting Started in Java. Bill Pugh Dept. of Computer Science Univ. of Maryland, College Park

JAVA. 1. Introduction to JAVA

AJAX and Persistence: Emerging Patterns and Pain Points

COSC 2206 Internet Tools. The HTTP Protocol

Handling the Client Request: HTTP Request Headers

Oral Question Bank for CL-3 Assignment

A Telemetry Browser built with Java Components

Transcription:

core programming Using Applets as Front Ends to Server-Side Programs 1 2001-2003 Marty Hall, Larry Brown http://

2 Applet Front Ends Agenda Sending GET data and having the browser display the results Sending GET data and processing the results within the applet (HTTP tunneling) Using object serialization to exchange highlevel data structures between applets and servlets Sending POST data and processing the results within the applet (HTTP tunneling) Bypassing the HTTP server altogether

3 Applet Front Ends Sending GET Request and Displaying Resultant Page Applet requests that browser display page showdocument try { URL programurl = new URL(baseURL + "?" + somedata); getappletcontext().showdocument(programurl); } catch(malformedurlexception mue) {... }; URL-encode the form data String somedata = name1 + "=" + URLEncoder.encode(val1) + "&" + name2 + "=" + URLEncoder.encode(val2) + "&" +... namen + "=" + URLEncoder.encode(valN);

GET Request Example: Applet } public class SearchApplet extends Applet implements ActionListener {... public void actionperformed(actionevent event) { String query = URLEncoder.encode(queryField.getText()); SearchSpec[] commonspecs = SearchSpec.getCommonSpecs(); for(int i=0; i<commonspecs.length-1; i++) { try { SearchSpec spec = commonspecs[i]; URL searchurl = new URL(spec.makeURL(query, "10")); String framename = "results" + i; getappletcontext().showdocument(searchurl, framename); } catch(malformedurlexception mue) {} } } 4 Applet Front Ends

5 Applet Front Ends GET Request Example: Utility Class public class SearchSpec { private String name, baseurl, numresultssuffix; private static SearchSpec[] commonspecs = { new SearchSpec("google", "http://www.google.com/search?q=", "&num="),... }; } public String makeurl(string searchstring, String numresults) { return(baseurl + searchstring + numresultssuffix + numresults); }...

6 Applet Front Ends Get Request Example: HTML File <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN"> <HTML> <HEAD> <TITLE>Parallel Search Engine Results</TITLE> </HEAD> <FRAMESET ROWS="120,*"> <FRAME SRC="SearchAppletFrame.html" SCROLLING="NO"> <FRAMESET COLS="*,*,*"> <FRAME SRC="GoogleResultsFrame.html" NAME="results0"> <FRAME SRC="InfoseekResultsFrame.html" NAME="results1"> <FRAME SRC="LycosResultsFrame.html" NAME="results2"> </FRAMESET> </FRAMESET>

Get Request: Initial Result 7 Applet Front Ends

GET Request: Submission Result 8 Applet Front Ends

9 Applet Front Ends HTTP Tunneling Idea Open a socket connection to port 80 on the server and communicate through HTTP Advantages Communicate through firewalls Server-side programs only needs to return the data, not a complete HTML document Disadvantages Can only tunnel to server from which the applet was loaded Applet, not browser, receives the response Cannot easily display HTML

HTTP Tunneling and GET Requests Create URL object referring to applet s host URL dataurl = new URL( ); Create a URLConnection object URLConnection connection = dataurl.openconnection(); Instruct browser not to cache URL data connection.setusecaches(false); Set any desired HTTP headers Create an input stream Call connection.getinputstream; wrap in higher-level stream Read data sent from server E.g., call readline on BufferedReader Close the input stream 10 Applet Front Ends

11 Applet Front Ends HTTP Tunneling Template: Client Side URL currentpage = getcodebase(); String protocol = currentpage.getprotocol(); String host = currentpage.gethost(); int port = currentpage.getport(); String urlsuffix = "/servlet/someservlet"; URL dataurl = new URL(protocol, host, port, urlsuffix); URLConnection connection = dataurl.getconnection(); connection.setusecaches(false); connection.setrequestproperty("header", "value"); BufferedReader in = new BufferedReader( new InputStreamReader(connection.getInputStream())); String line; while ((line = in.readline())!= null) { dosomethingwith(line); } in.close();

12 Applet Front Ends Using Object Serialization with HTTP Tunneling Idea Server-side program (servlet) sends complete Java object Client-side program (applet) reads it Client-side program (applet) template: ObjectInputStream in = new ObjectInputStream( connection.getinputstream()); SomeClass object = (SomeClass)in.readObject(); dosomethingwith(object);

13 Applet Front Ends Using Object Serialization with HTTP Tunneling (Continued) Server-side program (servlet) template: String contenttype = "application/x-java-serialized-object"; response.setcontenttype(contenttype); ObjectOutputStream out = new ObjectOutputStream( response.getoutputstream()); SomeClass object = new SomeClass(...); out.writeobject(value); out.flush();

Example: Live Scrolling Data 14 Applet Front Ends

15 Applet Front Ends Sending POST Data to Server Applet sends POST request to server Processes the response directly Url currentpage = getcodebase(); String protocol = currentpage.getprotocol(); String host = currentpage.gethost(); int port = currentpage.getport(); String urlsuffix = "/servlet/someservlet"; URL dataurl = new URL(protocol, host, port, urlsuffix); URLConnection connection = dataurl.openconnection(); connection.setusecaches(false); connection.setdooutput(true);

16 Applet Front Ends Sending POST Data to Server (Continued) Character or Binary Data ByteArrayOutputStream bytestream = new ByteArrayOutputStream(512); PrintWriter out = new PrintWriter(byteStream, true); out.print(data); out.flush(); connection.setrequestproperty( "Content-Length", String.valueOf(byteStream.size())); connection.setrequestproperty( "Content-Type", "application/x-www-form-urlencoded"); bytestream.writeto(connection.getoutputstream());

17 Applet Front Ends Sending POST Data to Server Serialized Data ByteArrayOutputStream bytestream = new ByteArrayOutputStream(512); ObjectOutputStream out = new ObjectOutputStream(byteStream); out.writeobject(data); out.flush(); connection.setrequestproperty( "Content-Length", String.valueOf(byteStream.size())); connection.setrequestproperty( "Content-Type", "application/x-java-serialized-object"); bytestream.writeto(connection.getoutputstream());

18 Applet Front Ends Sending POST Data: Example Sends data to a servlet that returns an HTML page showing form data it receives Displays result in an AWT TextArea

Bypassing the HTTP Server If you are using applets, you don't have to communicate via HTTP JDBC RMI SOAP (perhaps via JAX-RPC) Raw sockets Advantages Simpler More efficient Disadvantages Can only talk to server from which applet was loaded Subject to firewall restrictions You have to have a second server running 19 Applet Front Ends

Summary Send data via GET and showdocument Can access any URL Only browser sees result Send data via GET and URLConnection Can only access URLs on applet's home host Applet sees results Applet can send simple data Server can send complex data (including Java objects) Send data via POST and URLConnection Can only access URLs on applet's home host Applet sees results Applet can send complex data (including Java objects) Server can send complex data (including Java objects) Bypass Web Server 20 Applet Front Ends

core programming Questions? 21 2001-2003 Marty Hall, Larry Brown http://