© Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development:...

83
© Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite Applications Dr. Donald F. Ferguson [email protected]

Transcript of © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development:...

Page 1: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

© Donald F. Ferguson, 2014. All rights reserved.

Topics in Modern Internet Application Development:Project 1a Observations,Message Queuing, REST, Composite Applications

Dr. Donald F. [email protected]

Page 2: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

2 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Page 3: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

3 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Agenda

Page 4: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

4 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Agenda

• Class process– The Great WebEx Train Wreck

– Modified Approach to What I Present in Lectures

• Project discussions and questions– 1a/b project comments/observations

– Overall Application Structure

– Design patterns applied to 1st application

– Project 2, or “How does a message queue fit into an application?”

• New Topics– Message Queueing (not Pub/Sub, which we will cover later)

– Concepts

– Patterns

– REST– Concepts

– Best Practices

– Implementation

• Discussion, Q&A

Page 5: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

5 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

ClassProcess

Page 6: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

6 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

The Great WebEx Train Wreck• WebEx project reviews

– Seemed like a good idea at the time.

– I should have– Explained how to use WebEx, and how to give web presentations.

– Provide a template of the TLDS and an example.

– We are not mature enough in the concepts for design/project presentations/reviews I need to spend more interactive, collaborative, whiteboard time with each team.

• I investigated some alternate approaches– Google+ Hangouts:

– Not sure any better. Seems to just add video to WebEx formats.

– UNI accounts not authorized. You would all need new Google+ IDs.

– GoToMeeting, Lync, etc. are very similar to WebEx.

– Nothing seems to handle collaborative whiteboard conversations well.

• I have to do this the old fashioned way for now – F2F– I will be available from 8am – 10am before class on Thursday.

– I will try to spend all Thursday afternoon at Columbia.

– I will come into Columbia other days, including weekends on a variable schedule.

Page 7: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

7 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Class Process• I have been

– Explaining concepts abstractly to

– Enable you to choose your preferred implementation language and framework.

• You did well on the project, – But needed help mapping concepts into specific technologies

– And the mapping will become more complex

• New approach– I am going to slow down a bit and move forward when everyone/most teams have mastered and implemented the

concepts.

– Use examples mostly from the J2EE– Most complete and integrated

