Package examples.webservices.handler.log
This example shows how to create a WebLogic Web service based on a handler chain and a Java backend component.See:
Class Summary
Client This class illustrates how to use the JAX-RPC API to dynamically invoke a WebLogic Web service implemented with both a handler chain and the EchoString
Java class.EchoString Java class that implements the backend component of the EchoString Web service. LogHandler Class that implements a handler in the handler chain, used to access the SOAP request and response message. Package examples.webservices.handler.log Description
This example shows how to create a WebLogic Web service based on a handler chain and a Java backend component.
The handler chain contains a single handler called
LogHandler
. This handler implements thejavax.xml.rpc.handler.Handler
interface. It implements the init method with code to create a newweblogic.logging.NonCatalogLogger
object, then implements thehandleRequest
andhandleResponse
methods to write the request and response SOAP messages to the log file.The Java class,
EchoString
, defines a single method calledechoString
that takes as input a String and simply returns the same String.The handler chain and the Java backend component are combined in a single Web service operation called
echoString
. When a client application invokes this operation, theLogHandler
handler first handles the SOAP request by logging the SOAP message to a log file, then theechoString
method is invoked, then the handler chain takes the SOAP response and logs it to a log file, and finally the response is sent back to the client application.This example does not use servicegen to generate the
web-services.xml
file, but rather shows an already created deployment descriptor that defines theLogHandler
handler, theechoString
Java class backend components, and the public operation that combines the handler chain and the backend component.The build.xml file compiles, assembles, packages, deploys, and runs the example.
Client.java
is a dynamic client application that does not use the WebLogic-generated client JAR file to invoke the Web service. Rather, the client application dynamically discovers the public operations, using thejavax.xml.rpc.Call
JAX-RPC API, based on the URL of the Web service.
Additional Resources for examples.webservices.handler.log
web-services.xml The Web services deployment descriptor file that describes the handler chain, the single handler, LogHandler
, the Java backend component, and theechoString
operation that combines the handler chain and Java component into a single public operation.application.xml The application deployment descriptor. build.xml The Java Ant build script that compiles the handler and Java classes, creates a WAR file that contains the web-services.xml file, then packages all these components into a deployable EAR file. The build file also compiles the dynamic client application.
The following sections describe how to build and run the example.
Prerequisites
Before you run this example, you need:
- WebLogic Server Version 8.1
Build the Example
To build the example, follow these steps:
- Set up your development shell as described in Quick Start.
- Change to the $SAMPLES_HOME\server\examples\src\examples\webservices\handler\log directory, where SAMPLES_HOME refers to the main WebLogic Server examples directory, such as d:\beahome\weblogic81\samples.
- Assemble and compile the example by executing the Java ant utility at the command line:
prompt> ant
Run the Example
- Start the examples WebLogic Server.
- In your development shell, run the Client Java application using the following command:
prompt> ant run- After building and running the example, you can view the Web Service Home Page using the following URL:
http://www.setgetweb.com:port/handler_log/EchoString
where
- www.setgetweb.com refers to the machine on which WebLogic Server is running
- port refers to port on which WebLogic Server is listening
From the Web Service Home Page you can view the generated WSDL, and test the Web service to make sure it's working correctly.
Check the Output
If the example executes successfully, you should see the following output on the client:run: [java] Calling Web Service at: http://www.setgetweb.com:7001/handler_log/EchoString?WSDL [java] [java] The client passed the value "BEAS" to the webservice, expecting to get back the same string: [java] BEAS
You should see the following output in the command shell from which you started WebLogic Server:** Request: SOAPMessageImpl[SOAPPartImpl[SOAPEnvelopeImpl[<env:Header> </env:Header>SOAPBody[<m:echoString xmlns:m=""> <param0 xsi:type="xsd:string">BEAS</param0> </m:echoString>]]]] String: BEAS ** Response: SOAPMessageImpl[SOAPPartImpl[SOAPEnvelopeImpl[<env:Header> </env:Header>SOAPBody[<m:echoStringResponse xmlns:m="http://www.bea.com/servers/wls70/samples/examples/webservices/handler/log"> <result xsi:type="xsd:string">BEAS</result></m:echoStringResponse>]]]]
See Also
Read more about:
- WebLogic Web services in Programming WebLogic Web Services.
- Additional Web Service Examples on the dev2dev Web site or from the