Вы находитесь на странице: 1из 12

Sun Microsystems, Inc.

901 San Antonio Road


Palo Alto, CA 94303
U.S.A. 650-960-1300

JavaBeans CORBA:


, ,
, CORBA, JavaBeans (EJB
). , Java 2 Platform, Enterprise
Edition (J2EE) CORBA (Common Object Request Broker Architecture).
January 2002
Copyright 2002 Sun Microsystems, Inc., 901 San Antonio Road, Palo Alto, California 94303, U.S.A. All rights reserved.
Sun Microsystems, Inc. , ,
. , ,
, http://www.sun.com/patents
.
, , .

Sun .
, ,
Sun.
Sun, Sun Microsystems, Sun logo, Java, Enterprise JavaBeans, EJB, J2EE J2SE
Sun Microsystems, Inc. .
UNIX X/Open
Company, Ltd.

JavaBeans CORBA:

, ,
, CORBA, JavaBeans (EJB
). , Java 2 Platform, Enterprise
Edition (J2EE) CORBA (Common Object Request Broker Architecture).
J2EE , ,
, JavaBeans (EJB),
.
, , J2EE
, , -,
.
EJB ,
, . JavaBeans
,
, , .
CORBA Object Management Group (OMG), ,
, .

IIOP (Internet Inter-ORB Protocol), CORBA


