Tools of the trade J SON, M AVEN, A PACHE COMMON Photo from

Slides:



Advertisements
Similar presentations
WEB DESIGN TABLES, PAGE LAYOUT AND FORMS. Page Layout Page Layout is an important part of web design Why do you think your page layout is important?
Advertisements

24-Aug-14 HTML Forms. 2 What are forms? is just another kind of HTML tag HTML forms are used to create (rather primitive) GUIs on Web pages Usually the.
SOAP.
JSON Valery Ivanov.
Forms Review. 2 Using Forms tag  Contains the form elements on a web page  Container tag tag  Configures a variety of form elements including text.
Tutorial 10 Programming with JavaScript
Computer Science 101 Web Access to Databases Overview of Web Access to Databases.
Chapter 6 DOJO TOOLKITS. Objectives Discuss XML DOM Discuss JSON Discuss Ajax Response in XML, HTML, JSON, and Other Data Type.
® IBM Software Group © 2006 IBM Corporation How to read/write XML using EGL This Learning Module shows how to utilize an EGL Library to read/write an XML.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
JQuery CS 268. What is jQuery? From their web site:
COMMUNICATION Team 5 ADIL KHAN. COMMUNICATION Team 5 COMMUNICATION PROVIDER Two Modules Comprise the CommunicationProvider SmilTransporter CloudDataProvider.
1 Web Developer & Design Foundations with XHTML Chapter 6 Key Concepts.
Lecture 3 – Data Storage with XML+AJAX and MySQL+socket.io
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
Database-Driven Web Sites, Second Edition1 Chapter 8 Processing ASP.NET Web Forms and Working With Server Controls.
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
CSCI 6962: Server-side Design and Programming Introduction to AJAX.
Avro Apache Course: Distributed class Student ID: AM Name: Azzaya Galbazar
JavaScript, Fourth Edition Chapter 12 Updating Web Pages with AJAX.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
CSCI 6962: Server-side Design and Programming Web Services.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
Copyright © Curt Hill Sounds, Resource Packs, JSON What more would you want?
Tutorial 10 Programming with JavaScript. XP Objectives Learn the history of JavaScript Create a script element Understand basic JavaScript syntax Write.
Tutorial 10 Programming with JavaScript
Done by: Hanadi Muhsen1 Tutorial 1.  Learn the history of JavaScript  Create a script element  Write text to a Web page with JavaScript  Understand.
Cross Site Integration “mashups” cross site scripting.
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.
Serialization. Serialization is the process of converting an object into an intermediate format that can be stored (e.g. in a file or transmitted across.
JSP Filters 23-Oct-15. JSP - FILTERS A filter is an object that can transform a request or modify a response. Filters are not servlets; they don't actually.
Java server pages. A JSP file basically contains HTML, but with embedded JSP tags with snippets of Java code inside them. A JSP file basically contains.
DT228/3 Web Development Databases. Querying a database: Partial info Search engines, on-line catalogues often need to allow user to search a database.
JavaScript - Basic Concepts Prepared and Presented by Hienvinh Nguyen, Afshin Tiraie.
Server - Client Communication Getting data from server.
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
JSP BASICS AND ARCHITECTURE. Goals of JSP Simplify Creation of dynamic pages. Separate Dynamic and Static content.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
©SoftMooreSlide 1 Introduction to HTML: Forms ©SoftMooreSlide 2 Forms Forms provide a simple mechanism for collecting user data and submitting it to.
HTML Forms.
AJAX. Ajax  $.get  $.post  $.getJSON  $.ajax  json and xml  Looping over data results, success and error callbacks.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Bayu Priyambadha, S.Kom. Static content  Web Server delivers contents of a file (html) 1. Browser sends request to Web Server 3. Web Server sends HTML.
Introduction to JavaScript MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/2/2016.
JSON. JSON as an XML Alternative JSON is a light-weight alternative to XML for data- interchange JSON = JavaScript Object Notation It’s really language.
Google Code Libraries Dima Ionut Daniel. Contents What is Google Code? LDAPBeans Object-ldap-mapping Ldap-ODM Bug4j jOOR Rapa jongo Conclusion Bibliography.
JSON (Copied from and from Prof Da Silva) Week 12 Web site:
JavaScript and AJAX 2nd Edition Tutorial 1 Programming with JavaScript.
JQuery, JSON, AJAX. AJAX: Async JavaScript & XML In traditional Web coding, to get information from a database or a file on the server –make an HTML form.
CS3220 Web and Internet Programming RESTful Web Service
The Client-Server Model
Tutorial 10 Programming with JavaScript
Google Web Toolkit Tutorial
Node.js Express Web Services
Networks Problem Set 1 Due Oct 3 Bonus Date Oct 2
Testing REST IPA using POSTMAN
Session V HTML5 APIs - AJAX & JSON
WEB API.
Chapter 9 Web Services: JAX-RPC, WSDL, XML Schema, and SOAP
Asynchronous Javascript And XML
HTML Level II (CyberAdvantage)
HTML5 AJAX & JSON APIs
JavaScript & jQuery AJAX.
Tutorial 10 Programming with JavaScript
Tutorial 10: Programming with javascript
PHP and JSON Topics Review JSON.
Presentation transcript:

Tools of the trade J SON, M AVEN, A PACHE COMMON Photo from

JSON  JSON is an alternative to XML for transmitting data  JSON is an increasingly popular because it is more concise and therefore faster to process and deliver.  JSON is tightly integrated with JavaScript. JSON stands for JavaScript Object Notation.  Uses a compact object notation that is similar to but not identical to JavaScript object literals.  The syntax is extremely simple and flexible. 2

JSON  There are only several 'kinds' of things in JSON  Numbers 1.2, 3, -12  Booleans true, false  Strings "this is a string"  Objects { … something goes here… }  Lists [ items are listed here separated by commas] 3

JSON 4 [ { "first_name" : "Aaron", "last_name" : "Rogers", "pro_bowler" : "true", "rating" : "112.3" }, { "first_name" : "Adam", "last_name" : "Sandler", "pro_bowler" : "false", "rating" : "3" } ] [ { "first_name" : "Aaron", "last_name" : "Rogers", "pro_bowler" : "true", "rating" : "112.3" }, { "first_name" : "Adam", "last_name" : "Sandler", "pro_bowler" : "false", "rating" : "3" } ] { "name" : "Packers", "players" : [ { "first_name" : "Aaron", "last_name" : "Rogers", "pro_bowler" : "true", "rating" : "112.3" }, { "first_name" : "Adam", "last_name" : "Sandler", "pro_bowler" : "false", "rating" : "3" } ], "wins" : "5", "losses" : "2" } { "name" : "Packers", "players" : [ { "first_name" : "Aaron", "last_name" : "Rogers", "pro_bowler" : "true", "rating" : "112.3" }, { "first_name" : "Adam", "last_name" : "Sandler", "pro_bowler" : "false", "rating" : "3" } ], "wins" : "5", "losses" : "2" }

W HY JSON?  JSON is useful for AJAX calls.  HTML documents often contain JavaScript functions that get data from servers. A user presses a button (get information about something) A JavaScript function requests data from a server The data is returned as JSON The JavaScript function uses the data to generate an HTML fragment that is inserted into the document The HTML document is not reloaded; but rather a small portion is modified. 5

H ANDLING JSON  JavaScript just "works" with JSON.  var player = {"name" : "Rogers", "rating", "112.3" };  var n = player.name;  var rating = player.rating;  Java does not just "work".  String json = "{\"name\":\"Rogers\",\"rating\",\"112.3\"}";  Player p = ?  There are really just two main challenges to processing JSON with Java  Serializing : converting a Java object to JSON  Deserializing : converting JSON to a Java object. 6

F LEX JSON  A JSON processing library that provides two main services: serializing and deserializing  Consider an example where we are writing Java to process the following classes. 7 Parts of this tutorial from

F LEX JSON E XAMPLE  The code below shows how to serialize an object and the result. 8 public String lookupPerson(Long id) { Person p = entityManager.findPerson(id); return new JSONSerializer.serialize(p); } public String lookupPerson(Long id) { Person p = entityManager.findPerson(id); return new JSONSerializer.serialize(p); }

I NCLUDES  Note that the result did not have entries for phoneNumbers or addresses. This is because the serializer only serializes the non-collection fields.  You can force serialization of collections by using the include method. 9

10

F LEX JSON E XAMPLE  Include is a variable-argument method. You can include as many elements as you would like in one call.  Note that "addresses.zipcode" means the zipcode of all address objects in the list. 11

F LEX JSON E XAMPLE  Excludes work like includes. You can specifically prevent a field from appearing in the generated JSON.  Include can take wildcards. Also, the order of includes is semantically meaningful.  "*" means "everything"  "*.class" means "any class field".  For each field, the includes are evaluated to answer the question: should it be serialized. That question is answered by the first applicable include or exclude. 12

D EEP F LEX  The serializer class has a deepSerialize method that sends the entire object graph to JSON. This is essentially 'include everything'. 13

D ESERIALIZE  This is more complicated since JSON has no typing information.  Serializing takes java objects (for which the class is known) and serializes the object.  Deserializing requires that flex knows what classes to generate from the un-typed JSON. 14

D ESERIALIZE  If the JSON comes with "class" fields then things are easy.  Person p = new JSONDeserializer ().deserialize(json);  For this code to work, the json string must have class fields within it.  If the JSON doesn't come with class fields  Person p = new JSONDeserializer ().deserialize(json, Person.class);  If you have a collection (interface) of items.  List pList = new JSONDeserialize >().use("values", Person.class).deserialize(json, ArrayList.class) 15

E XAMPLE  Write a service that pulls information from other services.  Domain.nr is a web service. You enter a domain name and it will generate permutations. Some of these may be available and others not.   To process with a Java Servlet, you should  Write class(es) that correspond to the JSON api.  Write other class(es) that correspond to the JSON that your service will produce.  Write a mapper that converts between the two types of classes. 16

M AVEN  Maven is a build-management tool.  It is often used for dependency management (among many other things).  If you use a 3 rd party library you must either  Download jar files and make sure they are copied into the build path  Declare a dependency in a "pom.xml" file. This file configures Maven for your project. Maven will download any declared dependencies and ensure that they are available in the build path. 17

H TTP C LIENT  The Apache Software Foundation produces high-quality software. We will use numerous libraries from Apache throughout this course.  The HttpClient package is a Java library for pulling data from servers.  Just a set of Java classes  Fully supports all of HTTP (GET, POST, PUT, DELETE,…)  Supports encryption  Good utilities for caching and io management. 18

H TTP C LIENT  The most basic function of HttpClient is to execute HTTP methods.  Execution involves one or several HTTP request / HTTP response exchanges (these are transparent).  Clients provide a request object to execute. The HttpClient then does the following: Transmits the request to the target server Returns a corresponding response object May alternately throw an exception if execution 19

H TTP C LIENT 20

 HTTP messages may carry a content entity.  Requests that use entities are referred to as entity enclosing requests. The HTTP specification defines two entity enclosing request methods: POST and PUT.  Responses are usually expected to enclose a content entity.  The entity is the http body. 21

H TTP C LIENT  The recommended way to consume an entity is by using  HttpEntity#getContent()  HttpEntity#writeTo(OutputStream) 22