27
CONCORDIA UNIVERSITY Department of Computer Science SOEN 487 Web Services and Applications FINAL EXAM: April 17, 2013 (ANSWER) 19:00 - 22:00 – (3 hours) IDENTIFICATION: First Name ______________ Last Name_______________ ID ________________ Signature _______________ Information: 1. This is a close book exam. 2. Please answer all questions – 100 points as shown. 3. Please put your answer to the multiple choice questions in the table below. Question s Mark Questions Mark Section I Answer Section II 1 /2 1 /8 2 /2 2 /5 3 /2 3 /5 4 /2 5 /2 Section III 6 /2 1 /12 7 /2 2 /10 1

Web viewsystems. programming language. ... Services have control over the logic they ... the flight tickets will be issued and the hotel booking and the rental car booking

  • Upload
    buingoc

  • View
    215

  • Download
    0

Embed Size (px)

Citation preview

CONCORDIA UNIVERSITYDepartment of Computer Science

SOEN 487 Web Services and ApplicationsFINAL EXAM: April 17, 2013 (ANSWER) 19:00 - 22:00 – (3 hours) IDENTIFICATION:

First Name ______________ Last Name_______________ ID ________________

Signature _______________

Information:1. This is a close book exam.2. Please answer all questions – 100 points as shown.3. Please put your answer to the multiple choice questions in the table below.

Questions

Mark Questions Mark

Section I Answer

Section II

1 /2 1 /82 /2 2 /53 /2 3 /54 /25 /2 Section III6 /2 1 /127 /2 2 /108 /2 3 /109 /2 4 /1010 /211 /212 /213 /214 /215 /2

1

IDENTIFICATION:

First Name ______________ Last Name_______________ ID ________________

Signature _______________

Section I: Multiple Choices (30 points)

1. A Web Services can be created regardless of theA. systemsB. programming languageC. servicesD. internet

Answer: B

2. This method ensures that each XML element type and attribute name has a unique identity.

A. namespaceB. fully-qualified domain nameC. QName D. named pipe

Answer: A

3. Canonical XML specification is designed toA. Determine if two XML documents are logically equivalentB. Digitally encrypt an XML documentC. Digitally sign an XML documentsD. Use multibyte encoding in XML document

Answer: A

4. Which statement about namespace is NOT true?A. Namespace is defined as attributeB. The namespace URI is used by the parser to look up informationC. The prefix is a short name for the namespaceD. Namespace can avoid name crash.

Answer: B

5. SOAP is used to transfer the:A. controlB. outputC. dataD. None of the above

Answer: C

2

3

6. UDDI is used for listing what ______ are available.A. dataB. controlC. programsD. services

Answer: D

7. Which of the following URLs is the same origin of httpː//www.example.com/dir/page.html

A. httpː//www.example.com/dir2/other.htmlB. httpː//www.example.com:81/dir/other.htmlC. https://www.example.com/dir/other.htmlD. http://en.example.com/dir/other.htmlE. http://example.com/dir/other.html

Answer: A

8. The Web services cannot offer the application components like:A. currency conversionB. weather reportsC. language translationD. web browsers

Answer: D

9. The XML provides the ________ in which you can write the specialized languages to express the complex interactions between the clients and the services or between the components of a composite service.

A. languageB. meta languageC. metaD. services

Answer: B

10. Which of these are not the elements WSDL ?A. TypesB. Port TypeC. ServiceD. destination

Answer: D

11. Which of these test do use an HTTP POST and will send the XML response.A. <?xml version="1.0" encoding="utf-8" ?>

<short xmlns="http://tempuri.org/">38</short>B. <?xml ?>

<short xmlns="http://tempuri.org/">38</short>C. <?xml version="1.0" encoding="utf-8" ?>

<short xmlns="http://tempuri.org/">38D. <short xmlns="http://tempuri.org/">38</short>

Answer: A

4

12. Which of the following tag is not part of WS-BPEL2.0 specification? [Select multiple correct answers]

A. <envelope>B. <invoke>C. <activity>D. <assign>

Answer: A, C

13. The “green page” in UDDI containsA. The general information of a businessB. Technical capacity of a serviceC. List how many services included in a businessD. Classification information of a business

Answer: B

14. Check the code below and select All correct answers [Select multiple correct answers] <portType name="SubmitPurchaseOrderPortType"> <operation name="SubmitPurchaseOrder"> <input name="order" message="SubmitPurchaseOrderMessage"/> </operation></portType>

