02267 software development of web services
play

02267: Software Development of Web Services 1.1 Software - PDF document

Technical University of Denmark Fall 2016 DTU Compute Homework week 1 H. Baumeister November 12, 2018 Associate Professor 02267: Software Development of Web Services 1.1 Software installation Install the OpenESB v3 software (includes the


  1. Technical University of Denmark Fall 2016 DTU Compute Homework week 1 H. Baumeister November 12, 2018 Associate Professor 02267: Software Development of Web Services 1.1 Software installation • Install the OpenESB v3 software (includes the Netbeans IDE) and the Glassfish v4 application server on your computer. Instructions for installing the software can be found at http://www.imm.dtu.dk/courses/02267 . 1.2 Web Service Implementation • Implement a simple Order Web service. The service has operations orderProduct, payOrder, getOrderInfo”, i.e, – orderProduct takes an order number (string), customer name (string), an amount (integer), and a product (string) and returns the order number as a string – getOrderInfo takes as argument an order number and returns a string with the information of the order, e.g., ”Order number 2: Customer Peter has ordered 10 pencil. Payment is okay” for an order made by customer Peter who has ordered 10 amount of product ”pencil” and where payment was okay. If the payment is not okay, then ”Payment is not okay” should be returned instead of ”Payment is okay” – payOrder is a service that initiates payment by taking as argument a credit card number (string), e.g. ”12345”, and an order number (string). The result is true if the payment succeeds and false if not. ∗ Note that you don’t have to implement the business logic for payment (this will come later). Instead, for some fixed customer names, the payment always succeeds and for other customer names, the payment always fails – These functions are best implemented using a HashMap < String, Order > , where Order is class with attributes orderNumber (string), customer (string), product (string), amount (int), and isPaid (boolean) ∗ Note that the business logic should be very simple, e.g., the business logic does not need to check if there already exists an order with the same order number in the map (this will come later). The existing entry is just overritten. • Implement a JUnit test class that is using the order Web service. 1

  2. – Write at least one test method for each operation orderProduct, payOrder, and getOrderInfo testing the operations – Write also a test method for getOrderInfo , where the order number is not a key in the map. ∗ What happens in this case? Note that this is about observing how system errors and exceptions are handled and propagated from the server to the client, not yet about how to avoid these or how to fix them. This will come later. • Tip: First implement orderProduct with its tests, then getOrderInfo first with existing order numbers plus test and then with non-existent order numbers plus tests, and at last payOrder.with its tests. You can skip the implementation of payOrder if you run out of time. 2

  3. Technical University of Denmark Fall 2016 DTU Compute Homework week 2 H. Baumeister November 12, 2018 Associate Professor 02267: Software Development of Web Services 2.1 Software installation and the Order Web service • If you haven’t finished the exercise from last week, do so this week. 2.2 Web Service Monitoring • Using tcpmon, check what messages are exchanged between client and server from previous weeks’ exercise (see instructions on the course Web page). • How is the message exchange different from the others when the server throws an exception that is not caught (e.g. getting the order information for a non-existent order number)? 2.3 Calling and Monitoring a Web service This exercise gives you another possibility to use JUnit to access a Web service and monitor the message exchange. a) Write a client for the temperature convertion Web service offered by webservicex.net. You find the WSDL of that service here: http://www.webservicex.net/ConvertTemperature.asmx?WSDL . Download the WSDL to generate the client stubs. – You can also use other Web services announced at http://free-web-services. com . Make sure they are SOAP based services. We cover REST based services later in the lecture. b) Using JUnit, create test methods for testing the use of that Web service. One of the tests should convert 100 degrees Celsius in Fahrenheit; the other 100 degrees Fahrenheit in Celsius. From the services being offered in the WSDL file (and af- ter you have generated the WSDL client stubs) you should be using the SOAP based services, i.e. ConvertTemperatureSoap or ConvertTemperatureSoap2. The temeprature units have corresponding constants defined in the class Temperature- Unit, DEGREE CELSIUS and DEGREE FAHRENHEIT. c) Monitor the communication between your client and the server using tcpmon 3

  4. Technical University of Denmark Fall 2016 DTU Compute Homework week 3 H. Baumeister November 12, 2018 Associate Professor 02267: Software Development of Web Services 3.1 WSDL Create a WSDL file for a calendar service. The service should offer two operations. One operation stores an appointment (a string) for a specific date (for simplicity, we just consider appointments that take on a whole day) and another operation returns the appointment stored for a specific day. • Create a WSDL file calendar.wsdl • The Web service should define the namespace http://ws.imm.dtu.dk/calendar • The file should contain the port type calendarServicePortType with two operations – addAppointment that takes a xsd:date and a String and returns nothing ∗ Implement addAppointment as a one-way operation – getAppointment that takes an xsd:date and returns a String • The Web service should use SOAP-RPC binding where the parameters are trans- ported in the SOAP body • You can use the NetBeans wizard/editor File > new file > XML > WSDL document to create a WSDL document 3.2 Web Service from WSDL • Create a Web service based on the WSDL file from the previous section. The appointments can be stored in a HashMap. • You can use the NetBeans wizard File > new file > Web Services > Web Services from WSDL to create the Web service implementation stubs from a WSDL file • Implement the correct application logic for the Web service 4

  5. 3.3 Web Service Client • Create a client for the Web service in the previous exercise to test the Web service. – Note, use the WSDL generated by the GlassFish server instead of the original WSDL file. The reason is, that for JAX-WS Web services, GlassFish changes the SOAP address from the one provided in the original WSDL file. 1 Make one test which adds an appointment for a date and then gets the ap- pointment for that date: make sure that the texts are the same 2 Make a second test that adds an appointment for the same date as in the first test, but with a different text for the appointment. • Use tcpmon or Wireshark to observe the traffic between client and server – How do SOAP messages for the one-way operation addAppointment differ from getAppointment ? Are they different? • Questions – When you run both tests, what will happen if it takes, e.g., 3 seconds for the Web service to add an appointment? (Discuss with the TA’s or me, what should happen; try it out and explain what really happens :-) – You can wait for three seconds with Thread.sleep(3000); • The following code snippet creates a XMLGregorianCalendar for a specific date (i.e., 15.9.2011): Note that the date has to be of the form yyyy-mm-dd , i.e., two digits for month and day. For example, yyyy-m-dd does not work. import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeFactory; import javax.xml.datatype.XMLGregorianCalendar; ... DatatypeFactory df = DatatypeFactory.newInstance(); XMLGregorianCalendar date = df.newXMLGregorianCalendar("2011-09-15"); ... 5

  6. Technical University of Denmark Fall 2016 DTU Compute Homework week 4 H. Baumeister November 12, 2018 Associate Professor 02267: Software Development of Web Services Purpose of the exercise • The purpose of this exercise is to learn to precisely control the contents of SOAP messages through WSDL and XML Schema. • Please read all the exercise text before you start implementing. White Pages Service • Write a White Pages Web service that adds a person to a phone book (called addPerson) and then finds persons in that phone book (called findPerson) given a partly filled person object. • For example, if in the query only the last name of the person is known, then the Web service should return a list of person objects having the same last name and which have all of the information filled (e.g. first name, phone number, address, e.t.c.). • The exercise uses the same development process as with last weeks exercise: first, a WSDL is created from which the Web service implementation stubs are generated. The difference is, that now the Web service uses user defined datatypes, defined as XML schema in the WSDL document, and that the WSDL document completely defines the body of the SOAP message using document style. 4.1 White Pages Service: AddPerson Operation • The addPerson operation takes as argument a person and returns a status element containing the string ”done” when adding the person was successful • If there is exists already a person with the same first- and last name in the phone book, a fault message should be returned An example of a successful message exchange is: Request 6

Recommend


More recommend