KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > iiop > J2EEInitializer


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.iiop;
24
25 import java.lang.reflect.Constructor JavaDoc;
26
27 import org.omg.CORBA.ORB JavaDoc;
28 import org.omg.CORBA.TSIdentification;
29 import org.omg.PortableInterceptor.ClientRequestInterceptor JavaDoc;
30 import org.omg.PortableInterceptor.ServerRequestInterceptor JavaDoc;
31 import org.omg.PortableInterceptor.ORBInitializer JavaDoc;
32 import org.omg.PortableInterceptor.Current JavaDoc;
33 import org.omg.IOP.Codec JavaDoc;
34 import org.omg.IOP.CodecFactory JavaDoc;
35 import org.omg.IOP.Encoding JavaDoc;
36 import org.omg.IOP.ENCODING_CDR_ENCAPS JavaDoc;
37
38 import com.sun.enterprise.log.Log;
39
40 import com.sun.enterprise.iiop.security.SecClientRequestInterceptor;
41 import com.sun.enterprise.iiop.security.SecServerRequestInterceptor;
42 import com.sun.enterprise.iiop.security.SecurityService;
43 import com.sun.enterprise.iiop.security.SecurityServiceImpl;
44 import com.sun.enterprise.iiop.security.Csiv2Manager;
45
46 import com.sun.corba.ee.spi.legacy.interceptor.ORBInitInfoExt;
47 import com.sun.jts.pi.InterceptorImpl;
48 import java.util.logging.*;
49 import com.sun.logging.*;
50
51 /**
52  * This file implements an initializer class for all portable interceptors
53  * used in the J2EE RI (currently security and transactions).
54  * It registers the IOR, client and server request interceptors.
55  *
56  * @author Vivek Nagar
57  */

58
59 public class J2EEInitializer extends org.omg.CORBA.LocalObject JavaDoc
60         implements ORBInitializer JavaDoc
61 {
62     private static Logger _logger=null;
63     static{
64        _logger=LogDomains.getLogger(LogDomains.CORBA_LOGGER);
65         }
66
67     private static final String JavaDoc SEC_INTEROP_CLIENTINT_PROP = "interop.secinterceptor.client";
68     private static final String JavaDoc SEC_INTEROP_SERVERINT_PROP = "interop.secinterceptor.server";
69
70     public J2EEInitializer() {
71     try {
72         System.setProperty(
73             com.sun.jts.pi.InterceptorImpl.CLIENT_POLICY_CHECKING,
74             String.valueOf(false));
75     } catch ( Exception JavaDoc ex ) {
76         _logger.log(Level.WARNING,"iiop.readproperty_exception",ex);
77     }
78     }
79
80     /**
81      * This method is called during ORB initialization.
82      * @param the info object that provides initialization attributes
83      * and operations by which interceptors are registered.
84      */

85     public void pre_init(org.omg.PortableInterceptor.ORBInitInfo JavaDoc info)
86     {
87     }
88
89     /**
90      * This method is called during ORB initialization.
91      * @param the info object that provides initialization attributes
92      * and operations by which interceptors are registered.
93      */

94     public void post_init(org.omg.PortableInterceptor.ORBInitInfo JavaDoc info)
95     {
96         Codec JavaDoc codec = null;
97
98     if(_logger.isLoggable(Level.FINE)){
99         _logger.log(Level.FINE,"J2EE Initializer post_init");
100         // Create a Codec that can be passed to interceptors.
101
_logger.log(Level.FINE,"Creating Codec for CDR encoding");
102     }
103
104         CodecFactory JavaDoc cf = info.codec_factory();
105   
106         byte major_version = 1;
107         byte minor_version = 2;
108         Encoding JavaDoc encoding = new Encoding JavaDoc(ENCODING_CDR_ENCAPS.value,
109                                          major_version, minor_version);
110         try {
111             codec = cf.create_codec(encoding);
112
113         // register CSIv2 interceptors.
114
ClientConnectionInterceptor cci =
115                  new ClientConnectionInterceptor("ClientConnInterceptor",1);
116             info.add_client_request_interceptor(cci);
117
118             String JavaDoc clientSecInterceptor = System.getProperty(SEC_INTEROP_CLIENTINT_PROP);
119             String JavaDoc serverSecInterceptor = System.getProperty(SEC_INTEROP_SERVERINT_PROP);
120
121             ClientRequestInterceptor JavaDoc creq;
122             ServerRequestInterceptor JavaDoc sreq;
123
124             if( clientSecInterceptor == null ) {
125                 creq = new SecClientRequestInterceptor(
126                     "SecClientRequestInterceptor", codec);
127             }
128             else {
129                 try {
130                     Class JavaDoc cInterceptorClass =
131                         Class.forName( clientSecInterceptor );
132
133                     // Find two-parameter constructor:
134
Class JavaDoc[] paramTypes = new Class JavaDoc[2];
135                     paramTypes[0] = java.lang.String JavaDoc.class;
136                     paramTypes[1] = org.omg.IOP.Codec JavaDoc.class;
137
138                     Object JavaDoc[] params = new Object JavaDoc[2];
139                     params[0] = "SecClientRequestInterceptor";
140                     params[1] = codec;
141
142                     Constructor JavaDoc constructor = cInterceptorClass.getConstructor(
143                         paramTypes );
144
145                     creq = (ClientRequestInterceptor JavaDoc)
146                         constructor.newInstance( params );
147                 }
148                 catch( Exception JavaDoc e ) {
149             if (_logger.isLoggable(Level.FINE)) {
150             _logger.log(Level.FINE,"Exception registering security client request receptor",e);
151             _logger.log(Level.FINE,"Going to register default security client request interceptor");
152             }
153                     creq = new SecClientRequestInterceptor(
154                         "SecClientRequestInterceptor", codec);
155                 }
156             }
157
158             if( serverSecInterceptor == null ) {
159                 sreq = new SecServerRequestInterceptor(
160                     "SecServerRequestInterceptor", codec);
161             }
162             else {
163                 try {
164                     Class JavaDoc sInterceptorClass =
165                         Class.forName( serverSecInterceptor );
166
167                     // Try two-parameter form of constructor:
168
Class JavaDoc[] paramTypes = new Class JavaDoc[2];
169                     paramTypes[0] = java.lang.String JavaDoc.class;
170                     paramTypes[1] = org.omg.IOP.Codec JavaDoc.class;
171
172                     Object JavaDoc[] params = new Object JavaDoc[2];
173                     params[0] = "SecServerRequestInterceptor";
174                     params[1] = codec;
175
176                     Constructor JavaDoc constructor = sInterceptorClass.getConstructor(
177                         paramTypes );
178
179                     sreq = (ServerRequestInterceptor JavaDoc)
180                         constructor.newInstance( params );
181                 }
182                 catch( Exception JavaDoc e ) {
183             if (_logger.isLoggable(Level.FINE)) {
184             _logger.log(Level.FINE,"Exception registering security server request receptor",e);
185             _logger.log(Level.FINE,"Going to register default security server request interceptor");
186             }
187                     sreq = new SecServerRequestInterceptor(
188                         "SecServerRequestInterceptor", codec);
189                 }
190             }
191
192             info.add_client_request_interceptor(creq);
193
194             ServerConnectionInterceptor sci =
195                 new ServerConnectionInterceptor(2);
196             info.add_server_request_interceptor(sci);
197             info.add_server_request_interceptor(sreq);
198
199         SecurityService ss = new SecurityServiceImpl();
200         Csiv2Manager.setSecurityService(ss);
201
202
203         // register JTS interceptors
204
// first get hold of PICurrent to allocate a slot for JTS service.
205
Current JavaDoc pic = (Current JavaDoc)info.resolve_initial_references("PICurrent");
206
207         // allocate a PICurrent slotId for the transaction service.
208
int[] slotIds = new int[2];
209         slotIds[0] = info.allocate_slot_id();
210         slotIds[1] = info.allocate_slot_id();
211
212         InterceptorImpl interceptor =
213                 new InterceptorImpl(pic, codec, slotIds, null);
214             info.add_client_request_interceptor(interceptor);
215             info.add_server_request_interceptor(interceptor);
216
217         // Get the ORB instance on which this interceptor is being
218
// initialized
219
com.sun.corba.ee.spi.orb.ORB thisORB = ((ORBInitInfoExt)info).getORB();
220
221         PEORBConfigurator.setJTSInterceptor(interceptor, thisORB);
222
223         // add IOR Interceptor for CSIv2 and OTS tagged components
224
TxSecIORInterceptor iorInterceptor = new TxSecIORInterceptor(codec);
225         info.add_ior_interceptor(iorInterceptor);
226
227         } catch (Exception JavaDoc e) {
228         if(_logger.isLoggable(Level.FINE)){
229         _logger.log(Level.FINE,"Exception registering JTS interceptors",e);
230         }
231         throw new RuntimeException JavaDoc(e.getMessage());
232         }
233         
234     }
235 }
236
237
Popular Tags