    1   /***
    2    *
    3    * Copyright 2004 Hiram Chirino
    4    *
    5    * Licensed under the Apache License, Version 2.0 (the "License");
    6    * you may not use this file except in compliance with the License.
    7    * You may obtain a copy of the License at
    8    *
    9    * http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   *
    17   **/
    18  package org.activeio.oneport;
    19
    20  import java.rmi.RemoteException;
    21  import java.util.Properties;
    22
    23  import javax.naming.NamingException;
    24
    25  import org.omg.CORBA.ORB;
    26  import org.omg.CORBA.Object;
    27  import org.omg.PortableServer.POA;
    28  import org.omg.PortableServer.POAHelper;
    29
    30  import EDU.oswego.cs.dl.util.concurrent.Slot;
    31
    32  /***
    33   *
    34   */
    35  public class OpenORBOnePortSocketFactoryTest extends OnePortAsyncChannelServerTest {
    36
    37      static public Slot staticResultSlot;
    38      private ORB orb;
    39      private String serverRef;
    40      private TestIIOPServerImpl testIIOPServer;
    41      private POA rootPOA;
    42
    43      protected void startIIOPServer() throws Exception {
    44          staticResultSlot = resultSlot;
    45
    46          Properties props = new Properties();
    47          props.setProperty("org.omg.PortableInterceptor.ORBInitializerClass.org.activeio.oneport.OpenORBOpenPortFeatureInitializer", "");
    48          props.setProperty("org.omg.CORBA.ORBClass", "org.openorb.orb.core.ORB");
    49          props.setProperty("org.omg.CORBA.ORBSingletonClass", "org.openorb.orb.core.ORBSingleton");
    50
    51          OpenORBOpenPortFeatureInitializer.setContextSocketFactory(new OpenORBOpenPortSocketFactory(server));
    52          orb = ORB.init( new String[]{}, props );
    53          OpenORBOpenPortFeatureInitializer.setContextSocketFactory(null);
    54
    55          rootPOA = POAHelper.narrow( orb.resolve_initial_references( "RootPOA" ) );
    56
    57          TestIIOPServerImpl srv = new TestIIOPServerImpl();
    58          serverRef = orb.object_to_string( srv._this( orb ) );
    59          rootPOA.the_POAManager().activate();
    60          new Thread(){
    61              public void run() {
    62  	            orb.run();
    63              }
    64          }.start();
    65      }
    66
    67      protected void stopIIOPServer() throws Exception {
    68          orb.shutdown(true);
    69      }
    70
    71      protected void hitIIOPServer( ) throws NamingException, RemoteException
    72      {
    73          // Create a client side orb.
    74          Properties props = new Properties();
    75          props.setProperty("org.omg.CORBA.ORBClass", "org.openorb.orb.core.ORB");
    76          props.setProperty("org.omg.CORBA.ORBSingletonClass", "org.openorb.orb.core.ORBSingleton");
    77          ORB orb = ORB.init( new String[]{}, props );
    78
    79          Object obj = orb.string_to_object( serverRef );
    80          TestIIOPServer srv = TestIIOPServerHelper.narrow( obj );
    81          try {
    82              srv.test();
    83          } catch (Throwable e) {
    84              e.printStackTrace();
    85          } finally {
    86              orb.shutdown(true);
    87          }
    88      }
    89
    90  }