eBook - Apache Axis SOAP for Java | Soap | Web Service

Apache Axis SOAP for Java

Dennis M. Sosnoski Sosnoski Software Solutions, Inc. http://www.sosnoski.com

Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

Speaker Qualifications
 

Developer with over 30 years experience
¡ ¡

Systems software, data communications Commercial products (Amiga debugger, etc.)

 

 

 

 

Strictly Java for 5+ years Enterprise Java and XML for 3+ years XML in Java and Enterprise Java author: JavaWorld, IBM developerWorks President and lead consultant Sosnoski Software Solutions, Inc.
Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

Outline of Talk
   

SOAP and WSDL basics JAX-RPC / Apache Axis
¡ ¡

¡

Dynamic Invocation Interface & JWS Proxies and stubs Problem areas for interoperability

 

Conclusions

Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

Web Services
 

What’s a “web service”?
¡ ¡

¡

“Web” accessible - generally implies HTTP Service architecture - request/response XML data transfer
¡

 

Many serious web services in use for years
¡

Custom XML formats Code specific to service

 

Quiet growth based on convenience of XML
Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

Direct XML interfaces
 

Direct XML approach:
¡ ¡

¡

¡

¡

Specialized format (custom DTD/Schema) Industry- or application- specific XML document supplied directly to application Advantage of simpler documents, easier processing Drawback is cannot use SOAP infrastructure

 

 

Common approach for last three+ years The bulk of existing real world XML services
Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

What about SOAP?
 

XML-RPC the basis
¡ ¡

Remote calls with XML encoding Less efficient than binary, but much more convenient
¡

 

SOAP extended/enhanced XML-RPC
¡

¡

Microsoft-sponsored effort IBM joined in promoting as standard Basis for .NET marketing campaign

 

What most people mean by “web services”
Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

What is SOAP?
 

Simple Object Access Protocol Actually interfaces, not objects XML format for encoding data Usually request-response structure Transport normally HTTP, but can be anything (SMTP, etc.)
¢ ¢ ¢ ¢

Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

SOAP Message Structure
£

SOAP Envelope: Top-level wrapper

SOAP Header (Optional):
£

Extension information routing, authorization, etc.
£

SOAP Body:
£

Application data RPC call-response, error reporting, etc.

Envelope is wrapper for content, but no useful information Optional header can contain control information Body contains actual data in XML encoding Attachments can hold other types of data (binary, unencoded text, etc.)

Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

Simple RPC example
 

 

Flight tracking web service Call with carrier code and flight number:
public Date getFlightArrival(String carrier, int number)

 

Returns estimated arrival time:
Arrival for AS 25 is Sat Jun 15 00:32:19 PDT 2002

Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

SOAP request format
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle= "http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"> <SOAP-ENV:Body> <getFlightArrival> <op1 xsi:type="xsd:string">AS</op1> <op2 xsi:type="xsd:int">25</op2> </getFlightArrival> </SOAP-ENV:Body> </SOAP-ENV:Envelope>

Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

SOAP response format
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <SOAP-ENV:Body> <getFlightArrivalResponse SOAP-ENV:encodingStyle= "http://schemas.xmlsoap.org/soap/encoding/"> <getFlightArrivalResult xsi:type="xsd:dateTime" >2002-06-15T07:32:19.403Z</getFlightArrivalResult> </getFlightArrivalResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope>

Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

SOAP Envelope
 

 

Simple wrapper for message payload May specify encoding for message
¡

¡

¡

Specification defines one encoding, http://schemas.xmlsoap.org/soap/encoding Also known as “RPC encoding", this handles basic primitive types and arrays, composites of these types Other encodings may be used, including user-defined encodings

Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

SOAP Header
 

Can optionally add information to message:
¡ ¡

¡

Authentication information Session management Transaction management, etc.
¡

 

Very flexible, but standards needed
¡

Only a pair of attributes defined, not widely used .NET extends with its own set

Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

SOAP Body
 

 

Message payload container Three commonly-used formats:
¡ ¡

