02267: Software Development of Web Services



Similar documents
02267: Software Development of Web Services

Distribution and Integration Technologies

REST API Development. B. Mason Netapp E-Series

Cloud Elements! Marketing Hub Provisioning and Usage Guide!

REST vs. SOAP: Making the Right Architectural Decision

Security Testing For RESTful Applications

Types of Cloud Computing

Apache CXF Web Services

Lecture Notes course Software Development of Web Services

REST web services. Representational State Transfer Author: Nemanja Kojic

The full setup includes the server itself, the server control panel, Firebird Database Server, and three sample applications with source code.

Remote Access API 2.0

CONTRACT MODEL IPONZ DESIGN SERVICE VERSION 2. Author: Foster Moore Date: 20 September 2011 Document Version: 1.7

XML Processing and Web Services. Chapter 17

JASPERREPORTS SERVER WEB SERVICES GUIDE

Creating Web Services in NetBeans

REST services in Domino - Domino Access Services

SOA CERTIFIED JAVA DEVELOPER (7 Days)

Common definitions and specifications for OMA REST interfaces

MathCloud: From Software Toolkit to Cloud Platform for Building Computing Services

soapui Product Comparison

Principles and Foundations of Web Services: An Holistic View (Technologies, Business Drivers, Models, Architectures and Standards)

Fairsail REST API: Guide for Developers

WIRIS quizzes web services Getting started with PHP and Java

WEB SERVICES. Revised 9/29/2015

Hello World RESTful web service tutorial

SOA CERTIFIED CONSULTANT

Cloud Elements ecommerce Hub Provisioning Guide API Version 2.0 BETA

Cloud Powered Mobile Apps with Microsoft Azure

02267: Software Development of Web Services

Developing a Web Server Platform with SAPI Support for AJAX RPC using JSON

Enabling REST Services with SAP PI. Michael Le Peter Ha

Building and Using Web Services With JDeveloper 11g

Performance Testing Web 2.0

An Oracle White Paper June RESTful Web Services for the Oracle Database Cloud - Multitenant Edition

WEB SERVICES TEST AUTOMATION

Cross-domain Identity Management System for Cloud Environment

Building SOA Applications with JAX-WS, JAX- RS, JAXB, and Ajax

Chapter 1: Web Services Testing and soapui

JBoss SOAP Web Services User Guide. Version: M5

Internet Technologies. World Wide Web (WWW) Proxy Server Network Address Translator (NAT)

WA2087 Programming Java SOAP and REST Web Services - WebSphere 8.0 / RAD 8.0. Student Labs. Web Age Solutions Inc.

Session 6 Patterns and best practices in SOA/REST

HTTP Protocol. Bartosz Walter

JVA-561. Developing SOAP Web Services in Java

Progress OpenEdge REST

Getting started with API testing

Accessing Data with ADOBE FLEX 4.6

Computer Networks. Lecture 7: Application layer: FTP and HTTP. Marcin Bieńkowski. Institute of Computer Science University of Wrocław

NASSI-SCHNEIDERMAN DIAGRAM IN HTML BASED ON AML

The HTTP Plug-in. Table of contents

Integration Knowledge Kit Developer Journal

Application layer Web 2.0

Web Services ( )

Building Web Services with Apache Axis2

SoapUI NG Pro and Ready! API Platform Two-Day Training Course Syllabus

Introduction to Web services for RPG developers

TIBCO JASPERREPORTS SERVER WEB SERVICES GUIDE

Web Services API Developer Guide

Integrating Complementary Tools with PopMedNet TM

Passcreator API Documentation

RESTful web services & mobile push architectures

ITS. Java WebService. ITS Data-Solutions Pvt Ltd BENEFITS OF ATTENDANCE:

Cloud Elements! Events Management BETA! API Version 2.0

Agents and Web Services

Tutorial for Creating Resources in Java - Client

A standards-based approach to application integration

Web Services Tutorial

Qualys API Limits. July 10, Overview. API Control Settings. Implementation

Experiences with JSON and XML Transformations IBM Submission to W3C Workshop on Data and Services Integration October , Bedford, MA, USA