– Best documented (http://docs.oracle.com/javaee/, http://docs.oracle.com/javaee/7/tutorial/doc/home.htm, many books)

– I am most familiar with the implementation details

– I will start adding Node.js examples– Which many people consider

– Simpler

– More productive

– More modern

– But is all over the place in terms of documentation, frameworks, examples, … I have more work to pull together concrete examples.

Page 8: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

8 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Class Process• I have been

– Explaining concepts abstractly to

– Enable you to choose your preferred implementation language and framework.

• You did well on the project, – But needed help mapping concepts into specific technologies

– And the mapping will become more complex

• New approach– I am going to slow down a bit and move forward when everyone/most teams have mastered and implemented the

concepts.

– Use examples mostly from the J2EE– Most complete and integrated

– Best documented (http://docs.oracle.com/javaee/, http://docs.oracle.com/javaee/7/tutorial/doc/home.htm, many books)

– I am most familiar with the implementation details

– I will start adding Node.js examples– Which many people consider

– Simpler

– More productive

– More modern

– But is all over the place in terms of documentation, frameworks, examples, … I have more work to pull together concrete examples.

• Comments?• Feedback?• Suggestions?

Page 9: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

9 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

ProjectDiscussion

Page 10: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

10 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Project 1a/b

Page 11: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

11 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Application Structure

Web Application

CustomerController

Agent

Controller

V

V

Data Access Service

CustomerDS

AgentDS

ContactDS

Business Service

CR

MServ

ices

Custo

me

rFa

cade

Agent

Faca

de

V

V

V

HTML

Page 12: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

12 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

One Way – Three Modules

• Data Access Service implementing– Persistence and Object-Relational Mapping

– Intrinsic data consistency

• Business Service– Implementing a Business Function Service, which are trivial in the current application but become more complex in

real applications. For example, CRMService.transferCustomer(customerID, agentID) needs to– Check agent exists and retrieve agent object.

– Call agent.addCustomer(customerID).

– Call customer.setAgentId(agentID)

– Call Data Access Service to Update the data layer.

– Two Business Façade Services that– Wrap the Business Function Service

– Surface the APIs for customer role and agent role.

• Two UI Controllers, with each being– Set of HTML5 forms, JSPs, page definitions, … for the role specific UI

– Service logic for interacting with the Business Façade Service call business logic

– And logic for controlling page flow based on input returned from Business Façade Service

– (Which we will eventually redo in AnularJS)

Page 13: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

13 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Service?

• Service?– What is a service?– BTW, telling us to write a “service locator” without telling us what a service

is what not very nice.

• Module?– What is a module?– If you tell us to write modules without telling us what they are, we are

going to drop the course and take up Arabic.

• So, I will explain an example of– Module and– Service– And you can apply to your chosen language and framework.

Page 14: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

14 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

What is a Service?A concrete (non-normative) example could be …

• A stateless, singletone plain-old-java-object (POJO)• Exposing only methods, with parameters that are only value objects• Wrapped with at least one protocol handler

– That – Receives “messages”– Routes to a POJO method– Get return result– Maps to a response

– A concrete example could be– A J2EE Servlet– That maps

– …/GetCustomer/21 service.getCustomer(21) and– Converts customerVO JSON, XML or something similar

• Eclipse generates the protocol handler for REST and Web Services,and other languages have frameworks that do something similar.

Page 15: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

15 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Value Object/Transfer Object Example

Page 16: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

16 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Value Object/Transfer Object• Consider Customer

– A sequence of code of the form– getName()– getID()– … …– setName()– Set ID()

– Does not work well “over the network.”

• Instead,– Implement entity gets and sets (and DB updates) using transfer/value objects.– Application Objects’ parameters are transfer/value objects.– A business entity typically delegates onto embedded value object.

• Assume a remote with local optimization for business objects– Use transfer/value objects.– Be prepared to handle exceptions.– Even though the operation may not go remote.

Page 17: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

17 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Value Objects – An Approach

Page 18: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

18 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Value Objects – An Approach

• Having CustomerVO and Agent VO– Have properties of the form

– lastName

– firstName

– middleInitial

– phoneNo

– Etc.

– Is a bad idea because I have to find an change all VOs if I later decide– I want to add title and suffice to name, I have to find all the VOs

– I want to separate telephone number into two fields: 1) Country Code, 2) Number

– Want to add CRMService.updateCustomerAddress(cid, addressVO) in additionto CRMService.updateCustomer(cid, customerVO).

• What is in the VOBase? Common functions like– toJSON(), fromJSON()

– isSame() that compares UUIDs

– Etc.

Page 19: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

19 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

But That is a Java way of Doing Things

• JavaScript is – An Object language– That does not have classes, but is not fully committed to no classes– And uses object templates to get OO-like reuse

• You get similar function, and increased flexibility by,– Creating a prototype for addressVO, phoneNoVO, …– Creating a prototype for CustomerVO and AgentVO of the form

– prototype.address = new AddressVO()– prototype.phoneNo = new PhoneNoVO()– … …

– Note:– I am not sure this is exactly the approach. I need to play with prototypes some more.– There are Web tutorials on prototype/class best practices.

Page 20: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

20 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

OO is the Old Way

• Object Oriented is– A conceptual approach to

– Reuse of callable APIs (Interface)– Reuse of implementation (Inheritance)– And other application best practices

– OO languages, like Java, are a (somewhat restrictive) realization of the best practices

• You can, and should, apply the patterns in class-less languages– Abstraction (Simplicity): API caller should not understand implementation details– Encapsulation (Robustness): Code and data are one unit. I do not break my code

by changing function and not data or vice versa.– Polymorphism (reuse): I can write a single piece of code that can interact with

more than one implementation of an interface.– Inheritance (reuse): I can write code once and reuse in multiple “classes.” This is

where things go sideways.

Page 21: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

21 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Going Sideways• Should

– Customer and Agent– Subclass from Person?

• What happens if I add– BusinessPartner– ContractEmployee– Vendor

• I can wind up with– ContractEmployeeAndAgent implements ContractEmployee, Agent– CustomerAndAgent implements Customer, Agent– BusinessPartnerAndCustomer implements Customer, BusinessPartner– And what happens if an Agent suddenly transitions to Contractor?

