Consuming, providing and publishing Web Services

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    Consuming, providing and publishing Web Services - Presentation Transcript

    1. The Software Environment Writing WS Consumers Writing WS Providers Consuming, Providing & Publishing WS Ioannis G. Baltopoulos Department of Computer Science Imperial College London Inverted CERN School of Computing, 2005 Geneva, Switzerland Ioannis G. Baltopoulos Consuming, Providing & Publishing WS
    2. The Software Environment Writing WS Consumers Writing WS Providers The Software Environment 1 The tools Apache Axis Writing WS Consumers 2 Using WSDL2Java Writing WS Providers 3 Using Java2WSDL UDDI Overview Publishing Services on UDDI Ioannis G. Baltopoulos Consuming, Providing & Publishing WS
    3. The Software Environment The tools Writing WS Consumers Apache Axis Writing WS Providers The Software Environment For this tutorial we are going to use the following software environment. Java Producers and Consumers will be based on Java version 1.4.2. Eclipse THE IDE for writing Java code. Version used is 3.1M4 Ant Build tool used for automating the development process. Tomcat The Web Application container hosting the WS. Axis An open source WS implementation for Java; currently in version 1.2RC2. Ioannis G. Baltopoulos Consuming, Providing & Publishing WS
    4. The Software Environment The tools Writing WS Consumers Apache Axis Writing WS Providers Apache Tomcat (5.0.28) Installation and Notes Web Site http://jakarta.apache.org/tomcat/ Step by step installation Download the required file from 1 http://jakarta.apache.org/site/binindex.cgi#tomcat Extract the downloaded file in a directory of your choice. 2 Start the server from tomcat/bin/startup 3 Validate installation by going to http://localhost:8080/ 4 Ioannis G. Baltopoulos Consuming, Providing & Publishing WS
    5. The Software Environment The tools Writing WS Consumers Apache Axis Writing WS Providers Apache Axis Installation and Notes Web Site http://ws.apache.org/axis/ Step by step installation Download the required file from 1 http://ws.apache.org/axis/releases.html Extract the downloaded file in a directory of your choice. 2 Copy the axis/webapps directory to tomcat/webapps. 3 Restart the web server. 4 Validate installation by going to 5 http://localhost:8080/axis/happyaxis.jsp Ioannis G. Baltopoulos Consuming, Providing & Publishing WS
    6. The Software Environment The tools Writing WS Consumers Apache Axis Writing WS Providers Apache Axis The Purpose of the Application Definition Axis is the means by which SOAP messages are taken from the transport layer and are handed to the Web Service and the means by which any response is formatted in SOAP messages and sent back to the requester. Structure of a Webapp It is in itself a web application. ROOT Comes with many useful tools \\WEB-INF Java2WSDL \\classes WSDL2Java \\lib Administration Client web.xml TCP Monitor SOAP Monitor server-config.wsdd Ioannis G. Baltopoulos Consuming, Providing & Publishing WS
    7. The Software Environment The tools Writing WS Consumers Apache Axis Writing WS Providers Apache Axis Architectural Components Axis Engine - The main entry point into the SOAP processor Handlers - The basic building blocks inside Axis that link Axis to existing back-end systems Chain - An ordered collection of handlers Transports - Mechanisms by which SOAP messages flow in and out of Axis Deployment/Configuration - Means through which Web Services are made available through Axis Serializers/Deserializers - Code that will convert native datatypes into XML and back. Ioannis G. Baltopoulos Consuming, Providing & Publishing WS
    8. The Software Environment The tools Writing WS Consumers Apache Axis Writing WS Providers Axis Architectural Diagram Ioannis G. Baltopoulos Consuming, Providing & Publishing WS
    9. The Software Environment Writing WS Consumers Using WSDL2Java Writing WS Providers WS Consumers The process of writing a consumer Locate the wsdl file for the service you’re interested in. Use WSDL2Java to generate the stub classes. Writing the actual client code. Ioannis G. Baltopoulos Consuming, Providing & Publishing WS
    10. The Software Environment Writing WS Consumers Using WSDL2Java Writing WS Providers WSDL2Java Command line and options A tool for generating glue code in writing consumers and providers. Command Line java org.apache.axis.wsdl.WSDL2Java wsdl-file Options NOTE Used to specify the The following files must -o directory output directory be on the CLASSPATH. axis.jar Package specification -p package commons-discovery.jar for the output files commons-logging.jar Verbose output -v jaxrpc.jar Generate test files -t saaj.jar Generate server side -s wsdl4j.jar code Ioannis G. Baltopoulos Consuming, Providing & Publishing WS
    11. The Software Environment Writing WS Consumers Using WSDL2Java Writing WS Providers Example Usage Using a public weather web service Capeclear offers a public weather service where given the location code of an airport (”LHR”,”LGW”, etc) it returns a complete weather report including temperature, humidity, wind direction. Example WSDL2Java.bat http://live.capescience.com/wsdl/GlobalWeather.wsdl -o %PROJECT BASE%\\src\\java -p ch.cern.it.csc -v Ioannis G. Baltopoulos Consuming, Providing & Publishing WS
    12. The Software Environment Writing WS Consumers Using WSDL2Java Writing WS Providers Generated Files What gets generated from the WSDL file WSDL clause Java class(es) generated For each <type> A java class. A holder if this type is used as an in- out/out parameter For each <portType> A java interface For each <binding> A stub class For each <service> A service interface. A service implementation (locator) For each <binding> A skeleton class An implementation template class For all <services> One deploy.wsdd file One undeploy.wsdd file Ioannis G. Baltopoulos Consuming, Providing & Publishing WS
    13. The Software Environment Writing WS Consumers Using WSDL2Java Writing WS Providers Generated Files Relationship & Location of generated files Ioannis G. Baltopoulos Consuming, Providing & Publishing WS
    14. The Software Environment Writing WS Consumers Using WSDL2Java Writing WS Providers Client Code Example Tying all the generated files together! Example import java.rmi.RemoteException; public class Client { public static void main(String[] args) { ServiceLocator locator = new ServiceLocator(); ServicePort service = locator.getService(); try { Report report = service.getReport(\"Status\"); } catch (RemoteException e) { e.printStackTrace(); } } } Ioannis G. Baltopoulos Consuming, Providing & Publishing WS
    15. The Software Environment Using Java2WSDL Writing WS Consumers UDDI Overview Writing WS Providers Publishing Services on UDDI Writing Providers The two approaches Instant Deployment Very simple way of providing a Web Service Customized Deployment More elaborate Ioannis G. Baltopoulos Consuming, Providing & Publishing WS
    16. The Software Environment Using Java2WSDL Writing WS Consumers UDDI Overview Writing WS Providers Publishing Services on UDDI Instant Deployment Step by step Copy any Java source file that implements a web service into 1 the axis directory no special code is required all public, non-static methods are exposed if the class is in a package, copy it to the appropriate subdirectory Change the file extension from .java to .jws 2 Place all related .class files under WEB-INF/classes 3 View the WSDL of a JWS web service using the following 4 URL in a web browser http://host:port/axis/filename.jws?wsdl Ioannis G. Baltopoulos Consuming, Providing & Publishing WS
    17. The Software Environment Using Java2WSDL Writing WS Consumers UDDI Overview Writing WS Providers Publishing Services on UDDI Example An example using Instant Deployment A very simple banking web service. The bank allows the following four operations Create an Account Get the balance of an Account Withdraw a given amount from an Account Deposit a given amount to an Account To implement it we will use two basic classes A class Account A BankingService class Ioannis G. Baltopoulos Consuming, Providing & Publishing WS
    18. The Software Environment Using Java2WSDL Writing WS Consumers UDDI Overview Writing WS Providers Publishing Services on UDDI The Account class public class Account { private String number; private String owner; private double balance; public void withdraw(double amount) { balance -= amount; } public void deposit(double amount) { balance += amount; } public double getBalance() { return balance; } } Ioannis G. Baltopoulos Consuming, Providing & Publishing WS
    19. The Software Environment Using Java2WSDL Writing WS Consumers UDDI Overview Writing WS Providers Publishing Services on UDDI The BankingService class public class BankingService { public void withraw(Account ac, double amount) { ac.withdraw(amount); } public void deposit(Account ac, double amount) { ac.deposit(amount); } public Account createAccount(String owner) { return new Account(); } public double getBalance(Account ac) { return ac.getBalance(); } } Ioannis G. Baltopoulos Consuming, Providing & Publishing WS
    20. The Software Environment Using Java2WSDL Writing WS Consumers UDDI Overview Writing WS Providers Publishing Services on UDDI The Result A trivial banking service Step by step We’ve written the code. 1 Copy the BankingService file under axis. 2 Change the file extension from .java to .jws 3 Compile and copy the Account.class file under 4 WEB-INF/classes View the WSDL of the Banking Service using the following 5 URL in a web browser http://host:8080/axis/BankingService.jws?wsdl Ioannis G. Baltopoulos Consuming, Providing & Publishing WS
    21. The Software Environment Using Java2WSDL Writing WS Consumers UDDI Overview Writing WS Providers Publishing Services on UDDI Limitations The limitations of using instant deployment The use of instant deployment is only intended for simple web services. Here are some reasons why this is so You cannot use packages in the pages As the code is compiled at run time you can not find out about errors until after deployment. There is limited control over the serialization/deserialization process. The actual source code is placed on the web server Sometimes the source code is not available Ioannis G. Baltopoulos Consuming, Providing & Publishing WS
    22. The Software Environment Using Java2WSDL Writing WS Consumers UDDI Overview Writing WS Providers Publishing Services on UDDI Using Custom Deployment The process of creating a Web Service Step by step Write a Facade interface the subsystem you want to expose as 1 a Web Service. Create a WSDL file either manually or by using the 2 Java2WSDL tool that comes with Axis. Create Bindings using the WSDL2Java tool making sure to 3 activate the options for emitting server side code as well as deployment descriptors. Package all the files in a .jar file 4 Copy the file to the WEB-INF/lib 5 Use the AdminClient tool to deploy the Web Services to Axis. 6 Ioannis G. Baltopoulos Consuming, Providing & Publishing WS
    23. The Software Environment Using Java2WSDL Writing WS Consumers UDDI Overview Writing WS Providers Publishing Services on UDDI Java2WSDL Command line and options A tool for generating a WSDL file from existing Java code Command Line java org.apache.axis.wsdl.Java2WSDL wsdl-file Options Specifies the output filename -o filename Specifies the URI of the service -l uri Target namespace of the wsdl -n namespace Generate test files -p package namespace Verbose output -v Ioannis G. Baltopoulos Consuming, Providing & Publishing WS
    24. The Software Environment Using Java2WSDL Writing WS Consumers UDDI Overview Writing WS Providers Publishing Services on UDDI Generate Server Side Bindings Using WSDL2Java The next step in the process is generating the server side bindings and the deployment descriptors (deploy.wsdd, undeploy.wsdd). Run the WSDL2Java tool using the -s and -S options (see earlier slides for consumer generation). Discard the client specific files Package all the .class files in a .jar file. Use jar cvf filename.jar file(s) Copy the generated file into the WEB-INF/lib directory. Ioannis G. Baltopoulos Consuming, Providing & Publishing WS
    25. The Software Environment Using Java2WSDL Writing WS Consumers UDDI Overview Writing WS Providers Publishing Services on UDDI Service Deployment Using the AdminClient tool and the .wsdd files Deployment Descriptor Files End with .wsdd (usually named deploy.wsdd and undeploy.wsdd) Specifies Axis components to be deployed or undeployed Specifies special type mappings between XML and Java Command Line java org.apache.axis.client.AdminClient filename.wsdd Options Specifies the host -h host Specifies the port -p port Sets the path to the Axis Servlet -s servletPath Ioannis G. Baltopoulos Consuming, Providing & Publishing WS
    26. The Software Environment Using Java2WSDL Writing WS Consumers UDDI Overview Writing WS Providers Publishing Services on UDDI Web Services at CERN How to structure your projects The structure of a new Web Services project is exactly the Structure of a Webapp same as a Web Application. ROOT To start, you can copy the axis \\WEB-INF web application to your \\classes workspace, \\lib web.xml remove the axis-specific files server-config.wsdd and you have an empty Web Services project! NOTE: The server-config.wsdd file was extracted from the axis.jar. This is the file that needs to be updated with the contents of deploy.wsdd. Ioannis G. Baltopoulos Consuming, Providing & Publishing WS
    27. The Software Environment Using Java2WSDL Writing WS Consumers UDDI Overview Writing WS Providers Publishing Services on UDDI Web Services at CERN Where and how to deploy them Step by step deployment Edit the server-config.wsdd file and copy the contents of 1 the deploy.wsdd file that was created by WSDL2Java. Edit the web.xml file so that it reflects the name of your 2 application and the URL you want to use. Pack application in a .war file using the following command: 3 jar cvf filename.jar file(s) Go to the URL: 4 http://lxb0752.cern.ch/jps Point file field to your .war file and you’re done! 5 For more information about this specific service talk to Michal Kwiatek. Ioannis G. Baltopoulos Consuming, Providing & Publishing WS
    28. The Software Environment Using Java2WSDL Writing WS Consumers UDDI Overview Writing WS Providers Publishing Services on UDDI UDDI Overview Universal Description, Discovery and Integration (UDDI) Definition UDDI is a specification for creating distributed Web-based registries of Web services. It defines A UDDI registry which stores information on businesses, the services offered by these businesses, and technical information about these services. The data model and programming API that provides a way to publish and locate all kinds of services. Specifically, UDDI is said to support three kinds of registry data White Pages (organizing businesses by name) Yellow Pages (organizing businesses by category) Green Pages (organizing businesses by service) Ioannis G. Baltopoulos Consuming, Providing & Publishing WS
    29. The Software Environment Using Java2WSDL Writing WS Consumers UDDI Overview Writing WS Providers Publishing Services on UDDI The Colored Papers White, yellow and green pages White Pages Yellow Pages They contain information on a Yellow pages contain categorized business itself, including information about the services A name, provided by a business. Contact details Categorization is done by assigning one or more Location of the business taxonomies to the business. Unique identifiers Green Pages Green pages contain technical information about a service which a business offers. You can find information like Service location the category to which this service belongs Ioannis G. Baltopoulos Consuming, Providing & Publishing WS
    30. The Software Environment Using Java2WSDL Writing WS Consumers UDDI Overview Writing WS Providers Publishing Services on UDDI UDDI Data structures Specifying entries in the Registry UDDI defines five data type structures to specify an entry in the registry. Each of these data structures is represented by an XML document, containing both technical and descriptive information. These are: <businessEntity> <businessService> <bindingTemplate> <tModel> <publisherAssertion> Ioannis G. Baltopoulos Consuming, Providing & Publishing WS
    31. The Software Environment Using Java2WSDL Writing WS Consumers UDDI Overview Writing WS Providers Publishing Services on UDDI Data Structure Details I <businessEntity> The businessEntity structure contains all descriptive information about the business and the services it offers. Information includes name and description of the business as well as contact information, categorization, and relationships to other businesses. This structure can be seen as the top-level structure of the service in the registry. <businessService> Each businessEntity structure contains one or more businessService structures. A businessService structure describes a categorized set of services a business offers. A businessService element is not owned by one businessEntity element, but can be shared among multiple businesses. Ioannis G. Baltopoulos Consuming, Providing & Publishing WS
    32. The Software Environment Using Java2WSDL Writing WS Consumers UDDI Overview Writing WS Providers Publishing Services on UDDI Data Structure Details II <bindingTemplate> The bindingTemplate structure contains a technical description of a service. Each bindingTemplate belongs to a single businessService element. <tModel> One of the key elements of UDDI is the tModel. A tModel describes the specification, the behavior, the concept, or even the shared design to which a service complies. It provides specific information about how to interact with this service. The content of a tModel structure consists of a key, a name, an optional description, and a URL element. The URL, in most cases, points to a location where you can find more information about this particular tModel. Two conventions have been applied for using tModels. Ioannis G. Baltopoulos Consuming, Providing & Publishing WS
    33. The Software Environment Using Java2WSDL Writing WS Consumers UDDI Overview Writing WS Providers Publishing Services on UDDI Data Structure Details III <publisherAssertion> The publisherAssertion structure contains information about a relationship between two parties asserted by one or both. Many businesses, such as large corporations or marketplaces, are not effectively represented by a single businessEntity. A publisherAssertion can be used to denote the relationship between the businesses. The content of a publisherAssertion structure consists of a key (fromKey) for the first business, a key (toKey) of the second business, and a reference (keyedReference) that designates the asserted relationship in terms of a keyName, keyValue pair within a tModel. Ioannis G. Baltopoulos Consuming, Providing & Publishing WS
    34. The Software Environment Using Java2WSDL Writing WS Consumers UDDI Overview Writing WS Providers Publishing Services on UDDI Publishing Services on UDDI The manual way of doing things Step by step installation Logon to http://www.uddi.org/ 1 Select a registry from IBM, Microsoft, SAP or NTT 2 Obtain login and password 3 Follow the step by step instructions on the website 4 Ioannis G. Baltopoulos Consuming, Providing & Publishing WS
    35. The Software Environment Using Java2WSDL Writing WS Consumers UDDI Overview Writing WS Providers Publishing Services on UDDI Concluding Remarks In this lecture we saw the software environment for developing and deploying Web Services in Java how to write Web Service consumers how to write Web Service providers using instant and custom deployment deployment. what UDDI is and how to manually publish Web Services to the Registry. Ioannis G. Baltopoulos Consuming, Providing & Publishing WS

    + Ioannis BaltopoulosIoannis Baltopoulos, 9 months ago

    custom

    811 views, 0 favs, 0 embeds more stats

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 811
      • 811 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 14
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories