Search in sources :

Example 41 with SocketFactory

use of javax.net.SocketFactory in project java-apns by notnoop.

the class ApnsFeedbackConnectionTest method connectionParsedThree.

@Test
public void connectionParsedThree() {
    SocketFactory sf = MockingUtils.mockSocketFactory(null, threeStream);
    ApnsFeedbackConnection connection = new ApnsFeedbackConnection(sf, "localhost", 80);
    checkParsedThree(connection.getInactiveDevices());
}
Also used : SocketFactory(javax.net.SocketFactory) Test(org.junit.Test)

Example 42 with SocketFactory

use of javax.net.SocketFactory in project jodd by oblac.

the class SocketHttpConnectionProvider method createSSLSocket.

/**
	 * Creates a SSL socket. Enables default secure enabled protocols if specified.
	 */
protected SSLSocket createSSLSocket(String host, int port, int connectionTimeout, boolean trustAll, boolean verifyHttpsHost) throws IOException {
    SocketFactory socketFactory = getSocketFactory(proxy, true, trustAll);
    Socket socket;
    if (connectionTimeout < 0) {
        socket = socketFactory.createSocket(host, port);
    } else {
        // creates unconnected socket
        // unfortunately, this does not work always
        //			sslSocket = (SSLSocket) socketFactory.createSocket();
        //			sslSocket.connect(new InetSocketAddress(host, port), connectionTimeout);
        //
        // Note: SSLSocketFactory has several create() methods.
        // Those that take arguments all connect immediately
        // and have no options for specifying a connection timeout.
        //
        // So, we have to create a socket and connect it (with a
        // connection timeout), then have the SSLSocketFactory wrap
        // the already-connected socket.
        //
        socket = new Socket();
        //sock.setSoTimeout(readTimeout);
        socket.connect(new InetSocketAddress(host, port), connectionTimeout);
    // continue to wrap this plain socket with ssl socket...
    }
    // wrap plain socket in an SSL socket
    SSLSocket sslSocket;
    if (socket instanceof SSLSocket) {
        sslSocket = (SSLSocket) socket;
    } else {
        if (socketFactory instanceof SSLSocketFactory) {
            sslSocket = (SSLSocket) ((SSLSocketFactory) socketFactory).createSocket(socket, host, port, true);
        } else {
            sslSocket = (SSLSocket) (getDefaultSSLSocketFactory(trustAll)).createSocket(socket, host, port, true);
        }
    }
    // sslSocket is now ready
    String enabledProtocols = JoddHttp.defaultSecureEnabledProtocols;
    if (enabledProtocols != null) {
        String[] values = StringUtil.splitc(enabledProtocols, ',');
        StringUtil.trimAll(values);
        sslSocket.setEnabledProtocols(values);
    }
    if (verifyHttpsHost) {
        SSLParameters sslParams = new SSLParameters();
        sslParams.setEndpointIdentificationAlgorithm("HTTPS");
        sslSocket.setSSLParameters(sslParams);
    }
    return sslSocket;
}
Also used : SSLParameters(javax.net.ssl.SSLParameters) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) SocketFactory(javax.net.SocketFactory) InetSocketAddress(java.net.InetSocketAddress) SSLSocket(javax.net.ssl.SSLSocket) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) Socket(java.net.Socket) SSLSocket(javax.net.ssl.SSLSocket)

Example 43 with SocketFactory

use of javax.net.SocketFactory in project jodd by oblac.

the class SocketHttpConnectionProvider method createSocket.

/**
	 * Creates a socket using socket factory.
	 */
protected Socket createSocket(String host, int port, int connectionTimeout) throws IOException {
    SocketFactory socketFactory = getSocketFactory(proxy, false, false);
    if (connectionTimeout < 0) {
        return socketFactory.createSocket(host, port);
    } else {
        // creates unconnected socket
        Socket socket = socketFactory.createSocket();
        socket.connect(new InetSocketAddress(host, port), connectionTimeout);
        return socket;
    }
}
Also used : SSLSocketFactory(javax.net.ssl.SSLSocketFactory) SocketFactory(javax.net.SocketFactory) InetSocketAddress(java.net.InetSocketAddress) Socket(java.net.Socket) SSLSocket(javax.net.ssl.SSLSocket)

Example 44 with SocketFactory

use of javax.net.SocketFactory in project hadoop by apache.

the class HAServiceTarget method getProxyForAddress.

private HAServiceProtocol getProxyForAddress(Configuration conf, int timeoutMs, InetSocketAddress addr) throws IOException {
    Configuration confCopy = new Configuration(conf);
    // Lower the timeout so we quickly fail to connect
    confCopy.setInt(CommonConfigurationKeysPublic.IPC_CLIENT_CONNECT_MAX_RETRIES_KEY, 1);
    SocketFactory factory = NetUtils.getDefaultSocketFactory(confCopy);
    return new HAServiceProtocolClientSideTranslatorPB(addr, confCopy, factory, timeoutMs);
}
Also used : HAServiceProtocolClientSideTranslatorPB(org.apache.hadoop.ha.protocolPB.HAServiceProtocolClientSideTranslatorPB) Configuration(org.apache.hadoop.conf.Configuration) SocketFactory(javax.net.SocketFactory)

Example 45 with SocketFactory

use of javax.net.SocketFactory in project hadoop by apache.

the class HAServiceTarget method getZKFCProxy.

/**
   * @return a proxy to the ZKFC which is associated with this HA service.
   */
public ZKFCProtocol getZKFCProxy(Configuration conf, int timeoutMs) throws IOException {
    Configuration confCopy = new Configuration(conf);
    // Lower the timeout so we quickly fail to connect
    confCopy.setInt(CommonConfigurationKeysPublic.IPC_CLIENT_CONNECT_MAX_RETRIES_KEY, 1);
    SocketFactory factory = NetUtils.getDefaultSocketFactory(confCopy);
    return new ZKFCProtocolClientSideTranslatorPB(getZKFCAddress(), confCopy, factory, timeoutMs);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) SocketFactory(javax.net.SocketFactory) ZKFCProtocolClientSideTranslatorPB(org.apache.hadoop.ha.protocolPB.ZKFCProtocolClientSideTranslatorPB)

Aggregations

SocketFactory (javax.net.SocketFactory)66 Socket (java.net.Socket)25 Test (org.junit.Test)25 IOException (java.io.IOException)18 InetSocketAddress (java.net.InetSocketAddress)14 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 SSLSocket (javax.net.ssl.SSLSocket)10 OutputStream (java.io.OutputStream)9 ServerSocket (java.net.ServerSocket)9 SocketAddress (java.net.SocketAddress)6 Configuration (org.apache.hadoop.conf.Configuration)5 ServerSocketFactory (javax.net.ServerSocketFactory)4 InputStream (java.io.InputStream)3 InetAddress (java.net.InetAddress)3 UnknownHostException (java.net.UnknownHostException)3 ProtocolSocketFactory (org.apache.commons.httpclient.protocol.ProtocolSocketFactory)3 StandardSocketFactory (org.apache.hadoop.net.StandardSocketFactory)3 ByteChunk (org.apache.tomcat.util.buf.ByteChunk)3 SocketException (java.net.SocketException)2