J2EE Web Services Work - PowerPoint PPT Presentation

1 / 60
About This Presentation
Title:

J2EE Web Services Work

Description:

thomasamarrs_at_comcast.net. Who ... JBoss.Net. Bundled with JBoss 3.x. Non-standard. Tightly ... Platforms (J2EE, .Net) Operating Systems. Programming ... – PowerPoint PPT presentation

Number of Views:390
Avg rating:3.0/5.0
Slides: 61
Provided by: CE1
Category:

less

Transcript and Presenter's Notes

Title: J2EE Web Services Work


1
J2EE Web Services _at_ Work
  • Tom Marrs
  • Principal/Senior Software Architect
  • Vertical Slice, Inc.
  • thomasamarrs_at_comcast.net

2
Who Am I?
  • Background
  • Lead author of JBoss At Work A Practical Guide
    (OReilly, November 2005)
  • Presented at
  • XML One/Web Services One
  • No Fluff Just Stuff Symposia
  • User Groups
  • Forming Denver JBUG
  • Past President of DJUG
  • Related Experience
  • Used Web Services on Java/J2EE projects
  • Spent a lot of time fixing problems

3
Learning Objectives
  • As a result of this presentation you will learn
  • When and when not to use Web Services
  • How J2EE 1.4 and Web Services fit
  • Expose an EJB as a J2EE 1.4 Web Service
  • How to work around broken Open Source tools
  • Advanced J2EE Web Services Issues (a.k.a Reality)

4
Prerequisites
  • Java
  • Core language
  • Exposure to J2EE Basics JSPs, Servlets, EJBs
  • XML
  • Schema
  • Web Services

5
Session Non-Agenda
  • In this Session, we will not discuss
  • In-depth Web Service Architecture
  • Every last detail on SOAP, WSDL, and UDDI Yuck!
  • In-depth details on JBoss or other J2EE
    application servers

6
Session Agenda
  • In this Session we will discuss
  • Business Reasons for Using Web Services
  • Web Service Architecture
  • J2EE/JBoss and Web Services
  • Implementing/Deploying a Web Service
  • Packaging a Web Service
  • Consuming a Web Service
  • Advanced J2EE Web Services Issues
  • Summary

7
Session Roadmap
  • Where are we?
  • Business Reasons for Using Web Services
  • JAW Motors B2B
  • Reasons to Consider Web Services
  • When Not to Use Web Services
  • J2EE Web Service Architecture
  • J2EE/JBoss and Web Services
  • Implementing/Deploying a Web Service
  • Packaging a Web Service
  • Developing a Web Service Client
  • Advanced J2EE Web Services Issues
  • Summary

8
JAW Motors B2B
  • JAW Motors A fictitious auto dealership
  • Has a web site that shows its inventory
  • Wants to move beyond a web site
  • Can increase business by sharing inventory with
    VBAD (Virtual Big Auto Dealership)
  • The problem interoperability
  • JAW Motors uses Java/J2EE
  • VBAD uses non-Java technology

9
Reasons to Consider Web Services
  • Business
  • You need to communicate with external clients
  • Technical
  • You need to communicate with non-Java clients
  • Your clients are outside the firewall
  • Political
  • Management mandates the use of Web Services

10
When Not to Use Web Services
  • All your clients are Java-based
  • Communicating between J2EE architecture layers
  • You control the object model
  • Serialization/remoting are expensive
  • Web Services/XML processing takes longer
  • Dont Use XML to Communicate Unless You Really,
    Really Have To Floyd Marinescu, The Middleware
    Company
  • Remember Web Services/XML are for integration

11
Session Roadmap
  • Business Reasons for Using Web Services
  • Web Service Architecture
  • What are Web Services?
  • Web Service Terminology
  • Web Service Invocation
  • J2EE/JBoss and Web Services
  • Implementing/Deploying a Web Service
  • Packaging a Web Service
  • Developing a Web Service Client
  • Advanced J2EE Web Services Issues
  • Summary

12
What are Web Services?
  • Network applications that
  • Use
  • SOAP (Simple Object Access Protocol)
  • WSDL (Web Services Definition Language)
    Definition/Description
  • Exchange information via XML documents
  • Platform-independent
  • Not tied to Java, CORBA, etc.
  • There are 80 Web Service implementations

