Fri, 24 Sep 2010 22:42:14 -0700
6891766: Vulnerabilities in use of reflection in CORBA
Reviewed-by: hawtin
duke@1 | 1 | /* |
skoppar@205 | 2 | * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. |
duke@1 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@1 | 4 | * |
duke@1 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@1 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair@158 | 7 | * published by the Free Software Foundation. Oracle designates this |
duke@1 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@158 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
duke@1 | 10 | * |
duke@1 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@1 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@1 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@1 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@1 | 15 | * accompanied this code). |
duke@1 | 16 | * |
duke@1 | 17 | * You should have received a copy of the GNU General Public License version |
duke@1 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@1 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@1 | 20 | * |
ohair@158 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@158 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@158 | 23 | * questions. |
duke@1 | 24 | */ |
duke@1 | 25 | |
duke@1 | 26 | package com.sun.corba.se.impl.transport; |
duke@1 | 27 | |
duke@1 | 28 | import java.io.IOException; |
duke@1 | 29 | import java.net.InetSocketAddress; |
duke@1 | 30 | import java.net.ServerSocket; |
duke@1 | 31 | import java.net.Socket; |
duke@1 | 32 | import java.nio.channels.SelectableChannel; |
duke@1 | 33 | import java.nio.channels.SelectionKey; |
duke@1 | 34 | import java.nio.channels.ServerSocketChannel; |
duke@1 | 35 | import java.nio.channels.SocketChannel; |
duke@1 | 36 | import java.util.Iterator; |
duke@1 | 37 | |
duke@1 | 38 | import com.sun.corba.se.pept.broker.Broker; |
duke@1 | 39 | import com.sun.corba.se.pept.encoding.InputObject; |
duke@1 | 40 | import com.sun.corba.se.pept.encoding.OutputObject; |
duke@1 | 41 | import com.sun.corba.se.pept.protocol.MessageMediator; |
duke@1 | 42 | import com.sun.corba.se.pept.transport.Acceptor; |
duke@1 | 43 | import com.sun.corba.se.pept.transport.Connection; |
duke@1 | 44 | import com.sun.corba.se.pept.transport.ContactInfo; |
duke@1 | 45 | import com.sun.corba.se.pept.transport.EventHandler; |
duke@1 | 46 | import com.sun.corba.se.pept.transport.InboundConnectionCache; |
duke@1 | 47 | import com.sun.corba.se.pept.transport.Selector; |
duke@1 | 48 | |
duke@1 | 49 | import com.sun.corba.se.spi.extension.RequestPartitioningPolicy; |
duke@1 | 50 | import com.sun.corba.se.spi.ior.IORTemplate; |
duke@1 | 51 | import com.sun.corba.se.spi.ior.TaggedProfileTemplate; |
duke@1 | 52 | import com.sun.corba.se.spi.ior.iiop.IIOPAddress ; |
duke@1 | 53 | import com.sun.corba.se.spi.ior.iiop.IIOPFactories; |
duke@1 | 54 | import com.sun.corba.se.spi.ior.iiop.IIOPProfileTemplate ; |
duke@1 | 55 | import com.sun.corba.se.spi.ior.iiop.GIOPVersion ; |
duke@1 | 56 | import com.sun.corba.se.spi.ior.iiop.AlternateIIOPAddressComponent; |
duke@1 | 57 | import com.sun.corba.se.spi.logging.CORBALogDomains; |
duke@1 | 58 | import com.sun.corba.se.spi.orb.ORB; |
duke@1 | 59 | import com.sun.corba.se.spi.orbutil.threadpool.Work; |
duke@1 | 60 | import com.sun.corba.se.spi.protocol.CorbaMessageMediator; |
duke@1 | 61 | import com.sun.corba.se.spi.transport.CorbaAcceptor; |
duke@1 | 62 | import com.sun.corba.se.spi.transport.CorbaConnection; |
duke@1 | 63 | import com.sun.corba.se.spi.transport.SocketInfo; |
duke@1 | 64 | import com.sun.corba.se.spi.transport.SocketOrChannelAcceptor; |
duke@1 | 65 | |
duke@1 | 66 | import com.sun.corba.se.impl.encoding.CDRInputObject; |
duke@1 | 67 | import com.sun.corba.se.impl.encoding.CDROutputObject; |
duke@1 | 68 | import com.sun.corba.se.impl.logging.ORBUtilSystemException; |
duke@1 | 69 | import com.sun.corba.se.impl.oa.poa.Policies; // REVISIT impl/poa specific |
duke@1 | 70 | import com.sun.corba.se.impl.orbutil.ORBConstants; |
duke@1 | 71 | import com.sun.corba.se.impl.orbutil.ORBUtility; |
duke@1 | 72 | |
duke@1 | 73 | // BEGIN Legacy support. |
duke@1 | 74 | import com.sun.corba.se.spi.legacy.connection.LegacyServerSocketEndPointInfo; |
duke@1 | 75 | // END Legacy support. |
duke@1 | 76 | |
duke@1 | 77 | /** |
duke@1 | 78 | * @author Harold Carr |
duke@1 | 79 | */ |
duke@1 | 80 | public class SocketOrChannelAcceptorImpl |
duke@1 | 81 | extends |
duke@1 | 82 | EventHandlerBase |
duke@1 | 83 | implements |
duke@1 | 84 | CorbaAcceptor, |
duke@1 | 85 | SocketOrChannelAcceptor, |
duke@1 | 86 | Work, |
duke@1 | 87 | // BEGIN Legacy |
duke@1 | 88 | SocketInfo, |
duke@1 | 89 | LegacyServerSocketEndPointInfo |
duke@1 | 90 | // END Legacy |
duke@1 | 91 | { |
duke@1 | 92 | protected ServerSocketChannel serverSocketChannel; |
duke@1 | 93 | protected ServerSocket serverSocket; |
duke@1 | 94 | protected int port; |
duke@1 | 95 | protected long enqueueTime; |
duke@1 | 96 | protected boolean initialized; |
duke@1 | 97 | protected ORBUtilSystemException wrapper ; |
duke@1 | 98 | protected InboundConnectionCache connectionCache; |
duke@1 | 99 | |
duke@1 | 100 | // BEGIN Legacy |
duke@1 | 101 | protected String type = ""; |
duke@1 | 102 | protected String name = ""; |
duke@1 | 103 | protected String hostname; |
duke@1 | 104 | protected int locatorPort; |
duke@1 | 105 | // END Legacy |
duke@1 | 106 | |
duke@1 | 107 | public SocketOrChannelAcceptorImpl(ORB orb) |
duke@1 | 108 | { |
duke@1 | 109 | this.orb = orb; |
duke@1 | 110 | wrapper = ORBUtilSystemException.get( orb, |
duke@1 | 111 | CORBALogDomains.RPC_TRANSPORT ) ; |
duke@1 | 112 | |
duke@1 | 113 | setWork(this); |
duke@1 | 114 | initialized = false; |
duke@1 | 115 | |
duke@1 | 116 | // BEGIN Legacy support. |
duke@1 | 117 | this.hostname = orb.getORBData().getORBServerHost(); |
duke@1 | 118 | this.name = LegacyServerSocketEndPointInfo.NO_NAME; |
duke@1 | 119 | this.locatorPort = -1; |
duke@1 | 120 | // END Legacy support. |
duke@1 | 121 | } |
duke@1 | 122 | |
duke@1 | 123 | public SocketOrChannelAcceptorImpl(ORB orb, int port) |
duke@1 | 124 | { |
duke@1 | 125 | this(orb); |
duke@1 | 126 | this.port = port; |
duke@1 | 127 | } |
duke@1 | 128 | |
duke@1 | 129 | // BEGIN Legacy support. |
duke@1 | 130 | public SocketOrChannelAcceptorImpl(ORB orb, int port, |
duke@1 | 131 | String name, String type) |
duke@1 | 132 | { |
duke@1 | 133 | this(orb, port); |
duke@1 | 134 | this.name = name; |
duke@1 | 135 | this.type = type; |
duke@1 | 136 | } |
duke@1 | 137 | // END Legacy support. |
duke@1 | 138 | |
duke@1 | 139 | //////////////////////////////////////////////////// |
duke@1 | 140 | // |
duke@1 | 141 | // pept.transport.Acceptor |
duke@1 | 142 | // |
duke@1 | 143 | |
duke@1 | 144 | public boolean initialize() |
duke@1 | 145 | { |
duke@1 | 146 | if (initialized) { |
duke@1 | 147 | return false; |
duke@1 | 148 | } |
duke@1 | 149 | if (orb.transportDebugFlag) { |
duke@1 | 150 | dprint(".initialize: " + this); |
duke@1 | 151 | } |
duke@1 | 152 | InetSocketAddress inetSocketAddress = null; |
duke@1 | 153 | try { |
duke@1 | 154 | if (orb.getORBData().getListenOnAllInterfaces().equals(ORBConstants.LISTEN_ON_ALL_INTERFACES)) { |
duke@1 | 155 | inetSocketAddress = new InetSocketAddress(port); |
duke@1 | 156 | } else { |
duke@1 | 157 | String host = orb.getORBData().getORBServerHost(); |
duke@1 | 158 | inetSocketAddress = new InetSocketAddress(host, port); |
duke@1 | 159 | } |
duke@1 | 160 | serverSocket = orb.getORBData().getSocketFactory() |
duke@1 | 161 | .createServerSocket(type, inetSocketAddress); |
duke@1 | 162 | internalInitialize(); |
duke@1 | 163 | } catch (Throwable t) { |
duke@1 | 164 | throw wrapper.createListenerFailed( t, Integer.toString(port) ) ; |
duke@1 | 165 | } |
duke@1 | 166 | initialized = true; |
duke@1 | 167 | return true; |
duke@1 | 168 | } |
duke@1 | 169 | |
duke@1 | 170 | protected void internalInitialize() |
duke@1 | 171 | throws Exception |
duke@1 | 172 | { |
duke@1 | 173 | // Determine the listening port (for the IOR). |
duke@1 | 174 | // This is important when using emphemeral ports (i.e., |
duke@1 | 175 | // when the port value to the constructor is 0). |
duke@1 | 176 | |
duke@1 | 177 | port = serverSocket.getLocalPort(); |
duke@1 | 178 | |
duke@1 | 179 | // Register with transport (also sets up monitoring). |
duke@1 | 180 | |
duke@1 | 181 | orb.getCorbaTransportManager().getInboundConnectionCache(this); |
duke@1 | 182 | |
duke@1 | 183 | // Finish configuation. |
duke@1 | 184 | |
duke@1 | 185 | serverSocketChannel = serverSocket.getChannel(); |
duke@1 | 186 | |
duke@1 | 187 | if (serverSocketChannel != null) { |
duke@1 | 188 | setUseSelectThreadToWait( |
duke@1 | 189 | orb.getORBData().acceptorSocketUseSelectThreadToWait()); |
duke@1 | 190 | serverSocketChannel.configureBlocking( |
duke@1 | 191 | ! orb.getORBData().acceptorSocketUseSelectThreadToWait()); |
duke@1 | 192 | } else { |
duke@1 | 193 | // Configure to use listener and reader threads. |
duke@1 | 194 | setUseSelectThreadToWait(false); |
duke@1 | 195 | } |
duke@1 | 196 | setUseWorkerThreadForEvent( |
duke@1 | 197 | orb.getORBData().acceptorSocketUseWorkerThreadForEvent()); |
duke@1 | 198 | |
duke@1 | 199 | } |
duke@1 | 200 | |
duke@1 | 201 | public boolean initialized() |
duke@1 | 202 | { |
duke@1 | 203 | return initialized; |
duke@1 | 204 | } |
duke@1 | 205 | |
duke@1 | 206 | public String getConnectionCacheType() |
duke@1 | 207 | { |
duke@1 | 208 | return this.getClass().toString(); |
duke@1 | 209 | } |
duke@1 | 210 | |
duke@1 | 211 | public void setConnectionCache(InboundConnectionCache connectionCache) |
duke@1 | 212 | { |
duke@1 | 213 | this.connectionCache = connectionCache; |
duke@1 | 214 | } |
duke@1 | 215 | |
duke@1 | 216 | public InboundConnectionCache getConnectionCache() |
duke@1 | 217 | { |
duke@1 | 218 | return connectionCache; |
duke@1 | 219 | } |
duke@1 | 220 | |
duke@1 | 221 | public boolean shouldRegisterAcceptEvent() |
duke@1 | 222 | { |
duke@1 | 223 | return true; |
duke@1 | 224 | } |
duke@1 | 225 | |
duke@1 | 226 | public void accept() |
duke@1 | 227 | { |
duke@1 | 228 | try { |
duke@1 | 229 | SocketChannel socketChannel = null; |
duke@1 | 230 | Socket socket = null; |
duke@1 | 231 | if (serverSocketChannel == null) { |
duke@1 | 232 | socket = serverSocket.accept(); |
duke@1 | 233 | } else { |
duke@1 | 234 | socketChannel = serverSocketChannel.accept(); |
duke@1 | 235 | socket = socketChannel.socket(); |
duke@1 | 236 | } |
duke@1 | 237 | orb.getORBData().getSocketFactory() |
duke@1 | 238 | .setAcceptedSocketOptions(this, serverSocket, socket); |
duke@1 | 239 | if (orb.transportDebugFlag) { |
duke@1 | 240 | dprint(".accept: " + |
duke@1 | 241 | (serverSocketChannel == null |
duke@1 | 242 | ? serverSocket.toString() |
duke@1 | 243 | : serverSocketChannel.toString())); |
duke@1 | 244 | } |
duke@1 | 245 | |
duke@1 | 246 | CorbaConnection connection = |
duke@1 | 247 | new SocketOrChannelConnectionImpl(orb, this, socket); |
duke@1 | 248 | if (orb.transportDebugFlag) { |
duke@1 | 249 | dprint(".accept: new: " + connection); |
duke@1 | 250 | } |
duke@1 | 251 | |
duke@1 | 252 | // NOTE: The connection MUST be put in the cache BEFORE being |
duke@1 | 253 | // registered with the selector. Otherwise if the bytes |
duke@1 | 254 | // are read on the connection it will attempt a time stamp |
duke@1 | 255 | // but the cache will be null, resulting in NPE. |
duke@1 | 256 | getConnectionCache().put(this, connection); |
duke@1 | 257 | |
duke@1 | 258 | if (connection.shouldRegisterServerReadEvent()) { |
duke@1 | 259 | Selector selector = orb.getTransportManager().getSelector(0); |
duke@1 | 260 | selector.registerForEvent(connection.getEventHandler()); |
duke@1 | 261 | } |
duke@1 | 262 | |
duke@1 | 263 | getConnectionCache().reclaim(); |
duke@1 | 264 | |
duke@1 | 265 | } catch (IOException e) { |
duke@1 | 266 | if (orb.transportDebugFlag) { |
duke@1 | 267 | dprint(".accept:", e); |
duke@1 | 268 | } |
duke@1 | 269 | orb.getTransportManager().getSelector(0).unregisterForEvent(this); |
duke@1 | 270 | // REVISIT - need to close - recreate - then register new one. |
duke@1 | 271 | orb.getTransportManager().getSelector(0).registerForEvent(this); |
duke@1 | 272 | // NOTE: if register cycling we do not want to shut down ORB |
duke@1 | 273 | // since local beans will still work. Instead one will see |
duke@1 | 274 | // a growing log file to alert admin of problem. |
duke@1 | 275 | } |
duke@1 | 276 | } |
duke@1 | 277 | |
duke@1 | 278 | public void close () |
duke@1 | 279 | { |
duke@1 | 280 | try { |
duke@1 | 281 | if (orb.transportDebugFlag) { |
duke@1 | 282 | dprint(".close->:"); |
duke@1 | 283 | } |
duke@1 | 284 | Selector selector = orb.getTransportManager().getSelector(0); |
duke@1 | 285 | selector.unregisterForEvent(this); |
duke@1 | 286 | if (serverSocketChannel != null) { |
duke@1 | 287 | serverSocketChannel.close(); |
duke@1 | 288 | } |
duke@1 | 289 | if (serverSocket != null) { |
duke@1 | 290 | serverSocket.close(); |
duke@1 | 291 | } |
duke@1 | 292 | } catch (IOException e) { |
duke@1 | 293 | if (orb.transportDebugFlag) { |
duke@1 | 294 | dprint(".close:", e); |
duke@1 | 295 | } |
duke@1 | 296 | } finally { |
duke@1 | 297 | if (orb.transportDebugFlag) { |
duke@1 | 298 | dprint(".close<-:"); |
duke@1 | 299 | } |
duke@1 | 300 | } |
duke@1 | 301 | } |
duke@1 | 302 | |
duke@1 | 303 | public EventHandler getEventHandler() |
duke@1 | 304 | { |
duke@1 | 305 | return this; |
duke@1 | 306 | } |
duke@1 | 307 | |
duke@1 | 308 | //////////////////////////////////////////////////// |
duke@1 | 309 | // |
duke@1 | 310 | // CorbaAcceptor |
duke@1 | 311 | // |
duke@1 | 312 | |
duke@1 | 313 | public String getObjectAdapterId() |
duke@1 | 314 | { |
duke@1 | 315 | return null; |
duke@1 | 316 | } |
duke@1 | 317 | |
duke@1 | 318 | public String getObjectAdapterManagerId() |
duke@1 | 319 | { |
duke@1 | 320 | return null; |
duke@1 | 321 | } |
duke@1 | 322 | |
duke@1 | 323 | public void addToIORTemplate(IORTemplate iorTemplate, |
duke@1 | 324 | Policies policies, |
duke@1 | 325 | String codebase) |
duke@1 | 326 | { |
duke@1 | 327 | Iterator iterator = iorTemplate.iteratorById( |
duke@1 | 328 | org.omg.IOP.TAG_INTERNET_IOP.value); |
duke@1 | 329 | |
duke@1 | 330 | String hostname = orb.getORBData().getORBServerHost(); |
duke@1 | 331 | |
duke@1 | 332 | if (iterator.hasNext()) { |
duke@1 | 333 | // REVISIT - how does this play with legacy ORBD port exchange? |
duke@1 | 334 | IIOPAddress iiopAddress = |
duke@1 | 335 | IIOPFactories.makeIIOPAddress(orb, hostname, port); |
duke@1 | 336 | AlternateIIOPAddressComponent iiopAddressComponent = |
duke@1 | 337 | IIOPFactories.makeAlternateIIOPAddressComponent(iiopAddress); |
duke@1 | 338 | |
duke@1 | 339 | while (iterator.hasNext()) { |
duke@1 | 340 | TaggedProfileTemplate taggedProfileTemplate = |
duke@1 | 341 | (TaggedProfileTemplate) iterator.next(); |
duke@1 | 342 | taggedProfileTemplate.add(iiopAddressComponent); |
duke@1 | 343 | } |
duke@1 | 344 | } else { |
duke@1 | 345 | GIOPVersion version = orb.getORBData().getGIOPVersion(); |
duke@1 | 346 | int templatePort; |
duke@1 | 347 | if (policies.forceZeroPort()) { |
duke@1 | 348 | templatePort = 0; |
duke@1 | 349 | } else if (policies.isTransient()) { |
duke@1 | 350 | templatePort = port; |
duke@1 | 351 | } else { |
duke@1 | 352 | templatePort = orb.getLegacyServerSocketManager() |
duke@1 | 353 | .legacyGetPersistentServerPort(SocketInfo.IIOP_CLEAR_TEXT); |
duke@1 | 354 | } |
duke@1 | 355 | IIOPAddress addr = |
duke@1 | 356 | IIOPFactories.makeIIOPAddress(orb, hostname, templatePort); |
duke@1 | 357 | IIOPProfileTemplate iiopProfile = |
duke@1 | 358 | IIOPFactories.makeIIOPProfileTemplate(orb, version, addr); |
duke@1 | 359 | if (version.supportsIORIIOPProfileComponents()) { |
duke@1 | 360 | iiopProfile.add(IIOPFactories.makeCodeSetsComponent(orb)); |
duke@1 | 361 | iiopProfile.add(IIOPFactories.makeMaxStreamFormatVersionComponent()); |
duke@1 | 362 | RequestPartitioningPolicy rpPolicy = (RequestPartitioningPolicy) |
duke@1 | 363 | policies.get_effective_policy( |
duke@1 | 364 | ORBConstants.REQUEST_PARTITIONING_POLICY); |
duke@1 | 365 | if (rpPolicy != null) { |
duke@1 | 366 | iiopProfile.add( |
duke@1 | 367 | IIOPFactories.makeRequestPartitioningComponent( |
duke@1 | 368 | rpPolicy.getValue())); |
duke@1 | 369 | } |
duke@1 | 370 | if (codebase != null && codebase != "") { |
duke@1 | 371 | iiopProfile.add(IIOPFactories. makeJavaCodebaseComponent(codebase)); |
duke@1 | 372 | } |
duke@1 | 373 | if (orb.getORBData().isJavaSerializationEnabled()) { |
duke@1 | 374 | iiopProfile.add( |
duke@1 | 375 | IIOPFactories.makeJavaSerializationComponent()); |
duke@1 | 376 | } |
duke@1 | 377 | } |
duke@1 | 378 | iorTemplate.add(iiopProfile); |
duke@1 | 379 | } |
duke@1 | 380 | } |
duke@1 | 381 | |
duke@1 | 382 | public String getMonitoringName() |
duke@1 | 383 | { |
duke@1 | 384 | return "AcceptedConnections"; |
duke@1 | 385 | } |
duke@1 | 386 | |
duke@1 | 387 | //////////////////////////////////////////////////// |
duke@1 | 388 | // |
duke@1 | 389 | // EventHandler methods |
duke@1 | 390 | // |
duke@1 | 391 | |
duke@1 | 392 | public SelectableChannel getChannel() |
duke@1 | 393 | { |
duke@1 | 394 | return serverSocketChannel; |
duke@1 | 395 | } |
duke@1 | 396 | |
duke@1 | 397 | public int getInterestOps() |
duke@1 | 398 | { |
duke@1 | 399 | return SelectionKey.OP_ACCEPT; |
duke@1 | 400 | } |
duke@1 | 401 | |
duke@1 | 402 | public Acceptor getAcceptor() |
duke@1 | 403 | { |
duke@1 | 404 | return this; |
duke@1 | 405 | } |
duke@1 | 406 | |
duke@1 | 407 | public Connection getConnection() |
duke@1 | 408 | { |
duke@1 | 409 | throw new RuntimeException("Should not happen."); |
duke@1 | 410 | } |
duke@1 | 411 | |
duke@1 | 412 | //////////////////////////////////////////////////// |
duke@1 | 413 | // |
duke@1 | 414 | // Work methods. |
duke@1 | 415 | // |
duke@1 | 416 | |
duke@1 | 417 | /* CONFLICT: with legacy below. |
duke@1 | 418 | public String getName() |
duke@1 | 419 | { |
duke@1 | 420 | return this.toString(); |
duke@1 | 421 | } |
duke@1 | 422 | */ |
duke@1 | 423 | |
duke@1 | 424 | public void doWork() |
duke@1 | 425 | { |
duke@1 | 426 | try { |
duke@1 | 427 | if (orb.transportDebugFlag) { |
duke@1 | 428 | dprint(".doWork->: " + this); |
duke@1 | 429 | } |
duke@1 | 430 | if (selectionKey.isAcceptable()) { |
duke@1 | 431 | accept(); |
duke@1 | 432 | } else { |
duke@1 | 433 | if (orb.transportDebugFlag) { |
duke@1 | 434 | dprint(".doWork: ! selectionKey.isAcceptable: " + this); |
duke@1 | 435 | } |
duke@1 | 436 | } |
duke@1 | 437 | } catch (SecurityException se) { |
duke@1 | 438 | if (orb.transportDebugFlag) { |
duke@1 | 439 | dprint(".doWork: ignoring SecurityException: " |
duke@1 | 440 | + se |
duke@1 | 441 | + " " + this); |
duke@1 | 442 | } |
duke@1 | 443 | String permissionStr = ORBUtility.getClassSecurityInfo(getClass()); |
duke@1 | 444 | wrapper.securityExceptionInAccept(se, permissionStr); |
duke@1 | 445 | } catch (Exception ex) { |
duke@1 | 446 | if (orb.transportDebugFlag) { |
duke@1 | 447 | dprint(".doWork: ignoring Exception: " |
duke@1 | 448 | + ex |
duke@1 | 449 | + " " + this); |
duke@1 | 450 | } |
duke@1 | 451 | wrapper.exceptionInAccept(ex); |
duke@1 | 452 | } catch (Throwable t) { |
duke@1 | 453 | if (orb.transportDebugFlag) { |
duke@1 | 454 | dprint(".doWork: ignoring Throwable: " |
duke@1 | 455 | + t |
duke@1 | 456 | + " " + this); |
duke@1 | 457 | } |
duke@1 | 458 | } finally { |
duke@1 | 459 | |
duke@1 | 460 | // IMPORTANT: To avoid bug (4953599), we force the |
duke@1 | 461 | // Thread that does the NIO select to also do the |
duke@1 | 462 | // enable/disable of Ops using SelectionKey.interestOps(). |
duke@1 | 463 | // Otherwise, the SelectionKey.interestOps() may block |
duke@1 | 464 | // indefinitely. |
duke@1 | 465 | // NOTE: If "acceptorSocketUseWorkerThreadForEvent" is |
duke@1 | 466 | // set to to false in ParserTable.java, then this method, |
duke@1 | 467 | // doWork(), will get executed by the same thread |
duke@1 | 468 | // (SelectorThread) that does the NIO select. |
duke@1 | 469 | // If "acceptorSocketUseWorkerThreadForEvent" is set |
duke@1 | 470 | // to true, a WorkerThread will execute this method, |
duke@1 | 471 | // doWork(). Hence, the registering of the enabling of |
duke@1 | 472 | // the SelectionKey's interestOps is done here instead |
duke@1 | 473 | // of calling SelectionKey.interestOps(<interest op>). |
duke@1 | 474 | |
duke@1 | 475 | Selector selector = orb.getTransportManager().getSelector(0); |
duke@1 | 476 | selector.registerInterestOps(this); |
duke@1 | 477 | |
duke@1 | 478 | if (orb.transportDebugFlag) { |
duke@1 | 479 | dprint(".doWork<-:" + this); |
duke@1 | 480 | } |
duke@1 | 481 | } |
duke@1 | 482 | } |
duke@1 | 483 | |
duke@1 | 484 | public void setEnqueueTime(long timeInMillis) |
duke@1 | 485 | { |
duke@1 | 486 | enqueueTime = timeInMillis; |
duke@1 | 487 | } |
duke@1 | 488 | |
duke@1 | 489 | public long getEnqueueTime() |
duke@1 | 490 | { |
duke@1 | 491 | return enqueueTime; |
duke@1 | 492 | } |
duke@1 | 493 | |
duke@1 | 494 | |
duke@1 | 495 | // |
duke@1 | 496 | // Factory methods. |
duke@1 | 497 | // |
duke@1 | 498 | |
duke@1 | 499 | // REVISIT: refactor into common base or delegate. |
duke@1 | 500 | public MessageMediator createMessageMediator(Broker broker, |
duke@1 | 501 | Connection connection) |
duke@1 | 502 | { |
duke@1 | 503 | // REVISIT - no factoring so cheat to avoid code dup right now. |
duke@1 | 504 | // REVISIT **** COUPLING !!!! |
duke@1 | 505 | ContactInfo contactInfo = new SocketOrChannelContactInfoImpl(); |
duke@1 | 506 | return contactInfo.createMessageMediator(broker, connection); |
duke@1 | 507 | } |
duke@1 | 508 | |
duke@1 | 509 | // REVISIT: refactor into common base or delegate. |
duke@1 | 510 | public MessageMediator finishCreatingMessageMediator(Broker broker, |
duke@1 | 511 | Connection connection, |
duke@1 | 512 | MessageMediator messageMediator) |
duke@1 | 513 | { |
duke@1 | 514 | // REVISIT - no factoring so cheat to avoid code dup right now. |
duke@1 | 515 | // REVISIT **** COUPLING !!!! |
duke@1 | 516 | ContactInfo contactInfo = new SocketOrChannelContactInfoImpl(); |
duke@1 | 517 | return contactInfo.finishCreatingMessageMediator(broker, |
duke@1 | 518 | connection, messageMediator); |
duke@1 | 519 | } |
duke@1 | 520 | |
duke@1 | 521 | public InputObject createInputObject(Broker broker, |
duke@1 | 522 | MessageMediator messageMediator) |
duke@1 | 523 | { |
duke@1 | 524 | CorbaMessageMediator corbaMessageMediator = (CorbaMessageMediator) |
duke@1 | 525 | messageMediator; |
duke@1 | 526 | return new CDRInputObject((ORB)broker, |
duke@1 | 527 | (CorbaConnection)messageMediator.getConnection(), |
duke@1 | 528 | corbaMessageMediator.getDispatchBuffer(), |
duke@1 | 529 | corbaMessageMediator.getDispatchHeader()); |
duke@1 | 530 | } |
duke@1 | 531 | |
duke@1 | 532 | public OutputObject createOutputObject(Broker broker, |
duke@1 | 533 | MessageMediator messageMediator) |
duke@1 | 534 | { |
duke@1 | 535 | CorbaMessageMediator corbaMessageMediator = (CorbaMessageMediator) |
duke@1 | 536 | messageMediator; |
duke@1 | 537 | return new CDROutputObject((ORB) broker, corbaMessageMediator, |
duke@1 | 538 | corbaMessageMediator.getReplyHeader(), |
duke@1 | 539 | corbaMessageMediator.getStreamFormatVersion()); |
duke@1 | 540 | } |
duke@1 | 541 | |
duke@1 | 542 | //////////////////////////////////////////////////// |
duke@1 | 543 | // |
duke@1 | 544 | // SocketOrChannelAcceptor |
duke@1 | 545 | // |
duke@1 | 546 | |
duke@1 | 547 | public ServerSocket getServerSocket() |
duke@1 | 548 | { |
duke@1 | 549 | return serverSocket; |
duke@1 | 550 | } |
duke@1 | 551 | |
duke@1 | 552 | //////////////////////////////////////////////////// |
duke@1 | 553 | // |
duke@1 | 554 | // Implementation. |
duke@1 | 555 | // |
duke@1 | 556 | |
duke@1 | 557 | public String toString() |
duke@1 | 558 | { |
duke@1 | 559 | String sock; |
duke@1 | 560 | if (serverSocketChannel == null) { |
duke@1 | 561 | if (serverSocket == null) { |
duke@1 | 562 | sock = "(not initialized)"; |
duke@1 | 563 | } else { |
duke@1 | 564 | sock = serverSocket.toString(); |
duke@1 | 565 | } |
duke@1 | 566 | } else { |
duke@1 | 567 | sock = serverSocketChannel.toString(); |
duke@1 | 568 | } |
duke@1 | 569 | |
duke@1 | 570 | return |
duke@1 | 571 | toStringName() + |
duke@1 | 572 | "[" |
duke@1 | 573 | + sock + " " |
duke@1 | 574 | + type + " " |
duke@1 | 575 | + shouldUseSelectThreadToWait() + " " |
duke@1 | 576 | + shouldUseWorkerThreadForEvent() |
duke@1 | 577 | + "]" ; |
duke@1 | 578 | } |
duke@1 | 579 | |
duke@1 | 580 | protected String toStringName() |
duke@1 | 581 | { |
duke@1 | 582 | return "SocketOrChannelAcceptorImpl"; |
duke@1 | 583 | } |
duke@1 | 584 | |
duke@1 | 585 | protected void dprint(String msg) |
duke@1 | 586 | { |
duke@1 | 587 | ORBUtility.dprint(toStringName(), msg); |
duke@1 | 588 | } |
duke@1 | 589 | |
duke@1 | 590 | protected void dprint(String msg, Throwable t) |
duke@1 | 591 | { |
duke@1 | 592 | dprint(msg); |
duke@1 | 593 | t.printStackTrace(System.out); |
duke@1 | 594 | } |
duke@1 | 595 | |
duke@1 | 596 | // BEGIN Legacy support |
duke@1 | 597 | //////////////////////////////////////////////////// |
duke@1 | 598 | // |
duke@1 | 599 | // LegacyServerSocketEndPointInfo and EndPointInfo |
duke@1 | 600 | // |
duke@1 | 601 | |
duke@1 | 602 | public String getType() |
duke@1 | 603 | { |
duke@1 | 604 | return type; |
duke@1 | 605 | } |
duke@1 | 606 | |
duke@1 | 607 | public String getHostName() |
duke@1 | 608 | { |
duke@1 | 609 | return hostname; |
duke@1 | 610 | } |
duke@1 | 611 | |
duke@1 | 612 | public String getHost() |
duke@1 | 613 | { |
duke@1 | 614 | return hostname; |
duke@1 | 615 | } |
duke@1 | 616 | |
duke@1 | 617 | public int getPort() |
duke@1 | 618 | { |
duke@1 | 619 | return port; |
duke@1 | 620 | } |
duke@1 | 621 | |
duke@1 | 622 | public int getLocatorPort() |
duke@1 | 623 | { |
duke@1 | 624 | return locatorPort; |
duke@1 | 625 | } |
duke@1 | 626 | |
duke@1 | 627 | public void setLocatorPort (int port) |
duke@1 | 628 | { |
duke@1 | 629 | locatorPort = port; |
duke@1 | 630 | } |
duke@1 | 631 | |
duke@1 | 632 | public String getName() |
duke@1 | 633 | { |
duke@1 | 634 | // Kluge alert: |
duke@1 | 635 | // Work and Legacy both define getName. |
duke@1 | 636 | // Try to make this behave best for most cases. |
duke@1 | 637 | String result = |
duke@1 | 638 | name.equals(LegacyServerSocketEndPointInfo.NO_NAME) ? |
duke@1 | 639 | this.toString() : name; |
duke@1 | 640 | return result; |
duke@1 | 641 | } |
duke@1 | 642 | // END Legacy support |
duke@1 | 643 | } |
duke@1 | 644 | |
duke@1 | 645 | // End of file. |