430 likes | 700 Vues
Integration with CORBA. Liang Tian. April 23, 2001. Outline. J2EE and CORBA. Integration. Servlet and CORBA Objects. JSP and CORBA Objects. EJB and CORBA Objects. Summary. J2EE and CORBA. J2EE and CORBA architectures both can provide developing environment for distributed applications.
E N D
Integration with CORBA Liang Tian April 23, 2001
Outline J2EE and CORBA Integration Servlet and CORBA Objects JSP and CORBA Objects EJB and CORBA Objects Summary
J2EE and CORBA J2EE and CORBA architectures both can provide developing environment for distributed applications. Each of the two architectures can provide multi-platform support, which makes application running in heterogeneous environment possible and easier. The implementation language is different.
J2EE and CORBA J2EE: entirely in Java. Application components benefit from “Write Once, Run Anywhere” model. Difficult in using the existing third-party non-Java code and making components running in non-Java client environments.
J2EE and CORBA CORBA: any one of supported programming languages. APIs written in different languages. Difficult in moving non-Java CORBA components from one platform to another. Flexible in implementation language and portability is not very good.
J2EE and CORBA Integration of J2EE and CORBA architectures. Share the benefits and reduce the limitations. J2EE and CORBA can work together very well. Our objective is to show how objects in CORBA architecture can be accessed from various J2EE application components.
WroxQuotes CORBA Object Demo Set Initial Object Reference Port
WroxQuotes CORBA Object Demo Server Running
WroxQuotes CORBA Object Demo Client Output
Integration Servlet JSP WroxQuotes CORBA Object EJB Web Container CORBA Server EJB Container
Integration Creating a Java Servlet that retrieves quotes information from WroxQuotes CORBA Object. Constructing a JavaServer Page that retrieves quotes information from WroxQuotes CORBA Object . Constructing Enterprise JavaBean that “wrap” CORBA Object and provide information to client.
Servlets and CORBA Objects CORBA Object HTML Form Servlet
Servlets and CORBA Objects Initializing ORB Accessing Naming Services Locating the Object Invoking the Method on Object Constructing resulting HTML Page Servlet.java
Servlets and CORBA Objects Initializing ORB ……. String port = getServletContext().getInitParameter("ORBInitialPort" ); String host = getServletContext().getInitParameter("ORBInitialHost" ); Properties orbProps = new Properties(); orbProps.put("org.omg.CORBA.ORBInitialPort", port); orbProps.put("org.omg.CORBA.ORBInitialHost", host); orb = org.omg.CORBA.ORB.init(args, orbProps); ……. Servlet.java
Servlets and CORBA Objects Accessing Naming Services & Locating the Object org.omg.CORBA.Object contextObj = orb.resolve_initial_references("NameService"); NamingContext rootContext = NamingContextHelper.narrow (contextObj); NameComponent name = new NameComponent("WroxQuotes", ""); NameComponent namePath[] = { name }; org.omg.CORBA.Object obj = rootContext.resolve(namePath); quoteObj = WroxStocks.WroxQuotesHelper.narrow(obj); Servlet.java
Servlets and CORBA Objects Invoking the Method on CORBA Object …… String symbolList = request.getParameter("Symbols"); String symbols[ ] = parseSymbolList(symbolList); try { if (quoteObj != null) { quotes = quoteObj.getQuoteList(symbols); } response.setContentType("text/html"); …… Servlet.java
Servlets and CORBA Objects Constructing Resulting HTML Page …… if (quotes != null) { out.println("<td align=\"center\">" + quotes[i].symb + "</td>"); out.println("<td>" + quotes[i].volume + "</td>"); out.println("<td>" + quotes[i].bid + "</td>"); out.println("<td>" + quotes[i].ask + "</td>"); } …… Servlet.java
Servlets and CORBA Objects HTML Form …… <form method=GET action="servlet/WroxQuotesServlet"> <br/> <h3>WroxStocks Quote Service</h3> <p>Symbol(s): <input type="TEXT" name="Symbols" size=30> <p><p>Enter stock symbol or multiple symbols delimited by spaces <p><input type="SUBMIT" name="SUBMIT" value="Get"> <input type="RESET" name="RESET" value="Reset"> </form> …… Form.html
Servlets and CORBA Objects Demo web.xml, application.xml, server.xml, default-web-site.xml java -jar orion.jar tnameserv -ORBInitialPort 1100 java -cp %CLASSPATH% WroxQuotesServer -ORBInitialPort 1100 http://localhost/WroxQuotes/
JSP and CORBA Objects JavaBean CORBA Object HTML Form JSP
JSP and CORBA Objects Initializing ORB Accessing Naming Services Locating the Object Invoking the Method on Object Bean.java
JSP and CORBA Objects Resulting Page <%@ page import="WroxStocks.WroxQuotesPackage.Quote" errorPage="WroxQuotesError.jsp"%> <jsp:useBean id="WroxQuotesBean" scope="application" class="WroxQuotesBean" > <% String port = application.getInitParameter("ORBInitialPort" ); String host = application.getInitParameter("ORBInitialHost" ); WroxQuotesBean.init(port, host ); %> </jsp:useBean> <% String symbols = request.getParameter( "Symbols" );%> Quotes.jsp
JSP and CORBA Objects Resulting Page …… <td align="center"> <%= quotes[i].symb %> </td> <td> <%= quotes[i].volume %> </td> <td> <%= quotes[i].bid %> </td> <td> <%= quotes[i].ask %> </td> <td align="center">04/23/2001 20:59:00</td> …… Quotes.jsp
JSP and CORBA Objects HTML Form …… <form method=GET action="WroxQuotes.jsp"> <br/> <h3>WroxStocks Quote Service</h3> <p>Symbol(s): <input type="TEXT" name="Symbols" size=30> <p><p>Enter stock symbol or multiple symbols delimited by spaces <p><input type="SUBMIT" name="SUBMIT" value="Get"> <input type="RESET" name="RESET" value="Reset"> </form> …… Form.html
JSP and CORBA Objects Demo web.xml, application.xml, server.xml, default-web-site.xml java -jar orion.jar tnameserv -ORBInitialPort 1100 java -cp %CLASSPATH% WroxQuotesServer -ORBInitialPort 1100 http://localhost/WroxQuotes/
EJB and CORBA Objects CORBA Object Client Application EJB
EJB and CORBA Objects Remote Interface …… public interface WroxQuotes extends EJBObject { public StockQuote getQuote(String symbol) throws UnknownSymbolException, RemoteException; public StockQuote[] getQuoteList(String[] symbols) throws UnknownSymbolException, RemoteException; } …… Quotes.java
EJB and CORBA Objects Home Interface import javax.ejb.EJBHome; import javax.ejb.CreateException; import java.io.Serializable; import java.rmi.RemoteException; public interface WroxQuotesHome extends EJBHome { WroxQuotes create() throws RemoteException, CreateException; } QuotesHome.java
EJB and CORBA Objects Initializing ORB Accessing Naming Services Locating the Object Invoking the Method on Object QuotesEJB.java
EJB and CORBA Objects Initializing ORB Accessing Naming Services Locating the Object public class WroxQuotesEJB implements SessionBean { WroxQuotesBean quotesBean; public WroxQuotesEJB() { …… quotesBean = new WroxQuotesBean(); quotesBean.init("1100", "localhost"); } …… QuotesEJB.java
EJB and CORBA Objects Invoking the Method on CORBA Object …… q = quotesBean.getQuotes(symbolList); result.symbol = q[0].symb; result.volume = q[0].volume; result.bid = q[0].bid; result.ask = q[0].ask; …… QuotesEJB.java
EJB and CORBA Objects Constructing Result …… for (int i = 0; i < q.length; i++) { result[i] = new StockQuote(); …… result[i].symbol = q[i].symb; result[i].volume = q[i].volume; result[i].bid = q[i].bid; result[i].ask = q[i].ask; …… cal.set(q[i].asOf.year, q[i].asOf.month, q[i].asOf.day, q[i].asOf.hour, q[i].asOf.minute, q[i].asOf.second); …… QuotesEJB.java
EJB and CORBA Objects Demo java -jar orion.jar tnameserv -ORBInitialPort 1100 java -cp %CLASSPATH% WroxQuotesServer -ORBInitialPort 1100 java -cp %CLASSPATH% WroxQuotesClient
Summary Initialize ORB Connect & Access Naming Services Obtain Object Reference & Locating the Object Invoke the Method on Remote Object Basic Steps
Summary “With the integration of J2EE and CORBA, we can easily build n-tier applications where Java and non-Java clients objects can seamlessly interact.” “By combining the benefits of Java and CORBA, our n-tier application can now be both accessible to new clients and able to accommodate new distributed objects without considering their implementation languages.” -- Professional Java Server Programming. J2EE Edition. p.1423
Summary J2EE and CORBA Integration Servlet and CORBA Objects JSP and CORBA Objects EJB and CORBA Objects Summary
Reference [1] Professional Java Server Programming. J2EE Edition. Chapter 29. Wrox Press. 2000. [2] Source Code of Professional Java Server Programming. J2EE Edition. Chapter 29. Wrox Press. 2000. Available at http://www.wrox.com
Integration with CORBA Liang Tian April 23, 2001