Download presentation
Presentation is loading. Please wait.
Published byFranklin Derek Reeves Modified over 8 years ago
1
INFSO-RI-508833 Enabling Grids for E-sciencE www.eu-egee.org Web services tools David Fergusson
2
Enabling Grids for E-sciencE INFSO-RI-508833 Web services tools Java based –ANT –JWSDP/J2EE/Java Beans –Axis –Tomcat C based –.Net –gSOAP Perl based –SOAP::Lite
3
Enabling Grids for E-sciencE INFSO-RI-508833 SOAP::Lite Collection of Perl modules which provides a simple and lightweight interface to Simple Object Access Protocol on both client and server side. –Used for much of the Alien grid implementation
4
Enabling Grids for E-sciencE INFSO-RI-508833 C based tools gSOAP –C and C++ toolkit which provides C/C++ - XML bindings for web services development –Comments from developers suggest that this implementation is fragile and can be buggy.NET –Microsoft web services implementation based on C# super-set of C. –Comments form developers – easy entry but lacks flexibility in more complex situations
5
Enabling Grids for E-sciencE INFSO-RI-508833 XML Parsing Xerces (originally Java, also C++ now) –Used in JWSDP modules, Axis DOM (Document Object Model) –Creates representation of document structure in memory SAX (Simple API for XML) –Simpler but less powerful parsing model
6
Enabling Grids for E-sciencE INFSO-RI-508833 Tomcat and Axis Both containers – add functionality to web servers Tomcat originally designed to add servlets to web servers – became used to support web services Axis new development to specifically support web services –Axis also includes a web services development environment
7
Enabling Grids for E-sciencE INFSO-RI-508833 Java web services Free distribution, cross platform Development environments –Java Web Services Development Package (JWSDP) –Java 2 Enterprise Edition (J2EE) –Java Beans
8
Enabling Grids for E-sciencE INFSO-RI-508833 ANT A java based ‘make’ tool
9
Enabling Grids for E-sciencE INFSO-RI-508833 Ant Ant – Another Neat Tool Ant is a tool for building projects It is written in Java and is therefore entirely platform independent It uses a build file, called build.xml, to determine how to build a particular project
10
Enabling Grids for E-sciencE INFSO-RI-508833 Understanding Ant The key to understanding Ant is to understand the build.xml file structure The root element is project There are then properties elements, which can be set externally or internally to the file There are also target elements which specify what actions are to be taken
11
Enabling Grids for E-sciencE INFSO-RI-508833 Example Project (1) The next few slides will demonstrate the use of Ant to build a very simple project There are three classes in the Project –Person Contains a name, age and an Address –Address Contains street, town and country information –Display Instantiates 3 Person classes and displays their details on the command line
12
Enabling Grids for E-sciencE INFSO-RI-508833 Example Project (2) All the source files are in a package structure in a directory called src An example output would be:
13
Enabling Grids for E-sciencE INFSO-RI-508833 Compile Example This example will perform a simple compile There is only one target, which will compile all classes in the same location as the source files
14
Enabling Grids for E-sciencE INFSO-RI-508833 More Complex Example This example will now create a directory called build and put the compiled code in there, preserving package structure
15
Enabling Grids for E-sciencE INFSO-RI-508833 Creating JAR files (1) This build.xml will require two runs: –One to compile and package in to a JAR –One to clean up unnecessary files...
16
Enabling Grids for E-sciencE INFSO-RI-508833 Creating JAR files (2)...
17
Enabling Grids for E-sciencE INFSO-RI-508833 Invoking targets Here dist invokes clean so we now only require one run of ant
18
Enabling Grids for E-sciencE INFSO-RI-508833 Setting the classpath To set the classpath, use the classpath task and specify the appropriate pathelement tags All of the above JAR files will now be on the class path when the source is compiled
19
Enabling Grids for E-sciencE INFSO-RI-508833 Copying Files The copy task in ant allow you to copy files and/or directories This example will copy the file MyFile.file to the Stilo directory under MyFiles
20
Enabling Grids for E-sciencE INFSO-RI-508833 Java Web Services Development Package
21
Enabling Grids for E-sciencE INFSO-RI-508833 JWSDP packages JWSDP saaj –soap with attachments API for java jaxp –jax parsing (XML) jaxb –XML – Java bindings jaxr –Jax for registries jax-rpc –Jax remote proceedure call
22
Enabling Grids for E-sciencE INFSO-RI-508833 JWSP – JAX-RPC
23
Enabling Grids for E-sciencE INFSO-RI-508833 What does jax–rpc do? The jax-rpc package provides a number of java packages which: –Given WSDL or Java Interface definitions generate ‘stub’ classes for web service providers or consumers. –Handles Java-XML bindings –Handles the generation of SOAP messages
24
Enabling Grids for E-sciencE INFSO-RI-508833 Note on serialisation Java web services (also C based ones) allow a developer to treat service classes as if they are local –ie. stubs are created All web services messages are XML (SOAP) This means that objects sent across web services must be translated to XML and back Means that classes seen by either side may not be identical Java XML Java Serialiser XML-Java bindings XML-Java bindings
25
Enabling Grids for E-sciencE INFSO-RI-508833 JAX-RPC API packages javax.xml.rpcCore classes for the client side programming model javax.xml.rpc.encodingJava primatives XML SOAP messages javax.xml.rpc.handlerprocessing XML messages javax.xml.rpc.handler.soap javax.xml.rpc.holderssupport the use of IO parameters javax.xml.rpc.serverminimal API for web service inplementation Javax.xml.rpc.soapspecific SOAP bindings
26
Enabling Grids for E-sciencE INFSO-RI-508833 JAX-RPC Architecture
27
Enabling Grids for E-sciencE INFSO-RI-508833 Java web service flow
28
Enabling Grids for E-sciencE INFSO-RI-508833 Client operation modes JAX-RPC allows two modes of operation –Synchronous request – response –One-way RPC Synchronous –This involves blocking the client until it receives a response –Is similar to a traditional java method call One – way –No client blocking –Service performs a operation without replying. –Not analogous to traditional method calls
29
Enabling Grids for E-sciencE INFSO-RI-508833 Comparing One-way and traditional methods A traditional java method call like –Public void request (int arg1, int arg2); –Does not return a value to the caller –However if it appeared in a web service interface definition it would be mapped to a synchronous request – response RPC –This is because it indicates that an exception may still need to be thrown to the client. –A one – way RPC cannot throw an exception.
30
Enabling Grids for E-sciencE INFSO-RI-508833 Synchronous method invocation Client Servlet Client invokes service Response returned to client Client waits until Server responds Server performs the requested action
31
Enabling Grids for E-sciencE INFSO-RI-508833 One – way RPC invocation Client Servlet Client invokes service Server performs the requested action Client does not block While operation is performed
32
Enabling Grids for E-sciencE INFSO-RI-508833 Defining a service A service can be defined starting with: –A java interface –A WSDL document Which to use? –If the service end point interface is defined in java it may not be interoperable with services/clients defined in other languages –If the service is initially defined in WSDL it will be open
33
Enabling Grids for E-sciencE INFSO-RI-508833 Using JAX-RPC to create a service from a Java interface
34
Enabling Grids for E-sciencE INFSO-RI-508833 Interface method definitions The interface must extend java.rmi.remote Interface methods must declare that it throws java.rmi.RemoteException Service dependent exceptions can be thrown if they are checked exceptions derived from java.lang.Exception Method name-overloading is permitted Service endpoint interfaces may be extensions of other interfaces A java web service end point interface must obey the following rules:
35
Enabling Grids for E-sciencE INFSO-RI-508833 Supported data types Java primitives (eg. bool, int, float, etc) Primitive wrappers ( Boolean, Interger, Float, etc) Standard java classes (required - java.lang.String, java.util.Calendar, java.util.Date, java.math.BigDecimal, java.math.BigInterger ) Value types Holder classes Arrays (where all elements are supported types) Object by reference is not supported
36
Enabling Grids for E-sciencE INFSO-RI-508833 Value Types Class has a public no-argument constructor May be extended from any other class, may have static and instance methods, may implement any interface (except java.rmi.Remote and any derived) May have static fields, instance fields that are public, protected, package private or private but these must be supported types.
37
Enabling Grids for E-sciencE INFSO-RI-508833 Warning about comparing classes The values returned by service methods are in fact local classes created by JAX-RPC from the XML serialisation This means that comparisons using == should be avoided equals () should be used instead (inner static classes will not compare correctly)
38
Enabling Grids for E-sciencE INFSO-RI-508833 Serializer If you want to pass an un-supported java class you have to create your own serializer/deserializer to translate to and from XML. This not a trivial task as there is no JAX-RPC framework.
39
Enabling Grids for E-sciencE INFSO-RI-508833 Client side Implementation
40
Enabling Grids for E-sciencE INFSO-RI-508833 wscompile Generates –Compiled class files + optionally source files for stubs to interface with client side JAX-RPC –WSDL file –Model file Example commandline wscompile –gen:client –d output/client –classpath classpath config-file (add –keep –s to retain java source files)
41
Enabling Grids for E-sciencE INFSO-RI-508833 config.xml <service name=“……..” targetNamespace=“………………………” typeNamespace=“……………………………..” packageName=“……………………………….”> name = name of service targetNamespace = namespace of WSDL for names associated with the service eg. port type typeNamespace = namespace of WSDL for data types packageName = name of java package
42
Enabling Grids for E-sciencE INFSO-RI-508833 Generated files Some of the client side generated files: ServiceService.java Service_Impl.java Service_SerializerRegistry.java ExceptionServiceException_SOAPSerializer.java ServiceException_SOAPBuilder.java Value typeInfo_SOAPSerializer.java Info_SOAPBuilder.java InterfaceInterface_Stub.java method.java
43
Enabling Grids for E-sciencE INFSO-RI-508833 Service.java file The Service.java file corresponds to the definition of the interface for the web service, ie it contains the same info as the element in the config file. package servicePackage; import javax.xml.rpc.*; Public interface Service extends javax.aml.rpc.Service { public servicePackage getServicePort(); }
44
Enabling Grids for E-sciencE INFSO-RI-508833 Referencing the stub In order to get an object to reference the stub you have to instantiate Service_Impl. –(Unfortunately this name is only recommended) Service_Impl service = new Service_Impl (); value* name = (value)service.getServicePort (); With this reference you can call the methods of the service.
45
Enabling Grids for E-sciencE INFSO-RI-508833 Using JAX-RPC to create a service from a WSDL definition
46
Enabling Grids for E-sciencE INFSO-RI-508833 WSDL is an interface definition
47
Enabling Grids for E-sciencE INFSO-RI-508833 Getting the WSDL WSDL can be downloaded from a UDDI registry If the service uses JAXRPCServlet you can attach ?WSDL (or ?model ) to the URL request to get the WSDL (or model file). –Eg http://localhost:8080/Service/Servicename?WSDL
48
Enabling Grids for E-sciencE INFSO-RI-508833 A config.xml file Format of config file depends on whether wscompile is given a WSDL file, model file or Java
49
Enabling Grids for E-sciencE INFSO-RI-508833 Generate client side artifacts wscompile –gen:client –keep –s generated/client –d output/client –classpath classpath config.xml
50
Enabling Grids for E-sciencE INFSO-RI-508833 Some of the client side files generated by wscompile from WSDL ServiceService.java Service_Impl.java Service_SerializerRegistry.java ExceptionServiceException.java ServiceException_SOAPSerializer.java ServiceException_SOAPBuilder.java Value typeInfo.java Info_SOAPSerializer.java Info_SOAPBuilder.java InterfaceInterface_Stub.java method.java
51
Enabling Grids for E-sciencE INFSO-RI-508833 Stub interface Service_Impl service = new Service_Impl (); Object name = (Object)service.getServicePort(); Info[ ] name = Service.getServiceInfo(); The web service address is preconfigured using information from the WSDL element within the service’s element for its portType.
52
Enabling Grids for E-sciencE INFSO-RI-508833 Generation The information in the webservicesclient.xml file is read by the deployment tools. These generate a class which implements the Service interface They also generate the client side stubs which the application will call.
53
Enabling Grids for E-sciencE INFSO-RI-508833 Obtaining a Service object InitialContext ctx = new InitialContext (); Object service = (object)PortableRemoteObject.narrow (ctx.lookup (“java:comp/env/service/Service”), object.class); Object name = (object)service.getServicePort(); ((Stub)name)._setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY, args[0]);
54
Enabling Grids for E-sciencE INFSO-RI-508833 wscompile You can use the information in a config.xml file which specifies a WSDL definition to generate the classes required for the service: wscompile –import –f:norpcstructures –d output/interface config.xml -f:norpcstructures – avoids generating SOAP message creation classes.
55
Enabling Grids for E-sciencE INFSO-RI-508833 Deploying with JWSDP - Tomcat
56
Enabling Grids for E-sciencE INFSO-RI-508833 Deploying to a web container Create a WAR file –Java class file for service endpoint interface –Java class files for service implementation and resources – web.xml file containing deployment information –Class files for JAX-RPC tie classes JAX-RPC tie classes are implementation specific.
57
Enabling Grids for E-sciencE INFSO-RI-508833 Additional WAR files required for JWSDP WEB-INF/web.xml Web application deployment descriptor WEB-INF/jaxrpc-ri.xml JWSDP-specific deployment information WEB-INF/model Model file generated by wscompile
58
Enabling Grids for E-sciencE INFSO-RI-508833 web.xml file <!DOCTYPE web-app PUBLIC “-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN” “http://java.sun.com/j2ee/dtds/web-app_2_3.dtd”> Service Name A web service application
59
Enabling Grids for E-sciencE INFSO-RI-508833 Creating a deployable WAR file wsdeploy –o targetFileName portableWarFileName The process is informed by the content of the jaxrpc-ri.xml file. The archive contains: class files and resources compiled class files for the ties compiled class files for serializers WSDL (in WEB-INF directory) model file for the service ( in WEB-INF) modified web.xml file jaxrpc-ri-runtime.xml (based on jaxrpc-ri.xml )
60
Enabling Grids for E-sciencE INFSO-RI-508833 Package Structure for JAX-RPC Service Endpoint
61
Enabling Grids for E-sciencE INFSO-RI-508833 Files required in the JAR File typeFilename Service end point interfaceClasspath.service.name Classpath.service.Info Classpath.service.Exception Service interfaceClasspath.service.Service Application implementationClasspath.client.ServiceAppClien t WSDL fileService.wsdl Deployment descriptorsMETA-INF/application-client.xml META-INF/mapping.xml or META- INF/model META-INF/webservicesclient.xml Manifest fileMETA-INF/MANIFEST.MF
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.