JSP is visiting the CORBA service object as the client party

xiaoxiao2021-03-06  42

Unfair

Combined with J2EE and CORBA can make full use of the advantages of both to establish a better function. For example, the C implementation CORBA object is used as the service processing component to form a high performance business logic layer, and access the CORBA component in JSP. Floor. Let's take a look at an example of accessing a CORBA service object in JSP.

Software selection:

CORBA Service, we choose Zhongchuang Software Commercial Middleware Co., Ltd. (

INFORBUS of http://www.inforbus.com) (a distributed object middleware that follows CORBA specification), based on C is developed. Operating system selection IBM AIX (of course, you can also choose HP UNIX, Linux, or Windows).

CORBA client, in order to showcase the interoperability of CORBA, the ORB included in the JDK is used here. Of course, as a better choice, you can also use the INFORBUS's Java version to implement CORBA's client.

JSP Operation Environment, we choose COSCO Software Commercial Middleware Co., Ltd.

INFORWEB of http://www.inforbus.com (a application server that follows J2EE specification). The operating system selects Window (of course, you can also choose HP UNIX, Linux, or AIX).

Program implementation

Idl

IDL is a protocol for request calls for CORBA Services and clients. As long as you use the same IDL, client and service, you can perform seamless communication, and the development language of the client and the service party, the operating system has no relationship. Even you can choose a different CORBA middleware for the client and the server (as long as they follow the CORBA specification). When implementing the CORBA client program, you don't need to care about any details of the server, you need to care about only IDL!

Here we define the IDL shown below (file name Appteest.IDL):

Module Example {Interface A {Long Aoperation (in long ildata);

CORBA Services Program

The work that the CORBA service needs to do is mainly: map IDL to C , implement the interface defined in IDL (ie implementation processing logic), and write a main program instantiated service object.

1. Map IDL to C

This only needs to call the INFORBUS IDL compiler IDL, execute the following command:

IDL Apptest.IDL

This command will produce four files: Apptest.h, appteest.cpp, apptest_skel.cpp, apptest_skel.cpp, which contains Skeleton.

2. Implement the interface defined in IDL

Inherit Skeleton, implement the IDL interface definition, complete your business logic in the implementation class, in this example we implements a simple logic, multiply the received parameters by 2, then return the results, the code is as follows:

// 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 // Contains CORBA System Class Library #include Using Namespace Std; #include // Operation AOperation Realization CORBA :: Long A_Impl :: AOperation (CORBA :: "ildata) {CORBA :: SystemException) {CORBA :: SystemException) {CORBA :: Systemexception) {CORBA :: {Ret; Ret = ILDATA * 2; Return Ret;} 3. Write a main program instantiation Service object service

In the main program, establish a CORBA environment, instantiate the service object and register the name service, then start waiting for the request, the code is as follows (for):

// / / file name: server.cpp #include #include #include #include #include #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 (); A_impl * AImpl = new A_impl (); PortableServer :: ServantBase_var servantA = AImpl; PortableServer :: ObjectId_var Aid = rootPOA -> Activate_Object (Servanta); CORBA :: Object_var a = rootpoa -> servant_to_reference (servanta); cosnam INAME.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 application implementation

In the web application, it is mainly through a JSP to access the CORBA service object and showcase the Corba client. Implementing a web application requires two aspects: mapping the IDL to Java, sending requests in JSP and showing results.

1. Map IDL to Java

This only needs to call JDK IDL compiler IDLJ, execute the following command:

IDLJ Apptest.IDL

This command will produce five files: A. Java, AOperations.java, AHELPER.JAVA, AHOLDER.JAVA and _Astub.java include STUB.

2. Send a request and display the result in the JSP.

In order to avoid containing too many Script in JSP, the code to send the request is separated from JSP to a simple Java class.

The code of the Java class is 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 well fly * / 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; out = a.aopert:}}}

The code for the JSP file is as follows (INDEX.JSP):

<% @ Page ContentType = "Text / HTML; Charset = GB2312"%> <% @ Page Import = "EXAMPLE.ACLIENT"%> Hello Jsp Corba Client </ Title> </ head > <Body> 3 * 2 = <% = ACLIENT.OPA (3)%> </ body> </ html></p> <p>Ok, compile your program, run the name service, run the CORBA service, run the application server INFORWEB, deploy the web application, and then you can access it through the browser.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-76497.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="76497" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.041</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'AvDJuFWEHUBvC0JjrZa1ZNcQOAP_2BUGz4mHtTIxDRs171rx6A2ej7LANANiPuMEKEKXbdLwzP7V042vdtoMhmyw_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>