| 1 26 27 package com.rift.coad.lib.interceptor.iiop; 29 30 import java.net.InetAddress ; 32 import org.omg.CORBA.Any ; 33 import org.omg.CORBA.LocalObject ; 34 import org.omg.CORBA.ORB ; 35 import org.omg.IOP.Codec ; 36 import org.omg.IOP.TaggedComponent ; 37 import org.omg.IOP.TAG_JAVA_CODEBASE ; 38 import org.omg.PortableInterceptor.IORInterceptor ; 39 import org.omg.PortableInterceptor.IORInfo ; 40 41 import org.apache.log4j.Logger; 43 44 import com.rift.coad.lib.configuration.Configuration; 46 import com.rift.coad.lib.configuration.ConfigurationFactory; 47 import com.rift.coad.lib.deployment.DeploymentLoader; 48 import com.rift.coad.lib.interceptor.InterceptorException; 49 import com.rift.coad.lib.httpd.RequestListenerThread; 50 import com.rift.coad.lib.httpd.HttpDaemon; 51 52 58 public class CodebaseIORInterceptor extends LocalObject implements 59 IORInterceptor { 60 61 private final static String URL_FORMAT = "http://%s:%d/codebase/%s"; 63 64 protected static Logger log = 66 Logger.getLogger(CodebaseIORInterceptor.class); 67 68 private String hostname = null; 70 private int port = 0; 71 private Codec codec = null; 72 73 78 public CodebaseIORInterceptor(Codec codec) throws InterceptorException { 79 this.codec = codec; 80 try { 81 Configuration config = ConfigurationFactory.getInstance().getConfig( 82 RequestListenerThread.class); 83 hostname = config.getString(RequestListenerThread.HTTP_HOST, 85 InetAddress.getLocalHost().getCanonicalHostName()); 86 port = (int)config.getLong(RequestListenerThread.HTTP_PORT, 87 HttpDaemon.DEFAULT_PORT); 88 89 } catch (Exception ex) { 90 throw new InterceptorException("Failed to init the code base " + 91 "IOR interceptor because : " + ex.getMessage(),ex); 92 } 93 } 94 95 96 101 public String name() { 102 return "CodebaseIORInterceptor"; 103 } 104 105 106 109 public void destroy() { 110 } 112 113 114 122 public void establish_components(IORInfo info) { 123 try { 124 String stubcodeName = DeploymentLoader.ClassLoaderLookup.getInstance(). 125 getStubCodeForLoader(Thread.currentThread(). 126 getContextClassLoader()); 127 if (stubcodeName != null) { 128 String url = String.format(URL_FORMAT,hostname,port, 129 stubcodeName); 130 Any any = ORB.init().create_any(); 131 any.insert_string(url); 132 info.add_ior_component(new TaggedComponent ( 133 TAG_JAVA_CODEBASE.value,codec.encode_value(any))); 134 } 135 } catch (Exception ex) { 136 log.error("Failed to add the entry to the ior : " + ex.getMessage(), 137 ex); 138 } 139 } 140 } 141 | Popular Tags |