A. This is a notification operation.B. This is a one-way operation.C. This is a two-way operation.D. JAX-WS implementation that may throw a predefined exceptions.E. JAX-WS implementation that does not throw predefined exception.

Answer: B, D

15. XML Digital Signature is used toA. Digitally sign an XML documentB. Using the sender’s private key to create signatureC. Include a digest created by an ecryption algorithmD. All of the above

Answer: D

5

Section II: Short Answer Questions (18 points)

1. Draw the SOA triangle and explain 1) the roles and their functions in this triangle (3points); 2) the open specifications used by the roles (3 points) ; 3) the advantages to use SOA techniques (2 points).

Answer:

Service encapsulation

Service interoperability

Service abstraction - Beyond what is described in the service contract, services hide logic from the outside world

Service loose coupling - Services maintain a relationship that minimizes dependencies and only requires that they maintain an awareness of each other

Service contract - Services adhere to a communications agreement, as defined collectively by one or more service description documents

Service reusability - Logic is divided into services with the intention of promoting reuse

Service composability - Collections of services can be coordinated and assembled to form composite services

Service autonomy – Services have control over the logic they encapsulate

Service statelessness – Services minimize retaining information specific to an activity

Service discoverability – Services are designed to be outwardly descriptive so that they can be found and assessed via available discovery mechanism

6

WSDL

UDDI

SOAP

2. Explain the differences of SOAP services and RESTful services. Suggest the criteria when to use which services. You can analyze from a) standards; b) development process; c) system architecture etc. (5 points).

Answer:

SOAP services follow industrial standards, such as SOAP, WSDL, BPEL. RESTful services do not have commonly agreed standard per se. RESTful services use HTTP operations to access resources. RESTful services regard each resource over the Internet as a URL and access to it via HTTP queries.

Because SOAP follows open standards, it is possible to automate code generation. RESTful services do not have such advantages.

SOAP services are for enterprise applications, while RESTful services are for marshups and Web site presentations.

3. Please draw two Petri nets to represent two business processes respectively. Process 1 and Process 2 have services A, B, C, D as activities. In Process 1: service A is the first service; after A, either service B or service C can be invoked; after B or C, service D is the last service in the process. In Process 2: service A is the first service; after A, service B and C can be invoked in parallel; after B and C, service D is the last service in the process. (5 points)

Answer:

7

A

B C

D

A

D

B

Section III: Answer the Following Questions with Code (52 points)

Question 1 JAX-WS programming (15 marks)Please read the following WSDL file for a book catelog service. The book catelog service has three operations: getContent returns all the books in the catelog; addBook inserts a book into the catelog; removeBook removes a book from the catelog, if the title exists, otherwise, a fault message is returned. Please read the WSDL file and implement the service in JAX-WS. Hints/requirements:1) Defint the classes Book and BookException or anyother classes necessary (3 points)2) Program the service functions and use JAX-WS annotations. Pay attention to the input and output data type. For example, getContent should return a list of Books. (5 points)3) Use EJB or XML for persistency of the catelog (2 points).4) Handle exception properly (5 points)

The book catelog service WSDL:<?xml version="1.0" encoding="UTF-8"?><!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.1-hudson-28-. --><!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.1-hudson-28-. --><definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://flydragontech.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://flydragontech.com/" name="BookCatalogServiceService"><types><xsd:schema><xsd:import namespace="http://flydragontech.com/" schemaLocation="http://localhost:8080/BookCatalog/BookCatalogServiceService?xsd=1"/></xsd:schema></types><message name="getContent"><part name="parameters" element="tns:getContent"/></message><message name="getContentResponse"><part name="parameters" element="tns:getContentResponse"/></message><message name="addBook"><part name="parameters" element="tns:addBook"/></message><message name="addBookResponse"><part name="parameters" element="tns:addBookResponse"/></message><message name="removeBook"><part name="parameters" element="tns:removeBook"/></message><message name="removeBookResponse"><part name="parameters" element="tns:removeBookResponse"/></message><message name="BookException"><part name="fault" element="tns:BookException"/></message><portType name="BookCatalogService"><operation name="getContent">

8