¡

RPC encoded – encoding defined by SOAP specification Document literal – XML message with format determined by schema (WXS) Wrapped – document literal variation, with call parameters as children of root element

 

Service defines the format to use (WSDL)
Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

RPC encoded
 

Remote Procedure Call - like CORBA or RMI
¡ ¤

Call parameters and result encoded in body Encoding allows for graphs of simple objects

¥

¥

As with CORBA, allows [in/out], and [out] parameters returned in addition to return value Optionally used by .NET

Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

Document literal
¥

¥

An XML document is passed each way Flexible, but less cross-compatible
¤ ¤

Working with XML documents, not method calls Requires code at each end to convert to data

Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

Wrapped
¥

Yet another Microsoft “innovation”:
¤

Given a call with parameters “a”, “b” and “c”
¦ ¦

Define a top-level element with children “a”, “b” and “c” Pass the element as document literal SOAP body

¤

¤

Preferred .NET approach Not a bad approach, but creates interoperability problems

Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

SOAP Attachments
¥

SOAP Body content issues:
¤

¤

¤

Character set restricted in XML (only whitespace allowed below 0x20) XML must be well formed - single root element, all tags closed, etc. Binary data must be encoded with heavy overhead

¥

¥

¥

Attachments use MIME multipart message format (except Microsoft...) Any type of data to accompany SOAP Avoids XML encoding issues
Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

The role of WSDL
¥

Web Services Description Language
¥

Based on abstract definitions and bindings:
¤

types – types defined for use in messages
¤

messages - the data being exchanged
¤

port types - collections of operations
¤

binding - concrete protocol and data format
¤

service - a collection of ports

¥

Allows automatic proxy generation, etc.
Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

WSDL sample
<?xml version="1.0" encoding="UTF-8"?> <definitions name="FlightService" targetNamespace=...> <message name="getFlightArrival"> <part name="String_1" type="xsd:string"/> <part name="int_2" type="xsd:int"/> </message> <message name="getFlightArrivalResponse"> <part name="result" type="xsd:dateTime"/> </message> <portType name="FlightRemote"> <operation name="getFlightArrival"> <input message="tns:getFlightArrival"/> <output message="tns:getFlightArrivalResponse"/> </operation> </portType> (continued...)
Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

WSDL sample (cont.)
<binding name="FlightRemoteBinding" type="tns:FlightRemote"> <operation name="getFlightArrival"> <input><soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="encoded" namespace="http://allflighttracking.com/wsdl"/> </input> <output><soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="encoded" namespace="http://allflighttracking.com/wsdl"/> </output> <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"/> </binding> <service name="Flight"> <port name="FlightRemotePort" binding="tns:FlightRemoteBinding"> <soap:address location="http://localhost:8080/axis/..."/> </port> </service> </definitions>
Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

SOAP/WSDL Applications
¥

“Web page equivalent” services:
¤ ¤

¤

Information retrieval (quotes, weather, prices, etc.) Calculations (interest payments, currency and unit conversions, etc.) Simple actions (messaging, registration, etc.)
¤

¥

Developing applications:
Connecting distributed program components (cross platform and cross programming language) Intrasystem software component communications
¤

Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

Real-world usage
¥

.NET “vision”?
¤

¤

¤

Revenue from web services not likely near term - what would service consumers pay for? Exposing services to all and sundry a security risk Dubious advantages over HTML “web services”
¤

¥

Behind the firewall - hot!
¤

Increasing usage within corporations Connecting applications on diverse platforms - CORBA equivalent
Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

What about UDDI?
¥

UDDI an automated directory service
¤ ¤

Automatically register your services Lookup other services of interest
¤

¥

Very fun, but “where's the beef?”
¤

Big gap between WSDL and UDDI functionalities No automated way for programs to use information
¦

Human interpretation required to write connecting code

¤

Why not just look up via HTML web page?
Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

¥

WSIF trying to span the gap

JAX-RPC
¥

Java API for XML-based RPC
¤ ¤

¤