13
Web Service Terminology
  • SOAP (Simple Object Access Protocol)
  • An XML-based (text) wire protocol
  • Enables remote communication
  • Platform-neutral
  • WSDL (Web Services Definition Language)
  • Interface descriptor
  • UDDI (Universal Description, Discovery, and
    Integration)
  • Registry of Web Services
  • Used for discovering Web Services

14
Web Service Invocation
15
Session Roadmap
  • Business Reasons for Using Web Services
  • Web Service Architecture
  • J2EE/JBoss and Web Services
  • JBoss 4.x and Web Services
  • J2EE 1.4 and Web Services
  • Implementing/Deploying a Web Service
  • Packaging a Web Service
  • Developing a Web Service Client
  • Advanced J2EE Web Services Issues
  • Summary

16
JBoss 4.x and Web Services
  • JBoss.Net
  • Bundled with JBoss 3.x
  • Non-standard
  • Tightly Coupled to Apache Axis
  • XDoclet tags and deployment worked well
  • Now deprecated
  • JBossWS
  • Part of JBoss 4.x
  • Follows J2EE 1.4 standard
  • Moving away from Apache Axis
  • Decent Deployment
  • XDoclet needs help

17
J2EE 1.4 and Web Services
  • Interoperability
  • WS-I (Web Service Interoperability) compliance
  • Platforms (J2EE, .Net)
  • Operating Systems
  • Programming Languages
  • JSR-109
  • Standard Deployment Runtime
  • Descriptors
  • Web Service Engine details hidden
  • Still some bleed-through

18
J2EE 1.4 and Web Services continued
  • Can expose the following as Web Services
  • EJBs
  • POJOs
  • Were doing an EJB

19
Session Roadmap
  • Business Reasons for Using Web Services
  • Web Service Architecture
  • J2EE/JBoss and Web Services
  • Implementing/Deploying a Web Service Only 103
    Easy Steps ?
  • Service Endpoint Interface
  • Modify ejb-jar.xml
  • webservice.xml
  • JAX-RPC Mapping File
  • WSDL File (Oh the Joy!)
  • Fixing the WSDL URL
  • Modifying the EJB
  • Web Service Data Types Collections
  • Packaging a Web Service
  • Developing a Web Service Client
  • Advanced J2EE Web Services Issues
  • Summary

20
The System So Far
  • JAW Motors web site
  • JSPs
  • Controller Servlet
  • Stateless Session Bean InventoryFacadeBean
  • Hibernate DAOs
  • We want to expose InventoryFacadeBean.findAllAvail
    ableCars() as a Web Service

21
Service Endpoint Interface
  • Exposes business methods as Web Services
  • Acts as a server-side stub
  • Similar to EJB Remote Interface

22
Service Endpoint Interface continued
  • package com.jbossatwork.ws
  • /
  • Service endpoint interface for
    InventoryFacade.
  • /
  • public interface InventoryEndpoint
  • extends java.rmi.Remote
  • public com.jbossatwork.ws.CarDTOArray
    findAvailableCars()
  • throws java.rmi.RemoteException
  • // InventoryEndpoint.java

23
Modifying ejb-jar.xml
  • InventoryFacadeSB
  • InventoryFacade
  • com.jbossatwork.ws.InventoryEndpoint
  • ejb-jar.xml

24
webservices.xml
  • Defines and registers the InventoryService Web
    Service
  • Ties Service Endpoint Interface class to the
    InventoryFacadeBean EJB
  • Tells J2EE app server where to find WSDL and
    JAX-RPC Mapping files in EJB JAR file.

25
webservices.xml continued
  • xmlns"http//java.sun.com/xml/ns/j2ee"
  • xmlnsxsi"http//www.w3.org/2001/XMLSchema-insta
    nce"
  • xsischemaLocation"http//java.sun.com/xml/ns/j2
    ee
  • http//www.ibm.com/webservices/xsd/j2ee_web_servic
    es_1_1.xsd"
  • version"1.1"
  • InventoryServ
    ice
  • META-INF/wsdl/InventoryService.
    wsdl
  • META-INF/inventory-ma
    pping.xml
  • Inventoryomponent-name
  • InventoryEndpointPort-port
  • com.jbossatwork.ws.InventoryEndpoi
    nt
  • InventoryFacadelink

26
JAX-RPC Mapping File
  • Helps JAX-RPC compiler map Java objects to WSDL
    objects
  • Complex Java objects lead to complex JAX-RPC and
    WSDL files