, , ,
. CORBA,
http://www.omg.org/gettingstarted/gettingstartedindex.htm.
CORBA Java, ,
. CORBA
Java 2 JavaBeans, Java Remote Method Invocation API,
IIOP (Java RMI-IIOP), Java IDL API (Java IDL).
OMG Interface Definition Language (IDL) , .
IDL . IDL IDL
, OMG . OMG IDL
http://www.omg.org/gettingstarted/omg_idl.htm.
Java IDL Java ,
OMG IDL IIOP, Object Management Group (http://www.omg.org). Java RMI over IIOP
API CORBA javax.rmi API.
EJB Java RMI
, Java RMI-IIOP.
EJB CORBA
:

, ORB , ,
, JavaBeans (EJB) .
EJB-
EJB-.
CORBA-, , Java,
EJB-, OMG IDL .

CORBA,
. CORBA ,
, CORBA, Java, C++, C, Smalltalk, COBOL, Ada, Lisp
Python. Java- , CORBA, , Java RMI-IIOP API, .
, J2EE,
.

CORBA-,

, CORBA-, EJB.
++, ,
CORBA.
CORBA-, ,
:
1. .
2. CORBA IDL.
3. CORBA-.
4. .
5. .
:

Java RMI-IIOP.
.
.

.
.
I:
,
String, Java RMI-IIOP CORBA.
.
1. : Logger.java, LoggerHome.java, LoggerEJB.java LogMessage.java
/Java/src/ejbinterop.
Logger.java
Logger.java , , ,
EJBObject. EJB , .
// 1: Logger.java
package ejbinterop;
import javax.ejb.EJBObject;
import java.rmi.RemoteException;
/**
* String
* .
*/
public interface Logger extends EJBObject
{
/**
*
* .
*/
void logString(String message) throws RemoteException;
}
LoggerHome.java
LoggerHome.java EJBHome. EJBHome
EJB. , ,
EJB, -,
EJB.
// 2: LoggerHome.java
package ejbinterop;
import
import
import
public
{
}

java.rmi.RemoteException;
javax.ejb.EJBHome;
javax.ejb.CreateException;
interface LoggerHome extends EJBHome

Logger create() throws RemoteException, CreateException;

LoggerEJB.java
LoggerEJB.java .
, - .
, .

String
.
// 3: LoggerEJB.java
package ejbinterop;
import
import
import
import

javax.ejb.*;
java.util.*;
java.rmi.*;
java.io.*;

/**
* String
* .
*/
public class LoggerEJB implements SessionBean {
public LoggerEJB() {}
public void ejbCreate() {}
public void ejbRemove() {}
public void ejbActivate() {}
public void ejbPassivate() {}
public void setSessionContext(SessionContext sc) {}
/**
*
* .
*/
public void logString(String message) {
LogMessage msg = new LogMessage(message);
System.out.println(msg);
}
}
LogMessage.java
LogMessage.java , String,
, .
// 4: LogMessage.java
package ejbinterop;
import java.io.Serializable;
import java.util.Date;
import java.text.*;
/**
* ,
* .
*/
public class LogMessage implements Serializable
{
private String message;
private long datetime;
/**
* , .
* .
*/
public LogMessage(String msg) {
message = msg;
datetime = (new Date()).getTime();
}
/**
* String, .
*/
public String toString() {

StringBuffer sbuf = new StringBuffer();


DateFormat dformat
= DateFormat.getDateTimeInstance(DateFormat.MEDIUM,
DateFormat.LONG);
FieldPosition fpos = new
FieldPosition(DateFormat.DATE_FIELD);
dformat.format(new Date(datetime), sbuf, fpos);
sbuf.append(": ");
sbuf.append(message);
return sbuf.toString();

2. , , :

javac -classpath $J2EE_HOME/lib/j2ee.jar:<ejbinterop_directory> *.java

.class- .java- . ,
, , J2EE_HOME .
$J2EE_HOME Unix. %J2EE_HOME%
Windows.
II: CORBA IDL
IDL- .class- Java, .
rmic Java- IDL. IDL
, API .
3. rmic .class- Java, ,
:
rmic -idl -noValueMethods -classpath
$J2EE_HOME/lib/j2ee.jar:<path_to_ejbinterop_dir>
-d <path_to_where_idl_files_should_be_generated>
ejbinterop.Logger ejbinterop.LoggerHome
.jar-, javax.ejb,
ejbinterop. Java 2 Platform, Enterprise Edition (J2EE), version 1.3 Reference
Implementation (RI), .jar- $J2EE_HOME/lib/j2ee.jar.
rmic ,
noValueMethods. rmic
, CORBA.
IDL, ++. ,
, ,
Java.
.
rmic .class- Java , d,
:
o
o
o
o
o
o
o
o
o
o
o
o
o
o

java/lang/Ex.idl
java/lang/Exception.idl
java/lang/Object.idl
java/lang/Throwable.idl
java/lang/ThrowableEx.idl
javax/ejb/CreateEx.idl
javax/ejb/CreateException.idl
javax/ejb/EJBHome.idl
javax/ejb/EJBMetaData.idl
javax/ejb/EJBObject.idl
javax/ejb/Handle.idl
javax/ejb/HomeHandle.idl
javax/ejb/RemoveEx.idl
javax/ejb/RemoveException.idl

o
o

ejbinterop/Logger.idl
ejbinterop/LoggerHome.idl

. API,
Java. , EJBMetaData ,
, ,
Java. IDL, IDL
Java IDL rmic.
. CORBA , Java IDL
Ex, CORBA,
Java. .
http://java.sun.com/j2se/1.4/docs/guide/idl/jidlExceptions.html.
4. IDL IDL C++ ++
++, IDL. ++,
.
III: CORBA-
, CORBA.
++, , Object Request Broker (ORB) corbaname URL LoggerHome,
String . include
ORB-.
ORBacus C++ 4.0.5 ++ .
URL corbaname URL , CORBA.
.
J2EE v 1.3, CORBA Interoperable Naming Service (INS). INS
CORBA Object Services (COS) Naming Service,
J2EE. INS
http://java.sun.com/j2se/1.4/docs/guide/idl/jidlNaming.html#INS.
:
o

Object Request Broker (ORB). ORB , , ,


.

LoggerName , URL corbaname.

, LoggerHome.

LoggerEJB.

, EJB.

5. , ++ .
++. ORBacus C++ 4.0.5 ++
.
// 5: Client.cpp
#include <fstream.h>
// C++ ORB include
// C++ ORBacus 4.0.5
#include <OB/CORBA.h>
#include <OB/OBORB.h>
// include, IDL

#include
#include
#include
#include
#include
#include

<java/lang/Exception.h>
<java/lang/Throwable.h>
<javax/ejb/CreateException.h>
<javax/ejb/RemoveException.h>
<ejbinterop/Logger.h>
<ejbinterop/LoggerHome.h>

/**
* ORB corbaname URL LoggerHome,
* .
*/
void run(CORBA::ORB_ptr orb, const char* logger_home_url)
{
cout << "Looking for: " << logger_home_url << endl;
// LoggerHome
// corbaname URL
CORBA::Object_var home_obj
= orb->string_to_object(logger_home_url);
//
ejbinterop::LoggerHome_var home
= ejbinterop::LoggerHome::_narrow(home_obj.in());
assert(!CORBA::is_nil(home));
// Logger EJB
ejbinterop::Logger_var logger = home->create();
CORBA::WStringValue_var msg =
new CORBA::WStringValue((const CORBA::WChar*)L"Message
from a C++ client");
cout << "Logging..." << endl;
//
logger->logString(msg);
// ,
// EJB
logger->remove();
cout << "Done" << endl;
}
/**
* main, ,
* ORB, .
*/
int main(int argc, char* argv[])
{
int exit_code = 0;
CORBA::ORB_var orb;
try {
//
if (argc != 2) {
cerr << "Usage: Client <corbaname URL of LoggerHome>" << endl;
return 1;
}
// ORB
orb = CORBA::ORB_init(argc, argv);
//
// : ,
// .
// _OB_id
// ORBacus C++.
CORBA::ValueFactory factory = new java::lang::Throwable_init;
orb -> register_value_factory(java::lang::Throwable::_OB_id(),
factory);
factory -> _remove_ref();
factory = new java::lang::Exception_init;
orb -> register_value_factory(java::lang::Exception::_OB_id(),
factory);
factory -> _remove_ref();
factory = new javax::ejb::CreateException_init;

orb -> register_value_factory(javax::ejb::CreateException::_OB_id(),


factory);
factory -> _remove_ref();
factory = new javax::ejb::RemoveException_init;
orb -> register_value_factory(javax::ejb::RemoveException::_OB_id(),
factory);
factory -> _remove_ref();
//
run(orb, argv[1]);
} catch(const CORBA::Exception& ex) {
// , CORBA
cerr << ex._to_string() << endl;
exit_code = 1;
}
// ORB
if (!CORBA::is_nil(orb)) {
try {
orb -> destroy();
} catch(const CORBA::Exception& ex) {
cerr << ex._to_string() << endl;
exit_code = 1;
}
}
return exit_code;

6. ++
++, Client.cpp. ,
.

IV:
7. ,
. LoggerEJB
J2EE 1.3 Reference Implementation (RI).
1.

RI :
$J2EE_HOME/bin/j2ee verbose

2.

, J2EE 1.3 RI J2EE server startup complete,


:
$J2EE_HOME/bin/deploytool

3.

File -> New -> Application.

4.

Application File Name field Logger.ear ,


.

5.

Application Display Name field Logger.

6.

OK .

7.

File -> New -> Enterprise Bean.

8.

Next, Introduction. , .

9.

New EnterpriseBean Wizard Edit Contents.

10. Available Files .class- ejbinterop:


Logger.class, LoggerHome.class,LoggerEJB.class, LogMessage.class. OK, Next.
11. Stateless Session Bean Type.
12. ejbinterop.LoggerEJB Enterprise Bean Class.
13. ejbinterop.LoggerHome Remote Home Interface.
14. ejbinterop.Logger Remote Interface.
15. Next , Security Settings.
16. Deployment Settings.
17. Support Client Choice.
18. OK .
19. Finish.
20. Tools -> Deploy.
21. Java RMI-IIOP client only, Return Client JAR.
22. Next.
23. ejbinterop/logger JNDI Name LoggerEJB.
24. Finish.
25. File -> Exit .
Logger LoggerEJB .

V:
8. . URL
, :
Client corbaname:iiop:1.2@localhost:1050#ejbinterop/logger
URL,
o

Client .

corbaname , .

iiop:1.2 ORB IIOP GIOP 1.2.

-, , localhost.
localhost IP- , .

1050 , . J2EE v.1.3 RI


1050. # (Client corbaname:iiop:1.2@localhost:1050)
URL, .

ejbinterop/logger , .

J2EE 1.3 Reference Implementation,


:

Sep 21, 2001 3:33:07 PM PDT: Message from a C++ client ejbinterop/
logger is the name to be resolved from the Naming Service.

VI: J2EE
9. J2EE. :
$J2EE_HOME/bin/j2ee -stop
, ,
, .

RMI-IIOP
, Java RMI-IIOP,
. , ++, :

CLASSPATH .jar-,
J2EE, . .jar-
.

J2EE 1.3 RI Return Client Jar


Deploytool Deploy.

Java RMI-IIOP LoggerEJB.


, ++. URL,
++.
// 6: LogClient.java
package ejbinterop;
import
import
import
import
import

java.rmi.RemoteException;
javax.rmi.*;
java.io.*;
javax.naming.*;
javax.ejb.*;

/**
* Java RMI-IIOP, EJB.
*/
public class LogClient
{
/**
* ORB corbaname URL LoggerHome,
* .
*/
public static void run(String loggerHomeURL)
throws CreateException, RemoveException,
RemoteException, NamingException
{
System.out.println("Looking for: " + loggerHomeURL);
// InitialContext.
// CosNaming, .
InitialContext ic = new InitialContext();
// LoggerHome ,
// corbaname URL
Object homeObj = ic.lookup(loggerHomeURL);
//
LoggerHome home
= (LoggerHome)PortableRemoteObject.narrow(homeObj,
LoggerHome.class);
// Logger EJB
Logger logger = home.create();

System.out.println("Logging...");
//
logger.logString("Message from a Java RMI-IIOP client");
// ,
// EJB
logger.remove();
System.out.println("Done");

}
/**
* main, ,
* ORB, .
*/
public static void main(String args[])
{
try {
if (args.length != 1) {
System.out.println("Args: corbaname URL of LoggerHome");
System.exit(1);
}
LogClient.run(args[0]);
} catch (Throwable t) {
t.printStackTrace();
System.exit(1);
}
}

Java RMI-IIOP
Java RMI-IIOP :
1. .java- ejbinterop/ :
javac -classpath $J2EE_HOME/lib/j2ee.jar:<ejbinterop_directory> *.java
2. JavaBean ,
. Return Client JAR Tools -> Deploy
Java RMI-IIOP. J2EE RI.
3. , :
java -classpath $J2EE_HOME/lib/j2ee.jar:
<path to LoggerClient.jar>/LoggerClient.jar:
<directory_above_ejbinterop>:<ejbinterop_directory>
ejbinterop.LogClient
corbaname:iiop:1.2@localhost:1050#ejbinterop/logger
, J2EE RI, :
Jan 31, 2002 2:27:47 PM PST: Message from a Java RMI-IIOP client
, , :
Looking for: corbaname:iiop:1.2@localhost:1050#ejbinterop/logger
Logging...
Done
4. J2EE.

valuetype. , -noValueMethods
rmic.
, IDL ++, ,
valuetype.

Logger , LogMessage.


,
. :

Java, java.util,
.
, IDL,
. , Java Object Serialization RMI-IIOP API
,
CORBA Java 2 Platform, Standard Edition
(J2SE).

IDL.

. IDL.
IDL, EJB.
CORBA . ,
LogMessage IDL, IDL
Java EJB Logger.

EJB.
CORBA IDL . Java IDL
IDL,
IDL.
, , Java.

.
- , ,
.
, .


, J2EE, CORBA
JavaBeans:

IONA - Calling Enterprise Beans from CORBA Clients

http://www.iona.com/docs/iportal_application_server/3.0/DevelopGuide/html/intro-RMI.html#311099
BEA - EJB-to-CORBA/Java Simpapp Sample Application http://edocs.bea.com/wle/wle50/interop/ejbcorba.htm
Borland - Sevens steps to build a VisiBroker C++ CORBA Client for an EJB Server

http://www.borland.com/devsupport/appserver/faq/ejbcpp/ejb_cpp.html