Portable and interoperable web services using Java JSR-101 in Java Community Process SOAP attachments supported through SAAJ
¤

¥

Core technology for J2EE 1.4
¤

JSR-109 defines web services deployment descriptors With EJB 2.1 supports direct stateless session bean web services
Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

¥

Now available as 1.0 release

What it does
¥

JAX-RPC maps SOAP/WSDL to RMI:
¤

¤

¤

WSDL port equivalent to remote interface (interface extending java.rmi.Remote) WSDL operation to remote interface method Methods throw java.rmi.RemoteException (SOAP Faults converted to/from RemoteExceptions)
¤

¥

Supports a subset of RMI operation
Only some types - primitives and wrappers, bean-likes, String, Date, BigInteger, BigDecimal, etc. Others will use JAXB or pluggable serializers
¤

Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

Dynamic invocation
¥

Dynamic Invocation Interface (DII):
¤ ¤

No static stubs for client Configure service information on the fly
¦

¦

¦

Create javax.xml.rpc.Service from javx.xml.rpc.ServiceFactory instance Create javax.xml.rpc.Call and configure (endpoint, operation, parameters, return type, etc.) Execute with Call.invoke()

§

Or with Axis, use WSDL for service information

¨

Flexible and easy for simple services
Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

Apache Axis SOAP
¨

Successor to Apache SOAP (itself originally based on IBM SOAP4J):
§ §

§

§

§

Potentially much faster Greatly enhanced flexibility Automatic WSDL generation for deployed services Tools for WSDL to Java and Java to WSDL generation JAX-RPC compatibility

¨

1.0 Release October 7, 2002!
Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

Working with Apache Axis
¨

¨

¨

¨

¨

“happyaxis” status view for web server deployment Easy web application deployment to J2EE server “Drop-in" deployment of simple services through JWS source code TCPMonitor, other tools Basic usage demo

Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

Axis deployment descriptors
¨

WSDD deployment descriptors
§

Extensive customization of server options
© ©

©

Service style specification – RPC, document, wrapped Allowed methods and required roles Transport specification
©

§

Handler chains for special processing
©

Logging or tracking usage Authorization / authentication

§

§

Custom serializers / deserializers Transport specification
Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

JAX-RPC proxies
¨

¨

Besides DII, JAX-RPC supports static linkage Define the service and generate code to link
§ §

§

Client-side stubs act as proxies for service Server-side ties act as proxies for client Adapt between your code and JAX-RPC libraries

Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

Service example
¨

Flight tracking web service with JAX-RPC:
Flight tracking client Generated Stubs JAX-RPC Runtime HTTP

Application code Generated by xrpcc tool

Flight tracking service Generated Ties JAX-RPC Runtime

SOAP Messages
Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

HTTP

Setting up example
¨

Using JAX-RPC with static stubs you need:
§ §

§

§

§

Service interface definition Service implementation xrpcc configuration file web.xml configuration file for service servlet Client program

¨

xrpcc builds stubs and ties from configuration

Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

Service interface definition
¨

¨

Interface definition extends java.rmi.Remote Methods throw java.rmi.RemoteException
package jaxrpc.flight; import java.rmi.Remote; import java.rmi.RemoteException; import java.util.Date; public interface FlightRemote extends Remote { public Date getFlightArrival(String carrier, int number) throws RemoteException; }

Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

Service implementation
¨

Service implements the interface
package jaxrpc.flight; import java.util.Date; public class FlightImpl implements FlightRemote { public Date getFlightArrival(String carrier, int num) { int offset = 60*60*1000; if (carrier.equalsIgnoreCase("ar")) { offset = 30*60*1000; } return new Date(System.currentTimeMillis()+offset); } }

Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

xrpcc configuration
¨

Defines configuration for code generation
<?xml version="1.0"?> <configuration xmlns="http://java.sun.com/jax-rpc-ri/xrpcc-config"> <rmi name="FlightService" targetNamespace="http://allflighttracking.com/wsdl" typeNamespace="http://allflighttracking.com/types"> <service name="Flight" packageName="jaxrpc.flight"> <interface name="jaxrpc.flight.FlightRemote" servantName="jaxrpc.flight.FlightImpl"/> </service> </rmi> </configuration>

Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