27
JAX-RPC Mapping File continued
  • ns/j2ee"
  • xmlnsxsi"http//www.w3.org/2001/XMLSchema-instan
    ce"
  • xsischemaLocation"http//java.sun.com/xml/ns/j2e
    e
  • http//www.ibm.com/webservices/xsd/j2ee_jaxrpc_ma
    pping_1_1.xsd" version"1.1"
  • com.jbossatwork.ws
  • http//localhost8080/jbossatwor
    k-ws/types
  • com.jbossatwork.ws
  • http//localhost8080/jbossatwor
    k-ws
  • com.jbossatwork.dto.CarDTOArrayva-type
  • t8080/jbossatwork-ws/types"
  • typeNSCarDTOArray
  • complexType

28
JAX-RPC Mapping File continued
  • com.jbossatwork.dto.CarDTOpe
  • t8080/jbossatwork-ws/types"
  • typeNSCarDTO
  • complexType
  • id
  • id
  • make
  • make
  • modele
  • model

29
JAX-RPC Mapping File continued
  • statusme
  • status
  • com.jbossatwork.ws.Inventor
    yService
  • alhost8080/jbossatwork-ws"
  • serviceNSInventoryService
  • InventoryEndpointPort
  • InventoryEndpointPortport-name

30
JAX-RPC Mapping File continued
  • com.jbossatwork.ws.InventoryEndpoint
  • host8080/jbossatwork-ws"
  • portTypeNSInventoryEndpoint
  • t8080/jbossatwork-ws"
  • bindingNSInventoryEndpointBinding
  • findAvailableCarsthod-name
  • findAvailableCarsation
  • com.jbossatwork.dto.C
    arDTOArray
  • lhost8080/jbossatwork-ws"
  • wsdlMsgNSInventoryEndpoint_findAvailabl
    eCarsResponse
  • resultge-part-name

31
JAX-RPC Mapping File continued
  • What were we trying to do?
  • InventoryEndpoint Service Endpoint Interface has
    a findAvailableCars() method that takes no
    parameters and returns a CarDTOArray

32
WSDL File (Oh the Joy!)
  • Describes a Web Service interface
  • Describes its parameters
  • Registers the web service with the server

33
WSDL File (Oh the Joy!) continued
  • targetNamespace"http//localhost8080/jbossatwork
    -ws"
  • xmlnstns"http//localhost8080/jbossatwork-ws"
  • xmlns"http//schemas.xmlsoap.org/wsdl/"
  • xmlnsxsd"http//www.w3.org/2001/XMLSchema"
  • xmlnsns2"http//localhost8080/jbossatwork-ws/ty
    pes"
  • xmlnssoap"http//schemas.xmlsoap.org/wsdl/soap/"
  • /jbossatwork-ws/types"
  • xmlnstnshttp//localhost8080/jbossa
    twork-ws/types
  • xmlnssoap11-enc"http//schemas.xmlso
    ap.org/soap/encoding/"
  • xmlnsxsi"http//www.w3.org/2001/XMLS
    chema-instance"
  • xmlnswsdl"http//schemas.xmlsoap.org
    /wsdl/"
  • xmlns"http//www.w3.org/2001/XMLSchem
    a"
  • nillable"true" minOccurs"0"
  • maxOccurs"unbounded"/ce

34
WSDL File (Oh the Joy!) continued
  • nillable"true"/
  • nillable"true"/
  • nillable"true"/
  • nillable"true"/
  • rs"/
  • rsResponse"
  • message
  • ailableCars"/
  • vailableCarsResponse"/

35
WSDL File (Oh the Joy!) continued
  • type"tnsInventoryEndpoint"
  • p.org/soap/http" style"rpc"/
  • namespace"http//localhost8080/jbossatwork-ws"/
  • namespace"http//localhost8080/jbossatwork-ws"/
  • binding"tnsInventoryEndpointBinding"
  • URL"/

36
WSDL File (Oh the Joy!) continued
  • What were we trying to do?
  • Tie the InventoryService web service to the
    InventoryEndpoint interface
  • Map CarDTO and CarDTOArray WSDL types to XSD data
    types
  • But I thought we already did this (!)
  • WSDL required for W3C
  • JAX-RPC required for J2EE

37
Fixing the WSDL URL
  • WSDL tells application server that it can choose
    its own URL

  • JBoss chooses
  • http//localhost8080/jaw/ejb/Inventory?wsdl

