Package org.jboss.remoting.transport

Examples of org.jboss.remoting.transport.Connector


      if (setUseClientIdentity)
      {
         config.put(Remoting.USE_CLIENT_CONNECTION_IDENTITY, useClientIdentity);
      }
      addExtraServerConfig(config);
      connector = new Connector(serverLocator, config);
      connector.create();
      invocationHandler = new TestInvocationHandler();
      connector.addInvocationHandler("test", invocationHandler);
      connector.start();
      listener = new TestConnectionListener();
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());
                 
         // Set ServerSocketFactory and SocketFactory in Connector.
         ServerSocketFactory ssf2 = getDefaultServerSocketFactory();
         connector.setServerSocketFactory(ssf2);
         SocketFactory sf2 = getDefaultCallbackSocketFactory();
         connector.setSocketFactory(sf2);
         connector.create();
         connector.addInvocationHandler("sample", new SampleInvocationHandler());
         connector.start();
        
         // Verify ServerSocketFactory is the one set in Connector.
         ServerInvoker serverInvoker = connector.getServerInvoker();
         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);
        
         // Set SocketFactory in Client.
         SocketFactory sf4 = getDefaultSocketFactory();
         client.setSocketFactory(sf4);
         client.connect();
        
         // Verify SocketFactory is the one set in Client.
         ClientInvoker clientInvoker = client.getInvoker();
         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 Connector.
         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");
      StaticTestListener.reset();
      String listenerClassName = StaticTestListener.class.getName();
      config.put(Remoting.SOCKET_CREATION_CLIENT_LISTENER, listenerClassName);
      Client client = new Client(locator, config);
      client.connect();
      Integer i = (Integer) client.invoke(new Integer(17));
      assertEquals(18, i.intValue());
      Thread.sleep(500);
      assertTrue(StaticTestListener.visited());
     
      client.disconnect();
      connector.stop();
      log.info(getName() + " PASSES");
   }
View Full Code Here

        .append("    <handler subsystem=\"test\">" + SampleInvocationHandler.class.getName() + "</handler>\n")
        .append("   </handlers>\n")
        .append("  </config>\n")
        .append(" </attribute>\n")
        .append("</mbean>\n").toString();
      Connector connector = new Connector();
      ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes());
      Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bais);
      Element element =  doc.getDocumentElement();
      connector.setConfiguration(element);
      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();
      System.out.println("hostName: " + hostName);
      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

      ServerSocketFactory ssf = getServerSocketFactory();
      serverConfig.put(Remoting.CUSTOM_SERVER_SOCKET_FACTORY, ssf);
      StaticTestListener.reset();
      String listenerClassName = StaticTestListener.class.getName();
      serverConfig.put(Remoting.SOCKET_CREATION_SERVER_LISTENER, listenerClassName);
      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(StaticTestListener.visited());
     
      client.disconnect();
      connector.stop();
      log.info(getName() + " PASSES");
   }
View Full Code Here

      String host = InetAddress.getLocalHost().getHostAddress();
      String locatorURI = getTransport() + "://" + host + ":" + port;
      InvokerLocator locator = new InvokerLocator(locatorURI);
      HashMap serverConfig = new HashMap();
      addServerConfig(serverConfig);
      connector = new Connector(locator, serverConfig);
      connector.create();
      connector.addInvocationHandler("test", new TestHandler());
      connector.addConnectionListener(new TestListener());
      connector.start();
   }
View Full Code Here

        .append("    <handler subsystem=\"test\">" + SampleInvocationHandler.class.getName() + "</handler>\n")
        .append("   </handlers>\n")
        .append("  </config>\n")
        .append(" </attribute>\n")
        .append("</mbean>\n").toString();
      Connector connector = new Connector();
      ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes());
      Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bais);
      Element element =  doc.getDocumentElement();
      connector.setConfiguration(element);
      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

      .append("    <handler subsystem=\"test\">" + SampleInvocationHandler.class.getName() + "</handler>\n")
      .append("   </handlers>\n")
      .append("  </config>\n")
      .append(" </attribute>\n")
      .append("</mbean>\n").toString();
      Connector connector = new Connector();
      ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes());
      Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bais);
      Element element =  doc.getDocumentElement();
      connector.setConfiguration(element);
      try
      {
         connector.create();
         InvokerLocator expected = new InvokerLocator("socket://" + getLocalHost() + ":" + port + "/?timeout=10000");
         InvokerLocator actual = connector.getLocator();
         log.info("Expected: " + expected);
         log.info("Actual:   " + actual);InetAddress.getLocalHost();
         assertEquals(expected, actual);
      }
      catch (Exception e)
      {
         log.error("Exception caught " + e.getMessage());
      }
      finally
      {
         connector.stop();
      }

      log.info(getName() + " PASSES");
   }
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();
         connector.addInvocationHandler("sample", new SampleInvocationHandler());
         connector.start();

         // Verify ServerSocketFactory is the one passed in config map.
         ServerInvoker serverInvoker = connector.getServerInvoker();
         assertTrue(ssf1 == serverInvoker.getServerSocketFactory());
        
        
         /////////////////////////////////////
         /////    Do client side test.    ////
         /////////////////////////////////////
         HashMap cconfig = new HashMap();
        
         // Put SocketFactory in config map.
         SocketFactory sf2 = getDefaultSocketFactory();
         cconfig.put(Remoting.CUSTOM_SOCKET_FACTORY, sf2);
        
         // 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(sf2 == 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 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(sf1 == callbackClientInvoker.getSocketFactory());
        
         client.disconnect();
         callbackConnector.stop();
         connector.stop();
         log.info(getName() + " PASSES");
      }
      catch (Throwable t)
      {
View Full Code Here

      .append("    <handler subsystem=\"test\">" + SampleInvocationHandler.class.getName() + "</handler>\n")
      .append("   </handlers>\n")
      .append("  </config>\n")
      .append(" </attribute>\n")
      .append("</mbean>\n").toString();
      Connector connector = new Connector();
      ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes());
      Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bais);
      Element element =  doc.getDocumentElement();
      connector.setConfiguration(element);
      try
      {
         connector.create();
         InvokerLocator expected = new InvokerLocator("socket://" + fixHostnameForURL(host) + ":" + port + "/?timeout=10000");
         InvokerLocator actual = connector.getLocator();
         log.info("Expected: " + expected);
         log.info("Actual:   " + actual);
         assertEquals(expected, actual);
         return true;
      }
      catch (Exception e)
      {
         log.error("Exception caught ", e);
         return false;
      }
      finally
      {
         connector.stop();
      }
   }
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.