How To Write A Web Server In Javascript

Building Web Services with XML Service Utility Library (XSUL)

1.264 Lecture 24. Service Oriented Architecture Electronic Data Interchange (EDI) Next class: Anderson chapter 1, 2. Exercise due before class

Developing Java Web Services

GlassFish. Developing an Application Server in Open Source

WWW. World Wide Web Aka The Internet. dr. C. P. J. Koymans. Informatics Institute Universiteit van Amsterdam. November 30, 2007

Onset Computer Corporation

Programming Autodesk PLM 360 Using REST. Doug Redmond Software Engineer, Autodesk

Integration of Hotel Property Management Systems (HPMS) with Global Internet Reservation Systems

Designing RESTful Web Applications

Mobility Information Series

How To Create A C++ Web Service

Literature Review Service Frameworks and Architectural Design Patterns in Web Development

vcloud Air Platform Programmer's Guide

Java Web Services Training

Sentinel EMS v7.1 Web Services Guide

Contents. 2 Alfresco API Version 1.0

Developing ASP.NET MVC 4 Web Applications

Intruduction to Groovy & Grails programming languages beyond Java

What is Distributed Annotation System?

Web Services Advanced Topics

Lesson 4 Web Service Interface Definition (Part I)

Visualizing a Neo4j Graph Database with KeyLines

EAI OVERVIEW OF ENTERPRISE APPLICATION INTEGRATION CONCEPTS AND ARCHITECTURES. Enterprise Application Integration. Peter R. Egli INDIGOO.

T Network Application Frameworks and XML Web Services and WSDL Tancred Lindholm

Transcription:

02267: Software Development of Web Services Week 8 Hubert Baumeister huba@dtu.dk Department of Applied Mathematics and Computer Science Technical University of Denmark Fall 2015 1

Recap I BPEL: I Doing things in parallel: the flow construct I Transactions in BPEL: compensatiion handler I RESTful Web services I Introduction and simple example 2

Contents RESTful Services Resources Representations JSON Project Introduction 3

REST = Representational State Transfer I REST is an architecture style defined by Roy Fielding, one of the authors of HTTP 1.0 and 1.1 I Characteristics I Client-server I Stateless I The server does not hold any application state (e.g. state regarding a session); all the information needs to be provided by the client! improves scalability I Cachebale I Uniform Interface I use of standard methods, e.g. GET, POST,... I use of standard representation, e.g. MIME types 4

What are RESTful Web Services? Concepts I Resource: Identified by URI: http://localhost: 8080/sr/resources/students/123 I Representation: Mime types, e.g. test/plain, application/xml, application/json, / I Uniform Interface: HTTP Verbs: GET, POST, PUT (PATCH), DELETE I Hyperlinks: Business logic (next steps in the business process)! next week 5

Student Registration I Classical Web Services focus on services (= operations) I RESTful Web Services focus on resources URI Path Resource Class HTTP Methods ---------------------------------------------------------- /institute InstituteResource GET, PUT /institute/address InstituteResource GET, PUT /students StudentsResource GET, POST /students/{id} StudentResource GET, PUT, DELETE I CRUD: Create, Read, Update, Delete 6

Student Registration: Institute Resource Institute resource I When accessing http://localhost: 8080/sr/webresources/intitute using GET, DTU is returned I Accessing the same URL using PUT with a string, the name of the institution is changed URI Path Resource Class HTTP Methods ---------------------------------------------------------------------- /institute InstituteResource GET, PUT I Bottom up development: 1 JAX-RS annotated client (2) WADL (Web Application Description Language) 3 Client using Jersey 7

Java implementation: JAX-RS annotations package ws.dtu; import javax.ws.rs.get; import javax.ws.rs.put; import javax.ws.rs.path; import javax.ws.rs.core.mediatype; @Path("institute") public class InstituteResource { private static String name = "DTU"; @GET @Produces(MediaType.TEXT_PLAIN) public String getinstitutename() { return name; } @PUT @Consumes(MediaType.TEXT_PLAIN) public void setinstitutename(string input) { name = input; } } @Path("reset") // Resets the name for testing purposes @PUT public void reset() { name = "DTU"; } 8