38
Fixing the WSDL URL continued
  • We want a meaningful URL
  • 4.0//EN"
  • "http//www.jboss.org/j2ee/
    dtd/jboss_4_0.dtd"
  • InventoryFacade
  • Inventorynent-name
  • jbossatwork-ws/Invento
    ryService

39
Modifying the EJB
  • /
  • _at_ejb.bean
  • name"InventoryFacade"
  • view-type"all"
  • _at_wsee.port-component
  • name"Inventory"
  • wsdl-port"InventoryEndpointPort"
  • service-endpoint-interface"com.jbossatwork.ws
    .InventoryEndpoint"
  • service-endpoint-bean"com.jbossatwork.ejb.Inv
    entoryFacadeBean"
  • _at_ejb.interface
  • service-endpoint-class"com.jbossatwork.ws.Inv
    entoryEndpoint"
  • /
  • public class InventoryFacadeBean implements
    SessionBean

40
Modifying the EJB continued
  • /
  • _at_ejb.interface-method
  • view-type"all"
  • /
  • public CarDTOArray findAvailableCars() throws
    EJBException
  • CarDTOArray carDTOArray new
    CarDTOArray()
  • CarDTO cars (CarDTO)
    listAvailableCars().toArray(new CarDTO0)
  • carDTOArray.setCars(cars)
  • return carDTOArray
  • /
  • _at_ejb.interface-method
  • view-type"both"
  • /

41
Web Services Data Types
  • Parameters and Return values must conform to
    JavaBean rules
  • Default Constructor
  • Each private/protected data member must have
    public getter/setter
  • Must be Serializable

42
Web Services and Collections
  • WSDL/XSD doesnt understand Java Collections
  • package com.jbossatwork.dto
  • import java.io.Serializable
  • import com.jbossatwork.dto.CarDTO
  • public class CarDTOArray implements Serializable
  • private CarDTO cars
  • public CarDTOArray()
  • public CarDTO getCars()
  • return cars
  • public void setCars(CarDTO cars)
  • this.cars cars

43
Session Roadmap
  • Business Reasons for Using Web Services
  • Web Service Architecture
  • J2EE/JBoss and Web Services
  • Implementing/Deploying a Web Service
  • Packaging a Web Service - Good Tools Gone Bad
  • EJB JAR File Structure
  • What Are We Automating?
  • What About the Tools?
  • Ant Build Script
  • Developing a Web Service Client
  • Advanced J2EE Web Services Issues
  • Summary

44
EJB JAR File Structure
  • META-INF/
  • ejb-jar.xml
  • jboss.xml
  • webservices.xml
  • inventory-mapping.xml (JAX-RPC Mapping File)
  • wsdl/
  • InventoryService.wsdl
  • com/jbossatwork/ws/
  • InventoryEndpoint.class
  • Everything else is the same

45
What Are We Automating?
  • Generate 3 new descriptors
  • webservices.xml
  • JAX-RPC Mapping File
  • WSDL
  • Generate Service Endpoint Interface
  • Modify ejb-jar.xml and jboss.xml

46
What About the Tools?
  • XDoclet is broken (!)
  • Can generate (with minor mistakes)
  • Service Endpoint Interface
  • webservice.xml
  • Modify ejb-jar.xml
  • Ant fixes XDoclets mistakes
  • JWSDP (Java Web Services Developers Pack)
  • Generate WSDL and JAX-RPC Mapping Files

47
Ant Build Script Generate Service Endpoint
Interface
  • dp-1.5"/
  • om/jbossatwork/ws/InventoryEndpoint.java"
  • javax.ejb.EJBException,
  • java.rmi.RemoteException
  • java.rmi.RemoteException

48
Ant Build Script Fix the URL
  • "
  • Invento
    ryFacade
  • InventoryFacade/ejb-name
  • Inv
    entory
  • jbos
    satwork-ws/InventoryService

49
Ant Build Script Generate webservices.xml
  • let"
  • classname"xdoclet.modules.wsee.W
    seeDocletTask"
  • classpathref"xdoclet.lib.path"/
  • oryService.wsdl"
  • jaxrpcMappingFile"META-INF/in
    ventory-mapping.xml"
  • wseeSpec"1.1"
  • destdir"gen.source.dir"
  • excludedtags"_at_version,_at_author
    "
  • addedtags"_at_xdoclet-generated
    at TODAY"
  • verbose"true"
  • name"InventoryService"/

