packaging tool
Download
Report
Transcript packaging tool
Web Services in WebLogic Server
Aaron Mulder
Chief Technical Officer
Chariot Solutions LLC
Learning Objectives
• In this presentation, we'll discuss
– The advantages of web services
– Exposing EJBs as web services in
WebLogic 6.1 and WebLogic 7.0
– Invoking web services from applications
running in WebLogic 6.1/7.0
Copyright © 2002 Chariot Solutions LLC
About Aaron Mulder
• Chief Technical Officer of Chariot Solutions
• Published author (Professional EJB, and a
forthcoming WebLogic 7 handbook)
• Presented at JavaOne 2001/2002, and the
Philadelphia Java Users Group
• Member of the JSR-88 Expert Group (J2EE
Application Deployment)
• Contributed to open-source projects such
as JBoss, OpenEJB, and PostgreSQL
Copyright © 2002 Chariot Solutions LLC
Presentation Agenda
• About web services
• WebLogic support for web services
• WebLogic 6.1 in detail
• WebLogic 7.0 in detail
• Conclusions, Q&A
Copyright © 2002 Chariot Solutions LLC
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
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
• Source code is included on CD
• There are no particular WebLogic
Console configuration requirements
• We'll focus on EJB access, as that is
what J2EE 1.4 standardizes
• Inportant: WebLogic client libraries can
be freely redistributed
Copyright © 2002 Chariot Solutions LLC
WL6.1: Overview
• Expose stateless session beans via web
services
• Some limitations on EJB interface
• Can't expose selected methods
• The easy tool doesn't support security, or
apps larger than a single EJB JAR
• The advanced procedure can't generate
client code
• Examples use WebLogic 6.1 SP3
Copyright © 2002 Chariot Solutions LLC
WL6.1: Architecture
WAR
EJB JARs
SOAP Servlets
Session Beans
Client
Error Servlet
WSDL JSPs
Copyright © 2002 Chariot Solutions LLC
WL6.1: Developing the EJB
• No method overloading
• Limited data types in parameters, return
value
• boolean • Boolean • String
• short
• Short
• BigDecimal
• byte[]
• 1-D array of these
• int
• Integer
• Date
• JavaBean with
• long
• Long
• Element
these types of
• float
• Float
• Document
properties
• double
• Double
• DocumentFragment
Copyright © 2002 Chariot Solutions LLC
WL6.1: Easy Packaging Tool
• Create EJB JAR like usual
• Run setEnv script in
weblogic/config/domain
• Use wsgen Ant task to create web
services WAR and an EAR with the EJB
JAR and WAR
• Deploy the EAR like usual
Copyright © 2002 Chariot Solutions LLC
WL6.1: wsgen Ant script
<wsgen destpath="example-wsgen.ear"
context="/examples"
protocol="http">
<rpcservices path="myejb.jar">
<rpcservice bean="Bean1"
uri="/web-services/bean1" />
</rpcservice>
</wsgen>
Configuration Parameters:
• EAR name
• Web application context
• Protocol (http/https)
• Source EJB JAR
• ejb-name from EJB JAR
• EJB sub-context
Copyright © 2002 Chariot Solutions LLC
WL6.1: Advanced Packaging
• Advantages
– Security settings
– Multiple EJB JARs, existing WAR/EAR
– Custom layout, URLs
• Procedure
–
–
–
–
Configure servlets & EJB refs in WAR
Generate WSDL JSPs
Add WAR, EJB JARs to EAR
Use easy packaging to generate client
Copyright © 2002 Chariot Solutions LLC
WL6.1: Configure the WAR
• Add an invocation servlet for each EJB
– weblogic.soap.server.servlet.StatelessBeanAdapter
– One <init-param> called ejb-ref whose value
is the JNDI name of the EJB Ref
• Add one error servlet in each WAR
– weblogic.soap.server.servlet.FaultHandler
• Add servlet mappings for each servlet
• Add an <error-page>
– Exception class weblogic.soap.FaultException
– Location matches error servlet mapping
Copyright © 2002 Chariot Solutions LLC
WL6.1: Configure the WAR, cont.
• Add an EJB Reference for each EJB
– ejb-ref name must match the argument to
the invocation servlet
• Add security-constraint, login-config, etc.
to secure the web service
– Will use WebLogic security realm like any
other web application
– Can separately secure the EJBs, but an
insecure servlet can't invoke a secure EJB
Copyright © 2002 Chariot Solutions LLC
WL6.1: DD Examples
• Too much to show here; provided on CD
• Typically web.xml with all the settings
described here, and weblogic.xml with
EJB reference resolution
• Can integrate these settings into existing
deployment descriptors for existing WAR
Copyright © 2002 Chariot Solutions LLC
WL6.1: Generate WSDL JSPs
• Run the setEnv script
• Add EJB JAR to the CLASSPATH
• Run the Remote2WSDL tool
java weblogic.soap.wsdl.Remote2WSDL -protocol http
com.chariotsolutions.example.Bean1 examples/web-services/bean1
> src/web/bean1-wsdl.jsp
Remote2WSDL Arguments
• Protocol (http/https)
• fully-qualified remote interface name
• context & URL to servlet, without leading /
• redirect output to a file
• check for extraneous “type-class-name” line
Copyright © 2002 Chariot Solutions LLC
WL6.1: WSDL JSP Aliasing
• Can add servlet and servlet mapping to
web.xml for WDSL JSPs
<servlet>
<servlet-name>Bean1WSDL</servlet-name>
<jsp-file>/bean1-wsdl.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>Bean1WSDL</servlet-name>
<url-pattern>/web-services/bean1.wsdl</url-pattern>
</servlet-mapping>
Copyright © 2002 Chariot Solutions LLC
WL6.1: Configuring the EAR
• Add web services WAR and EJB JAR
to application configuration
<application>
<display-name>Example of Web Services</display-name>
<module>
<ejb>example-ejbs.jar</ejb>
</module>
<module>
<web>
<web-uri>example-web-services.war</web-uri>
<context-root>/examples</context-root>
</web>
</module>
</application>
Copyright © 2002 Chariot Solutions LLC
WL6.1: Generate Client Code
• Only way to generate client code is to use
wsgen Ant task, and it only generates
clients for web services running in
WebLogic
• Can use a third-party tool such as Apache
SOAP or IBM Web Services Toolkit
Copyright © 2002 Chariot Solutions LLC
WL6.1: Invoking the Web Services
• Build a URL from the web app context
root and servlet url-pattern
• For the examples provided:
http://localhost:7001/examples/web-services/bean1
http://localhost:7001/examples/web-services/bean1.wsdl
• Be sure to configure a security realm or
comment out the security settings in
web.xml
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 SP1
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
• Generally same basic data types as
WebLogic 6.1, but 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>
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 processors
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
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/
http://www.xmltp.com/