~ubuntu-branches/ubuntu/oneiric/libjboss-remoting-java/oneiric

« back to all changes in this revision

Viewing changes to src/main/org/jboss/remoting/transport/rmi/RMIServerInvoker.java

  • Committer: Package Import Robot
  • Author(s): Torsten Werner
  • Date: 2011-09-09 14:01:03 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: package-import@ubuntu.com-20110909140103-hqokx61534tas9rg
Tags: 2.5.3.SP1-1
* Newer but not newest upstream release. Do not build samples.
* Change debian/watch to upstream's svn repo.
* Add patch to fix compile error caused by tomcat update.
  (Closes: #628303)
* Switch to source format 3.0.
* Switch to debhelper level 7.
* Remove useless Depends.
* Update Standards-Version: 3.9.2.
* Update README.source.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
* JBoss, Home of Professional Open Source
 
3
* Copyright 2005, JBoss Inc., and individual contributors as indicated
 
4
* by the @authors tag. See the copyright.txt in the distribution for a
 
5
* full listing of individual contributors.
 
6
*
 
7
* This is free software; you can redistribute it and/or modify it
 
8
* under the terms of the GNU Lesser General Public License as
 
9
* published by the Free Software Foundation; either version 2.1 of
 
10
* the License, or (at your option) any later version.
 
11
*
 
12
* This software is distributed in the hope that it will be useful,
 
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 
15
* Lesser General Public License for more details.
 
16
*
 
17
* You should have received a copy of the GNU Lesser General Public
 
18
* License along with this software; if not, write to the Free
 
19
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 
20
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 
21
*/
 
22
 
 
23
package org.jboss.remoting.transport.rmi;
 
24
 
 
25
import org.jboss.remoting.Home;
 
26
import org.jboss.remoting.InvocationRequest;
 
27
import org.jboss.remoting.InvokerLocator;
 
28
import org.jboss.remoting.Remoting;
 
29
import org.jboss.remoting.ServerInvoker;
 
30
import org.jboss.remoting.marshal.MarshalFactory;
 
31
import org.jboss.remoting.marshal.Marshaller;
 
32
import org.jboss.remoting.marshal.MarshallerDecorator;
 
33
import org.jboss.remoting.marshal.UnMarshaller;
 
34
import org.jboss.remoting.marshal.UnMarshallerDecorator;
 
35
import org.jboss.remoting.marshal.VersionedMarshaller;
 
36
import org.jboss.remoting.marshal.VersionedUnMarshaller;
 
37
import org.jboss.remoting.marshal.rmi.RMIMarshaller;
 
38
import org.jboss.remoting.marshal.rmi.RMIUnMarshaller;
 
39
import org.jboss.remoting.marshal.serializable.SerializableMarshaller;
 
40
import org.jboss.remoting.serialization.SerializationManager;
 
41
import org.jboss.remoting.serialization.SerializationStreamFactory;
 
42
import org.jboss.remoting.util.SecurityUtility;
 
43
import org.jboss.serial.io.JBossObjectOutputStream;
 
44
import org.jboss.util.propertyeditor.PropertyEditors;
 
45
import org.jboss.logging.Logger;
 
46
 
 
47
import javax.net.SocketFactory;
 
48
 
 
49
import java.beans.IntrospectionException;
 
50
import java.io.ByteArrayInputStream;
 
51
import java.io.ByteArrayOutputStream;
 
52
import java.io.IOException;
 
53
import java.io.ObjectOutputStream;
 
54
import java.net.InetAddress;
 
55
import java.net.UnknownHostException;
 
56
import java.rmi.AccessException;
 
57
import java.rmi.NotBoundException;
 
58
import java.rmi.Remote;
 
59
import java.rmi.RemoteException;
 
60
import java.rmi.registry.LocateRegistry;
 
61
import java.rmi.registry.Registry;
 
62
import java.rmi.server.ExportException;
 
63
import java.rmi.server.RMIClientSocketFactory;
 
64
import java.rmi.server.RMIServerSocketFactory;
 
65
import java.rmi.server.RemoteServer;
 
66
import java.rmi.server.ServerNotActiveException;
 
67
import java.rmi.server.UnicastRemoteObject;
 
68
import java.security.AccessController;
 
69
import java.security.PrivilegedAction;
 
70
import java.security.PrivilegedActionException;
 
71
import java.security.PrivilegedExceptionAction;
 
72
import java.util.HashMap;
 
73
import java.util.HashSet;
 
74
import java.util.Iterator;
 
75
import java.util.List;
 
76
import java.util.Map;
 
77
import java.util.Properties;
 
78
import java.util.Set;
 
79
 
 
80
/**
 
81
 * RMIServerInvoker
 
82
 *
 
83
 * @author <a href="mailto:jhaynie@vocalocity.net">Jeff Haynie</a>
 
84
 * @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
 
85
 * @version $Revision: 5255 $
 
86
 */
 
87
public class RMIServerInvoker extends ServerInvoker implements RMIServerInvokerInf, Cloneable
 
88
{
 
89
   public static String RMI_ONEWAY_MARSHALLING = "rmiOnewayMarshalling";
 
90
   
 
91
   private static final Logger log = Logger.getLogger(RMIServerInvoker.class);
 
92
 
 
93
   protected boolean isPrimaryServer = true;
 
94
   protected Set secondaryServers = new HashSet();
 
95
   protected boolean rmiOnewayMarshalling;
 
96
   
 
97
   private Remote stub;
 
98
   private RemotingRMIClientSocketFactory csf;
 
99
   
 
100
 
 
101
   /**
 
102
    * Default for how many connections are queued.  Value is 200.
 
103
    */
 
104
   public static final int BACKLOG_DEFAULT = 200;
 
105
 
 
106
   /**
 
107
    * Default port on which rmi registry will be started.  Value is 3455.
 
108
    */
 
109
   public static final int DEFAULT_REGISTRY_PORT = 3455;
 
110
 
 
111
   /**
 
112
    * Key for port on which rmi registry should be started on.
 
113
    */
 
114
   public static final String REGISTRY_PORT_KEY = "registryPort";
 
115
 
 
116
   private Marshaller marshaller = null;
 
117
   private UnMarshaller unmarshaller = null;
 
118
 
 
119
   public RMIServerInvoker(InvokerLocator locator)
 
120
   {
 
121
      super(locator);
 
122
   }
 
123
 
 
124
   public void start() throws IOException
 
125
   {
 
126
      super.start();
 
127
 
 
128
      if (isPrimaryServer)
 
129
      {
 
130
         List connectHomes = getConnectHomes();
 
131
         List homes = getHomes();
 
132
         
 
133
         if (connectHomes.size() != homes.size())
 
134
            throw new IOException("number of connect homes and bind homes must match in RMI transport");
 
135
         
 
136
         Home bindHome = (Home) homes.get(0);
 
137
         Home connectHome = (Home) connectHomes.get(0);
 
138
         initRMI(bindHome, connectHome);
 
139
 
 
140
         for (int i = 1; i < homes.size(); i++)
 
141
         {
 
142
            bindHome = (Home) homes.get(i);
 
143
            connectHome = (Home) connectHomes.get(i);
 
144
            RMIServerInvoker copy = copy();
 
145
            secondaryServers.add(copy);
 
146
            copy.initRMI(bindHome, connectHome);
 
147
         }
 
148
      }
 
149
   }
 
150
   
 
151
   protected void setup() throws Exception
 
152
   {
 
153
      Properties props = new Properties();
 
154
      props.putAll(getConfiguration());
 
155
      mapJavaBeanProperties(RMIServerInvoker.this, props, false);
 
156
      super.setup();
 
157
   }
 
158
   
 
159
   protected RMIServerInvoker copy() throws IOException
 
160
   {
 
161
      Object o = null;
 
162
      try
 
163
      {
 
164
         o = clone();
 
165
      }
 
166
      catch (CloneNotSupportedException e)
 
167
      {
 
168
         log.error("This should not happen", e);
 
169
         return this;
 
170
      }
 
171
      RMIServerInvoker server = (RMIServerInvoker) o;
 
172
      server.locator = locator;
 
173
      server.locator = new InvokerLocator(locator.getLocatorURI());
 
174
      server.locator.setHomeInUse(locator.getHomeInUse());
 
175
      server.isPrimaryServer = false;
 
176
      server.start();
 
177
      return server;
 
178
   }
 
179
   
 
180
   protected void initRMI(Home bindHome, Home connectHome) throws IOException
 
181
   {
 
182
      Registry registry = null;
 
183
      try
 
184
      {
 
185
         registry = getRegistry();
 
186
      }
 
187
      catch (Exception e)
 
188
      {
 
189
         throw new IOException(e.getMessage());
 
190
      }
 
191
 
 
192
      String bindHost = bindHome.host;
 
193
      int bindPort = bindHome.port;
 
194
      String clientConnectHost = connectHome.host;
 
195
 
 
196
      if(clientConnectHost == null)
 
197
      {
 
198
         clientConnectHost = bindHost;
 
199
      }
 
200
 
 
201
      locator.setHomeInUse(bindHome);
 
202
      RMIServerSocketFactory ssf = new RemotingRMIServerSocketFactory(getServerSocketFactory(), BACKLOG_DEFAULT, bindHost, getTimeout());
 
203
      csf = getRMIClientSocketFactory(clientConnectHost);
 
204
      stub = exportObject(this, bindPort, csf, ssf);
 
205
 
 
206
      log.debug("Binding server to \"remoting/RMIServerInvoker/" + bindPort + "\" in registry");
 
207
      rebind(registry, "remoting/RMIServerInvoker/" + bindPort, this);
 
208
      ClassLoader classLoader = getClassLoader(RMIServerInvoker.class);
 
209
      Map map = passConfigMapToMarshalFactory ? configuration : null;
 
210
      unmarshaller = MarshalFactory.getUnMarshaller(getLocator(), classLoader, map);
 
211
      marshaller = MarshalFactory.getMarshaller(getLocator(), classLoader, map);
 
212
   }
 
213
 
 
214
 
 
215
   protected RemotingRMIClientSocketFactory getRMIClientSocketFactory(String clientConnectHost)
 
216
   {
 
217
      // Remove server side socket creation listeners.
 
218
      HashMap remoteConfig = new HashMap(configuration);
 
219
      remoteConfig.remove(Remoting.CUSTOM_SERVER_SOCKET_FACTORY);
 
220
      remoteConfig.remove(Remoting.SOCKET_CREATION_CLIENT_LISTENER);
 
221
      remoteConfig.remove(Remoting.SOCKET_CREATION_SERVER_LISTENER);
 
222
      return new RemotingRMIClientSocketFactory(locator, clientConnectHost, getTimeout(), remoteConfig);
 
223
   }
 
224
   
 
225
   protected SocketFactory getDefaultSocketFactory()
 
226
   {
 
227
//      return SocketFactory.getDefault();
 
228
      /**
 
229
       * Returning null because by default, this socket factory
 
230
       * will be need to be serialized when exported.  Since the
 
231
       * default factory implementation returned from SocketFactory.getDefault()
 
232
       * is not serializable, it will not work.  Therefore, if return null,
 
233
       * will delay the creation of the socket factory until the RMIClientSocketFactory is
 
234
       * exported.
 
235
       */
 
236
      return null;
 
237
   }
 
238
 
 
239
 
 
240
   public RMIServerInvoker(InvokerLocator locator, Map configuration)
 
241
   {
 
242
      super(locator, configuration);
 
243
   }
 
244
 
 
245
   private Registry getRegistry() throws Exception
 
246
   {
 
247
      Registry registry = null;
 
248
 
 
249
      int port = DEFAULT_REGISTRY_PORT;
 
250
 
 
251
      // See if locator contains a specific registry port
 
252
      Map params = getConfiguration();
 
253
      if(params != null)
 
254
      {
 
255
         String value = (String) params.get(REGISTRY_PORT_KEY);
 
256
         if(value != null)
 
257
         {
 
258
            try
 
259
            {
 
260
               port = Integer.parseInt(value);
 
261
               log.debug("Using port " + port + " for rmi registry.");
 
262
            }
 
263
            catch(NumberFormatException e)
 
264
            {
 
265
               throw new Exception("Can not set the RMIServerInvoker RMI registry to port " + value + ".  This is not a valid port number.");
 
266
            }
 
267
         }
 
268
      }
 
269
 
 
270
      try
 
271
      {
 
272
         log.debug("Creating registry for " + port);
 
273
 
 
274
         registry = createRegistry(port);
 
275
      }
 
276
      catch(ExportException exportEx)
 
277
      {
 
278
         log.debug("Locating registry for " + port);
 
279
 
 
280
         // Probably means that the registry already exists, so just get it.
 
281
         registry = getRegistry(port);
 
282
      }
 
283
      if(log.isTraceEnabled())
 
284
      {
 
285
         log.trace("Got registry: " + registry);
 
286
      }
 
287
      return registry;
 
288
   }
 
289
 
 
290
   protected String getDefaultDataType()
 
291
   {
 
292
      return SerializableMarshaller.DATATYPE;
 
293
   }
 
294
 
 
295
   /**
 
296
    * destroy the RMI Server Invoker, which will unexport the RMI server
 
297
    */
 
298
   public void destroy()
 
299
   {
 
300
      super.destroy();
 
301
      try
 
302
      {
 
303
         try
 
304
         {
 
305
            log.debug("locator: " + locator + ", home: " + locator.getHomeInUse());
 
306
            log.debug(this + " primary: " + isPrimaryServer + " unbinding " + "remoting/RMIServerInvoker/" + locator.getPort() + " from registry");
 
307
            Registry registry = getRegistry();
 
308
            unbind(registry, "remoting/RMIServerInvoker/" + locator.getPort());
 
309
            log.debug("unbound " + "remoting/RMIServerInvoker/" + locator.getPort() + " from registry");
 
310
         }
 
311
         catch(Exception e)
 
312
         {
 
313
            if ("Finalizer".equalsIgnoreCase(Thread.currentThread().getName()))
 
314
               log.debug("thread: " + Thread.currentThread().getName() + " Error unbinding RMIServerInvoker from RMI registry.", e);
 
315
            else
 
316
               log.error("thread: " + Thread.currentThread().getName() + " Error unbinding RMIServerInvoker from RMI registry.", e);
 
317
         }
 
318
 
 
319
         UnicastRemoteObject.unexportObject(this, true);
 
320
 
 
321
      }
 
322
      catch(java.rmi.NoSuchObjectException e)
 
323
      {
 
324
 
 
325
      }
 
326
      
 
327
      if (csf != null)
 
328
         csf.clear();
 
329
      
 
330
      if (isPrimaryServer)
 
331
      {
 
332
         Iterator it = secondaryServers.iterator();
 
333
         while (it.hasNext())
 
334
         {
 
335
            RMIServerInvoker server = (RMIServerInvoker) it.next();
 
336
            it.remove();
 
337
            server.destroy();
 
338
         }
 
339
      }
 
340
   }
 
341
 
 
342
   protected void finalize() throws Throwable
 
343
   {
 
344
      destroy();
 
345
      super.finalize();
 
346
   }
 
347
 
 
348
   /**
 
349
    * returns true if the transport is bi-directional in nature, for example,
 
350
    * SOAP in unidirectional and SOCKETs are bi-directional (unless behind a firewall
 
351
    * for example).
 
352
    */
 
353
   public boolean isTransportBiDirectional()
 
354
   {
 
355
      return true;
 
356
   }
 
357
 
 
358
   public final Remote getStub()
 
359
   {
 
360
      return stub;
 
361
   }
 
362
 
 
363
   public Object transport(Object invocation)
 
364
         throws RemoteException, IOException
 
365
   {
 
366
 
 
367
      Object payload = invocation;
 
368
      if(unmarshaller != null && !(unmarshaller instanceof RMIUnMarshaller))
 
369
      {
 
370
         if(unmarshaller instanceof UnMarshallerDecorator)
 
371
         {
 
372
            payload = ((UnMarshallerDecorator) unmarshaller).removeDecoration(payload);
 
373
         }
 
374
         else
 
375
         {
 
376
            ByteArrayInputStream is = null;
 
377
            if (rmiOnewayMarshalling)
 
378
            {
 
379
               // Legacy treatment, pre 2.4.0
 
380
               ByteArrayOutputStream baos = new ByteArrayOutputStream();
 
381
               SerializationManager manager = SerializationStreamFactory.getManagerInstance(getSerializationType());
 
382
               ObjectOutputStream oos = manager.createOutput(baos);
 
383
               writeObject(oos, payload);
 
384
               oos.flush();
 
385
               oos.close();
 
386
               is = new ByteArrayInputStream(baos.toByteArray());
 
387
            }
 
388
            else
 
389
            {
 
390
               is = new ByteArrayInputStream((byte[]) payload);
 
391
            }
 
392
 
 
393
            try
 
394
            {
 
395
               if (unmarshaller instanceof VersionedUnMarshaller)
 
396
               {
 
397
                  payload = ((VersionedUnMarshaller) unmarshaller).read(is, null, getVersion());
 
398
                  is.close();
 
399
               }
 
400
               else
 
401
               {
 
402
                  payload = unmarshaller.read(is, null);
 
403
                  is.close();
 
404
               }
 
405
            }
 
406
            catch(ClassNotFoundException e)
 
407
            {
 
408
               log.debug("Could not unmarshall invocation request" + payload, e);
 
409
               throw new IOException(e.getMessage());
 
410
            }
 
411
         }
 
412
      }
 
413
 
 
414
      if (payload instanceof InvocationRequest)
 
415
      {
 
416
         InvocationRequest ir = (InvocationRequest) payload;
 
417
         Map metadata = ir.getRequestPayload();
 
418
         if (metadata == null)
 
419
         {
 
420
            metadata = new HashMap();
 
421
            ir.setRequestPayload(metadata);
 
422
         }
 
423
         try
 
424
         {
 
425
            String clientHost = RemoteServer.getClientHost();
 
426
            InetAddress clientAddress = getAddressByName(clientHost);
 
427
            metadata.put(Remoting.CLIENT_ADDRESS, clientAddress);
 
428
         }
 
429
         catch (ServerNotActiveException e)
 
430
         {
 
431
            throw new RemoteException(e.getMessage());
 
432
         }
 
433
      }
 
434
      Object response = invoke(payload);
 
435
 
 
436
      if(marshaller != null && !(marshaller instanceof RMIMarshaller) && !rmiOnewayMarshalling)
 
437
      {
 
438
         if(marshaller instanceof MarshallerDecorator)
 
439
         {
 
440
            response = ((MarshallerDecorator) marshaller).addDecoration(response);
 
441
         }
 
442
         else
 
443
         {
 
444
            ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
 
445
            if (marshaller instanceof VersionedMarshaller)
 
446
               ((VersionedMarshaller) marshaller).write(response, byteOut, getVersion());
 
447
            else
 
448
               marshaller.write(response, byteOut);
 
449
            
 
450
            byteOut.close();
 
451
            response = byteOut.toByteArray();
 
452
         }
 
453
      }
 
454
      return response;
 
455
   }
 
456
 
 
457
   public boolean isRmiOnewayMarshalling()
 
458
   {
 
459
      return rmiOnewayMarshalling;
 
460
   }
 
461
 
 
462
   public void setRmiOnewayMarshalling(boolean rmiOnewayMarshalling)
 
463
   {
 
464
      this.rmiOnewayMarshalling = rmiOnewayMarshalling;
 
465
   }
 
466
   
 
467
   static private ClassLoader getClassLoader(final Class c)
 
468
   {
 
469
      if (SecurityUtility.skipAccessControl())
 
470
      {
 
471
         return c.getClassLoader();
 
472
      }
 
473
 
 
474
      return (ClassLoader)AccessController.doPrivileged( new PrivilegedAction()
 
475
      {
 
476
         public Object run()
 
477
         {
 
478
            return c.getClassLoader();
 
479
         }
 
480
      });
 
481
   }
 
482
   
 
483
   static private void mapJavaBeanProperties(final Object o, final Properties props, final boolean isStrict)
 
484
   throws IntrospectionException
 
485
   {
 
486
      if (SecurityUtility.skipAccessControl())
 
487
      {
 
488
         PropertyEditors.mapJavaBeanProperties(o, props, isStrict);
 
489
         return;
 
490
      }
 
491
 
 
492
      try
 
493
      {
 
494
         AccessController.doPrivileged( new PrivilegedExceptionAction()
 
495
         {
 
496
            public Object run() throws IntrospectionException
 
497
            {
 
498
               PropertyEditors.mapJavaBeanProperties(o, props, isStrict);
 
499
               return null;
 
500
            }
 
501
         });
 
502
      }
 
503
      catch (PrivilegedActionException e)
 
504
      {
 
505
         throw (IntrospectionException) e.getCause();
 
506
      }
 
507
   }
 
508
   
 
509
   static private void writeObject(final ObjectOutputStream oos, final Object o)
 
510
   throws IOException
 
511
   {
 
512
      if (SecurityUtility.skipAccessControl() || !(oos instanceof JBossObjectOutputStream))
 
513
      {
 
514
         oos.writeObject(o);
 
515
         return;
 
516
      }
 
517
 
 
518
      try
 
519
      {
 
520
         AccessController.doPrivileged( new PrivilegedExceptionAction()
 
521
         {
 
522
            public Object run() throws IOException
 
523
            {
 
524
               oos.writeObject(o);
 
525
               return null;
 
526
            }
 
527
         });
 
528
      }
 
529
      catch (PrivilegedActionException e)
 
530
      {
 
531
         Throwable cause = e.getCause();
 
532
         if (cause instanceof IOException)
 
533
            throw (IOException) cause;
 
534
         else
 
535
            throw (RuntimeException) cause;
 
536
      }
 
537
   }
 
538
   
 
539
   static private InetAddress getAddressByName(final String host) throws UnknownHostException
 
540
   {
 
541
      if (SecurityUtility.skipAccessControl())
 
542
      {
 
543
         return InetAddress.getByName(host);
 
544
      }
 
545
      
 
546
      try
 
547
      {
 
548
         return (InetAddress)AccessController.doPrivileged( new PrivilegedExceptionAction()
 
549
         {
 
550
            public Object run() throws IOException
 
551
            {
 
552
               return InetAddress.getByName(host);
 
553
            }
 
554
         });
 
555
      }
 
556
      catch (PrivilegedActionException e)
 
557
      {
 
558
         throw (UnknownHostException) e.getCause();
 
559
      }
 
560
   }
 
561
 
 
562
   static private Registry createRegistry(final int port) throws RemoteException
 
563
   {
 
564
      if (SecurityUtility.skipAccessControl())
 
565
      {
 
566
         return LocateRegistry.createRegistry(port);
 
567
      }
 
568
      
 
569
      try
 
570
      {
 
571
         return (Registry) AccessController.doPrivileged( new PrivilegedExceptionAction()
 
572
         {
 
573
            public Object run() throws RemoteException
 
574
            {
 
575
               return LocateRegistry.createRegistry(port);
 
576
            }
 
577
         });
 
578
      }
 
579
      catch (PrivilegedActionException e)
 
580
      {
 
581
         throw (RemoteException) e.getCause();
 
582
      } 
 
583
   }
 
584
   
 
585
   static private Remote exportObject(final Remote object,
 
586
                                     final int port,
 
587
                                     final RMIClientSocketFactory csf,
 
588
                                     final RMIServerSocketFactory ssf)
 
589
   throws RemoteException
 
590
   {
 
591
      if (SecurityUtility.skipAccessControl())
 
592
      {
 
593
         return UnicastRemoteObject.exportObject(object, port, csf, ssf);
 
594
      }
 
595
      
 
596
      try
 
597
      {
 
598
         return (Remote) AccessController.doPrivileged( new PrivilegedExceptionAction()
 
599
         {
 
600
            public Object run() throws RemoteException
 
601
            {
 
602
               return UnicastRemoteObject.exportObject(object, port, csf, ssf);
 
603
            }
 
604
         });
 
605
      }
 
606
      catch (PrivilegedActionException e)
 
607
      {
 
608
         throw (RemoteException) e.getCause();
 
609
      }
 
610
   }
 
611
   
 
612
   static private Registry getRegistry(final int port) throws RemoteException
 
613
   {
 
614
      if (SecurityUtility.skipAccessControl())
 
615
      {
 
616
         return LocateRegistry.getRegistry(port);
 
617
      }
 
618
      
 
619
      try
 
620
      {
 
621
         return (Registry) AccessController.doPrivileged( new PrivilegedExceptionAction()
 
622
         {
 
623
            public Object run() throws RemoteException
 
624
            {
 
625
               return LocateRegistry.getRegistry(port);
 
626
            }
 
627
         });
 
628
      }
 
629
      catch (PrivilegedActionException e)
 
630
      {
 
631
         throw (RemoteException) e.getCause();
 
632
      } 
 
633
   }
 
634
   
 
635
   static private void rebind(final Registry registry, final String name, final Remote object)
 
636
   throws IOException
 
637
   {
 
638
      if (SecurityUtility.skipAccessControl())
 
639
      {
 
640
         registry.rebind(name, object);
 
641
         return;
 
642
      }
 
643
      
 
644
      try
 
645
      {
 
646
         AccessController.doPrivileged( new PrivilegedExceptionAction()
 
647
         {
 
648
            public Object run() throws IOException
 
649
            {
 
650
               registry.rebind(name, object);
 
651
               return null;
 
652
            }
 
653
         });
 
654
      }
 
655
      catch (PrivilegedActionException e)
 
656
      {
 
657
         throw (IOException) e.getCause();
 
658
      }
 
659
   }
 
660
   
 
661
   static private void unbind(final Registry registry, final String name)
 
662
   throws  AccessException, RemoteException, NotBoundException
 
663
   {
 
664
      if (SecurityUtility.skipAccessControl())
 
665
      {
 
666
         registry.unbind(name);
 
667
         return;
 
668
      }
 
669
      
 
670
      try
 
671
      {
 
672
         AccessController.doPrivileged( new PrivilegedExceptionAction()
 
673
         {
 
674
            public Object run() throws AccessException, RemoteException, NotBoundException
 
675
            {
 
676
               registry.unbind(name);
 
677
               return null;
 
678
            }
 
679
         });
 
680
      }
 
681
      catch (PrivilegedActionException e)
 
682
      {
 
683
         Throwable cause = e.getCause();
 
684
         if (cause instanceof AccessException)
 
685
            throw (AccessException) cause;
 
686
         else if (cause instanceof RemoteException)
 
687
            throw (RemoteException) cause;
 
688
         else
 
689
            throw (NotBoundException) cause;
 
690
      }
 
691
   }
 
692
}