50
Ant Build Script Fix webservices.xml
  • es.xml"
  • WEB-
    INF/
  • /replacevalue
  • es.xml"
  • -fileWEB-INF/
  • -file
  • es.xml"
  • acetoken
  • ue
  • es.xml"
  • lacetoken
  • ue

51
Ant Build Script Generate JAX-RPC Mapping and
WSDL files
  • depends"compile"
  • and WSDL files."/
  • includes"tools.jar"/
  • fork"true"
  • server"true"
  • features"rpcliteral"
  • mapping"gen.source.dir/inve
    ntory-mapping.xml"
  • config"wscompile-config.xml"
  • nonClassDir"gen.source.dir"

52
Session Roadmap
  • Business Reasons for Using Web Services
  • Web Service Architecture
  • J2EE/JBoss and Web Services
  • Implementing/Deploying a Web Service
  • Packaging a Web Service
  • Developing a Web Service Client
  • Generate Web Service Proxy Code
  • Client Code
  • Advanced J2EE Web Services Issues
  • Summary

53
Generate Web Service Proxy Code
  • description"Generates WS proxy code from WSDL"
  • url"InventoryService.wsdl"
  • verbose"true"
  • 080/jbossatwork-ws"
  • package"com.jbossatwork.clie
    nt"/
  • 080/jbossatwork-ws/types"

54
Client Code
  • package com.jbossatwork.client
  • public class MyAxisClient
  • public static void main(String args)
  • try
  • System.out.println("Finding
    InventoryService ...\n")
  • InventoryService service new
    InventoryServiceLocator()
  • System.out.println("Getting InventoryEndpoint
    ...\n")
  • InventoryEndpoint endpoint
    service.getInventoryEndpointPort()
  • System.out.println("Getting Cars ...")

55
Client Code continued
  • // If you're using J2SE 1.4, the next
    2 lines of code will work.
  • CarDTOArray carDTOArray endpoint.findAvailab
    leCars()
  • CarDTO cars carDTOArray.getCars()
  • // If you're using Java 5 (J2SE 1.5), delete
    the previous 2 lines of
  • // code and uncomment the next line of code.
    Axis 1.2.1 optimized away
  • // the CarDTOArray.
  • // CarDTO cars endpoint.findAvaila
    bleCars()
  • for (int i 0 i
  • System.out.println(
  • "Year " carsi.getModelYea
    r() ", Make "
  • carsi.getMake()
  • ", Model " carsi.getModel()
    ", status "
  • carsi.getStatus() "")
  • catch(Exception e)
  • e.printStackTrace()

56
Session Roadmap
  • Business Reasons for Using Web Services
  • Web Service Architecture
  • J2EE/JBoss and Web Services
  • Implementing/Deploying a Web Service
  • Packaging a Web Service - Good Tools Gone Bad
  • Developing a Web Service Client
  • Advanced J2EE Web Services Issues
  • Tool/Product Limitations
  • RPC vs. Document
  • Summary

57
Tool/Product Limitations
  • Apache Axis 1.2.x
  • Problems consuming Web Services with XSD types
  • Enumerations
  • Unbounded array of Choices
  • Need to fix generated code yuck!
  • Not yet WS-I compliant
  • JBoss 4.x
  • WS Engine still uses Axis
  • Serializer/De-Serializer problems with
    deep/complex object types
  • Use proprietary XML descriptor to fix the
    problem
  • Moving away from Axis
  • Still production-worthy
  • Commercial WS tools work better

58
RPC vs. Document
  • Havent we done this before?
  • RPC
  • Can lead to tightly coupled interface
  • Can be brittle
  • Tools dont always work
  • Simple procedure call
  • Document
  • Loosely coupled interface
  • Absorbs change better
  • No serializer/de-serializer issues
  • Requires extra design effort
  • Interpret client messages and perform actions
  • Use Castor

59
Summary
  • Use Web Services for interoperability
  • J2EE Web Service deployment is tedious
  • Tools make things easier be careful
  • Automate J2EE Web Service deployment
  • Work around broken tools
  • Encapsulate everything with Ant or Maven
  • Understand design tradeoffs
  • Know the limitations of your application server
    tools
  • Automate get on with your life you have
    better things to do

60
Questions?
  • Tom Marrs
  • Senior Software Architect
  • thomasamarrs_at_comcast.net
Write a Comment
User Comments (0)
About PowerShow.com