1 23 24 package com.sun.enterprise.iiop; 25 26 import java.io.IOException ; 27 import java.net.ServerSocket ; 28 import java.net.Socket ; 29 import java.net.UnknownHostException ; 30 31 import org.omg.CORBA.ORB ; 32 import org.omg.CORBA.COMM_FAILURE ; 33 import org.omg.CORBA.CompletionStatus ; 34 35 import com.sun.corba.ee.spi.transport.SocketInfo; 36 import com.sun.corba.ee.spi.legacy.connection.GetEndPointInfoAgainException; 37 import com.sun.corba.ee.spi.legacy.connection.ORBSocketFactory; 38 import com.sun.corba.ee.spi.ior.IOR; 39 import com.sun.corba.ee.spi.ior.iiop.IIOPProfileTemplate; 40 import com.sun.corba.ee.spi.ior.iiop.IIOPAddress; 41 import com.sun.corba.ee.impl.legacy.connection.EndPointInfoImpl; 42 43 import java.util.logging.*; 44 import com.sun.logging.*; 45 46 import org.omg.IOP.Codec ; 47 import org.omg.IOP.CodecFactory ; 48 import org.omg.IOP.CodecFactoryHelper ; 49 import org.omg.IOP.Encoding ; 50 51 import java.util.Hashtable ; 52 import org.omg.CORBA.Any ; 53 import org.omg.IOP.TaggedComponent ; 54 55 59 public class SocketFactory extends com.sun.corba.ee.impl.legacy.connection.DefaultSocketFactory { 60 61 private static Logger _logger=null; 62 static { 63 _logger=LogDomains.getLogger(LogDomains.CORBA_LOGGER); 64 } 65 66 private Hashtable endpointTable = new Hashtable (); 67 private Codec codec; 68 69 70 public SocketFactory() { 71 super(); 72 } 73 74 public SocketInfo getEndPointInfo(ORB orb, IOR ior, 75 SocketInfo endPointInfo) { 76 try { 77 IIOPProfileTemplate temp = (IIOPProfileTemplate)ior. 78 getProfile().getTaggedProfileTemplate(); 79 IIOPAddress primary = temp.getPrimaryAddress() ; 80 String host = primary.getHost().toLowerCase(); 81 int port = primary.getPort(); 82 83 if(_logger.isLoggable(Level.FINE)) { 84 _logger.log(Level.FINE,"ENDPOINT INFO:host=" +host + ", port=" + port); 85 } 86 87 if ((endPointInfo = (EndPointInfoImpl)endpointTable.get(host + port)) != null) 90 return endPointInfo; 91 92 TaggedComponent alternateAddressTaggedComponents[] = 93 ior.getProfile().getTaggedProfileTemplate(). 94 getIOPComponents((com.sun.corba.ee.spi.orb.ORB)orb, 95 org.omg.IOP.TAG_ALTERNATE_IIOP_ADDRESS.value 96 ); 98 if (alternateAddressTaggedComponents.length > 0) { 99 getCodec(orb); 100 for (int i = 0; i < alternateAddressTaggedComponents.length; i++) { 101 byte[] data = alternateAddressTaggedComponents[i].component_data; 102 Any any = null; 103 try { 104 any = codec.decode_value(data, 105 AlternateIIOPAddressComponentHelper.type()); 106 } catch (org.omg.IOP.CodecPackage.TypeMismatch e) { 107 if (_logger.isLoggable(Level.FINE)){ 108 _logger.log(Level.FINE,"Exception codec TypeMismatch",e); 109 } 110 throw new RuntimeException (e.toString()); 111 } catch (org.omg.IOP.CodecPackage.FormatMismatch e) { 112 if (_logger.isLoggable(Level.FINE) ){ 113 _logger.log(Level.FINE,"Exception codec FormatMismatch",e); 114 } 115 throw new RuntimeException (e.toString()); 116 } 117 AlternateIIOPAddressComponent iiopAddress = 118 AlternateIIOPAddressComponentHelper.extract(any); 119 if ((endPointInfo = (EndPointInfoImpl)endpointTable. 125 get(iiopAddress.host + iiopAddress.port)) != null) { 126 138 endpointTable.put(host + port, endPointInfo); 139 return endPointInfo; 140 } 142 } 143 endPointInfo = new EndPointInfoImpl(ORBSocketFactory.IIOP_CLEAR_TEXT, port, host); 145 endpointTable.put(host + port, endPointInfo); 146 } else { 147 148 endPointInfo = new EndPointInfoImpl(ORBSocketFactory.IIOP_CLEAR_TEXT, port, host); 149 endpointTable.put(host + port, endPointInfo); 150 } 151 return endPointInfo; 152 } catch ( Exception ex ) { 153 if (_logger.isLoggable(Level.FINE)){ 154 _logger.log(Level.FINE,"Exception getting End point info",ex); 155 } 156 throw new RuntimeException (ex.getMessage()); 157 } 158 } 159 160 private Codec getCodec(ORB orb) 161 { 162 if (codec == null) { 163 synchronized (this) { 164 CodecFactory codecFactory = null; 165 try { 166 codecFactory = CodecFactoryHelper.narrow( 167 orb.resolve_initial_references("CodecFactory")); 168 } catch (org.omg.CORBA.ORBPackage.InvalidName e) { 169 System.out.println("Getting org.omg.CORBA.ORBPackage.InvalidName exception"); 170 } 171 Encoding encoding = new Encoding ((short)0, (byte)1, (byte)2); 172 try { 173 codec = codecFactory.create_codec(encoding); 174 } catch (org.omg.IOP.CodecFactoryPackage.UnknownEncoding e) { 175 System.out.println("Getting org.omg.IOP.CodecFactoryPackage.UnknownEncoding exception"); 176 } 177 } 178 } 179 return codec; 180 } 181 182 private int shortToInt( short value ) 183 { 184 if (value < 0) 185 return value + 65536 ; 186 return value ; 187 } 188 189 } 190 | Popular Tags |