1 23 24 package com.rift.coad.lib.interceptor.iiop; 26 27 import java.util.StringTokenizer ; 29 import org.omg.CORBA.LocalObject ; 30 import org.omg.PortableInterceptor.ORBInitInfo ; 31 import org.omg.PortableInterceptor.ORBInitializer ; 32 import org.omg.PortableInterceptor.ClientRequestInterceptor ; 33 import org.omg.PortableInterceptor.ServerRequestInterceptor ; 34 import java.lang.reflect.Constructor ; 35 import org.omg.IOP.Codec ; 36 import org.omg.IOP.Encoding ; 37 import org.omg.IOP.ENCODING_CDR_ENCAPS ; 38 39 import com.rift.coad.lib.configuration.Configuration; 41 import com.rift.coad.lib.configuration.ConfigurationFactory; 42 43 48 public class InterceptorIntializer extends LocalObject implements 49 ORBInitializer { 50 51 private static final String CLIENT_INTERCEPTORS = "client_interceptors"; 53 private static final String SERVER_INTERCEPTORS = "server_interceptors"; 54 55 private Configuration config = null; 57 58 63 public InterceptorIntializer() throws SecurityInterceptorException { 64 try { 65 config = ConfigurationFactory.getInstance().getConfig( 66 this.getClass()); 67 } catch (Exception ex) { 68 throw new SecurityInterceptorException( 69 "Failed to retrieve the configuration : " + ex.getMessage(), 70 ex); 71 } 72 } 73 74 75 80 public void pre_init(ORBInitInfo info) { 81 82 } 83 84 85 90 public void post_init(ORBInitInfo info) { 91 try { 92 StringTokenizer tokenizer = new StringTokenizer (config.getString( 93 CLIENT_INTERCEPTORS),","); 94 while (tokenizer.hasMoreTokens()) { 95 Class ref = Class.forName(tokenizer.nextToken().trim()); 96 System.out.println("Retrieve interceptor class : " + 97 ref.getName()); 98 Constructor constructor = ref.getConstructor( 99 ORBInitInfo .class); 100 info.add_client_request_interceptor( 101 (ClientRequestInterceptor )constructor.newInstance(info)); 102 103 } 104 tokenizer = new StringTokenizer (config.getString( 105 SERVER_INTERCEPTORS),","); 106 while (tokenizer.hasMoreTokens()) { 107 Class ref = Class.forName(tokenizer.nextToken().trim()); 108 System.out.println("Retrieve interceptor class : " + 109 ref.getName()); 110 Constructor constructor = ref.getConstructor( 111 ORBInitInfo .class); 112 info.add_server_request_interceptor( 113 (ServerRequestInterceptor )constructor.newInstance(info)); 114 System.out.println("Add interceptor : " + ref.getName()); 115 } 116 117 Encoding encoding = new Encoding (ENCODING_CDR_ENCAPS.value, 119 (byte)1, 120 (byte)2 ); 121 Codec codec = info.codec_factory().create_codec(encoding); 122 info.add_ior_interceptor(new CodebaseIORInterceptor(codec)); 123 } catch (Exception ex) { 124 System.out.println("Failed to initialize the interceptor"); 125 ex.printStackTrace(System.out); 126 throw new SecurityInterceptorException( 127 "Failed to init the interceptors : " + ex.getMessage(),ex); 128 } 129 } 130 131 132 133 134 } 135 | Popular Tags |