Service servlet configuration
¨

Configures servlet providing JAX-RPC service

... <web-app> <display-name>FlightApplication</display-name> <servlet> <servlet-name>JAXRPCEndpoint</servlet-name> <display-name>JAXRPCEndpoint</display-name> <servlet-class> com.sun.xml.rpc.server.http.JAXRPCServlet </servlet-class> <init-param> <param-name>configuration.file</param-name> <param-value>/WEB-INF/Flight_Config.properties</param-value> </init-param> <load-on-startup>0</load-on-startup> </servlet> ...
Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

Client program
¨

Uses generated stubs to connect to service

... public class FlightClient { public static void main(String[] args) { try { FlightRemote_Stub stub = (FlightRemote_Stub) (new Flight_Impl().getFlightRemote()); stub._setProperty (javax.xml.rpc.Stub.ENDPOINT_ADDRESS_PROPERTY, args[0]); String carrier = args[1]; int number = Integer.parseInt(args[2]); Date arrive = stub.getFlightArrival(carrier, number); System.out.println("Arrival for " + carrier + ' ' + number + " is " + arrive); } catch (RemoteException ex) { ...
Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

Deployment steps
¨

¨

¨

¨

¨

¨

¨

Compile service interface and implementation Run xrpcc to generate server ties Optionally build war file for deployment Deploy to servlet engine (e.g., Tomcat) Run xrpcc to generate client stubs Compile client application (if used) Run client application (if used)
Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

The Axis approach
¨

Uses easier tools than JAX-RPC
§ §

§

WSDL2Java for generating Java classes from WSDL Java2WSDL for generating WSDL from Java classes Can combine the two for easy generation

¨

Demo

Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

Advanced Axis

Limited EJBProvider support for direct EJB interface Asynchronous messaging extensions

General form currently preliminary JMS support preliminary, should be in GA release

Sessions via HTTP cookies or SOAP headers Both RPC and Messaging providers

Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

Interoperability issues

Sessions can be awkward:

JAX-RPC uses HTTP cookies or SSL connections Microsoft uses Header entry Axis supports both forms “Manual” handling also possible

Attachments not yet cross-platform:

Basic .NET has no support for attachments Microsoft does support DIME – but not the developing standard of Soap with Attachments
Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

Interoperability issues

Primitive data types can limit usage:

Java has no unsigned types, no JAX-RPC support Axis supports these anyway Incompatibilities with char, floating point, etc.

Complex structures even more of a problem:

Structures such as HashMap have no standard form Custom serializers / deserializers needed everywhere Probably best to just go to document-literal
Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

Conclusions

JAX-RPC standard for web services in Java

Converts to RMI terms Much more limited than RMI in terms of data types Out now, part of J2EE 1.4 (including session beans)

Apache Axis open source and flexible JAX-RPC

Many added features Commercial-friendly Apache license

Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

Closing thought
“Remember, web services are just large distributed apps with a crude protocol, high latency, and interop problems between implementations. Oh, and no callbacks through firewalls." - Steve Loughran Axis User List

Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

Resources

JAX-RPC home http://java.sun.com/xml/jaxrpc/index.html Web Services & Java home http://java.sun.com/j2ee/webservices/index.html Java Web Services tutorial http://java.sun.com/xml/docs.html#tutorials Apache Axis - http://xml.apache.org/axis/index.html SOAP 1.1 - http://www.w3.org/TR/SOAP WSDL 1.1 - http://www.w3.org/TR/wsdl Author Web Site - http://www.sosnoski.com
Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

Questions?

JAX-RPC / Apache Axis questions?

Contact me at dms@sosnoski.com

Copyright © 2002, Sosnoski Software Solutions, Inc. All rights reserved.

Sign up to vote on this title
UsefulNot useful