JSP as a customer service to visit CORBA Object
Flying with the J2EE and CORBA can fully utilize the advantages of the establishment of two more functional and better performance of applications, such as C + + can be used to achieve the CORBA object as a business processing component, a high-performance Yewuluojiceng, in JSP visit CORBA Component the establishment of the show. Below we view with a visit to CORBA in JSP clients example.
Software options:
CORBA services side, we have a choice in the software business middleware Limited (http://www.inforbus.com) InforBus (a follow standard CORBA distributed object middleware), based on C + + development. IBM AIX operating system choices (of course, you can also choose HP UNIX, Linux or Windows like).
CORBA client side, in order to demonstrate ability to CORBA interoperability, where the use of the ORB included in the JDK. Of course, as a better option, you can also use the Java version InforBus to achieve CORBA client side.
JSP operating environment, we have a choice in the software business middleware Limited (http://www.inforbus.com) InforWeb (J2EE follow a standardized application server). Select Window operating system (Of course, you can also choose HP UNIX, Linux or AIX like).
Program IDL
IDL is the CORBA services and customers to call to request the agreement, as long as the use of the same IDL, and the customer service side on the communications can be seamlessly, and with customers and the services to the development of language, the operating system did not, You can even, and services for customers to choose different CORBA middleware (as long as they follow the CORBA specification). CORBA customers in achieving the procedures, you do not concern any details of the service, you need only concern IDL!
Here we define the IDL as follows (document, entitled apptest.idl):
- Module example (
- Interface A (
- Long AOperation (in long ilData);
- );
- );
CORBA services, CORBA services program needs to be done to achieve the main work: IDL mapping to C + +, IDL achieve defined in the interface (ie, to achieve processing logic), examples of the preparation of a main program services provide services.
1. IDL will be mapped to C + +
This need only call InforBus idl the IDL compiler, the Executive Order as follows:
Idl apptest.idl
This command will have four documents: apptest.h, apptest.cpp, apptest_skel.cpp, apptest_skel.cpp, which includes the Skeleton.
2. Achieve IDL interface defined in the inheritance Skeleton achieve IDL interface definitions, in the realization of the complete your business logic, in this case, we achieved a simple logic, will receive the parameters multiplied by 2, and then Back to the results, the code below:
- ////////////////////////////////////////
- / / File Name: apptest_impl.h
- # Ifndef APPTEST_IMPL_H
- # Define APPTEST_IMPL_H
- # Include "apptest_skel.h"
- Class A_impl: public POA_example:: A, PortableServer:: RefCountServantBase (
- Public:
- Virtual CORBA:: Long AOperation (CORBA:: Long ilData)
- Throw (CORBA:: SystemException);
- );
- # Endif
- ////////////////////////////////////////////////// / / / /
- / / File Name: apptest_impl.cpp
- / / Class library system includes CORBA
- # Include <STARCORBA.h>
- Using namespace std;
- # Include <apptest_impl.h>
- / / Implementation of operation AOperation
- CORBA:: Long A_impl:: AOperation (CORBA:: Long ilData)
- Throw (CORBA:: SystemException) (
- CORBA:: Long ret;
- Ret = ilData * 2;
- Return ret;
- )
3. Examples of the preparation of a main program services in the provision of services in the main program, the establishment of CORBA environment, and examples of client services registered to the name, and then started waiting for the request, the code below (to):
- ///////////////////////////////////////////
- / / File Name: Server.cpp
- # Include <stdio.h>
- # Include <STARCORBA.h>
- # Include <STARCosNaming.h>
- # Include <stdlib.h>
- # Include <errno.h>
- # Include "apptest_impl.h"
- Using namespace std;
- Int main (int argc, char * argv [], char * []) (
- CORBA:: ORB_var orb;
- Orb = CORBA:: ORB_init (argc, argv);
- CORBA:: Object_var nameobj =
- Orb -> resolve_initial_references ( "NameService");
- CosNaming:: NamingContext_var nc =
- CosNaming:: NamingContext:: _narrow (nameobj.in ());
- CORBA:: Object_var poaObj =
- Orb -> resolve_initial_references ( "RootPOA");
- PortableServer:: = POA_var rootPOA
- PortableServer:: POA:: _narrow (poaObj);
- PortableServer:: = POAManager_var manager
- RootPOA -> the_POAManager ();
- AImpl A_impl * = new A_impl ();
- PortableServer:: = AImpl ServantBase_var servantA;
- PortableServer:: = ObjectId_var Aid
- RootPOA -> activate_object (servantA);
- CORBA:: Object_var A =
- RootPOA -> servant_to_reference (servantA);
- CosNaming:: Name AName;
- AName. Length (1);
- AName [0]. Id = CORBA:: string_dup ( "A");
- AName [0]. Kind = CORBA:: string_dup ( "OperationA");
- Nc -> rebind (AName, A.in ());
- Manager -> activate ();
- Orb -> run ();
- Nc -> unbind (AName);
- Return EXIT_SUCCESS;
- )
Web applications, Web applications primarily through a JSP visit CORBA objects and services on display, here as CORBA client side. Web application needs to be done to achieve two tasks: IDL mapping to Java, in JSP send the request and display the results.
1. Will be mapped to the Java IDL
JDK this need only call the IDL compiler idlj, the Executive Order as follows:
Idlj apptest.idl
This command will have five documents: A.java, AOperations.java, AHelper.java, AHolder.java and _ AStub.java, which includes the Stub.
2. Sent in JSP request and display the results.
In order to avoid too much of the JSP Script, the request will be sent here from the JSP code separation to a simple Java class.
Java class code as follows (AClient.java):
- / *
- * AClient.java
- * /
- Package example;
- Import org.omg.CORBA .*;
- Import org.omg.CORBA.ORBPackage. InvalidName;
- Import org.omg.CosNaming .*;
- Import org.omg.CosNaming.NamingContextPackage. CannotProceed;
- Import org.omg.CosNaming.NamingContextPackage. NotFound;
- / **
- * @ Author of Flying
- * /
- (Public class AClient
- Public static int opA (int num) throws Exception (
- String args [] = ( "-ORBInitRef"
- "NameService = corbaloc: iiop: 192.168.60.158:900 / NameService");
- ORB orb = ORB. Init (args, null);
- Org.omg.CORBA. Object objRef;
- ObjRef = orb.resolve_initial_references ( "NameService");
- NamingContext ncRef = NamingContextHelper. Narrow (objRef);
- NameComponent nc = new NameComponent ( "A", "OperationA");
- NameComponent path nc [] = ();
- Org.omg.CORBA. Object objA;
- ObjA = ncRef.resolve (path);
- A a = AHelper.narrow (objA);
- Int out;
- A.AOperation out = (num);
- Return out;
- )
- )
JSP documents code as follows (index.jsp):
- <% @ Page contentType = "text / html; gb2312 charset ="%>
- <% @ Page import = "example.AClient"%>
- <html>
- <head>
- <title> Hello JSP CORBA Client </ title>
- </ Head>
- <body>
- 3 * 2 = <= AClient.opA% (3)%>
- </ Body>
- </ Html>
Well, the compiler of your procedures, operation name, Operation CORBA service procedures, InforWeb running an application server, the deployment of Web applications, and can be visited by the browser.








0 Comments to “JSP as a customer service to visit CORBA Object”
No Comments. Send your comment.
Leave a Reply
You must be logged in to post a comment.