How to expose CORBA object as JAX-RPC Web
Service
Date: 12-Nov-2003
After reading this how-to document you
should be able to:
- Understand what is a JAX-RPC Web Service
- Write a JAX-RPC Service that exposes CORBA object as a
service.
Introduction
This document demonstrates how to expose
CORBA object as a JAX-RPC Web Service.
Overview of JAX-RPC Web Services
The Java API for XML-based remote procedure
calls (JAX-RPC) provides standard way of building portable and
interoperable SOAP based Web Services. It simplifies the process of
building Web services that incorporate XML-based RPC. In JAX-RPC, a
remote procedure call is represented by an XML-based protocol such as
SOAP. The SOAP specification defines envelope structure, encoding
rules, and a convention for representing remote procedure calls and
responses. These calls and responses are transmitted as SOAP messages
over HTTP. Read more on JAX-RPC Web Services here.
The CORBA Technology
Common Object Request Broker Architecture
(CORBA) specifies a system which provides interoperability between
objects in a heterogeneous, distributed environment and in a way
transparent to the programmer. The CORBA objects can be accessed from
various programming languages, platforms and locations through the
object Interface using Object Request Broker (ORB) component. The
interface to the CORBA object is written in IDL (Interface Definition
Language) which helps to abstract the services provided by the object
from the actual object implementation. The implementation of the object
(also called as Servant) can be in any programming language like Java,
C++,Smalltalk etc. The client can also be written in variety of
languages as long as it adheres to the IDL interface and there is
mapping provided by CORBA IDL between the client and the target object
programming languages.
The communication between the client and
CORBA object takes place through the Object Request Broker (ORB)
component. The ORB provides a mechanism for transparently communicating
client requests to target object implementations. The ORB simplifies
distributed programming by decoupling the client from the details of
the method invocations. This makes client requests appear to be local
procedure calls. When a client invokes an operation, the ORB is
responsible for finding the object implementation, transparently
activating or deactivating the object, ensuring interaction security,
delivering the request to the object, and returning any response to the
client.
J2SE introduced idlj,
a 100% Java IDL that provides Java API for interoperability and
integration with CORBA. It supports Java based ORB over IIOP and IDL to
Java compilation for generating client-side stubs and server-side code
skeletons. More information about JDK CORBA development, read this article.
JDK provides orbd
(The Object Request Broker Daemon) which consists of Naming Services
and the Server Manager. It is used to enable clients to transparently
locate and invoke persistent objects on servers in the CORBA
environment. Read more on ordb here.
Software Requirements
-
Oracle Application Server Containers
for J2EE 10g or later. You can
download the OC4J from Oracle Technology Network.
-
JDK1.4.x or above This can be
downloaded here
-
Apache Ant
v1.5 or later.
- How To Example Source code zip
Description
The How-To Example
The example with this how to explains how to
expose CORBA object as Web Service.
The example provides an IDL interface named
Hello.idl which declares a method sayHello taking a string type as input
parameter. The IDL-to-Java compiler, idlj,
is used to generate the client side Java bindings and the server side
skeleton from Hello.idl file as follows :
idlj -fclient -fserver Hello.idl
The CORBA servant (CORBA back-end Object) is
developed using JDK1.4 from the IDL file.
The how to uses Oracle's Web Services
Assembler tool to generate the service artifacts. The Web Service
assembler tool takes as input, an XML config file that describes the
service. It uses the definitions in the WSDL file to generate service
artifacts like types, interfaces, tie and stub classes, compiles all
the classes and produces an Enterprise Archive file that can be
deployed to an application server to run the Web Service.
Listing 1 shows the Hello.idl file, the
interface to CORBA object. It defines a simple sayHello
method which takes in a string parameter and returns a string.
module oraclecorba { interface Hello { string sayHello( in string param ); }; };
|
|
Listing 1
Listing 2 shows the service-config.xml
file that describes the service for use by WSA. <corba-port>
tag is used to expose the Corba object as Web Service.
<?xml version="1.0"?> <web-services>
<!-- service ear output directory --> <output>dist/corba_hello.ear</output> <context>/</context> <web-service targetNamespace="http://oracle.j2ee.ws/corba/Hello" typeNamespace="http://oracle.j2ee.ws/corba/Hello/types"> <service-name>Corba_hello</service-name> <display-name>Hello display name</display-name> <description>Hello description</description>
<!-- create a rpc literal service --> <message-format style="rpc" use="literal"/> <source-output-dir>build/src/service</source-output-dir>
<corba-port interface="oraclecorba.Hello">
<!-- specify corbaname URL of corba object with host and port where NameService is running -->
<corbanameURL>corbaname::localhost:1050#oracle.corba/Hello</corbanameURL> <uri>/corba_hello</uri> </corba-port>
<idl> <!-- This requires idlj.exe in PATH env. variable. idlj.exe can be found at <JDK1.4>\bin\idlj.exe. --> <idl-file>Hello.idl</idl-file> </idl> </web-service> </web-services>
|
|
Listing 2
Listing 3 shows the implementation of
servant class CorbaHelloImpl.java class.It
defines the methods exposed by Hello.idl
interface.
package oracle.demo.corba;
import oraclecorba.HelloPOA; import org.omg.CORBA.ORB;public class CorbaHelloImpl extends HelloPOA { private ORB orb; public void setORB(ORB orb_val) { orb = orb_val; } public String sayHello( String param ) { System.out.println("==== CorbaHelloImpl(servant) sayHello: " + param); return param; } // implement shutdown() method public void shutdown() { orb.shutdown(false); } }
|
|
Listing 3
Listing 4 shows the sample client to access
the CORBA Web Service. The client stubs are generated by WSA tool using
the client-config.xml file.
package oracle.demo.corba;
import java.net.URL;
// JAX-RPC related imports import javax.xml.rpc.ServiceFactory; import javax.xml.rpc.Stub;public class HelloClient { // URL where corba service is running public static final String DEFAULT_URL = "http://localhost:8888/corba_hello/hello"; /* * The main method definition. It instantiates the client * Stub ,sets service url on Stub and invokes * method on web service */ public static void main(String[] args) throws Exception
{ String address = DEFAULT_URL;
// get the Service URL from class arguments if( args != null && args.length > 0 ) { address = args[0]; }
// instantiate service factory ServiceFactory factory = ServiceFactory.newInstance(); //Load Corba Hello WebService client-side proxy(stub). Corba_hello hello = (Corba_hello)factory.loadService( new
URL( address + "?WSDL" ), Corba_hello.class, null); HelloPort port = hello.getHelloPortPort();
// set the endpoint property of Stub to Web Service URL ((Stub)port)._setProperty( Stub.ENDPOINT_ADDRESS_PROPERTY,address );
// invoke Web Service method String result = port.sayHello( "Hello CORBA Web Service!"); System.out.println( "HelloClient: " + result ); } }
|
|
Listing 4
Preparing and Running the Example
Extract the corbaservice.zip
file. This will create corbaservice
directory containing documentation and source code of the how-to.
In the following steps <OC4J>
refers to directory where OC4J is installed.
| Step a: |
Start OC4J from <OC4J>/j2ee/home directory on a command
prompt as follows:
java -jar oc4j.jar
|
| Step b: |
Navigate to corbaservice,
the sample home directory on new command window . Include ANT_HOME/bin in the PATH environment variable.
Set the following properties required by the ant build script
-
Set the ORACLE_HOME
environment variable to your <OC4J> root
directory.
Example:
Windows : set ORACLE_HOME=c:\oc4j10g
Unix : ORACLE_HOME=/home/oc4j10g export ORACLE_HOME
-
Set the J2EE_HOME
environment variable to your <OC4J>/j2ee/home
directory.
Example:
Windows : set J2EE_HOME=c:\oc4j10g\j2ee\home
UNIX : J2EE_HOME=/home/oc4j10g/j2ee/home export J2EE_HOME
-
Set the JAVA_HOME
environment variable to your Java installation directory.
Example:
Windows : set JAVA_HOME=c:\j2sdk1.4
UNIX : JAVA_HOME=/home/j2sdk1.4 export JAVA_HOME
|
| Step c: |
Start the CORBA Naming Server. Open a new command window
and perform Step b. Now execute the following command.
ant run-orbd
The step executes command orbd -ORBInitialPort 1050 to start the server.
|
| Step c: |
Start the CORBA Servant. Open a new command window and
perform Step b. Now execute the following command.
ant run-servant
|
| Quick Start |
|
Once you have the server configured and running, execute
the following command from the prompt in Step b:
>ant
The service artifacts and implementation class will be
compiled and placed into a WAR which is then placed into an EAR.
The EAR will be deployed to OC4J. Next the stubs and
client will be compiled. Finally the service will be invoked by the
client and you should see the output on the stdout of the client.
|
| Step by Step |
| Step 1: |
Generate the service artifacts.
This step will generate the service artifacts which
include interfaces and Tie classes. Examine the corbaservice/config/service-config.xml
file. It provides information of CORBA object and Name Service.
To generate the service EAR file: ant
gen-service
The source code for the service-artifacts will be
placed in the corbaservice/build/src/service
directory. The WSA tool generates the EAR file in corbaservice/dist
directory.
Ignore any warnings.
|
| Step 4: |
Deploy and bind the CORBA WebService application:
The service is now ready to be deployed. Examine the corba_hello.ear in the corbaservice/dist
directory using WinZip or any zip file browser. It should contain a WAR
file named corba_hello-web.war. This WAR
file contains all the service artifacts, implementation classes, as
well as the web deployment descriptor (web.xml)
.
To deploy this ear to a running instance of oc4j type: ant deploy-service
After this task is complete you can check your Web
Service by typing in the following URL into a Web browser:
http://localhost:8888/corba_hello/corba_hello
You can invoke the sayHello method from Web Browser.
|
| Step 5: |
Run the demo.
This step generates client stubs required to access the
Web Service and runs the client. Examine the file
HelloClient.java in corbaservice/src/client/oracle/demo/corba
directory. Notice that this class uses the stubs to set an endpoint
address and to invoke methods on the remote service.
To run the client type: ant
run-corba-hello-client
You should also see following from CORBA servant:
CorbaHelloImpl(servant) sayHello : Hello CORBA Web
Service!
|
To undeploy the Web Service execute the
command : ant undeploy-service
Resources
Summary
This how-to document explained how expose
CORBA object as JAX-RPC Web Service and access it from a remote client.
|