session 2 - web services- java and voice console
TRANSCRIPT
VoiceConsole 3.0Web Services
© 2008 Vocollect, Inc. Proprietary & Confidential
Web ServicesWeb Services Overview
Session Overview
• Web Services
– Service Oriented Architecture (SOA)
– XML and HTTP
– XML-RPC, SOAP and WSDL
• Java and Web Services
© 2008 Vocollect, Inc. Proprietary & Confidential
• Java and Web Services
– Apache SOAP, Axis, Axis2 and CXF
– Sun Microsystems JAX-WS
• VoiceConsole and Web Services
2
Service Oriented Architecture
• Definitions
– “Service-oriented architecture (SOA) is a method for systems development and integration where functionality is grouped
around business processes and packaged as
© 2008 Vocollect, Inc. Proprietary & Confidential
around business processes and packaged as interoperable services.” (Wikipedia)
– SOA is a collection of interacting services communicating through standardized messages.
– SOA ties a service provider to a service requester (sometimes by way of a service broker or directory).
4
Service Oriented Architecture
© 2008 Vocollect, Inc. Proprietary & Confidential
5
mrwebservice.wordpress.com
Service Oriented Architecture
• Examples
– “Web 2.0”
– Geocoded mashups
– Unified email services
– Portals
© 2008 Vocollect, Inc. Proprietary & Confidential
– Portals
• Benefits
– Reusability
– Adaptability / Flexibility
– Autonomy
– Unification6
Service Oriented Architecture
• Communications Implementation
– HTTP
• Stateless
• Loosely coupled
– XML
© 2008 Vocollect, Inc. Proprietary & Confidential
– XML
• Composable
• Formal contract
– WSDL
• Formal contract
• Discoverable
7
XML and HTTP
• HyperText Transfer Protocol
– Communicates over TCP/IP
– Standard formatting
– Used as a platform to relay content from provider to requester
© 2008 Vocollect, Inc. Proprietary & Confidential
provider to requester
– Stateless and Flexible
• eXtended Markup Language
– Highly structured content representation
– Namespaces for language specification
– Simple and portable9
XML and HTTP
Sample XML File
<?xml version="1.0"?> <email>
<from> <address>[email protected]</address>
</from>
© 2008 Vocollect, Inc. Proprietary & Confidential
10
</from><to>
<address>[email protected]</address><address>[email protected]</address>
</to><subject>Welcome</subject><message>Hello, welcome to vocollect!</message>
</email>
XML-RPC
• Lightweight XML syntax for requesting
procedure calls over HTTP
• Created in 1998, patented in 2006, still a
very useful means of communication
• Benefits:
© 2008 Vocollect, Inc. Proprietary & Confidential
• Benefits:
– Simple
– Minimalist
– Easy to use
– Platform independent
12
XML-RPC
• Example request:– employees.getFullName(1087293);
– <?xml version="1.0"?><methodCall>
<methodName>employees.getFullName</methodName><params>
<param><value><int>1087293</int></value></param>
© 2008 Vocollect, Inc. Proprietary & Confidential
<param><value><int>1087293</int></value></param></params>
</methodCall>
• Example response:– “John Denver”
– <?xml version="1.0"?><methodResponse>
<params><param><value><string>John Denver</string></value></param>
</params></methodResponse>
14
SOAP
• SOAP = Simple Object Access Protocol
• Second generation of XML-RPC
• Version 1.2 W3C Recommendation in 2003
• Unlimited options for data types
© 2008 Vocollect, Inc. Proprietary & Confidential
• Unlimited options for data types
• Encoding styles
– Remote Procedure Call: Bloated version of XML-RPC
– Document Literal: Uses WSDL to define syntax for SOAP calls
16
SOAP
• Benefits
– Human readable messages
– Improved error detection
– Hardware is available for XML processing
– Speaks over HTTP/HTTPS (can use SMTP)
© 2008 Vocollect, Inc. Proprietary & Confidential
– Speaks over HTTP/HTTPS (can use SMTP)
– Platform and language independent
• Drawbacks
– Not binary therefore lengthy and cumbersome
– Slower than CORBA / other middleware
18
WSDL
• Web Service Description Language
– Contract between provider and requester
– Describes the API of the Web Service
– Obtained easily via HTTP
– Single resource location for all WS developers
© 2008 Vocollect, Inc. Proprietary & Confidential
– Single resource location for all WS developers
– Universal Description, Discovery and Integration (UDDI) servers for WSDL (outdated)
• Complex XML format
– Yields flexibility to describe transaction details
– More difficult to read than an XSD file
– Tools are available to build WSDL files20
WSDL
© 2008 Vocollect, Inc. Proprietary & Confidential
21
ibm.com – WebSphere Studio Information Center
WSDL
• Types
– Similar to XSD type definitions
• Messages
– Define expected request and response formats
• portTypes
© 2008 Vocollect, Inc. Proprietary & Confidential
• portTypes
– Describe an available service’s input, output and fault messages
• Bindings
– Specify protocols to use for specific services
22
The Good News
• Freely available Web Services tools
– UDDI directory browsers
– WSDL viewers and editors
– Web Service call testers
– Plugins for IDEs (e.g. Eclipse)
© 2008 Vocollect, Inc. Proprietary & Confidential
– Plugins for IDEs (e.g. Eclipse)
– HowTos and tutorials for just about anything
• Also available (but not free)
– Full featured XML suites (e.g. Stylus Studio)
– Many, many books
24
For Our Purposes
• In this class, we will:
– Use XML over HTTP to communicate
– Not use WSDL (VC does not provide it)
• Use libraries to form SOAP requests
• Call parameters and return values in the guide
© 2008 Vocollect, Inc. Proprietary & Confidential
• Call parameters and return values in the guide
– Focus on using a Web Service rather than implementing or exposing one
25
Why Java?
• Java lends itself to SOA development
– Platform and hardware independent
– Completely object (service) oriented
– Security and reliability built in
– Producing web apps since 1994
© 2008 Vocollect, Inc. Proprietary & Confidential
– Producing web apps since 1994
• Major Web Services frameworks
– Apache (SOAP, Axis, Axis2, CXF and more)
– Sun Microsystems (JAX-WS)
26
Java and Web Services
• Good-to-Know Acronyms
– JAXB: Java Architecture for XML Binding
• Provides a way to map Java classes to XML
– JAX-RPC: Java API for XML-based RPC
• Subsystem for generating stub classes to perform
© 2008 Vocollect, Inc. Proprietary & Confidential
• Subsystem for generating stub classes to perform SOAP calls behind-the-scenes for seamless integration
– REST: REpresentational State Transfer
• Architectural style describing how the web works
• Alternative concept to SOAP or RPC methodology
– SAAJ: SOAP with Attachments API for Java
• Allows for attachments within SOAP messages
27
Java and Web Services
• Apache SOAP
– Supports SOAP 1.0 only
– Uses the DOM (Document Object Model) for XML communication
– No built-in WSDL or UDDI support
© 2008 Vocollect, Inc. Proprietary & Confidential
– No built-in WSDL or UDDI support
– Old, slow, proprietary API, issues with interoperability and extensibility
– No longer under development; replaced by Apache Axis
28
Java and Web Services
• Apache Axis 1.x
– Supports SOAP 1.0, 1.1, 1.2 and WSDL 1.1
– Implements the JAX-RPC (Java over XML for Remote Procedure Calls) API
– Can be used to easily serve Web Services
© 2008 Vocollect, Inc. Proprietary & Confidential
– Can be used to easily serve Web Services
– Provides mechanisms for data binding
• Automatic XSD and SOAP conversion to Java core data types
– WSDL2Java
• Create stub Java classes from a WSDL file
• Very useful for coding
• If WSDL changes, stub classes must be regenerated29
Java and Web Services
• Apache Axis2
– Redesign of Axis 1.x
• Improvements in speed, memory, flexibility, etc.
• Supports SOAP 1.1, 1.2, and REST
• Supports WSDL 1.1 and 2.0
© 2008 Vocollect, Inc. Proprietary & Confidential
• Supports WSDL 1.1 and 2.0
• Built on AXIOM (Apache pull-based XML object model)
– Additional data binding mechanisms
• ADB (Axis Data Binding)
• XMLBeans
• JibX
• JaxBRI
30
Java and Web Services
• Apache CXF
– formerly XFire from Codehaus
– Supports SOAP 1.1, 1.2 and REST
– Implements JAX-WS APIs (very flexible)
– Supports Spring 2.0 XML syntax
© 2008 Vocollect, Inc. Proprietary & Confidential
– Supports Spring 2.0 XML syntax
– Data binding
• Aegis Databinding 2.0.x
• JAXB
– Can be deployed, configured and frontended in multiple ways
31
Java and Web Services
• Sun Microsystems JAX-WS
– Supports SOAP 1.1, 1.2
– Part of the Metro Web Services stack
– Also under Project GlassFish (tomcat-based application server)
© 2008 Vocollect, Inc. Proprietary & Confidential
application server)
– JAX-RPC 2.0 � JAX-WS 2.0
• JAX-WS uses annotations (@WebService)
• Otherwise the spec is generally the same
– Built into the Java EE platform
– Only supports JAXB for data binding
32
For Our Purposes
• We will use Axis 1.x
– VoiceConsole does not provide UDDI or WSDL
– VoiceConsole speaks SOAP 1.0
– Apache SOAP is outdated
– No need for stub classes or special data
© 2008 Vocollect, Inc. Proprietary & Confidential
– No need for stub classes or special data binding libraries
– Only requesting services, not providing them
– Structured, replicable format to perform calls
33
VoiceConsole 3.0 Highlights
• Operators
– Create new operators
– Manage operator voice templates
– Organize operators into teams
– Load operators onto devices
© 2008 Vocollect, Inc. Proprietary & Confidential
– Load operators onto devices
– Send messages to operators and teams
– View operator’s device settings (volume, pitch, speed, etc.)
34
VoiceConsole 3.0 Highlights
• Devices
– View current state of all devices
– Load VoiceClient onto devices
– Collect device debug
– Enable Bluetooth and create pairings with
© 2008 Vocollect, Inc. Proprietary & Confidential
– Enable Bluetooth and create pairings with peripherals
• VoiceApplications (Tasks)
– Create task packages with configurable settings
– Include the host and service information to link the device to VoiceLink
– Load task packages onto devices35
Why WS with VC?
• Apply custom business rules
• Integrate with an existing application
• Implement complex migrations
• Run customized reports
© 2008 Vocollect, Inc. Proprietary & Confidential
• Run customized reports
• Inspect and verify VoiceConsole data
• Inventory hardware and software
• Additional examples in the guide, along
with strategies
36
VoiceConsole Web Services
• Operator Management
– Create operator
– Import operator templates
– Fetch all operators
– Fetch all templates by operator
– Fetch operator by ID
© 2008 Vocollect, Inc. Proprietary & Confidential
– Fetch operator by ID
– Modify operator ID
– Send message to operators
– Delete operators
• Device Management
– Fetch all devices
– Import device37
VoiceConsole Web Services
• Operator Teams Management
– Create operator team
– Fetch all operator teams
– Send messages to operator team
© 2008 Vocollect, Inc. Proprietary & Confidential
• Task Management
– Import task
– Create task package
– Fetch task with data
– Fetch all tasks
– Fetch all task packages
38
For Our Purposes
• VMWare image running VoiceConsole
– Web interface will show changes made by our demo application
• Implement a system integration with an
existing employee management app
© 2008 Vocollect, Inc. Proprietary & Confidential
existing employee management app
– Create operators
– Fetch operators
– Modify operators
– Delete operators
– Send messages to operators
39
Code Preview - fetchAllOperators
import java.net.URL;
import java.util.Vector;
import org.apache.axis.client.Service;
import org.apache.axis.client.Call;
import javax.xml.namespace.QName;
Service service = new Service();
try {
Call call = (Call) service.createCall();
© 2008 Vocollect, Inc. Proprietary & Confidential
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new URL("http://localhost:8080/VoiceConsole/servlet/rpcrouter"));
call.setUsername("admin");
call.setPassword("passwd");
call.setOperationName(new QName("urn:com.vocollect.voiceconsole.web.soap.OperatorAccess", "fetchAllOperators"));
call.addParameter("sitePk", org.apache.axis.encoding.XMLType.XSD_INT, javax.xml.rpc.ParameterMode.IN);
call.setReturnType(org.apache.axis.encoding.XMLType.SOAP_VECTOR);
Vector res = (Vector) call.invoke(new Object[] {-1});
} catch (Exception e) {
e.printStackTrace();
}
return res;
40
Further Reading (Web Services)
• SOA
– http://www.service-architecture.com
• XML-RPC
– http://www.xmlrpc.com
• SOAP
© 2008 Vocollect, Inc. Proprietary & Confidential
• SOAP
– http://www.w3schools.com/soap
– http://www.w3.org/TR/soap
• WSDL
– http://www.w3schools.com/WSDL
– http://www.w3.org/TR/wsdl
41
Further Reading (Java and WS)
• Framework compatibility comparisons
– http://xfire.codehaus.org/Stack+Comparison
– http://www.predic8.com/axis2-cxf-jax-ws-comparison.htm
– http://www.theserverside.com/tt/articles/article.t
© 2008 Vocollect, Inc. Proprietary & Confidential
– http://www.theserverside.com/tt/articles/article.tss?l=AxisAxis2andCXF
• SOAP / Web Services frameworks
– http://ws.apache.org/axis
– http://ws.apache.org/axis2
– http://cxf.apache.org
– https://jax-ws.dev.java.net42