What Are Web Services?

Download Report

Transcript What Are Web Services?

Web Services in WebLogic Server
Tom Purcell
Chariot Solutions LLC
Agenda
• In this presentation, we'll discuss
– Distinguishing features of WebLogic 7.0
– Exposing EJBs as web services in
WebLogic 7.0
– Invoking web services from applications
running in WebLogic 7.0
Copyright © 2002 Chariot Solutions LLC
About Tom Purcell
•
•
•
•
•
•
Enterprise Architect with Chariot Solutions
Published articles…
Presented at JavaOne 2003…
Runs the DVBUG…
In IT since 1985…
[email protected]
Copyright © 2002 Chariot Solutions LLC
About Chariot Solutions
• Information Technology provider focused
on automating business processes
• Team of leading Java architects on staff
• Technical expertise in software architecture
and development, and systems integration
• Proven track record with companies such
as ExxonMobil, Midas, Rosenbluth
International, UGI Utilities, and the State of
New Jersey
Copyright © 2002 Chariot Solutions LLC
Introduction to WebLogic 7
Distinguishing Features
•
•
•
•
•
•
Installation (easy via a wizard)
Domains (configuration groups)
Startup (easy via provided script)
Deployment (copy EAR into deploy dir)
Management (nice web interface)
Extensions to J2EE (clustering, web
services, etc.)
Copyright © 2002 Chariot Solutions LLC
Installation
• BEA offers both a “network install” which
downloads features on demand, and a
regular full installer package (200MB)
• You can download the “platform”
(includes Portal, Integration, Workshop
products) or just the Server
• Downloads come with 1-year, 5-client-IP,
15-DB-connection development license
• Can get the JRockit JVM with it
Copyright © 2002 Chariot Solutions LLC
Installation, cont.
• Installer includes a JVM
• You will be prompted for a “BEA Home
Directory” where it stores the license, etc.
• The products are installed to a separate
dir, though default is under BEA Home
• After the product install, you can run the
“configuration wizard” to set up domains
(without a domain, you can only run the
demos – more on this later)
Copyright © 2002 Chariot Solutions LLC
Installation Screen Shots
Copyright © 2002 Chariot Solutions LLC
Installation Screen Shots
Copyright © 2002 Chariot Solutions LLC
Domains
• WebLogic groups configuration settings
into “domains”
• Each domain has its own set of server
configuration info, its own deployed
applications, etc.
• Each domain runs in a different JVM
• Several server instances can be grouped
into a single domain to share
applications, resources, etc.
Copyright © 2002 Chariot Solutions LLC
A Development Domain
• Contains a single server instance (the
“admin server”
• Is your typical standalone development
or QA server
Copyright © 2002 Chariot Solutions LLC
A Clustered Domain
• Contains a single “admin server” instance to
manage all the other instances
• Contains one or more “managed servers”,
which are dumb and just obey the admin
server
• All administration and deployment is initiated
through the admin server
• Typically the application runs only on the
managed servers (the admin server is
dedicated to administration)
• Admin server often doesn’t need a license
Copyright © 2002 Chariot Solutions LLC
Creating a Domain
• Done through the “configuration wizard”
• This wizard can be run at the end of the
installation routine
• Can also be run from the Start menu, or
the weblogic7/common/bin directory
• Wizard prompts for things like, should it
be a standalone server or an admin
server with managed servers
Copyright © 2002 Chariot Solutions LLC
Configuration Wizard Screen Shots
Copyright © 2002 Chariot Solutions LLC
Configuration Wizard Screen Shots
• Each domain that will be run simultaneously should have
different listen ports (most traffic goes over these ports)
Copyright © 2002 Chariot Solutions LLC
Configuration Wizard Screen Shots
• An administrative account must be created; this username
and password must be provided to start the server
Copyright © 2002 Chariot Solutions LLC
Configuration Wizard Screen Shots
Copyright © 2002 Chariot Solutions LLC
Domain Directory
• Domain directory contains:
–
–
–
–
–
Startup scripts (startWebLogic.cmd / .sh)
Configuration file (config.xml)
Subdirectory for deployments (applications/)
Subdirectory for logs (logs/)
Environment configuration scripts (to add
WebLogic tools to PATH/CLASSPATH, etc.
named setEnv.cmd / .sh)
– Various other config files
Copyright © 2002 Chariot Solutions LLC
Customizing the Startup Script
• Environment variables to set in the script:
– Set the admin user/password so no login is
required to start the server
set WLS_USER=…
set WLS_PW=…
– Set “development mode” so any applications in the
application/ directory are auto-deployed
set STARTMODE=false
– Add things (JDBC drivers) to the CLASSPATH
set POST_CLASSPATH=foo.jar;…
Copyright © 2002 Chariot Solutions LLC
Starting the Server
• Run the
startWebLogic
script to start
the server, or
use the Start
menu entry
Copyright © 2002 Chariot Solutions LLC
Deploying Applications
• If the server is set for development mode,
copy the application to applications/ dir
• Otherwise, use the deployment function
in the management console
• You can deploy an EJB JAR, WAR, RAR,
EAR, or an expanded directory structure
laid out like any of those
• In development mode, updating the files
under applications/ will redeploy
Copyright © 2002 Chariot Solutions LLC
Management
• All management is done through the
“console” web application
• It has a tree view on the left with
available resources, application modules,
etc.
• Click something on the left, and you get
detailed information and options in the
area to the right
• http://localhost:7001/console/
Copyright © 2002 Chariot Solutions LLC
Console Screen Shots
Copyright © 2002 Chariot Solutions LLC
WebLogic’s Extensions to J2EE
• Clustering
• Web Services
• JMS Bridge (lets 2 JMS implementations
pass messages back and forth)
• Guesses about CMP’s future
Copyright © 2002 Chariot Solutions LLC
Web Services
Why Web Services?
• Interoperability
–
–
–
–
hardware platforms
programming languages
applications
business partners
• Alternatives
– CORBA
– RMI
– Proprietary protocols (XML, binary, etc.)
Copyright © 2002 Chariot Solutions LLC
What Are Web Services?
• Generic protocol, transport
• For today's discussion
–
–
–
–
SOAP 1.1 (1.2 in not out)
WSDL 1.1
HTTP or HTTPS
JAX-RPC
• Registry services
– UDDI 2.0
Copyright © 2002 Chariot Solutions LLC
What Does WebLogic Support?
• WebLogic 6.1
– First release with web services support
– Tools to generate web services servlet/JSP
code for stateless session EJBs and JMS
destinations
– Crippled tool to generate client code to
invoke web services
– No standards-based support
Copyright © 2002 Chariot Solutions LLC
What Does WebLogic Support?
• WebLogic 7.0
– Improved web services support
– Deployment Descriptor-based web services
support
– Tool to generate client code to invoke any
web service (based on WSDL)
– JAX-RPC support
• WebLogic 8.0 ?
– J2EE 1.4/EJB 2.1 web services support
Copyright © 2002 Chariot Solutions LLC
Overview of Examples
• For the rest of the presentation, we'll dig
into the code and procedures
• There are no particular WebLogic
Console configuration requirements
• Expose existing EJB 2.0 CMP application
• Important: WebLogic client libraries can
be freely redistributed
Copyright © 2002 Chariot Solutions LLC
WebLogic 7.0 Web Services
• More options for what backs the web
services (individual EJB methods, etc.)
• Supports additional data types
• Can interact with SOAP messages
• Client need not receive a response
• Generates JAX-RPC clients from WSDL
• Quick-start tool from WSDL
• Uses web services DD
• Examples use WebLogic 7.0 SP4
Copyright © 2002 Chariot Solutions LLC
WL7.0: Architecture
WAR
SOAP Handler
Chain
Client
EJB JAR
Session Beans
web-services.xml
?
SOAP Handler
Chain
Copyright © 2002 Chariot Solutions LLC
WL7.0: Developing the EJB
• Still can't expose overloaded methods
• You can generate or code custom XML
serializers for unknown data types (such
as Java Beans)
• Additional built-in types include:
byte/Byte, char/Character, BigInteger,
Calendar
Copyright © 2002 Chariot Solutions LLC
WL7.0: Easy Packaging Tool
• Create an EJB JAR like normal
• Run the setEnv script to set environment,
add webserviceclient.jar to CLASSPATH
• Run an Ant script with servicegen to
create an EAR from an EJB JAR
• Deploy the EAR
• servicegen has loads of options, but still
doesn't integrate well into an existing
application
Copyright © 2002 Chariot Solutions LLC
WL7.0: servicegen Ant Script
<servicegen destEar="example-servicegen.ear"
contextURI="examples" >
<service ejbJar="example-ejbs.jar"
targetNamespace="java:mypackage.name"
serviceName="Bean1"
includeEJBs="Bean1"
serviceURI="/web-services/bean1"
generateTypes="True"
expandMethods="True"
style="rpc" >
<client packageName="com.chariotsolutions.example"/>
</service>
</servicegen>
Copyright © 2002 Chariot Solutions LLC
WL7.0: Advanced Packaging
• Procedure
– Develop and package the EJBs
– Create the web-services.xml deployment
descriptor
– Package the WAR, including web.xml for
security, and classes for SOAP handlers
– Package the EAR, including EJB JARs and
WAR
– Build the client code
Copyright © 2002 Chariot Solutions LLC
WL7.0: web-services.xml
<web-services>
<web-service name="Bean1"
targetNamespace="java:mypackage.name"
uri="/web-services/bean1">
<components>
<stateless-ejb name="Bean1">
<ejb-link path="example-ejbs.jar#Bean1" />
</stateless-ejb>
</components>
<operations>
<operation method="saySomething"
component="Bean1" />
</operations>
</web-service>
</web-services>
(See sample)
Copyright © 2002 Chariot Solutions LLC
WL7.0: More web-services.xml
• Use embedded XML schemas with
namespaces to identify custom data types
(see also the autotype Ant task)
• Use method parameters to support in/out
parameters
• Use method of “ * ” to support all methods
on an EJB
• Specify one-way operations
• Specify SOAP handlers
Copyright © 2002 Chariot Solutions LLC
WL7.0: Package WAR & EAR
• web-services.xml goes in WEB-INF/ in
the WAR
• SOAP handler classes go in WEB-INF/lib
or WEB-INF/classes
• Security, WSDL URL aliasing goes in
web.xml
• No need for EJB refs in web.xml
• EAR needs references to WAR and EJB
JARs like before (application.xml)
Copyright © 2002 Chariot Solutions LLC
WL7.0: Deploy EAR
• Deploy the EAR like normal
• Web services appear in the Console
under Deployments/Web Services
Components
• Use these URLs to access the web
services and WSDL:
http://localhost:7001/examples/web-services/bean1
http://localhost:7001/examples/web-services/bean1?WSDL
Copyright © 2002 Chariot Solutions LLC
WL7.0: Client Code
• Run setEnv script, add webserviceclient.jar
• Generate client code from the WSDL using
the clientgen Ant task
<clientgen
wsdl="c:/examples/src/web/bean1.wsdl"
serviceName="Bean1"
packageName="com.chariotsolutions.example.client"
clientJar="c:/examples/dist/bean1-client.jar"
/>
• Can also specify a normal URL for the
WSDL
Copyright © 2002 Chariot Solutions LLC
WL7.0: Coding a Client
• Add webserviceclient.jar and client JAR to
CLASSPATH
• Configure JAXM/JAX-RPC system
properties
• Use the generated classes to invoke the
Web Service
• Or, use a much more complicated process
to dynamically interact with arbitrary web
services based on WSDL
Copyright © 2002 Chariot Solutions LLC
WL7.0: Client Code
System.setProperty("javax.xml.soap.MessageFactory",
"weblogic.webservice.core.soap.MessageFactoryImpl");
System.setProperty("javax.xml.rpc.ServiceFactory",
"weblogic.webservice.core.rpc.ServiceFactoryImpl");
...
Bean1_Impl stub = new Bean1_Impl();
Bean1Port bean = stub.getBean1Port(username, password);
String response = bean.saySomething();
System.out.println("Bean1 said: "+response);
•This client will work against the service
deployed in WebLogic 6.1 or 7.0!
Copyright © 2002 Chariot Solutions LLC
Conclusions
• WebLogic 6.1 provides basic web
services, but limited client generation
• WebLogic 7.0 provides lots of options, but
taking full advantage makes it extremely
difficult to configure
• WebLogic 7.0 is nearly fully Ant-scriptable from client to server (WSDL?)
• EJB 2.1 will be greatly appreciated when
it arrives
Copyright © 2002 Chariot Solutions LLC
A Final Thought
How can web services
ease integration
challenges today?
Copyright © 2002 Chariot Solutions LLC
Questions?
http://www.chariotsolutions.com/
[email protected]