RESTful Client using Jersey Note that the video on the Web page uses an older version of the library Use the code presented in these slides instead import javax.ws.rs.client.*; import javax.ws.rs.core.mediatype;... public class StudentRegistrationTest { Client client = ClientBuilder.newClient(); WebTarget r = client.target("http://localhost:8070/sr/webresources/institute"); @Test public void testgetinstitutename() { String result = r.request().get(string.class); assertequals("dtu",result); } @Test public void testputinstitutename() { String expected = "Technical University of Denmark"; r.request().put(entity.entity(expected, MediaType.TEXT_PLAIN)); assertequals(expected,r.request().get(string.class)); } @Before public void resetinstitutename() { r.path("reset").request().put(entity.entity("", MediaType.TEXT_PLAIN)); } 9

Contents RESTful Services Resources Representations JSON Project Introduction 10

Student Registration extended I Classical Web Services focus on services (= operations) I RESTful Web Services focus on resources I Two types of resources: students (the list of all students) and student (one student) I Basic operations like register student, search student, access student data, update student data and delete student data is mapped to the appropriate HTTP method URI Path Resource Class HTTP Methods ------------------------------------------------------------ /institute InstituteResource GET, PUT /institute/address InstituteResource GET, PUT /students StudentsResource GET, POST /students/{id} StudentResource GET, PUT, DELETE I A particular student is accessed by its id, e.g. /students/123 11

Example: Student Registration Implementation I A resource path corresponds to one implementation class I StudentsResource (note the plural) import javax.ws.rs.*; @Path("students") public class StudentsResource { @POST @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.TEXT_PLAIN) public String registerstudent(student st) {... } } @GET @Produces(MediaType.TEXT_PLAIN) public String findstudent(@queryparam("name") String name) {... } I @QueryParam allows access to a query parameter, e.g. students?name=nielsen I Conversion from and to XML if XmlRootElement() is used @javax.xml.bind.annotation.xmlrootelement() public class Student {... } 12

Example: Student Registration Implementation Class StudentResource @Path("students/{id}") public class StudentResource { @GET @Produces(MediaType.APPLICATION_XML) public Student getstudent(@pathparam("id") String id){.. } @PUT @Produces(MediaType.APPLICATION_XML) public Student setstudent(@pathparam("id") String id, Student std) } @DELETE @Produces(MediaType.TEXT_PLAIN) public String deletestudent(@pathparam("id") String id, Student std) {.. } I id in the path is replaced by the actual id of the student I @PathParam( id ) allows to map that path component to a paramter in the Java method 13

Example: Student Registration Usage Through the browser I Advantage: Fast way to test a REST services I Disadvantage: Only works with GET operation 14

