Package javax.net

Examples of javax.net.SocketFactory


     *                            Guacamole proxy server.
     */
    public SSLGuacamoleSocket(String hostname, int port) throws GuacamoleException {

        // Get factory for SSL sockets
        SocketFactory socket_factory = SSLSocketFactory.getDefault();
       
        try {

            logger.debug("Connecting to guacd at {}:{} via SSL/TLS.",
                    hostname, port);

            // Get address
            SocketAddress address = new InetSocketAddress(
                InetAddress.getByName(hostname),
                port
            );

            // Connect with timeout
            sock = socket_factory.createSocket();
            sock.connect(address, SOCKET_TIMEOUT);

            // Set read timeout
            sock.setSoTimeout(SOCKET_TIMEOUT);

View Full Code Here


   * @return a socket factory
   */
  public static SocketFactory getSocketFactory(Configuration conf,
      Class<?> clazz) {

    SocketFactory factory = null;

    String propValue =
        conf.get("hadoop.rpc.socket.factory.class." + clazz.getSimpleName());
    if ((propValue != null) && (propValue.length() > 0))
      factory = getSocketFactoryFromProperty(conf, propValue);
View Full Code Here

  /**
   * Test that, if the socket factory throws an IOE, it properly propagates
   * to the client.
   */
  public void testSocketFactoryException() throws Exception {
    SocketFactory mockFactory = mock(SocketFactory.class);
    doThrow(new IOException("Injected fault")).when(mockFactory).createSocket();
    Client client = new Client(LongWritable.class, conf, mockFactory);
   
    InetSocketAddress address = new InetSocketAddress("127.0.0.1", 10);
    try {
View Full Code Here

    ) throws IOException, UnknownHostException, ConnectTimeoutException {
        if (params == null) {
            throw new IllegalArgumentException("Parameters may not be null");
        }
        int timeout = params.getConnectionTimeout();
        SocketFactory socketfactory = getSSLContext().getSocketFactory();
        if (timeout == 0) {
            return socketfactory.createSocket(host, port, localAddress, localPort);
        } else {
            Socket socket = socketfactory.createSocket();
            SocketAddress localaddr = new InetSocketAddress(localAddress, localPort);
            SocketAddress remoteaddr = new InetSocketAddress(host, port);
            socket.bind(localaddr);
            socket.connect(remoteaddr, timeout);
            return socket;
View Full Code Here

  }

  @Test
  public void testRTEDuringConnectionSetup() throws Exception {
    Configuration conf = HBaseConfiguration.create();
    SocketFactory spyFactory = spy(NetUtils.getDefaultSocketFactory(conf));
    Mockito.doAnswer(new Answer<Socket>() {
      @Override
      public Socket answer(InvocationOnMock invocation) throws Throwable {
        Socket s = spy((Socket)invocation.callRealMethod());
        doThrow(new RuntimeException("Injected fault")).when(s).setSoTimeout(anyInt());
View Full Code Here

        Tomcat.addServlet(ctx, servletName, servlet);
        ctx.addServletMapping("/", servletName);
        tomcat.getConnector().setProperty("socket.txBufSize", "1024");
        tomcat.start();

        SocketFactory factory = SocketFactory.getDefault();
        Socket s = factory.createSocket("localhost", getPort());

        ByteChunk result = new ByteChunk();
        OutputStream os = s.getOutputStream();
        os.write(("GET / HTTP/1.1\r\n" +
                "Host: localhost:" + getPort() + "\r\n" +
View Full Code Here

        Tomcat.addServlet(ctx, servletName, servlet);
        ctx.addServletMapping("/", servletName);
        tomcat.getConnector().setProperty("socket.txBufSize", "1024");
        tomcat.start();

        SocketFactory factory = SocketFactory.getDefault();
        Socket s = factory.createSocket("localhost", getPort());

        ByteChunk result = new ByteChunk();
        OutputStream os = s.getOutputStream();
        os.write(("GET / HTTP/1.1\r\n" +
                "Host: localhost:" + getPort() + "\r\n" +
View Full Code Here

         return null;

      if (socketFactory != null)
         return socketFactory;

      SocketFactory factory = null;

      Object obj = configuration.get(Remoting.CUSTOM_SOCKET_FACTORY);
      if (obj != null)
      {
         if (obj instanceof SocketFactory)
View Full Code Here

      _socket = ss.accept ();
    }
  else
    {
      // Get a client socket (the factory will connect it)
      SocketFactory sf = SocketFactory.getDefault ();
      _socket = sf.createSocket (_host, _port);
    }
      }
    catch (IOException ioe)
      {
  // This will grab UnknownHostException, too.
View Full Code Here

         HashMap sconfig = new HashMap();
        
         // Put ServerSocketFactory and SocketFactory in config map.
         ServerSocketFactory ssf1 = getDefaultServerSocketFactory();
         sconfig.put(Remoting.CUSTOM_SERVER_SOCKET_FACTORY, ssf1);
         SocketFactory sf1 = getDefaultCallbackSocketFactory();
         sconfig.put(Remoting.CUSTOM_SOCKET_FACTORY, sf1);
        
         // 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);
         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");
        
View Full Code Here

TOP

Related Classes of javax.net.SocketFactory

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.