[jboss-cvs] JBossRemoting/src/tests/org/jboss/test/remoting/transport/config ...

Ron Sigal ron_sigal at yahoo.com
Tue Aug 1 02:33:19 EDT 2006


  User: rsigal  
  Date: 06/08/01 02:33:19

  Modified:    src/tests/org/jboss/test/remoting/transport/config  
                        FactoryConfigTestCaseSSLParent.java
                        FactoryConfigTestCaseParent.java
  Log:
  JBREM-520:  Added treatment of configuration by setting xml configuration on Connector.
  
  Revision  Changes    Path
  1.6       +200 -3    JBossRemoting/src/tests/org/jboss/test/remoting/transport/config/FactoryConfigTestCaseSSLParent.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: FactoryConfigTestCaseSSLParent.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossRemoting/src/tests/org/jboss/test/remoting/transport/config/FactoryConfigTestCaseSSLParent.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -b -r1.5 -r1.6
  --- FactoryConfigTestCaseSSLParent.java	22 Jul 2006 07:27:34 -0000	1.5
  +++ FactoryConfigTestCaseSSLParent.java	1 Aug 2006 06:33:19 -0000	1.6
  @@ -36,6 +36,7 @@
   import org.jboss.remoting.transport.Connector;
   import org.jboss.remoting.transport.PortUtil;
   import org.jboss.remoting.transport.http.ssl.HTTPSClientInvoker;
  +import org.w3c.dom.Document;
   
   import javax.management.MBeanServer;
   import javax.management.MBeanServerFactory;
  @@ -44,6 +45,9 @@
   import javax.net.SocketFactory;
   import javax.net.ssl.SSLServerSocketFactory;
   import javax.net.ssl.SSLSocketFactory;
  +import javax.xml.parsers.DocumentBuilderFactory;
  +
  +import java.io.ByteArrayInputStream;
   import java.io.File;
   import java.io.IOException;
   import java.io.Serializable;
  @@ -67,8 +71,7 @@
      public static int secret;
      protected static HashMap initParameters = new HashMap();
      
  - 
  -   public void testFactoriesByPassingMBean()
  +   public void testFactoriesByPassingMBeanInXml()
      {
         // There is no specific test for factory identity here, since the ServerSocketFactory
         // MBeans do not expose access to their internal structure.  Instead, we define the
  @@ -115,10 +118,199 @@
            // Give different protocol than used by default factories.
            sconfig.put(SSLSocketBuilder.REMOTING_SSL_PROTOCOL, "TLS");
   
  +         Connector connector = new Connector(sconfig);
  +         mbeanServer.registerMBean(connector, new ObjectName("test:type=connector"));
  +         
  +         // Create another ServerSocketFactoryMBean
  +         secret = ((short) System.currentTimeMillis()) & 0xffff;
  +         service = getDefaultServerSocketFactory();
  +         serverSocketFactoryName = "jboss:type=serversocketfactory2";
  +         objName = new ObjectName(serverSocketFactoryName);
  +         mbeanServer.registerMBean(service, objName);
  +         
  +         // Create and set xml configuration document.
            int freeport = PortUtil.findFreePort(getHostName());
  +         StringBuffer buf = new StringBuffer();
  +         buf.append("<?xml version=\"1.0\"?>\n");
  +         buf.append("<config>");
  +         buf.append("   <invoker transport=\"" + getTransport() + "\">");
  +         buf.append("      <attribute name=\"serverBindAddress\">" + getHostName() + "</attribute>");
  +         buf.append("      <attribute name=\"serverBindPort\">" + freeport + "</attribute>");
  +         buf.append("      <attribute name=\"serverSocketFactory\">");
  +         buf.append(          serverSocketFactoryName);
  +         buf.append(      "</attribute>");
  +         buf.append("      <attribute name=\"socketFactory\">");
  +         buf.append(         getUniqueSocketFactoryClass());
  +         buf.append(      "</attribute>");
  +         buf.append("   </invoker>");
  +         buf.append("</config>");
  +         ByteArrayInputStream bais = new ByteArrayInputStream(buf.toString().getBytes());
  +         Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bais);
  +         connector.setConfiguration(xml.getDocumentElement());
  +         connector.create();
  +         
  +         connector.addInvocationHandler("sample", new SampleInvocationHandler());
  +         connector.start();
  +         ServerInvoker serverInvoker = connector.getServerInvoker();
  +         ServerSocketFactory ssf = serverInvoker.getServerSocketFactory();
  +         int ssfPort = PortUtil.findFreePort(getHostName());
  +         ServerSocket ss = ssf.createServerSocket(ssfPort);
  +         
  +         // Verify ServerSocketFactory is the one set in MBeanServer.
  +         assertEquals(secret, ss.getSoTimeout());
  +
  +         
  +         /////////////////////////////////////////////////
  +         /////    Make Client. There is no specific   //// 
  +         /////    client test for MBean server case.  ////
  +         /////////////////////////////////////////////////
  +         HashMap cconfig = new HashMap();
  +         
  +         // Put SocketFactory in config map.
  +         SocketFactory sf2 = getDefaultSocketFactory();
  +         cconfig.put(Remoting.CUSTOM_SOCKET_FACTORY, sf2);
  +         
  +         // Make Client use remote invoker.
            InvokerLocator locator = new InvokerLocator(getTransport() + "://" + getHostName() + ":" + freeport);
  -         Connector connector = new Connector(locator, sconfig);
  +         cconfig.put(InvokerLocator.FORCE_REMOTE, "true");
  +         
  +         // Put SSL parameters in config map.
  +         cconfig.put(SSLSocketBuilder.REMOTING_SOCKET_USE_CLIENT_MODE, "true");
  +         cconfig.put(SSLSocketBuilder.REMOTING_TRUST_STORE_TYPE, "JKS");
  +         trustStoreFilePath = getTruststoreFilePath();
  +         cconfig.put(SSLSocketBuilder.REMOTING_TRUST_STORE_FILE_PATH, trustStoreFilePath);
  +         cconfig.put(SSLSocketBuilder.REMOTING_TRUST_STORE_PASSWORD, "unit-tests-client");
  +         
  +         Client client = new Client(locator, cconfig);
  +         client.connect();
  +         
  +
  +         //////////////////////////////////////////////
  +         /////     Do server side callback test.   //// 
  +         //////////////////////////////////////////////
  +         Thread.sleep(500);
  +         freeport = PortUtil.findFreePort(getHostName());
  +         InvokerLocator callbackLocator = new InvokerLocator(getTransport() + "://" + getHostName() + ":" + freeport);
  +         Connector callbackConnector = new Connector(callbackLocator.getLocatorURI());
  +         ServerSocketFactory ssf3 = getDefaultCallbackServerSocketFactory();
  +         callbackConnector.setServerSocketFactory(ssf3);
  +         callbackConnector.create();
  +         callbackConnector.addInvocationHandler("sample", new SampleInvocationHandler());
  +         callbackConnector.start();
  +         
  +         CallbackHandler callbackHandler = new CallbackHandler();
  +         String callbackHandleObject = "myCallbackHandleObject";
  +         client.addListener(callbackHandler, callbackLocator, callbackHandleObject);
  +         
  +         // Verify that callback succeeded.
  +         assertEquals(1, callbackHandler.getCallbacks().size());
  +         
  +         // Verify callback SocketFactory was derived from ServerSocketFactory in MBeanServer.
  +         Field field = ServerInvoker.class.getDeclaredField("handlers");
  +         field.setAccessible(true);
  +         Map handlers = (Map) field.get(serverInvoker);
  +         Object obj = handlers.values().iterator().next();
  +         SampleInvocationHandler sampleInvocationHandler = (SampleInvocationHandler) obj;
  +         obj = sampleInvocationHandler.getCallbackHandler();
  +         ServerInvokerCallbackHandler serverInvokerCallbackHandler = (ServerInvokerCallbackHandler) obj;
  +         field = ServerInvokerCallbackHandler.class.getDeclaredField("callBackClient");
  +         field.setAccessible(true);
  +         Client callbackClient = (Client) field.get(serverInvokerCallbackHandler);
  +         ClientInvoker callbackClientInvoker = callbackClient.getInvoker();
  +         SocketFactory sf = callbackClientInvoker.getSocketFactory();
  +         
  +         // Show that callback socket factory comes from SSLServerSocketFactory MBean
  +         // instead of xml configuration.
  +         assertTrue(SSLSocketFactoryService.class == sf.getClass());
  +         Socket s = sf.createSocket(getHostName(), ssfPort);
  +         assertEquals(secret, s.getSoTimeout());
  +
  +         client.disconnect();
  +         callbackConnector.stop();
  +         connector.stop();
  +         log.info(getName() + " PASSES");
  +         
  +         
  +         connector.stop();
  +         log.info(getName() + " PASSES");
  +      }
  +      catch (Throwable t)
  +      {
  +         log.error(t);
  +         t.printStackTrace();
  +         log.info(getName() + " FAILS");
  +         fail();
  +      }
  +   }
  +   
  +   
  +   public void testFactoriesByPassingMBeanInConfigMap()
  +   {
  +      // There is no specific test for factory identity here, since the ServerSocketFactory
  +      // MBeans do not expose access to their internal structure.  Instead, we define the
  +      // default ServerSocketFactorys and SocketFactorys to use the SSL protocol.  Since
  +      // 
  +      try
  +      {
  +         /////////////////////////////////////
  +         /////    Do server side test.    //// 
  +         /////////////////////////////////////
  +         HashMap sconfig = new HashMap();
  +         secret = ((short) System.currentTimeMillis()) & 0xffff;
  +         
  +         // Put ServerSocketFactory MBean name in config map.
  +         ServerSocketFactory service = getDefaultServerSocketFactory();
  +         String serverSocketFactoryName = "jboss:type=serversocketfactory";
  +         ObjectName objName = new ObjectName(serverSocketFactoryName);
  +         MBeanServer mbeanServer = MBeanServerFactory.createMBeanServer();
  +         mbeanServer.registerMBean(service, objName);
  +         sconfig.put(ServerInvoker.SERVER_SOCKET_FACTORY, serverSocketFactoryName);
  +         
  +         // Make callback Client use remote invoker.
  +         sconfig.put(InvokerLocator.FORCE_REMOTE, "true");
  +         
  +         // Special case: tell HTTPSClientInvoker to ignore hostname in certificates.
  +         // This is because InvokerLocator turns "localhost" into "127.0.0.1". Should
  +         // be fixed by JBREM-497.
  +         sconfig.put(HTTPSClientInvoker.IGNORE_HTTPS_HOST, "true");
  +         
  +         // Put SSL keystore parameters in config map.
  +         sconfig.put(SSLSocketBuilder.REMOTING_SERVER_SOCKET_USE_CLIENT_MODE, "true");
  +         sconfig.put(SSLSocketBuilder.REMOTING_KEY_STORE_TYPE, "JKS");
  +         String keyStoreFilePath = getKeystoreFilePath();
  +         sconfig.put(SSLSocketBuilder.REMOTING_KEY_STORE_FILE_PATH, keyStoreFilePath);
  +         sconfig.put(SSLSocketBuilder.REMOTING_KEY_STORE_PASSWORD, "unit-tests-server");
  +         
  +         // Put SSL truststore parameters in config map.
  +         sconfig.put(SSLSocketBuilder.REMOTING_SOCKET_USE_CLIENT_MODE, "true");
  +         sconfig.put(SSLSocketBuilder.REMOTING_TRUST_STORE_TYPE, "JKS");
  +         String trustStoreFilePath = getTruststoreFilePath();
  +         sconfig.put(SSLSocketBuilder.REMOTING_TRUST_STORE_FILE_PATH, trustStoreFilePath);
  +         sconfig.put(SSLSocketBuilder.REMOTING_TRUST_STORE_PASSWORD, "unit-tests-client");
  +         
  +         // Give different protocol than used by default factories.
  +         sconfig.put(SSLSocketBuilder.REMOTING_SSL_PROTOCOL, "TLS");
  +
  +         int freeport = PortUtil.findFreePort(getHostName());
  +         Connector connector = new Connector(sconfig);
            mbeanServer.registerMBean(connector, new ObjectName("test:type=connector"));
  +         
  +         // Create and set xml configuration document.
  +         StringBuffer buf = new StringBuffer();
  +         buf.append("<?xml version=\"1.0\"?>\n");
  +         buf.append("<config>");
  +         buf.append("   <invoker transport=\"" + getTransport() + "\">");
  +         buf.append("      <attribute name=\"serverBindAddress\">" + getHostName() + "</attribute>");
  +         buf.append("      <attribute name=\"serverBindPort\">" + freeport + "</attribute>");
  +         buf.append("      <attribute name=\"socketFactory\">");
  +         buf.append(         getUniqueSocketFactoryClass());
  +         buf.append(      "</attribute>");
  +         buf.append("   </invoker>");
  +         buf.append("</config>");
  +         ByteArrayInputStream bais = new ByteArrayInputStream(buf.toString().getBytes());
  +         Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bais);
  +         connector.setConfiguration(xml.getDocumentElement());
  +         
            connector.create();
            connector.addInvocationHandler("sample", new SampleInvocationHandler());
            connector.start();
  @@ -151,6 +343,7 @@
            cconfig.put(SSLSocketBuilder.REMOTING_TRUST_STORE_FILE_PATH, trustStoreFilePath);
            cconfig.put(SSLSocketBuilder.REMOTING_TRUST_STORE_PASSWORD, "unit-tests-client");
            
  +         InvokerLocator locator = new InvokerLocator(getTransport() + "://" + getHostName() + ":" + freeport);
            Client client = new Client(locator, cconfig);
            client.connect();
            
  @@ -188,6 +381,10 @@
            Client callbackClient = (Client) field.get(serverInvokerCallbackHandler);
            ClientInvoker callbackClientInvoker = callbackClient.getInvoker();
            SocketFactory sf = callbackClientInvoker.getSocketFactory();
  +         
  +         // Show that callback socket factory comes from SSLServerSocketFactory MBean
  +         // instead of xml configuration.
  +         assertTrue(SSLSocketFactoryService.class == sf.getClass());
            Socket s = sf.createSocket(getHostName(), ssfPort);
            assertEquals(secret, s.getSoTimeout());
   
  
  
  
  1.5       +258 -44   JBossRemoting/src/tests/org/jboss/test/remoting/transport/config/FactoryConfigTestCaseParent.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: FactoryConfigTestCaseParent.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossRemoting/src/tests/org/jboss/test/remoting/transport/config/FactoryConfigTestCaseParent.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -b -r1.4 -r1.5
  --- FactoryConfigTestCaseParent.java	22 Jul 2006 07:27:34 -0000	1.4
  +++ FactoryConfigTestCaseParent.java	1 Aug 2006 06:33:19 -0000	1.5
  @@ -41,12 +41,16 @@
   import org.jboss.remoting.transport.Connector;
   import org.jboss.remoting.transport.PortUtil;
   import org.jboss.remoting.transport.http.ssl.HTTPSClientInvoker;
  +import org.w3c.dom.Document;
   
   import javax.management.MBeanServer;
   import javax.management.MBeanServerFactory;
   import javax.management.ObjectName;
   import javax.net.ServerSocketFactory;
   import javax.net.SocketFactory;
  +import javax.xml.parsers.DocumentBuilderFactory;
  +
  +import java.io.ByteArrayInputStream;
   import java.io.File;
   import java.io.IOException;
   import java.lang.reflect.Field;
  @@ -61,7 +65,7 @@
   /**
    * 
    * @author <a href="mailto:ron.sigal at jboss.com">Ron Sigal</a>
  - * @version $Revision: 1.4 $
  + * @version $Revision: 1.5 $
    * <p>
    * Copyright (c) Jun 13, 2006
    * </p>
  @@ -109,7 +113,7 @@
      }
      
      
  -   public void testFactoriesBySettingConnectorAndClient()
  +   public void testFactoriesBySettingInvokers()
      {
         try
         {
  @@ -154,22 +158,41 @@
            sconfig.put(SSLSocketBuilder.REMOTING_TRUST_STORE_FILE_PATH, trustStoreFilePath);
            sconfig.put(SSLSocketBuilder.REMOTING_TRUST_STORE_PASSWORD, "unit-tests-client");
            
  -         int freeport = PortUtil.findFreePort(getHostName());
  -         InvokerLocator locator = new InvokerLocator(getTransport() + "://" + getHostName() + ":" + freeport);
  -         Connector connector = new Connector(locator, sconfig);
  +         Connector connector = new Connector(sconfig);
            mbeanServer.registerMBean(connector, new ObjectName("test:type=connector"));
            
  -         // Set ServerSocketFactory and SocketFactory in Connector.
  +         // Create and set xml configuration document.
  +         int freeport = PortUtil.findFreePort(getHostName());
  +         StringBuffer buf = new StringBuffer();
  +         buf.append("<?xml version=\"1.0\"?>\n");
  +         buf.append("<config>");
  +         buf.append("   <invoker transport=\"" + getTransport() + "\">");
  +         buf.append("      <attribute name=\"serverBindAddress\">" + getHostName() + "</attribute>");
  +         buf.append("      <attribute name=\"serverBindPort\">" + freeport + "</attribute>");
  +         buf.append("      <attribute name=\"serverSocketFactory\">");
  +         buf.append(         getUniqueServerSocketFactoryClass());
  +         buf.append("      </attribute>");
  +         buf.append("      <attribute name=\"socketFactory\">");
  +         buf.append(         getUniqueSocketFactoryClass());
  +         buf.append("      </attribute>");
  +         buf.append("   </invoker>");
  +         buf.append("</config>");
  +         ByteArrayInputStream bais = new ByteArrayInputStream(buf.toString().getBytes());
  +         Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bais);
  +         connector.setConfiguration(xml.getDocumentElement());
  +         connector.create();
  +         
  +         // Set ServerSocketFactory and SocketFactory in ServerInvoker.
  +         ServerInvoker serverInvoker = connector.getServerInvoker();
            ServerSocketFactory ssf2 = getDefaultServerSocketFactory();
  -         connector.setServerSocketFactory(ssf2);
  +         serverInvoker.setServerSocketFactory(ssf2);
            SocketFactory sf2 = getDefaultCallbackSocketFactory();
  -         connector.setSocketFactory(sf2);
  -         connector.create();
  +         serverInvoker.setSocketFactory(sf2);
  +
            connector.addInvocationHandler("sample", new SampleInvocationHandler());
            connector.start();
            
  -         // Verify ServerSocketFactory is the one set in Connector.
  -         ServerInvoker serverInvoker = connector.getServerInvoker();
  +         // Verify ServerSocketFactory is the one set in ServerInvoker.
            assertTrue(ssf2 == serverInvoker.getServerSocketFactory());
            
            
  @@ -192,15 +215,16 @@
            cconfig.put(SSLSocketBuilder.REMOTING_TRUST_STORE_FILE_PATH, trustStoreFilePath);
            cconfig.put(SSLSocketBuilder.REMOTING_TRUST_STORE_PASSWORD, "unit-tests-client");
            
  +         InvokerLocator locator = new InvokerLocator(getTransport() + "://" + getHostName() + ":" + freeport);
            Client client = new Client(locator, cconfig);
  -         
  -         // Set SocketFactory in Client.
  -         SocketFactory sf4 = getDefaultSocketFactory();
  -         client.setSocketFactory(sf4);
            client.connect();
            
  -         // Verify SocketFactory is the one set in Client.
  +         // Set SocketFactory in ClientInvoker.
  +         SocketFactory sf4 = getDefaultSocketFactory();
            ClientInvoker clientInvoker = client.getInvoker();
  +         clientInvoker.setSocketFactory(sf4);
  +         
  +         // Verify SocketFactory is the one set in ClientInvoker.
            assertTrue(sf4 == clientInvoker.getSocketFactory());
            
            
  @@ -224,7 +248,7 @@
            // Verify that callback succeeded.
            assertEquals(1, callbackHandler.getCallbacks().size());
            
  -         // Verify callback SocketFactory is the one set in Connector.
  +         // Verify callback SocketFactory is the one set in SocketInvoker.
            Field field = ServerInvoker.class.getDeclaredField("handlers");
            field.setAccessible(true);
            Map handlers = (Map) field.get(serverInvoker);
  @@ -253,7 +277,7 @@
      }
     
      
  -   public void testFactoriesBySettingInvokers()
  +   public void testFactoriesBySettingConnectorAndClient()
      {
         try
         {
  @@ -298,23 +322,40 @@
            sconfig.put(SSLSocketBuilder.REMOTING_TRUST_STORE_FILE_PATH, trustStoreFilePath);
            sconfig.put(SSLSocketBuilder.REMOTING_TRUST_STORE_PASSWORD, "unit-tests-client");
            
  -         int freeport = PortUtil.findFreePort(getHostName());
  -         InvokerLocator locator = new InvokerLocator(getTransport() + "://" + getHostName() + ":" + freeport);
  -         Connector connector = new Connector(locator, sconfig);
  +         Connector connector = new Connector(sconfig);
            mbeanServer.registerMBean(connector, new ObjectName("test:type=connector"));
  -         connector.create();
            
  -         // Set ServerSocketFactory and SocketFactory in ServerInvoker.
  -         ServerInvoker serverInvoker = connector.getServerInvoker();
  +         // Create and set xml configuration document.
  +         int freeport = PortUtil.findFreePort(getHostName());
  +         StringBuffer buf = new StringBuffer();
  +         buf.append("<?xml version=\"1.0\"?>\n");
  +         buf.append("<config>");
  +         buf.append("   <invoker transport=\"" + getTransport() + "\">");
  +         buf.append("      <attribute name=\"serverBindAddress\">" + getHostName() + "</attribute>");
  +         buf.append("      <attribute name=\"serverBindPort\">" + freeport + "</attribute>");
  +         buf.append("      <attribute name=\"serverSocketFactory\">");
  +         buf.append(         getUniqueServerSocketFactoryClass());
  +         buf.append("      </attribute>");
  +         buf.append("      <attribute name=\"socketFactory\">");
  +         buf.append(         getUniqueSocketFactoryClass());
  +         buf.append("      </attribute>");
  +         buf.append("   </invoker>");
  +         buf.append("</config>");
  +         ByteArrayInputStream bais = new ByteArrayInputStream(buf.toString().getBytes());
  +         Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bais);
  +         connector.setConfiguration(xml.getDocumentElement());
  +                  
  +         // Set ServerSocketFactory and SocketFactory in Connector.
            ServerSocketFactory ssf2 = getDefaultServerSocketFactory();
  -         serverInvoker.setServerSocketFactory(ssf2);
  +         connector.setServerSocketFactory(ssf2);
            SocketFactory sf2 = getDefaultCallbackSocketFactory();
  -         serverInvoker.setSocketFactory(sf2);
  -
  +         connector.setSocketFactory(sf2);
  +         connector.create();
            connector.addInvocationHandler("sample", new SampleInvocationHandler());
            connector.start();
   
  -         // Verify ServerSocketFactory is the one set in ServerInvoker.
  +         // Verify ServerSocketFactory is the one set in Connector.
  +         ServerInvoker serverInvoker = connector.getServerInvoker();
            assertTrue(ssf2 == serverInvoker.getServerSocketFactory());
            
            
  @@ -337,15 +378,16 @@
            cconfig.put(SSLSocketBuilder.REMOTING_TRUST_STORE_FILE_PATH, trustStoreFilePath);
            cconfig.put(SSLSocketBuilder.REMOTING_TRUST_STORE_PASSWORD, "unit-tests-client");
            
  +         InvokerLocator locator = new InvokerLocator(getTransport() + "://" + getHostName() + ":" + freeport);
            Client client = new Client(locator, cconfig);
  -         client.connect();
            
  -         // Set SocketFactory in ClientInvoker.
  +         // Set SocketFactory in Client.
            SocketFactory sf4 = getDefaultSocketFactory();
  -         ClientInvoker clientInvoker = client.getInvoker();
  -         clientInvoker.setSocketFactory(sf4);
  +         client.setSocketFactory(sf4);
  +         client.connect();
            
  -         // Verify SocketFactory is the one set in ClientInvoker.
  +         // Verify SocketFactory is the one set in Client.
  +         ClientInvoker clientInvoker = client.getInvoker();
            assertTrue(sf4 == clientInvoker.getSocketFactory());
            
            
  @@ -369,7 +411,7 @@
            // Verify that callback succeeded.
            assertEquals(1, callbackHandler.getCallbacks().size());
            
  -         // Verify callback SocketFactory is the one set in SocketInvoker.
  +         // Verify callback SocketFactory is the one set in Connector.
            Field field = ServerInvoker.class.getDeclaredField("handlers");
            field.setAccessible(true);
            Map handlers = (Map) field.get(serverInvoker);
  @@ -443,10 +485,29 @@
            sconfig.put(SSLSocketBuilder.REMOTING_TRUST_STORE_FILE_PATH, trustStoreFilePath);
            sconfig.put(SSLSocketBuilder.REMOTING_TRUST_STORE_PASSWORD, "unit-tests-client");
            
  -         int freeport = PortUtil.findFreePort(getHostName());
  -         InvokerLocator locator = new InvokerLocator(getTransport() + "://" + getHostName() + ":" + freeport);
  -         Connector connector = new Connector(locator, sconfig);
  +         Connector connector = new Connector(sconfig);
            mbeanServer.registerMBean(connector, new ObjectName("test:type=connector"));
  +         
  +         // Create and set xml configuration document.
  +         int freeport = PortUtil.findFreePort(getHostName());
  +         StringBuffer buf = new StringBuffer();
  +         buf.append("<?xml version=\"1.0\"?>\n");
  +         buf.append("<config>");
  +         buf.append("   <invoker transport=\"" + getTransport() + "\">");
  +         buf.append("      <attribute name=\"serverBindAddress\">" + getHostName() + "</attribute>");
  +         buf.append("      <attribute name=\"serverBindPort\">" + freeport + "</attribute>");
  +         buf.append("      <attribute name=\"serverSocketFactory\">");
  +         buf.append(         getUniqueServerSocketFactoryClass());
  +         buf.append("      </attribute>");
  +         buf.append("      <attribute name=\"socketFactory\">");
  +         buf.append(         getUniqueSocketFactoryClass());
  +         buf.append("      </attribute>");
  +         buf.append("   </invoker>");
  +         buf.append("</config>");
  +         ByteArrayInputStream bais = new ByteArrayInputStream(buf.toString().getBytes());
  +         Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bais);
  +         connector.setConfiguration(xml.getDocumentElement());
  +         
            connector.create();
            connector.addInvocationHandler("sample", new SampleInvocationHandler());
            connector.start();
  @@ -475,6 +536,7 @@
            cconfig.put(SSLSocketBuilder.REMOTING_TRUST_STORE_FILE_PATH, trustStoreFilePath);
            cconfig.put(SSLSocketBuilder.REMOTING_TRUST_STORE_PASSWORD, "unit-tests-client");
            
  +         InvokerLocator locator = new InvokerLocator(getTransport() + "://" + getHostName() + ":" + freeport);
            Client client = new Client(locator, cconfig);
            client.connect();
   
  @@ -532,7 +594,159 @@
      }
      
      
  -   public void testFactoriesByClassName()
  +   public void testFactoriesByClassNameInXmlDoc()
  +   {
  +      try
  +      {
  +         /////////////////////////////////////
  +         /////    Do server side test.    //// 
  +         /////////////////////////////////////
  +         HashMap sconfig = new HashMap();
  +         
  +         // Put class names of ServerSocketFactory and SocketFactory in config map.
  +         sconfig.put(ServerInvoker.SERVER_SOCKET_FACTORY, ServerSocketFactory.getDefault().getClass().getName());
  +         sconfig.put(Remoting.SOCKET_FACTORY_NAME, SocketFactory.getDefault().getClass().getName());
  +         
  +         // Make callback Client use remote invoker.
  +         sconfig.put(InvokerLocator.FORCE_REMOTE, "true");
  +         
  +         // Special case: tell HTTPSClientInvoker to ignore hostname in certificates.
  +         // This is because InvokerLocator turns "localhost" into "127.0.0.1". Should
  +         // be fixed by JBREM-497.
  +         sconfig.put(HTTPSClientInvoker.IGNORE_HTTPS_HOST, "true");
  +         
  +         // Put ServerSocketFactory MBean name in config map.
  +         ServerSocketFactory serverSocketService = getDefaultServerSocketFactory();
  +         String serverSocketFactoryName = "jboss:type=serversocketfactory";
  +         ObjectName objName = new ObjectName(serverSocketFactoryName);
  +         MBeanServer mbeanServer = MBeanServerFactory.createMBeanServer();
  +         mbeanServer.registerMBean(serverSocketService, objName);
  +         sconfig.put(ServerInvoker.SERVER_SOCKET_FACTORY, serverSocketFactoryName);
  +         
  +         // Put SSL keystore parameters in config map.
  +         sconfig.put(SSLSocketBuilder.REMOTING_SERVER_SOCKET_USE_CLIENT_MODE, "true");
  +         sconfig.put(SSLSocketBuilder.REMOTING_KEY_STORE_TYPE, "JKS");
  +         String keyStoreFilePath = getKeystoreFilePath();
  +         sconfig.put(SSLSocketBuilder.REMOTING_KEY_STORE_FILE_PATH, keyStoreFilePath);
  +         sconfig.put(SSLSocketBuilder.REMOTING_KEY_STORE_PASSWORD, "unit-tests-server");
  +         
  +         // Put SSL truststore parameters in config map.
  +         sconfig.put(SSLSocketBuilder.REMOTING_SOCKET_USE_CLIENT_MODE, "true");
  +         sconfig.put(SSLSocketBuilder.REMOTING_TRUST_STORE_TYPE, "JKS");
  +         String trustStoreFilePath = getTruststoreFilePath();
  +         sconfig.put(SSLSocketBuilder.REMOTING_TRUST_STORE_FILE_PATH, trustStoreFilePath);
  +         sconfig.put(SSLSocketBuilder.REMOTING_TRUST_STORE_PASSWORD, "unit-tests-client");
  +         
  +         Connector connector = new Connector(sconfig);
  +         
  +         // Create and set xml configuration document.
  +         int freeport = PortUtil.findFreePort(getHostName());
  +         StringBuffer buf = new StringBuffer();
  +         buf.append("<?xml version=\"1.0\"?>\n");
  +         buf.append("<config>");
  +         buf.append("   <invoker transport=\"" + getTransport() + "\">");
  +         buf.append("      <attribute name=\"serverBindAddress\">" + getHostName() + "</attribute>");
  +         buf.append("      <attribute name=\"serverBindPort\">" + freeport + "</attribute>");
  +         buf.append("      <attribute name=\"serverSocketFactory\">" +
  +                              getUniqueServerSocketFactoryClass().getName() +
  +                          "</attribute>");
  +         buf.append("      <attribute name=\"socketFactory\">");
  +         buf.append(         getUniqueCallbackSocketFactoryClass().getName());
  +         buf.append(      "</attribute>");
  +         buf.append("   </invoker>");
  +         buf.append("</config>");
  +         ByteArrayInputStream bais = new ByteArrayInputStream(buf.toString().getBytes());
  +         Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bais);
  +         connector.setConfiguration(xml.getDocumentElement());
  +         
  +         connector.create();
  +         connector.addInvocationHandler("sample", new SampleInvocationHandler());
  +         connector.start();
  +
  +         // Verify ServerSocketFactory is the one passed in config map.
  +         ServerInvoker serverInvoker = connector.getServerInvoker();
  +         assertTrue(getUniqueServerSocketFactoryClass() ==
  +                    serverInvoker.getServerSocketFactory().getClass());
  +         
  +         
  +         /////////////////////////////////////
  +         /////    Do client side test.    //// 
  +         /////////////////////////////////////
  +         HashMap cconfig = new HashMap();
  +         
  +         // Put SocketFactory class name in config map.
  +         cconfig.put(Remoting.SOCKET_FACTORY_NAME, getUniqueSocketFactoryClass().getName());
  +         
  +         // Make Client use remote invoker.
  +         cconfig.put(InvokerLocator.FORCE_REMOTE, "true");
  +         
  +         // Put SSL parameters in config map.
  +         cconfig.put(SSLSocketBuilder.REMOTING_SOCKET_USE_CLIENT_MODE, "true");
  +         cconfig.put(SSLSocketBuilder.REMOTING_TRUST_STORE_TYPE, "JKS");
  +         trustStoreFilePath = getTruststoreFilePath();
  +         cconfig.put(SSLSocketBuilder.REMOTING_TRUST_STORE_FILE_PATH, trustStoreFilePath);
  +         cconfig.put(SSLSocketBuilder.REMOTING_TRUST_STORE_PASSWORD, "unit-tests-client");
  +         
  +         InvokerLocator locator = new InvokerLocator(getTransport() + "://" + getHostName() + ":" + freeport);
  +         Client client = new Client(locator, cconfig);
  +         client.connect();
  +
  +         // Verify SocketFactory is the one passed in config map.
  +         ClientInvoker clientInvoker = client.getInvoker();
  +         assertTrue(getUniqueSocketFactoryClass() == clientInvoker.getSocketFactory().getClass());
  +         
  +         
  +         //////////////////////////////////////////////
  +         /////     Do server side callback test.   //// 
  +         //////////////////////////////////////////////
  +         Thread.sleep(500);
  +         freeport = PortUtil.findFreePort(getHostName());
  +         InvokerLocator callbackLocator = new InvokerLocator(getTransport() + "://" + getHostName() + ":" + freeport);
  +         Connector callbackConnector = new Connector(callbackLocator.getLocatorURI());
  +         ServerSocketFactory ssf3 = getDefaultCallbackServerSocketFactory();
  +         callbackConnector.setServerSocketFactory(ssf3);
  +         callbackConnector.create();
  +         callbackConnector.addInvocationHandler("sample", new SampleInvocationHandler());
  +         callbackConnector.start();
  +         
  +         CallbackHandler callbackHandler = new CallbackHandler();
  +         String callbackHandleObject = "myCallbackHandleObject";
  +         client.addListener(callbackHandler, callbackLocator, callbackHandleObject);
  +         
  +         // Verify that callback succeeded.
  +         assertEquals(1, callbackHandler.getCallbacks().size());
  +         
  +         // Verify callback SocketFactory is the one passed in config map.
  +         Field field = ServerInvoker.class.getDeclaredField("handlers");
  +         field.setAccessible(true);
  +         Map handlers = (Map) field.get(serverInvoker);
  +         Object obj = handlers.values().iterator().next();
  +         SampleInvocationHandler sampleInvocationHandler = (SampleInvocationHandler) obj;
  +         obj = sampleInvocationHandler.getCallbackHandler();
  +         ServerInvokerCallbackHandler serverInvokerCallbackHandler = (ServerInvokerCallbackHandler) obj;
  +         field = ServerInvokerCallbackHandler.class.getDeclaredField("callBackClient");
  +         field.setAccessible(true);
  +         Client callbackClient = (Client) field.get(serverInvokerCallbackHandler);
  +         ClientInvoker callbackClientInvoker = callbackClient.getInvoker();
  +         assertTrue(getUniqueCallbackSocketFactoryClass() ==
  +                    callbackClientInvoker.getSocketFactory().getClass());
  +         
  +         client.disconnect();
  +         callbackConnector.stop();
  +         connector.stop();
  +         log.info(getName() + " PASSES");
  +      }
  +      catch (Throwable t)
  +      {
  +         log.error(t);
  +         t.printStackTrace();
  +         log.info(getName() + " FAILS");
  +         fail();
  +      }
  +   }
  +   
  +   
  +   public void testFactoriesByClassNameInConfigMap()
      {
         try
         {
  
  
  



More information about the jboss-cvs-commits mailing list