<input wsam:Action="http://flydragontech.com/BookCatalogService/getContentRequest" message="tns:getContent"/><output wsam:Action="http://flydragontech.com/BookCatalogService/getContentResponse" message="tns:getContentResponse"/></operation><operation name="addBook"><input wsam:Action="http://flydragontech.com/BookCatalogService/addBookRequest" message="tns:addBook"/><output wsam:Action="http://flydragontech.com/BookCatalogService/addBookResponse" message="tns:addBookResponse"/></operation><operation name="removeBook"><input wsam:Action="http://flydragontech.com/BookCatalogService/removeBookRequest" message="tns:removeBook"/><output wsam:Action="http://flydragontech.com/BookCatalogService/removeBookResponse" message="tns:removeBookResponse"/><fault message="tns:BookException" name="BookException" wsam:Action="http://flydragontech.com/BookCatalogService/removeBook/Fault/BookException"/></operation></portType><binding name="BookCatalogServicePortBinding" type="tns:BookCatalogService"><soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/><operation name="getContent"><soap:operation soapAction=""/><input><soap:body use="literal"/></input><output><soap:body use="literal"/></output></operation><operation name="addBook"><soap:operation soapAction=""/><input><soap:body use="literal"/></input><output><soap:body use="literal"/></output></operation><operation name="removeBook"><soap:operation soapAction=""/><input><soap:body use="literal"/></input><output><soap:body use="literal"/></output><fault name="BookException"><soap:fault name="BookException" use="literal"/></fault></operation></binding><service name="BookCatalogServiceService"><port name="BookCatalogServicePort" binding="tns:BookCatalogServicePortBinding"><soap:address location="http://localhost:8080/BookCatalog/BookCatalogServiceService"/></port></service></definitions>

The schema used:

9

<?xml version="1.0" encoding="UTF-8"?><!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.1-hudson-28-. --><xs:schema xmlns:tns=http://flydragontech.com/ xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0" targetNamespace="http://flydragontech.com/"><xs:element name="BookException" type="tns:BookException"/><xs:element name="addBook" type="tns:addBook"/><xs:element name="addBookResponse" type="tns:addBookResponse"/><xs:element name="getContent" type="tns:getContent"/><xs:element name="getContentResponse" type="tns:getContentResponse"/><xs:element name="removeBook" type="tns:removeBook"/><xs:element name="removeBookResponse" type="tns:removeBookResponse"/><xs:complexType name="addBook"><xs:sequence><xs:element name="title" type="xs:string" minOccurs="0"/><xs:element name="authors" type="xs:string" minOccurs="0"/><xs:element name="price" type="xs:double"/></xs:sequence></xs:complexType><xs:complexType name="addBookResponse"><xs:sequence><xs:element name="return" type="xs:boolean" minOccurs="0"/></xs:sequence></xs:complexType><xs:complexType name="getContent"><xs:sequence/></xs:complexType><xs:complexType name="getContentResponse"><xs:sequence><xs:element name="return" type="tns:book" minOccurs="0" maxOccurs="unbounded"/></xs:sequence></xs:complexType><xs:complexType name="book"><xs:sequence><xs:element name="authors" type="xs:string" minOccurs="0"/><xs:element name="price" type="xs:double"/><xs:element name="title" type="xs:string" minOccurs="0"/></xs:sequence></xs:complexType>

<xs:complexType name="removeBook"><xs:sequence><xs:element name="title" type="xs:string" minOccurs="0"/></xs:sequence></xs:complexType>

<xs:complexType name="removeBookResponse"><xs:sequence/></xs:complexType>

<xs:complexType name="BookException"><xs:sequence><xs:element name="message" type="xs:string" minOccurs="0"/></xs:sequence></xs:complexType></xs:schema>

10

Answer:

1) package com.flydragontech;

/** * * @author umroot */public class Book { private String title; private String authors; private double price;

Book(String title, String authors, double price) { super(); this.title = title; this.authors = authors; this.price = price;

}

Book(){ }

public String getAuthors() { return authors; }

public double getPrice() { return price; }

public String getTitle() { return title; }

public void setAuthors(String authors) { this.authors = authors; }

11

public void setPrice(double price) { this.price = price; }

public void setTitle(String title) { this.title = title; }}

/* * To change this template, choose Tools | Templates * and open the template in the editor. */

package com.flydragontech;

/** * * @author umroot */public class BookException extends Exception { public BookException(String msg) { super(msg); }

public BookException(String msg, Throwable th){ super(msg, th); }}

package com.flydragontech;

import java.util.List;import javax.jws.WebMethod;import javax.jws.WebParam;import javax.jws.WebService;

12

