1 20 21 package org.jacorb.orb; 22 23 import java.lang.reflect.Constructor ; 24 import java.net.*; 25 import java.util.*; 26 27 import org.jacorb.orb.giop.*; 28 import org.jacorb.orb.iiop.*; 29 import org.jacorb.orb.factory.SSLServerSocketFactory; 30 import org.jacorb.orb.factory.ServerSocketFactory; 31 import org.jacorb.orb.factory.SocketFactory; 32 import org.jacorb.orb.factory.SocketFactoryManager; 33 import org.jacorb.util.ObjectUtil; 34 35 import org.apache.avalon.framework.logger.*; 36 import org.apache.avalon.framework.configuration.*; 37 38 import org.omg.CORBA.INTERNAL ; 39 import org.omg.ETF.*; 40 import org.omg.PortableServer.POA ; 41 42 49 50 public class BasicAdapter 51 extends org.omg.ETF._HandleLocalBase 52 implements Configurable 53 { 54 public SSLServerSocketFactory ssl_socket_factory = null; 55 private ServerSocketFactory socket_factory = null; 56 57 private org.jacorb.orb.ORB orb; 58 private POA rootPOA; 59 60 private List listeners = new ArrayList(); 61 62 private MessageReceptorPool receptor_pool = null; 63 private ServerRequestListener request_listener = null; 64 private ReplyListener reply_listener = null; 65 66 private TransportManager transport_manager = null; 67 private GIOPConnectionManager giop_connection_manager = null; 68 69 70 private org.jacorb.config.Configuration configuration = null; 71 private Logger logger = null; 72 73 76 77 BasicAdapter( org.jacorb.orb.ORB orb, 78 POA rootPOA, 79 TransportManager transport_manager, 80 GIOPConnectionManager giop_connection_manager ) 81 { 82 this.orb = orb; 83 this.rootPOA = rootPOA; 84 this.transport_manager = transport_manager; 85 this.giop_connection_manager = giop_connection_manager; 86 } 87 88 91 92 public void configure(Configuration myConfiguration) 93 throws ConfigurationException 94 { 95 this.configuration = 96 (org.jacorb.config.Configuration)myConfiguration; 97 logger = 98 configuration.getNamedLogger("jacorb.orb.basic"); 99 100 socket_factory = 101 transport_manager.getSocketFactoryManager().getServerSocketFactory(); 102 103 if( configuration.getAttribute("jacorb.security.support_ssl","off").equals("on")) 104 { 105 if( ssl_socket_factory == null ) 106 { 107 String s = 108 configuration.getAttribute( "jacorb.ssl.server_socket_factory","" ); 109 if( s.length() == 0 ) 110 { 111 throw new org.omg.CORBA.INITIALIZE ( "SSL support is on, but the property \"jacorb.ssl.server_socket_factory\" is not set!" ); 112 } 113 114 try 115 { 116 Class ssl = ObjectUtil.classForName( s ); 117 118 Constructor constr = 119 ssl.getConstructor( new Class []{org.jacorb.orb.ORB.class }); 120 121 ssl_socket_factory = 122 (SSLServerSocketFactory)constr.newInstance( new Object []{ orb }); 123 124 ((Configurable)ssl_socket_factory).configure(configuration); 125 } 126 catch (Exception e) 127 { 128 logger.warn("Exception",e); 129 130 throw new org.omg.CORBA.INITIALIZE ( "SSL support is on, but the ssl server socket factory can't be instanciated (see trace)!" ); 131 } 132 } 133 134 } 135 136 receptor_pool = MessageReceptorPool.getInstance(myConfiguration); 137 138 request_listener = new ServerRequestListener( orb, rootPOA ); 139 request_listener.configure( configuration ); 140 reply_listener = new NoBiDirServerReplyListener(); 141 142 for (Iterator i = getListenerFactories().iterator(); 144 i.hasNext();) 145 { 146 Factories f = (Factories)i.next(); 147 Listener l = f.create_listener (null, (short)0, (short)0); 148 l.set_handle(this); 149 listeners.add (l); 150 } 151 152 for (Iterator i = listeners.iterator(); i.hasNext();) 154 { 155 ((Listener)i.next()).listen(); 156 } 157 } 158 159 public SSLServerSocketFactory getSSLSocketFactory() 160 { 161 return ssl_socket_factory; 162 } 163 164 165 169 private List getListenerFactories() 170 throws ConfigurationException 171 { 172 List result = new ArrayList(); 173 List tags = 174 configuration.getAttributeList("jacorb.transport.server.listeners"); 175 176 if (tags.isEmpty()) 177 { 178 result.addAll(transport_manager.getFactoriesList()); 179 } 180 else 181 { 182 for (Iterator i = tags.iterator(); i.hasNext();) 183 { 184 String s = ((String )i.next()); 185 int tag = -1; 186 try 187 { 188 tag = Integer.parseInt(s); 189 } 190 catch (NumberFormatException ex) 191 { 192 throw new RuntimeException 193 ("could not parse profile tag for listener: " + s 194 + " (should have been a number)"); 195 } 196 Factories f = transport_manager.getFactories (tag); 197 if (f == null) 198 throw new RuntimeException 199 ("could not find Factories for profile tag: " + tag); 200 else 201 result.add(f); 202 } 203 } 204 return result; 205 } 206 207 public RequestListener getRequestListener() 208 { 209 return request_listener; 210 } 211 212 218 public List getEndpointProfiles() 219 { 220 List result = new ArrayList(); 221 for (Iterator i = listeners.iterator(); i.hasNext();) 222 { 223 Listener l = (Listener)i.next(); 224 result.add (l.endpoint()); 225 } 226 return result; 227 } 228 229 234 private IIOPListener getIIOPListener() 235 { 236 if (listeners.size() == 1) 237 { 238 Listener l = (Listener)listeners.get(0); 239 if (l instanceof IIOPListener) 240 return (IIOPListener)l; 241 else 242 return null; 243 } 244 else 245 return null; 246 } 247 248 252 public int getPort() 253 { 254 IIOPListener l = getIIOPListener(); 255 if (l != null) 256 { 257 IIOPProfile profile = (IIOPProfile)l.endpoint(); 258 return profile.getAddress().getPort(); 259 } 260 else 261 { 262 throw new RuntimeException 263 ("Cannot find server port for non-IIOP transport"); 264 } 265 } 266 267 271 public int getSSLPort() 272 { 273 IIOPListener l = getIIOPListener(); 274 if (l != null) 275 { 276 IIOPProfile profile = (IIOPProfile)l.endpoint(); 277 return profile.getSSLPort(); 278 } 279 else 280 { 281 throw new RuntimeException 282 ("Non-IIOP transport does not have an SSL port"); 283 } 284 } 285 286 290 public boolean hasSSLListener() 291 { 292 return getSSLPort() != -1; 293 } 294 295 299 public String getAddress() 300 { 301 IIOPListener l = getIIOPListener(); 302 if (l != null) 303 { 304 IIOPProfile profile = (IIOPProfile)l.endpoint(); 305 String dnsEnable = 306 configuration.getAttribute("jacorb.dns.enable","off"); 307 308 if (dnsEnable.equals("on")) 309 return profile.getAddress().getHostname(); 310 else 311 return profile.getAddress().getIP(); 312 } 313 else 314 { 315 throw new RuntimeException 316 ("Cannot find server address for non-IIOP transport"); 317 } 318 } 319 320 325 public synchronized void deliverRequest( org.jacorb.orb.dsi.ServerRequest request, 326 org.omg.PortableServer.POA poa ) 327 { 328 org.jacorb.poa.POA tmp_poa = (org.jacorb.poa.POA)poa; 329 String scopes[] = request.remainingPOAName(); 330 331 try 332 { 333 for( int i=0; i < scopes.length-1; i++) 334 { 335 if( scopes[i].equals("")) 336 { 337 request.setRemainingPOAName(null); 338 break; 339 } 340 try 341 { 342 tmp_poa = tmp_poa._getChildPOA( scopes[i] ); 343 } 344 catch ( org.jacorb.poa.except.ParentIsHolding p ) 345 { 346 355 String [] rest_of_name = new String [scopes.length - i]; 356 for( int j = 0; j < i; j++ ) 357 rest_of_name[j] = scopes[j+i]; 358 request.setRemainingPOAName(rest_of_name); 359 break; 360 } 361 } 362 363 if( tmp_poa == null ) 364 { 365 throw new INTERNAL ("Request POA null!"); 366 } 367 else 368 { 369 370 ((org.jacorb.poa.POA)tmp_poa)._invoke( request ); 371 } 372 373 } 374 catch( org.omg.PortableServer.POAPackage.WrongAdapter wa ) 375 { 376 request.setSystemException( new org.omg.CORBA.OBJECT_NOT_EXIST ("unknown oid") ); 378 request.reply(); 379 } 380 catch( org.omg.CORBA.SystemException one ) 381 { 382 request.setSystemException( one ); 383 request.reply(); 384 } 385 catch( Throwable th ) 386 { 387 request.setSystemException( new org.omg.CORBA.UNKNOWN ( th.toString()) ); 388 request.reply(); 389 th.printStackTrace(); } 391 } 392 393 396 397 public void return_result(org.jacorb.orb.dsi.ServerRequest request) 398 { 399 request.reply(); 400 } 401 402 public void stopListeners() 403 { 404 for (Iterator i = listeners.iterator(); i.hasNext();) 405 { 406 ((Listener)i.next()).destroy(); 407 } 408 } 409 410 412 428 public boolean add_input (org.omg.ETF.Connection conn) 429 { 430 GIOPConnection giopConnection = 431 giop_connection_manager.createServerGIOPConnection 432 ( 433 conn.get_server_profile(), 434 conn, 435 request_listener, 436 reply_listener 437 ); 438 receptor_pool.connectionCreated( giopConnection ); 439 return true; 440 } 441 442 447 public void closed_by_peer (org.omg.ETF.Connection conn) 448 { 449 throw new org.omg.CORBA.NO_IMPLEMENT (); 453 } 454 455 463 public void signal_data_available (Connection conn) 464 { 465 throw new org.omg.CORBA.NO_IMPLEMENT (); 469 } 470 471 } 472 | Popular Tags |