• Programmers confuse composition with isA.

Page 22: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

22 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Composition

Page 23: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

23 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Composition

• Instead of complex inheritance– Use composition

– And delegation onto properties, which are real properties or a “named” property.

• If you have a reference to a person and want to access BusinessPartner elements– You do not need to

– Create a class CustomerAndBusinessPartnew

– And constantly cast Person into BusinessPartner

– You write aBp = (BusinessPartner) p.getFacet(“BusinessPartner”) orjust use reflection.

• This allows you to– Add BusinessPartner implementation without making lots of new classes

– Write code that manipulates the BusinessPartner API

– Factory code in your business partner logic that creates instances with the right facets

• This is a style of programming in Java but is really natural and flexible in JavaScript.

Page 24: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

24 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Data Access Pattern

• Separate business logic from persistence functions,and use a SOA.

• Some reasons– A local database may become a remote DB, and DB protocols

are not network friendly– Database implementation or schema may change over time.– Enable “unit testing.”

Customer

AgentCustomer

Agent

Data Service

Transfer/ValueObjects

Anti-Pattern

Best Practice Design Pattern

Page 25: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

25 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Play the Same Game for Services

Page 26: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

26 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Play the Same Game for Services

• Have a XXXDataService that implements– Create

– Retrieve

– Update

– Delete

• CustomerDataService and AgentDataService– Ensure basic consistency, e.g. phoneNo.countryCode != “C”

– Wrap SQL statements for reading/updating table(s)

• CRMDataService– Implements Create, Retrieve, Update, Delete for Customer and Agent

– By delegating onto CustomerDataService and AgentDataService

– And ensuring consistency, e.g.– Ensure that there is an Agent with ID=31 when I create a customer with agentID = 31.

– Set AgentID = null for every Customer with agentID=31 when I delete agent with AgentID = 31.

Page 27: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

27 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Consistency? Will Cover in Detail Later

• Transactions = {Atomicity, Consistency, Isolation, Durability}– Atomic: All create/update happen or none.– Consistent: Below– Isolation: This will blow your mind.– Durable: Basically, write the stuff to disk.

• The CRMDataAccess Service– Enable Atomic when updating multiple items by

– Starting transaction before all updates.– Committing transaction after all updates.

– Implement consistency rules intrinsic to data for all applications, e.g.– Constraints, e.g. A customer can have agentID=21 iff if there is an Agent with ID = 21.– Triggers, e.g. Deleting agent with ID = 31 sets customer.agentID = null for all customer that

currently have customer.agentID == 31.– Databases implement many approaches to consistency, but sometimes the “logic” is too

complicated for embedded stored procedures, triggers, etc.

Page 28: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

28 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Change Graphs• Some transfer/value objects

– Don’t have setX(y) update the property– Instead, keeps the original property,

and records {X is now “y”}– An implements getX() by getting the right value.

• The implementation of– myCustomer.update(aCustomerTO)– Processes the change graph and only updates

the properties that have changed.• Why?

– Some transfer/value objects are large/complex.– Updating everything, even if not changed

can have undesirable consequences– Unnecessary DB writes.– Unnecessary firing of DB triggers or RI rules.– Needless change notification events.

Transfer/Value

Objects

Page 29: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

29 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Change Graphs• Don’t database persistence frameworks automate change graphs?

By and large, yes.

• But, updates in “business logic” can trigger functions– Security

– Just because I can get name

– Does not mean I can update name

– Verification– If you call updateAddress

– I make a web call to UPS.com to validate the address

– Notification– If you update a customer’s agentID

– I send an email to the new agent’s and old agent’s manager notifying about the change.