/** * * @author umroot */@WebService()public class BookCatalogService {

XMLReader reader = new XMLReader();

/** * Web service operation */ @WebMethod(operationName = "addBook") public Boolean addBook(@WebParam(name = "title") String title, @WebParam(name = "authors") String authors, @WebParam(name = "price") double price) { //TODO write your implementation code here: return reader.addBook(title, authors, price); }

/** * Web service operation */ @WebMethod(operationName = "removeBook") public void removeBook(@WebParam(name = "title") String title) throws BookException { boolean result = reader.remove(title); if (result == false) { throw new BookException(title + " not exist."); } }

/** * Web service operation */ @WebMethod(operationName = "getContent") public List<Book> getContent() { return reader.getContent(); }

13

/** * Web service operation */ @WebMethod(operationName = "getBookNum") public Integer getBookNum() { XMLReader reader2 = new XMLReader(); int i = reader2.getContent().size(); return i; }

public static void main(String[] arg){ XMLReader reader = new XMLReader(); System.out.println(reader.getContent().size()); }

}

/* * To change this template, choose Tools | Templates * and open the template in the editor. */

package com.flydragontech;

import java.io.File;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.io.PrintWriter;import java.util.ArrayList;import java.util.Iterator;import java.util.List;import javax.xml.parsers.DocumentBuilder;import javax.xml.parsers.DocumentBuilderFactory;import org.w3c.dom.Document;import org.w3c.dom.Element;import org.w3c.dom.Node;import org.w3c.dom.NodeList;

public class XMLReader {

public static void main(String argv[]) {

14

XMLReader reader = new XMLReader(); try{ reader.remove("Herry Potter"); }catch(Exception e){ System.out.println(e); }

}

List<Book> getContent() { List<Book> list = new ArrayList<Book>(); try { File file = new File("BookXML.xml"); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(file); doc.getDocumentElement().normalize(); System.out.println("Root element " + doc.getDocumentElement().getNodeName()); NodeList nodeLst = doc.getElementsByTagName("book"); System.out.println("Information of all books");

for (int s = 0; s < nodeLst.getLength(); s++) {

Node fstNode = nodeLst.item(s);

if (fstNode.getNodeType() == Node.ELEMENT_NODE) {

Element fstElmnt = (Element) fstNode; NodeList fstNmElmntLst = fstElmnt.getElementsByTagName("title"); Element fstNmElmnt = (Element) fstNmElmntLst.item(0); NodeList fstNm = fstNmElmnt.getChildNodes(); Book aBook = new Book(); aBook.setTitle(((Node) fstNm.item(0)).getNodeValue()); //System.out.println("title : " + ((Node) fstNm.item(0)).getNodeValue()); NodeList lstNmElmntLst = fstElmnt.getElementsByTagName("authors"); Element lstNmElmnt = (Element) lstNmElmntLst.item(0); NodeList lstNm = lstNmElmnt.getChildNodes(); aBook.setAuthors(((Node) lstNm.item(0)).getNodeValue()); //System.out.println("authors : " + ((Node) lstNm.item(0)).getNodeValue()); NodeList lst = fstElmnt.getElementsByTagName("price"); Element lstE = (Element) lst.item(0); NodeList lstN = lstE.getChildNodes();

15

aBook.setPrice(Double.parseDouble(((Node) lstN.item(0)).getNodeValue())); list.add(aBook); }

} } catch (Exception e) { System.out.println(e); } return list; }

boolean remove(String title) throws BookException { boolean result = false; List<Book> list = getContent(); for(int i = 0; i< list.size(); i++){ Book book = list.get(i); if(book.getTitle().equals(title)){ list.remove(i); result = true; break; } } if (result == false) { throw new BookException(title + " not in catelog."); } writeXML(list); return result; }

Boolean addBook(String title, String authors, double price) { Book book = new Book(title, authors, price); List<Book> list = getContent(); list.add(book); writeXML(list); return true; }

private void writeXML(List<Book> list){ try{ PrintWriter out = new PrintWriter(new FileOutputStream("books.xml"));

16

String ENCODING = "ISO-8859-1"; out.println("<?xml version=\"1.0\" encoding=\""+ENCODING+"\"?>"); //out.println("<!DOCTYPE USERS SYSTEM \"users.dtd\">"); out.println("<books>"); for (int i=0;i<list.size();i++) { Book book = list.get(i); out.println("<book>"); out.println("<title>"+book.getTitle()+"</title>"); out.println("<authors>"+book.getAuthors()+"</authors>"); out.println("<price>"+book.getPrice()+"</price>"); out.println("</book>"); } out.println("</books>"); out.close(); }catch(IOException e){ System.out.println(e); } }}

17

Question 2 RESTful service (12 marks)Assume you have a RESTful service to lookup today’s IBM stock price. The singleton bean is shown in the text box at right. Please 1) program the server side code to response to the client query (5 points); 2) program the client side Ajax code for retrieving the prices and for changing the price (7 points).

Answer:

1)package flydragontech.com;

import javax.ws.rs.core.Context;import javax.ws.rs.core.UriInfo;import javax.ws.rs.PathParam;import javax.ws.rs.Consumes;import javax.ws.rs.PUT;import javax.ws.rs.Path;import javax.ws.rs.GET;import javax.ws.rs.Produces;

/** * REST Web Service * * @author umroot */

@Path("generic")public class GenericResource { @Context private UriInfo context;

private PriceSingleton pricebean = PriceSingleton.getInstance();

/** Creates a new instance of GenericResource */ public GenericResource() { }

/** * Retrieves representation of an instance of flydragontech.com.GenericResource * @return an instance of java.lang.String */ @GET

18

package com.flydragontech;public class StockPriceBean { private String price = "40.0"; private StockPriceBean() { } public static StockPriceBean getInstance() { return StockPriceBeanHolder.INSTANCE; } private static class StockPriceBeanHolder { private static final StockPriceBean INSTANCE = new StockPriceBean(); } public String getStockPrice(){ return StockPrice; } public void setStockPrice(String p){ this.StockPrice = p; } }

@Produces("application/xml") public String getXml() { //TODO return proper representation object return "<h3>The price is "+pricebean.getPrice()+"!</h3>"; }

/** * PUT method for updating or creating an instance of GenericResource * @param content representation for the resource * @return an HTTP response with content of the updated or created resource. */ @PUT @Consumes("application/xml") public void putXml(String content) { pricebean.setPrice(content); }}

2)

var str = ''; //Test code for HelloWorld str = '<h2>Test TemperatureServiceRest with JavaScript</h2><br>';

uri = 'http://localhost:8080/PriceServiceRest/resources/generic';

/* $.ajax({ type: "Get", url: uri, datatype: "text", success: function(data) { alert(data); } });*/

xmlHttp = new XMLHttpRequest(); xmlHttp.open("GET", uri, false); xmlHttp.send( null ); str += xmlHttp.responseText;

str +="<h3> set price to 30.0</h3>";

xmlHttp = new XMLHttpRequest(); xmlHttp.open("PUT", uri, false ); xmlHttp.send("30.0" );

xmlHttp = new XMLHttpRequest(); /*xmlHttp.onreadystatechange = function(){

19

if ( xmlHttp.readyState == 4 && xmlHttp.status == 200 )

alert(xmlHttp.responseText); str += xmlHttp.responseText; };*/ xmlHttp.open("GET", uri, false ); xmlHttp.send( null ); str += xmlHttp.responseText;

var n = document.getElementById('containerContent');n.innerHTML = n.innerHTML + str;

20

Question 3 Business Process Modeling for a travel agency (15 marks) A travel agency can book flights, hotels, and car rentals for a client upon request. The process starts by receiving a request message from a client. The flights should be booked first. Then the hotel and the rental car can be booked in parallel after the flight schedule is decided. The travel agency sends the booking information to the client for confirmation. If all the bookings are agreed upon, the travel agent asks credit card from the client. Once credit card is received, the credit card is charged. If the credit card is successfully charged, the flight tickets will be issued and the hotel booking and the rental car booking will be confirmed. If the bookings are not agreed by the client or the credit card is failed to be charged, the bookings will be cancelled without any charge. In all the cases, a confirmation will be sent to the client to finish the booking process.

The client can cancel a trip after the payment is done. The client can be refunded after being charged a certain amount of penalty. If the client sends in a cancellation request, the travel agency sends cancellations to the related companies. The airline always requires cancellation penalty. The hotel and the rental car company require cancellation penalty if the cancellation is made within 24 hours of the start hour of the service. The travel agency charges $100 for the service fee. The client receives whatever left and a confirmation of cancellation.

Please model the booking business process and the cancellation business process in Petri nets (10 points) and discuss if your model is correct (5 points). Please give your definition of correctness before you start the discussion.

21

Question 4 Automatic Service Composition (10 marks)

A set of available services with their inputs/outputs are listed in the following table: The composition query is (Din, Dout)=({A,B,C},{H}). (1) (5points) Please give the solution(s) to this service composition problem. Please explain the algorithm you use to get the solution. (2) (5 points) If you do not get an solution, explain if solutions exist or no. If you give a solution (or solutions), explain if there are other solutions than what you give in (1) exist in the problem.

service W1 W2 W3 W4 W5 W6 W7 W8

inputs A,B,C B,C C,E C,F K J H G

outputs

J E,F H G H C D H

22