1 23 24 package com.sun.enterprise.iiop; 25 26 import org.omg.CORBA.Any ; 27 import org.omg.CORBA.ORB ; 28 import org.omg.IOP.Codec ; 29 import org.omg.IOP.Encoding ; 30 import org.omg.IOP.TaggedComponent ; 31 import org.omg.PortableInterceptor.IORInfo ; 32 33 import com.sun.corba.ee.spi.legacy.connection.ORBSocketFactory; 34 import com.sun.corba.ee.spi.legacy.interceptor.IORInfoExt; 35 import com.sun.corba.ee.impl.interceptors.IORInfoImpl; 36 37 import java.util.logging.*; 38 import com.sun.logging.*; 39 40 import java.net.InetAddress ; 41 import java.net.SocketException ; 42 import java.net.NetworkInterface ; 43 import java.util.ArrayList ; 44 import java.util.Enumeration ; 45 46 public class IORAddrAnyInterceptor extends org.omg.CORBA.LocalObject 47 implements org.omg.PortableInterceptor.IORInterceptor { 48 49 public static final String baseMsg = IORAddrAnyInterceptor.class.getName(); 50 private static Logger _logger=null; 51 static { 52 _logger=LogDomains.getLogger(LogDomains.CORBA_LOGGER); 53 } 54 55 private Codec codec; 56 57 58 59 public IORAddrAnyInterceptor(Codec c) { 60 codec = c; 61 } 62 63 66 private static ArrayList getAllInetAddresses() { 67 ArrayList result = new ArrayList (); 68 try { 69 Enumeration e = NetworkInterface.getNetworkInterfaces(); 70 while (e.hasMoreElements()) { 71 NetworkInterface ni = (NetworkInterface )e.nextElement(); 72 Enumeration ee = ni.getInetAddresses(); 73 while (ee.hasMoreElements()) { 74 InetAddress addr = (InetAddress )ee.nextElement(); 75 result.add(addr); 76 } 77 } 78 } catch (SocketException se) { 79 _logger.log(Level.WARNING,"Exception getting all Network Interfaces",se); 80 return result; 81 } 82 return result; 83 } 84 85 102 public void destroy() { 103 } 104 105 126 public void establish_components(org.omg.PortableInterceptor.IORInfo iorInfo) { 127 try { 128 IORInfoExt iorInfoExt = (IORInfoExt) iorInfo; 129 int port = iorInfoExt.getServerPort(ORBSocketFactory.IIOP_CLEAR_TEXT); 130 131 ArrayList allInetAddress = getAllInetAddresses(); 132 addAddressComponents(iorInfo, allInetAddress, port); 133 com.sun.corba.ee.internal.corba.ORB orb = 134 (com.sun.corba.ee.internal.corba.ORB)((IORInfoImpl)iorInfo).getORB(); 135 Object [] userPorts = orb.getUserSpecifiedListenPorts().toArray(); 136 if (userPorts.length > 0) { 137 for (int i = 0; i < userPorts.length; i++) { 138 com.sun.corba.ee.internal.corba.ORB.UserSpecifiedListenPort p = 139 ((com.sun.corba.ee.internal.corba.ORB.UserSpecifiedListenPort)userPorts[i]); 140 addAddressComponents(iorInfo, allInetAddress, p.getPort()); 142 } 144 } 145 } catch (Exception e) { 146 _logger.log(Level.WARNING,"Exception in " + baseMsg, e); 147 } 148 } 149 150 162 public String name() { 163 return baseMsg; 164 } 165 166 protected short intToShort( int value ) 167 { 168 if (value > 32767) 169 return (short)(value - 65536) ; 170 return (short)value ; 171 } 172 173 private void addAddressComponents(org.omg.PortableInterceptor.IORInfo iorInfo, 174 ArrayList allInetAddress, int port) { 175 try { 176 for (int i = 0; i < allInetAddress.size(); i++) { 177 String address = ((InetAddress )allInetAddress.get(i)).getHostAddress(); 178 AlternateIIOPAddressComponent iiopAddress = 179 new AlternateIIOPAddressComponent(address, intToShort(port)); 180 Any any = ORB.init().create_any(); 181 AlternateIIOPAddressComponentHelper.insert(any, iiopAddress); 182 byte[] data = codec.encode_value(any); 183 TaggedComponent taggedComponent = 184 new TaggedComponent ( org.omg.IOP.TAG_ALTERNATE_IIOP_ADDRESS.value, 185 data); 187 iorInfo.add_ior_component(taggedComponent); 188 } 189 } catch (Exception e) { 190 _logger.log(Level.WARNING,"Exception in " + baseMsg, e); 191 } 192 } 193 194 } 195 | Popular Tags |