Package org.jboss.remoting.transport

Examples of org.jboss.remoting.transport.Connector


      log.info("entering " + getName());
      String host = InetAddress.getLocalHost().getHostAddress();
      int port = PortUtil.findFreePort(host);
      String locatorURI = getTransport() + "://" + host + ":" + port;
      InvokerLocator locator = new InvokerLocator(locatorURI);
      Connector connector = new Connector(locator);
      connector.create();
      connector.addInvocationHandler("test", new TestHandler());
      connector.start();
     
      HashMap config = new HashMap();
      config.put(InvokerLocator.FORCE_REMOTE, "true");
      TestListener listener1 = new TestListener();
      config.put(Remoting.SOCKET_CREATION_CLIENT_LISTENER, listener1);
      TestListener listener2 = new TestListener();
      config.put(Remoting.SOCKET_CREATION_SERVER_LISTENER, listener2);
      Client client = new Client(locator, config);
      assertFalse(listener1.visited());
      assertFalse(listener2.visited());
      client.connect();
      Integer i = (Integer) client.invoke(new Integer(17));
      assertEquals(18, i.intValue());
      Thread.sleep(500);
      assertTrue(listener1.visited());
      assertFalse(listener2.visited());
     
      client.disconnect();
      connector.stop();
      log.info(getName() + " PASSES");
   }
View Full Code Here


  
   protected void doTest(String host) throws Throwable
   {
      MBeanServer server = MBeanServerFactory.createMBeanServer();

      Connector connector = new Connector();
      port = PortUtil.findFreePort(host);
      locatorURI = getTransport() + "://" + host + ":" + port;
      serverLocator = new InvokerLocator(locatorURI);
      connector.setInvokerLocator(locatorURI);
      ObjectName obj = new ObjectName("jboss.remoting:type=Connector,transport=" + getTransport());
      server.registerMBean(connector, obj);
      connector.create();
      invocationHandler = new TestInvocationHandler();
      connector.addInvocationHandler("test", invocationHandler);
      connector.start();
     
      ServerInvoker serverInvoker = connector.getServerInvoker();
      ObjectName objectName = new ObjectName(serverInvoker.getMBeanObjectName());
      assertTrue(objectName.getCanonicalName().indexOf(host) >= 0);
      assertTrue(server.isRegistered(objectName));
      log.info(objectName + " is registered");
     
View Full Code Here

      serverConfig.put(Remoting.CUSTOM_SERVER_SOCKET_FACTORY, ssf);
      TestListener listener1 = new TestListener();
      serverConfig.put(Remoting.SOCKET_CREATION_SERVER_LISTENER, listener1);
      TestListener listener2 = new TestListener();
      serverConfig.put(Remoting.SOCKET_CREATION_CLIENT_LISTENER, listener2);
      Connector connector = new Connector(locator, serverConfig);
      connector.create();
      connector.addInvocationHandler("test", new TestHandler());
      connector.start();
     
      HashMap clientConfig = new HashMap();
      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
      Client client = new Client(locator, clientConfig);
      client.connect();
      Integer i = (Integer) client.invoke(new Integer(29));
      assertEquals(30, i.intValue());
      Thread.sleep(500);
      assertTrue(listener1.visited());
      assertFalse(listener2.visited());
     
      client.disconnect();
      connector.stop();
      log.info(getName() + " PASSES");
   }
View Full Code Here

      serverConfig.put(Remoting.SOCKET_CREATION_SERVER_LISTENER, listener1);
      TestListener listener2 = new TestListener();
      log.info("listener2: " + listener2);
      serverConfig.put(Remoting.SOCKET_CREATION_CLIENT_LISTENER, listener2);
      addExtraServerConfig(serverConfig);
      Connector connector = new Connector(locator, serverConfig);
      connector.create();
      connector.addInvocationHandler("test", new TestHandler());
      connector.start();
     
      HashMap clientConfig = new HashMap();
      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
      TestListener listener3 = new TestListener();
      log.info("listener3: " + listener3);
      clientConfig.put(Remoting.SOCKET_CREATION_CLIENT_LISTENER, listener3);
      TestListener listener4 = new TestListener();
      log.info("listener4: " + listener4);
      clientConfig.put(Remoting.SOCKET_CREATION_SERVER_LISTENER, listener4);
      addExtraClientConfig(clientConfig);
      Client client = new Client(locator, clientConfig);
      client.connect();
      client.addListener(new TestCallbackHandler(), null, null, true);
      Integer i = (Integer) client.invoke(new Integer(29));
      assertEquals(30, i.intValue());
      Thread.sleep(500);
      assertTrue(checkListenersVisited(listener1, listener2, listener3, listener4));
     
      client.disconnect();
      connector.stop();
      log.info(getName() + " PASSES");
   }