• And you really do not want to have every function/method repeatedly have– if (newValue != oldValue) { // do stuff }

– And sometimes actions get triggered just be calling the method, before your if statement.

Page 30: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

30 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Service Locator Pattern

• Isolates the client of a service/entity from finding the instance/class,which could be– Another class in the same JVM– A remote REST/Web Service– Have an implementation that depends on context, e.g. “I am in test mode.”

Page 31: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

31 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Service Locator

CustomerDS

AgenDSProxy AgentDSTie AgentDS

updateAddress(newA)is a local call.

updateAddress(newA)is a local call.

Implementation

• Converts newA to JSON

• Calls POST on …/CRMService/Create/Customer/…

Implementation

• Field POST

• Converts JSON Java class

• Makes local call

Page 32: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

32 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Service Locator

• Your code always calls a local “object,” which is– The actual target object (where you wrote your code) or– An object that

– Is polymorphically equivalent to the target– But know knows to convert into some type of remote network call

• Tools and frameworks typically generate the– Proxy– Skeleton/Tie object

• But how does your code know– Which one to call?– I cannot “hard code” the knowledge into my application, because I may refactor the code

and do not want to recompile.– The service locator has an API like locate(CRMDataService)– Looks in a config file, makes a JNDI call, … to determine where the target is– And returns the right kind of proxy.

Page 33: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

33 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Application Façade

• An Application Façade is yet-another-service, that simply delegates ontothe “full” Business Service

• Why would you use this?– I can write a control that

– Queries methods, and builds a table of button for callable methods

– That works for ANY service

– And does not show buttons for methods that I am not allowed to call

– I can evolve, rename, etc. my business interface– And only change the encapsulated façade’s implementation

– Instead of finding all my calling code.

Page 34: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

34 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Database SchemaI would have used a structure something like …

• Name = CREATE Table ( int id, String lname, String fname, string mname)

• Address = CREATE Table (int id, String sname, String streetno, String zipcode, …)

• Email = CREATE Table (int id, String domainName, String mailId)

• Person = CREATE TABLE (int id, int nameid, int addressid, int emailed, …)

• Agent = CREATE Table (int id, int personID, String employeeNo, int departmentID, …)

• Customer = CREATE Table (int id, int personID, String customerNo, int agentID, …)

• Contact =– ContactType = CREATE Table (int ID, String typeName)– Contact = CREATE Table (int contactID, int contactType, “blob” contactInfo)

Page 35: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

35 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Huh? Why would you do this?

• UI enablement, e.g.– Prepopulate ContactType table with entries like “email,” “phone call,” …– Write a UI widget for display/enter each type– I can populate the pull down for “Contact Type” by reading the ContactType table– I can put the right “widget” in the HTML by having a widget for each ContactType– I know how to interpret the blob column because I know the ContactType

• Think about some queries– Display everyone (Customer, Agent, Business Partner, Contractor, …)

that lives at address == “….”. I have to run a select on a bunch of tables.– Please show me all the addresses with zipcode = “10027” and then

show me everyone address in the zip code. I want to pick and address,and then show me everyone who lives at the address.

– I decide that I need to add apartmentNo to table. Do I really want to run Alter Table on Person, Business, Shipping Order, …

Page 36: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

36 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

What is a Module?

• Logical, deployable unit of code and configuration information– J2EE has

– EAR and WAR files– import statements for interfaces– Classpath/build path to find the archive files

– Node.js uses– The directory structure for underlying files (which is BTW the original approach in

J2EE)– require (‘foo.js’)– foo.export = … to export interfaces– Various frameworks to register files with URLs, e.g. Express app.get(… …)

• Do not worry about modules for now.

Page 37: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

37 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Summary

• I was way too abstract in the previous lectures.– I need to be more concrete with examples– And provide pseudo-code, or working examples.

• The process needs to be more iterative– Instead of explaining a concept and then having you submit a project– I need to explain the concept, have you take a first pass, and refine with

me.

• We need smaller, more incremental projects

Page 38: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

38 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Assignment1b

Page 39: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

39 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Two Parts

• Refactor the implementation in 1a– Define and implement a base framework.– Choose a set of design patterns.– You may reuse and extend existing implementations/frameworks.– Map code to “modules” with remotely callable interfaces.– Document and explain your design.

• Remotely callable? You will provide support in your application for at least two of your “Application Objects” for two of– Web Services (WSDL, SOAP)– REST– Message Queue

The remainder of this lecture will provide insight into whatREST, Web Services and Message Queues are.

Why didn’t you tell us this beforewe wrote the code?• 1a was to make sure you could setup and

use a runtime and IDE.

• “Before and after” helps fully appreciate a technology.You really appreciate matches when you havetried to start a fire with sticks.

• These are the decisions technical leaders make,and I really want to give you time to think about them.

Page 40: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

40 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

J2EE MessageDrivenBeans are an example

• A MessageDrivenBean– Implements an onMessage() method– Tells the “runtime” to register with a specific queue during initialization– The runtime automatically calls onMessage() when there is something to get.

• This is just a fancy form of– Create a thread– Loop, calling the queue API asking for messages– There are sample SDKs for AWS in several languages.

• An obvious question, “Why would you use a queue?”

Page 41: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

41 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Message Queuing

Web Services

REST

Page 42: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

42 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Do Not Panic

• Do not panic

• We are going to– Go through the concepts– You do some design and tinkering– We will discuss and refine– And incrementally add concepts

• The 1st assignment is just some simple code to put messages and get messages from AWS.– Int operation code– JSON data

Page 43: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

43 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

MessageQueueing

Page 44: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

44 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Message Queue Service Pattern

Point-to-Point communication between modules becomes fragile at scale• Adding modules P and Q requires finding and configuring all senders.• I want to send M to any one of X1, X2 and X3, but only one.• I want to make sure that someone processes M but do not want to hold the transaction

until I get a response (I may not even need the response).• My destinations are not “up” at the same times I am.

A

B

X

Y

Z

Anti-Pattern Best Practice Pattern

Page 45: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

45 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Message Exchange Patterns

Page 46: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

46 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Why Would I Use a Queuehttp://www.javacodegeeks.com/2013/06/working-with-amazon-simple-queue-service-using-java.html is one example)

• Flow control– My server may be able to process 100 reqs/second– There are thousands of clients– The aggregate rate could be 10 req/s or 300 req/s– Without a queue, clients would get connect failures under load

• The request is going to take a long time– Image reformatting and tagging– I cannot have my code “wait” for a response– And I do not want to write a lot of “Is it done yet?” calls

• I do not know (or care) which one implements the logic– I have 5 – 10 image processors for GIFs– I have 7 – 10 processors for .wav files– I do not want to know which ones are active, when and processing what.– I just want to put the “thing in a queue” knowing that someone will eventually pick it up.

• Think “email” for API calls

Page 47: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

47 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

JMS Server API

TopicSubscriber

Page 48: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

48 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Queueing and Publish/Subscribe

Message Queues Publish/Subscribe

Page 49: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

49 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Message Service• A Message (Event) is an Object with a

– Set of standard defined fields, e.g. timestamp, correlation ID, … common to all messages/events.

– A set of user defined metadata fields, e.g. customer ID, origin country, defined as conventions for the specific application.

– Message data.

• Two types of Destination– Queue

– Producers Put Messages– A Consumer Gets (and deletes) the next message M matching a predicate on fields– Put may be transactional; Get may be transactional

– Topics– Consumers subscribe to a Topic with a predicate on fields– All consumers receive a notification message when a producer

– Puts a message on the topic– And the fields match the selecting predicate

Page 50: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

50 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Topic Trees

e1

e2

• Subscribe to /sales• Will see e1 and e2• If they match the filter

Page 51: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

51 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Amazon SQS (I)

Selected“Send Msg”

Page 52: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

52 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Amazon SQS (I)

Page 53: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

53 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Amazon SQS (III)

Page 54: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

54 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Amazon SQS (IV)

Page 55: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

55 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Amazon SQS (V)

Page 56: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

56 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Amazon SQS (VI)

Page 57: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

57 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

REST

Page 58: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

58 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Overview

Page 59: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

59 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Representational State Transfer (REST)

• People confuse– Various forms of RPC/messaging over HTTP– With REST

• REST has six core tenets– Client/server– Stateless– Caching– Uniform Interface– Layered System– Code on Demand

Page 60: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

60 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

REST Tenets

• Client/Server (Obvious)

• Stateless is a bit confusing– The server/service maintains resource state, e.g. Customer and Agent info.– The conversation is stateless. The client provides all conversation state needed

for an API invocation. For example,– customerCursor.next(10) requires the server to remember the client’s position in the

iteration through the set.– A stateless call is customerCollection.next(“Bob”, 10). Basically, the client passes the

cursor position to the server.

• Caching– The web has significant caching (in browser, CDNs, …)– The resource provider must

– Consider caching policies in application design.– Explicitly set control fields to tell clients and intermediaries what to cache/when.

Page 61: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

61 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

REST Tenets• Uniform Interface

– Identify/locate resources using URIs/URLs– A fixed set of “methods” on resources

– myResource.deposit(21.13) is not allowed– The calls are

– Get– Post– Put– Delete

– Self-defining MIME types (Text, JSON, XML, …)– Default web application for using the API– URL/URI for relationship/association

• Layered System: Client cannot tell if connected to the server or an intermediary performing value added functions, e.g.

– Load balancing– Security– Idempotency

• Code on Demand (optional): Resource Get can deliver helper code, e.g.– JavaScript– Applets

Page 62: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

62 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

SSOL Page

Page 63: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

63 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Anatomy of a URL

• SSOL for the Classlist

https://ssol.columbia.edu/cgi-bin/ssol/DhbtiwfsFOMOeFQaDwqxAh/?p%.5Fr%.5Fid=k0F2vZ4ccAhzbcAg0QlK4h&p%.5Ft%.5Fid=1&tran%.5B1%.5D%.5Fentry=student&tran%.5B1%.5D%.5Fterm%.5Fid=20143&tran%.5B1%.5D%.5Fcid=COMSE6998&tran%.5B1%.5D%.5Fsecid=005&tran%.5B1%.5D%.5Fsch=&tran%.5B1%.5D%.5Fdpt=&tran%.5B1%.5D%.5Fback=&tran%.5B1%.5D%.5Ftran%.5Fname=scrs

• This is– Not REST– This is some form of Hogwarts spell– This is even bad for a web page

Page 64: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

64 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Anatomy of a URL

• HTTP://www.somedomain.edu/... The “server” container

• …/ssol/… The module/component

• …/listManager The Application Object or…/Class/COMSE6998-01 Entity Class (“Extent”) and ID

• .../WaitingList/… Contained Resource

• GET, POST, … on URL for CRUD

• Some details– …/WaitlingList/dff9/IQ Path navigation into resources– …/WaitlingList?op=“Approve”?CUID=“dff9” Method

Page 65: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

65 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

A Well-Designed REST Interfaceis not a Shallow Mapping ofA Good Conceptual Model.

You need an adaptor

Page 66: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

66 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

ASimpleExample

Page 67: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

67 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

App StructureSimple Valves

Mapping to Adaptors,which delegate onto

application logic

Page 68: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

68 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Simple Example

Adaptor Code

1. Process HTTP Req2. Delegate onto

app logic3. Produce HTTP RSP

Page 69: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

69 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Page 70: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

70 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Headers

Page 71: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

71 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Headers

Page 72: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

72 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

AnComplexExample

Page 73: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

73 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Example Considerations• Service Endpoint

– Endpoint– Endpoint Encryption

• Requests and Authentication– Request Headers– Request Timestamps– Request Authentication– Response Headers

• Resources– Resource Requests– Resource Representation– Resource Methods– Synchronous Operations– Asynchronous Operations– Success Response Codes– Failure Response Codes

• Resource Data Types– Atomic Types– Complex Type - Object or Structure– Resource Relationships– Resource References

• Pagination– Through HTTP Link Header– Syntax and Example of Pagination Link Header– Consistency Across Page Requests

• Versioning– Version Header– Version URI

• Saying “REST is not enough• You have to define a set of patterns/

conventions of URLs, headers, …

Page 74: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

74 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Endpoint

• <URL>/a/b/c?x=7&y=21 is a pretty straightforward concept, but …– How do I get info about customer “Ferguson?”

– …/Customer/Ferguson/Donald– …/Customer?lastName=“Ferguson”&firstName=“Donald”– ???

– Do I really want to– Find info about Don using …/Customer/Ferguson/Donald– Find info about agent using …/Agents?id=“21”

– How does it work if I can find customer by name or phone number?– How do I set a relationship between customer and agent?

– PUT …/Relationship/AgentFor?agent=“21”&”Customer=“Ferguson”– Or two PUTS, one on Customer and one on Agent?

• In the same way you have to define a framework for your application,you have to define a shape/pattern in your REST API model.

Page 75: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

75 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Headers – Some Choices I MadeHTTP Request Header Value Mandatory

auth-timestamp: The current POSIX time. Yes

auth-key: The user or client’s uniqueAPI KEY.

Yes

auth-signature: The HMAC-SHA256 digest for the request.

Yes

api-version: (Optional) API version string

No

Accept: (Optional) application/xml or application/json

No

Nonce: One time UUID to enableidempotency/duplicate detection

Page 76: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

76 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Response CodesOperation HTTP Request HTTP Response Codes Supported

READ GET 200 - OK with message body204 - OK no message body 206 - OK with partial message body

CREATE POST 201 - Resource created (Operation Complete)202 - Resource accepted (Operation Pending)

UPDATE PUT 202 - Accepted (Operation Pending)204 - Success (Operation Complete)

DELETE DELETE 202 - Accepted (Operation Pending)204 - Success (Operation Complete)

Examples of Link Headers in HTTP response: 

Link: <http://api/jobs/j1>;rel=monitor;title="update profile"Link: <http://api/reports/r1>;rel=summary;title=”access report” 

202 means

• Your request went asynch.

• The HTTP header Linkis where to poll for rsp.

Page 77: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

77 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Failure Response CodeError Response Code

Invalid Parameter 400 - Invalid parameter

Authentication 401 - Authentication failure

Permission Denied 403 - Permission denied

Not Found 404 - Resource not found

Invalid Request Method 405 - Invalid request method

Internal Server Error 500 - Internal Server Error

Service Unavailable 503 - Service Unavailable

Page 78: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

78 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Design Pattern ChoicesResource Requests

Collection https://ENDPOINT/NAMESPACE/RESOURCE[?QUERY_PARAMETERS]

Resource https://ENDPOINT/NAMESPACE/RESOURCE/RESOURCE_ID[?QUERY_PARAMETERS]

Collection Operation HTTP Request

Get all items in the collection GET /collection Should also return the URI of the collection itself.

Get an particular item in the collection

GET /collection/itemId

Get items match certain criteria GET /collection?property1=’value’

Add a new item to the collection POST /collection contents of new item …

Get items starting at 100 with page size=25

GET /collection?start=100&pageSize=25

Support for• Map• Array• Collection

Page 79: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

79 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Relationships

{“membership”: { “URI” : “http://dell.com/memberships/m12356”, “created” : “2013-08-01T12:00:00.0Z”, “owner” : “user123456”, “expire” : “never”, “group” : { “ref” : “http://dell.com/groups/g123456” }, “server” : { “ref” : “http://dell.com/servers/s123456”} }} 

"link": {         "href": "http://dell.com/api/resource1",          "rel": "self",         “title” : “server-s123456”      } 

Relationship as a resource

Relationship as a field in resource

Page 80: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

80 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Navigating Through Result Set• GET on collections, maps, … needs pagination and cursors

– Limit: What is the maximum number of elements you want?

– QueryID: A tag for the query that produced the original result set

– Offset references a specific element in a “page.”

• There is a standard for linking resources in logical sets, e.g.– Link: <http://example.com/TheBook/chapter2>; rel="previous"; title="previous chapter“>

– Indicates that "chapter2" is previous to this resource in a logical navigation path.

• Your API/framework can use this for result sets– Example 1

– GET /api/customers?status=“Gold” returns some number of “Gold” customers and

– Link Header for “next page” is Link: </api/customers?status=“Gold”&offset=50&limit=50>; rel="next last“

– Which is the URL for the “cursor.next set,” which has 50 elements and is also “last”

– Example 2– Get </api/customers?status=“Gold”&offset=50&limit=50> returns the “next” from example 1

– With Link Link: </api/asm/servers?status=ready&limit=50>; rel="prev first"

– Allowing you to go backwards to the previous “page.”

Page 81: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

81 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

2nd

Assignment

Page 82: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

82 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Composites Start with Components –What did this mean?

Page 83: © Donald F. Ferguson, 2014. All rights reserved. Topics in Modern Internet Application Development: Project 1a Observations, Message Queuing, REST, Composite.

83 © Donald F. Ferguson, 2014. All rights reserved.

Modern Internet App Development – Lecture 3:Project 1 Discussion, Message Queuing, REST, Composite Applications

Overall StructureConceptual Framework

Your “Classes”

REST Facade

Message Facade

Q

“Valve pattern” to• Check security• Reject duplicates• … …

Browser

REST Client