Example: Student Registration Usage I CURL (http://curl.haxx.se/: sending HTTP requests via the command line I Search for students curl http://localhost:8080/sr/resources/students\?name=fleming I Register a new student curl -X POST \ --data "<student><id>123</id><name>jimmy Jones</name></studen http://localhost:8080/sr/resources/students I Accessing the data of 345 curl http://localhost:8080/sr/resources/students/345 I Updating the data of student 456 curl -X PUT \ --data "<student><name>jimmy Jones</name></student>" \ http://localhost:8080/sr/resources/students/456 I Deleting an item curl -X DELETE http://localhost:8080/sr/resources/students/456 15

Using Postman plugin in Google Chrome I Apps::Web Store::Postman 16

Example: Student Registration Usage I Client c = ClientBuilder.newClient(); WebTarget r = c.target("http://localhost:8070/sr/webresources") I Search for a student String url = r.path("students").request().queryparam("name","fleming").get(string.class) I Register a new student Student student = new Student(); student.setname(..);... String id = r.path("students").request().post(entity.entity(student,mediatype.mediatype.application_xml), String.class; 17

Example: Student Registration Usage II I Accessing the data of 345 Student s = r.path("students").path("345").get(student.class); I Updating the data of student 456 Student student = new Student();... Student s = r.path("students").path("456").request().put(entity.entity(student,mediatype.application_xml), Student.class); I Deleting an item String res = r.path("456").request().delete(string.class); 18

Contents RESTful Services Resources Representations JSON Project Introduction 19

Multiple Representations registerstudent: data provided as XML or JSON @POST @Consumes("application/xml") @Produces("text/plain") public String registerstudentxml(student st) { return registerstudent(st); } @POST @Consumes("application/json") @Produces("text/plain") public String registerstudentjson(student st) { return registerstudent(st); } public String registerstudent(student student) { student.setid(nextfreestudentid()); students.put(student.getid(),student); String url = "http://localhost:8080/sr/resources/students/"; return url + student.getid(); } 20

HTTP Request JSON POST /sr/resources/students HTTP/1.1 Accept: */* Content-Type: application/json User-Agent: Java/1.6.0_37 Host: localhost:8070 Connection: keep-alive Transfer-Encoding: chunked 21 {"id":"133","name":"jimmy Jones"} 0 XML POST /sr/resources/students HTTP/1.1 Accept: */* Content-Type: application/xml User-Agent: Java/1.6.0_37 Host: localhost:8070 Connection: keep-alive Transfer-Encoding: chunked 6e <?xml version="1.0" encoding="utf-8" standalone="yes"?> <student> <id>133</id> <name>jimmy Jones</name> </student> 21

Client Code Student student = new Student(); student.setid("133"); student.setname("jimmy Jones"); String res = target.request().post(entity.entity(student, MediaType.APPLICATION_JSON), String.class); Entity.entity(...,MediaType... ) sets the Content-Type header of the HTTP request 22

Multiple Representations I getstudent: data returned as XML or JSON @GET @Produces("application/xml") public Student getstudentxml(@pathparam("id") String id) {; return getstudent(id); } @GET @Produces("application/json") public Student getstudentjson(@pathparam("id") String id) { return getstudent(id); } public Student getstudent(string id) { return students.get(id); } 23

HTTP Request XML GET /sr/resources/students/123 HTTP/1.1 Accept: application/xml User-Agent: Java/1.6.0_37 Host: localhost:8070 Connection: keep-alive HTTP/1.1 200 OK... Content-Type: application/xml... <?xml version="1.0" encoding="utf-8" standalone="yes"?> <student> <id>123</id> <name>jimmy Jones</name> </student> JSON GET /sr/resources/students/123 HTTP/1.1 Accept: application/json User-Agent: Java/1.6.0_37 Host: localhost:8070 Connection: keep-alive 24

Client Code Student student = target.path("123").request().accept(mediatype.application_xml)..get(student.class); accept(mediatype... ) sets the Accept header of the HTTP request 25

Contents RESTful Services Resources Representations JSON Project Introduction 26

JSON: JavaScript Object Notation Syntax: http://www.json.org I Basically: key value pairs or records or structs I Simple datatypes: object, string, number, boolean, null, arrays of values Eg. object { "name" : "Johan", "id" : 123 } Nested objects { "name" : "Johan", "id" : 123, "address" : { "city": "Copenhagen", "street": "Frørup Byvej 7" } } Eg. array of objects [ { "name" : "Johan", "id" : 123 }, { "name" : "Jakob", "id" : 423 } ] 27

JSON Advantages I lightweight { "name" : "Johan", "id" : 123 } I Compare to <?xml version="1.0" encoding="utf-8" standalone="yes"?> <student> <name>johan</name> <id>123</id> </student> I Easy to use with Javascript, e.g. var student = eval("("+ jsonstring + ")")! But: Security risk! Better var student = JSON.parse(jsonString) Disadvantage I JSON is not typed! Is { name : Johan, id : 123, foo : bar } a person object?! Each client has to check for himself if all the necessary fields are there 28

Next Week I RESTful Services I Error Handling I Implementing Business Processes I SOAP based Web services I Web service discovery: UDDI, WSIL 29

Contents RESTful Services Resources Representations JSON Project Introduction 30

Exam project introduction TravelGood I TravelGood is a travel agency allowing to manage itineraries, book them, and possibly cancel them! Detailed description on CampusNet I Business Process I Planning phase: get flight/hotel information, add flight/hotels to itineraries I Booking phase: book the itinerary I Cancel phase: possibly cancel the itinerary I Trips consists of flights and hotels I possible several flights and hotels I flights are always one-way I TravelGood works together with I Airline Reservation Agency: LameDuck I Hotel Reservation Agency: NiceView I Bank: FastMoney I will be provided at http://fastmoney.imm.dtu.dk:8080 31

Tasks (I) 1 Write a section on Web services (SOAP-based and RESTful) 2 Show the coordination protocol between the client and the travel agency as a state machine 3 Implement the Web services from the previous slide I Define the appropriate data structures I Services of LameDuck and NiceView I Two implementations for TravelGood a. BPEL process b. RESTful services 32

Tasks (2) 4 Create the JUnit tests testing the major behaviour of the planning, booking and cancelling 5 Web service discovery I Create WSIL files describing the services each company offers 6 Compare BPEL implementation with RESTful implementation 7 Advanced Web service technology I Discuss WS-Addressing, WS-Reliable Messaging, WS-Security, and WS-Policy 33

General remarks I The implementation can be done using Java with Netbeans but also using any other Web service technology, e.g..net I However BPEL must be used for composite Web services I All your Web services should be running and have the required JUnit tests or xunit for other programming languages, e.g NUnit for.net I During the project presentations you may be asked to show the running system by executing the clients I It might be helpful do use some helper services in BPEL processes to do complicated computations. I However these helper services are not allowed to call Web services if the helper service is not written in BPEL 34

Structure of the report 1. Introduction I Introduction to Web services 2. Coordination Protocol 3. Web service implementations 3.1 Data structures used 3.2 Airline- and hotel reservation services 3.3 BPEL implementation 3.4 RESTful implementation 4. Web service discovery 5. Comparison between RESTful and SOAP/BPEL Web services 6. Advanced Web service technology 7. Conclusion 8. Who did what No appendices 35

Reporting: Web service implementations I Each Web service should have a short description of what it does and how it is implemented I BPEL processes I graphical representation of the BPEL process in an understandable way (e.g. you can use several diagrams for showing a BPEL process, e.g. one for the overall structure and others for the details) I There is a feature in the BPEL designer of Netbeans to hide details I RESTful services I What are resources and why? I Mapping to HTTP verbs I Representation options and choices 36

What needs to be delivered? I Report (report xx.pdf) I application xx.zip I Source code projects (e.g. Netbeans projects) of the application so that I can deploy and run the projects I Implemented Web services I Simple services I Complex services (BPEL) I Tests 37

Important: Who did what in the project I It is important that with each section / subsection it is marked who is responsible for that part of the text. I There can only be one responsible person for each part of the text. I In addition, each WSDL, XSD, BPEL, Java,... file needs to have an author. I Who is author of which file should be listed in the section Who did What in the report I Make sure that each member of the group does something of each task (including RESTful WS and BPEL)! I Note that you all are responsible that the overall project looks good I Team work is among the learning objectives I Don t think: I am not responsible for this part, so I don t have to care how this part looks and contributes to the whole 38

General tips I It is likely to get better grades if you all work together and everybody is in fact responsible for every part in the report I Prioritise high risk task: Don t put off high risk tasks (like doing the BPEL processes) to the end of the project I Not so good: XML schema, WSDL file, Simple Web services, BPEL processes, Test I Better: work by user stories: book trip successful (Test, XML schema, WSDL file, Simple Web services, BPEL process), book trip with errors (... ), cancel trip successful (... ),... I Try to avoid waiting for each other I I can t do the WSDL files, because I am waiting for the other guy doing the XML schemata first 39

Schedule I Forming of project groups happens now I Project starts today and finishes midnight on Monday in lecture week 13 I Submission of the two files to the assignment module on CampusNet I Project presentations will be Tuesday 15 Friday 18.12: participation is mandatory I Help I Regarding the problem description I Technical help I Lab sessions before the lecture will continue through the project period and can be used for technical questions and problem clarifications I Please also send your Netbeans projects if you write an e-mail I Detailed task description on CampusNet 40