View Full Code Here

      serverLocator = new InvokerLocator(locatorURI);
      log.info("Starting remoting server with locator uri of: " + locatorURI);
      HashMap config = new HashMap();
      config.put(InvokerLocator.FORCE_REMOTE, "true");
      addExtraServerConfig(config);
      connector = new Connector(serverLocator, config);
      connector.create();
      invocationHandler = new TestInvocationHandler();
      connector.addInvocationHandler("test", invocationHandler);
      connector.start();
   }
View Full Code Here

         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);
         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();
        
         // Set ServerSocketFactory and SocketFactory in ServerInvoker.
         ServerInvoker serverInvoker = connector.getServerInvoker();
         ServerSocketFactory ssf2 = getDefaultServerSocketFactory();
         serverInvoker.setServerSocketFactory(ssf2);
         SocketFactory sf2 = getDefaultCallbackSocketFactory();
         serverInvoker.setSocketFactory(sf2);

         connector.addInvocationHandler("sample", new SampleInvocationHandler());
         connector.start();

         // Verify ServerSocketFactory is the one set in ServerInvoker.
         assertTrue(ssf2 == serverInvoker.getServerSocketFactory());
        
        
         /////////////////////////////////////
         /////    Do client side test.    ////
         /////////////////////////////////////
         HashMap cconfig = new HashMap();
        
         // Put SocketFactory in config map.
         SocketFactory sf3 = getDefaultSocketFactory();
         cconfig.put(Remoting.CUSTOM_SOCKET_FACTORY, sf3);
        
         // 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();
        
         // 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());
        
        
         //////////////////////////////////////////////
         /////     Do server side callback test.   ////
         //////////////////////////////////////////////
         Thread.sleep(500);
         freeport = PortUtil.findFreePort(getHostName());
         InvokerLocator callbackLocator = new InvokerLocator(getTransport() + "://" + getHostName() + ":" + freeport);
         HashMap config = new HashMap();
         addExtraCallbackConfig(config);
         Connector callbackConnector = new Connector(callbackLocator.getLocatorURI(), config);
         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 set in SocketInvoker.
         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(sf2 == callbackClientInvoker.getSocketFactory());
        
         client.disconnect();
         callbackConnector.stop();
         connector.stop();
         log.info(getName() + " PASSES");
      }
      catch (Throwable t)
      {
View Full Code Here

      log.info("entering " + getName());
      String host = InetAddress.getLocalHost().getHostAddress();
      int port = PortUtil.findFreePort(host);
      String locatorURI = getTransport() + "://" + host + ":" + port;
      InvokerLocator locator = new InvokerLocator(locatorURI);
      Connector connector = new Connector(locator);
      connector.create();
      connector.addInvocationHandler("test", new TestHandler());
      connector.start();
     
      HashMap config = new HashMap();
      config.put(InvokerLocator.FORCE_REMOTE, "true");
      FailingTestListener listener = new FailingTestListener();
      config.put(Remoting.SOCKET_CREATION_CLIENT_LISTENER, listener);
      Client client = new Client(locator, config);
     
      try
      {
        
         client.connect();
         client.invoke(new Integer(17));
         fail("didn't get expected exception");
      }
      catch (Exception e)
      {
         log.info("CAUGHT EXPECTED EXCEPTION");
      }
     
      client.disconnect();
      connector.stop();
      log.info(getName() + " PASSES");
   }
