1 / 20

Web Services

Web Services. Dr. Miguel A. Labrador Department of Computer Science & Engineering labrador@csee.usf.edu http://www.csee.usf.edu/~labrador. Outline. Introduction Web services components The Web Services API Creating a simple Web service Server side MIDlet. Web Services.

gefen
Download Presentation

Web Services

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Web Services Dr. Miguel A. Labrador Department of Computer Science & Engineering labrador@csee.usf.edu http://www.csee.usf.edu/~labrador

  2. Outline • Introduction • Web services components • The Web Services API • Creating a simple Web service • Server side • MIDlet

  3. Web Services • Created to allow any networked application client to find applications located anywhere in the Internet and use them as if they were locally installed applications • Regardless of platform • To realize this vision, four critical aspects are needed: • Develop and deploy applications that can be accessed and used by everyone • Describe the services • Web Services Definition Language (WSDL) • Find the services • Universal Description, Discovery, and Integration (UDDI) registry • Not really needed if you know the URL where the service is offered • Connect and use the services • Standard protocols and languages • HTTP, SOAP, RPC, XML

  4. The Java ME Platform Request Service Creates Service Provider Stub Web Service Application Creates Creates WSDL Document Client UDDI Finds and Obtains Service WSDL Registers

  5. The Web Services API • Based on JSR 172, J2ME Web Services APIs (WSA) • The purpose of this specification is to define an optional package that provides standard access from Java ME devices to Web services • Two optional packages • Java API for XML-based RPC (JAX-RPC) • Allows mobile devices to access remote XML-based Web services • Java API for interacting with SOAP-based Web services • Implementation of RPC in Java • Java API for XML Processing (JAXP) • Adds XML parsing capabilities to the Java ME platform • Can be used by all applications

  6. The Web Services API Client • JAXP API • Application • JAX-RPC API • JAX-RPC Stub • Service Provider Interface (SPI) • JAX-RPC Runtime • Server Service Request • MIDP 2.0 • CLDC 1.1 SOAP XML/HTTP • Operating System Service Response

  7. The JAX-RPC Package • Contains the javax.microedition.xml.rpc, javax.xml.namespace, javax.xml.rpc and javax.rmi packages • All classes and interfaces that make up the stub, SPI, and runtime • Stub makes requests to the runtime and receives service responses through the service provider interface • An instance of the stub class is generated by the stub generator. The instance is used to: • Set the properties of the stub to invoke an RPC • Make all appropriate format conversions • Create objects describing the input and return parameters • Encode the input values • Invoke the RPC • Decode the return value • The runtime contains all the functionality needed to transfer data to and from the server on behalf of the application

  8. The JAXP Package • Subset of the J2SE JAXP API • Includes the javax.xml.parsers, org.xmal.sax, org.xmal.sax.helpers packages • Parse XML data

  9. Creating a Web Service • Creating a Web service is very much automated in NetBeans • Let us go through the process of creating a Web service that functions like a calculator • MIDlet asks user for operands and type of operation (sum, …) • MIDlet sends request to Web server • Web server calculates the result and sends it back to MIDlet • Need to develop Web server part and MIDlet

  10. Web Service Part • The process consists of the following chronological steps • Define operations to perform (sum, subtraction, multiplication, division) • Define input and output parameters • Create a New Application Project • From the Categories list, select Web • From the Projects list, select Web Application • Write in the name of your project • Click Next and Finish • Create a new package for the project • Select project in Projects’ tab and right click on it • Select New->Java Package • Write in name and click on Finish

  11. Web Service Part • The process consists of the following chronological steps • Create Web Service • Select project in Projects’ tab and right click on it • Select New->Web Service • Write in Name • Select package just created and Finish • The configuration screen appears to define operations and parameters • Design the service

  12. Web Service Part

  13. Web Service Part • The process consists of the following chronological steps • Click on “Source” button to see the Web Service code that NetBeans automatically creates for you • Only need to include the code that performs each function in the respective part

  14. Creating a Web Service • The process consists of the following chronological steps • Save changes • Click on service and right click for Clean and Build • Click on service and right click to Undeploy and Deploy your project • NetBeans also automatically creates the WSDL file • http://IPadd:port (Glassfish 12796)/Project Name (Context Path from Properties/Run menu)/Web service name(CalculatorService)?wsdl • http://131.247.3.235:12796/WebAppExample/NewWebServiceService?wsdl • http://localhost:12796/LbsBook/ServerCalculatorService?wsdl

  15. Example WSDL File • <?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.1.3.1-hudson-417-SNAPSHOT. • --> • <!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is • JAX-WS RI 2.1.3.1-hudson-417-SNAPSHOT. • --> • <definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss- • wssecurity-utility-1.0.xsd" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" • xmlns:tns="http://services.client.book.edu.usf.cse/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" • xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://services.client.book.edu.usf.cse/" • name="ServerCalculatorService"> • - <types> • - <xsd:schema> • <xsd:import namespace="http://services.client.book.edu.usf.cse/" • schemaLocation="http://localhost:12796/LbsBook/ServerCalculatorService?xsd=1" /> • </xsd:schema> • </types> • - <message name="calculateSum"> • <part name="parameters" element="tns:calculateSum" /> • </message> • - <message name="calculateSumResponse"> • <part name="parameters" element="tns:calculateSumResponse" /> • </message> • - <message name="calculateSub"> • <part name="parameters" element="tns:calculateSub" /> • </message> • . . .

  16. Creating the MIDlet • The process consists of the following chronological steps • Next step is to create the MIDlet • Create New Project Mobility, MIDP Application • Write in name and click Finish • Create package as before • Select Project, right click, New Visual MIDlet • Write in the MIDlet name, select package • Select New Java ME Web Service Client • Provide URL of WSDL document • Click on Retrieve WSDL • NetBean creates application skeleton • Maps WSDL definitions to Java representation and XML data types to Java types • Design Visual MIDlet

  17. Creating a MIDlet

  18. Creating the MIDlet

  19. Creating the MIDlet • The process consists of the following chronological steps • Add the code public void commandAction(Command command, Displayable displayable) { // write pre-action user code here if (displayable == form) { if (command == okCommand) { // write pre-action user code here // write post-action user code here RunnabletheInvoker = new Runnable(){ public void run() { intop1 = Integer.parseInt(textField.getString()); intop2 = Integer.parseInt(textField1.getString()); ServerCalculatorService_StubremoteCalculator = new ServerCalculatorService_Stub(); intop3; try { op3 = remoteCalculator.calculateSum(op1, op2); textField2.setString(""+op3); } catch (RemoteException ex) { ex.printStackTrace(); textField2.setString(ex.getMessage()); } } }; Thread t = new Thread(theInvoker); t.start();

  20. Creating the MIDlet • The process consists of the following chronological steps • Run the MIDlet

More Related