View Full Code Here

   public void testBindingWithLocatorByName() throws Exception
   {
      System.setProperty(InvokerLocator.BIND_BY_HOST, "true");
      String locatorUrl = "socket://0.0.0.0:5600";

      Connector connector = new Connector(locatorUrl);
      connector.create();
      connector.start();

      // Verify that the InvokerLocator host is set properly.
      String connectorLocatorUrl = connector.getInvokerLocator();
      System.out.println("connector locator = " + connectorLocatorUrl);
      String hostName = InetAddress.getLocalHost().getHostName();
      assertFalse(-1 == connectorLocatorUrl.indexOf(hostName));

      // Verify that the ServerSocket is bound to address 0.0.0.0.
      ServerInvoker si = connector.getServerInvoker();
      assertTrue(si instanceof SocketServerInvoker);
      SocketServerInvoker ssi = (SocketServerInvoker) si;
      Field field = SocketServerInvoker.class.getDeclaredField("serverSocket");
      field.setAccessible(true);
      ServerSocket ss = (ServerSocket) field.get(ssi);
      assertNotNull(ss);
      System.out.println("ServerSocket bind address: " + ss.getInetAddress());
      InetAddress inetAddress = ss.getInetAddress();
      assertNotNull(inetAddress);
      assertEquals("0.0.0.0", inetAddress.getHostAddress());
     
      connector.stop();
      connector.destroy();
     
      // Make sure ServerInvoker was destroyed, which implies it was reregistered
      // under correct InvokerLocator.
      assertEquals(0, InvokerRegistry.getServerInvokers().length);
   }
View Full Code Here

      HashMap serverConfig = new HashMap();
      ServerSocketFactory ssf = getServerSocketFactory();
      serverConfig.put(Remoting.CUSTOM_SERVER_SOCKET_FACTORY, ssf);
      FailingTestListener listener = new FailingTestListener();
      serverConfig.put(Remoting.SOCKET_CREATION_SERVER_LISTENER, listener);
      Connector connector = new Connector(locator, serverConfig);
      connector.create();
      connector.addInvocationHandler("test", new TestHandler());
      connector.start();
     
      HashMap clientConfig = new HashMap();
      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
      clientConfig.put(ServerInvoker.TIMEOUT, "1000");
      final Client client = new Client(locator, clientConfig);
     
      class TestThread extends Thread
      {
         public boolean failed = false;
        
         public void run()
         {
            try
            {
               client.connect();
               client.invoke(new Integer(29));
               failed = true;
               client.disconnect();
               fail("invoke() should have timed out");
            }
            catch (Throwable t)
            {
               log.info("CAUGHT EXPECTED EXCEPTION");
            }
         }
      };

      TestThread t = new TestThread();
      t.start();
      Thread.sleep(2000);
      assertFalse(t.failed);
      connector.stop();
      log.info(getName() + " PASSES");
   }
View Full Code Here

   public void testBindingWithLocatorByAddress() throws Exception
   {
      System.setProperty(InvokerLocator.BIND_BY_HOST, "false");
      String locatorUrl = "socket://0.0.0.0:5600";

      Connector connector = new Connector(locatorUrl);
      connector.create();
      connector.start();

      // Verify that the InvokerLocator host is set properly.
      String connectorLocatorUrl = connector.getInvokerLocator();
      System.out.println("connector locator = " + connectorLocatorUrl);
      String hostName = InetAddress.getLocalHost().getHostAddress();
      assertFalse(-1 == connectorLocatorUrl.indexOf(hostName));

      // Verify that the ServerSocket is bound to address 0.0.0.0.
      ServerInvoker si = connector.getServerInvoker();
      assertTrue(si instanceof SocketServerInvoker);
      SocketServerInvoker ssi = (SocketServerInvoker) si;
      Field field = SocketServerInvoker.class.getDeclaredField("serverSocket");
      field.setAccessible(true);
      ServerSocket ss = (ServerSocket) field.get(ssi);
      assertNotNull(ss);
      System.out.println("ServerSocket bind address: " + ss.getInetAddress());
      InetAddress inetAddress = ss.getInetAddress();
      assertNotNull(inetAddress);
      assertEquals("0.0.0.0", inetAddress.getHostAddress());
     
      connector.stop();
      connector.destroy();
     
      // Make sure ServerInvoker was destroyed, which implies it was reregistered
      // under correct InvokerLocator.
      assertEquals(0, InvokerRegistry.getServerInvokers().length);
   }
View Full Code Here

TOP

Related Classes of org.jboss.remoting.transport.Connector

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.