Search in sources :

Example 1 with ServerSocketFactory

use of javax.net.ServerSocketFactory in project robovm by robovm.

the class MyServerSocketFactory method test_createServerSocket_I.

public final void test_createServerSocket_I() throws Exception {
    ServerSocketFactory sf = ServerSocketFactory.getDefault();
    ServerSocket ss = sf.createServerSocket(0);
    assertNotNull(ss);
    try {
        sf.createServerSocket(ss.getLocalPort());
        fail("IOException wasn't thrown");
    } catch (IOException expected) {
    }
    ss.close();
    try {
        sf.createServerSocket(-1);
        fail("IllegalArgumentException wasn't thrown");
    } catch (IllegalArgumentException expected) {
    }
}
Also used : ServerSocketFactory(javax.net.ServerSocketFactory) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException)

Example 2 with ServerSocketFactory

use of javax.net.ServerSocketFactory in project robovm by robovm.

the class MyServerSocketFactory method test_createServerSocket_II.

public final void test_createServerSocket_II() throws Exception {
    ServerSocketFactory sf = ServerSocketFactory.getDefault();
    ServerSocket ss = sf.createServerSocket(0, 0);
    assertNotNull(ss);
    try {
        sf.createServerSocket(ss.getLocalPort(), 0);
        fail("IOException wasn't thrown");
    } catch (IOException expected) {
    }
    ss.close();
    try {
        sf.createServerSocket(65536, 0);
        fail("IllegalArgumentException wasn't thrown");
    } catch (IllegalArgumentException expected) {
    }
}
Also used : ServerSocketFactory(javax.net.ServerSocketFactory) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException)

Example 3 with ServerSocketFactory

use of javax.net.ServerSocketFactory in project robovm by robovm.

the class MyServerSocketFactory method test_createServerSocket_IIInetAddress.

public final void test_createServerSocket_IIInetAddress() throws Exception {
    ServerSocketFactory sf = ServerSocketFactory.getDefault();
    ServerSocket ss = sf.createServerSocket(0, 0, InetAddress.getLocalHost());
    assertNotNull(ss);
    try {
        sf.createServerSocket(ss.getLocalPort(), 0, InetAddress.getLocalHost());
        fail("IOException wasn't thrown");
    } catch (IOException expected) {
    }
    ss.close();
    try {
        sf.createServerSocket(Integer.MAX_VALUE, 0, InetAddress.getLocalHost());
        fail("IllegalArgumentException wasn't thrown");
    } catch (IllegalArgumentException expected) {
    }
}
Also used : ServerSocketFactory(javax.net.ServerSocketFactory) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException)

Example 4 with ServerSocketFactory

use of javax.net.ServerSocketFactory in project jdk8u_jdk by JetBrains.

the class DefaultSSLServSocketFac method main.

public static void main(String[] args) throws Exception {
    // reserve the security properties
    String reservedSSFacProvider = Security.getProperty("ssl.ServerSocketFactory.provider");
    try {
        Security.setProperty("ssl.ServerSocketFactory.provider", "oops");
        ServerSocketFactory ssocketFactory = SSLServerSocketFactory.getDefault();
        SSLServerSocket sslServerSocket = (SSLServerSocket) ssocketFactory.createServerSocket();
    } catch (Exception e) {
        if (!(e.getCause() instanceof ClassNotFoundException)) {
            throw e;
        }
    // get the expected exception
    } finally {
        // restore the security properties
        if (reservedSSFacProvider == null) {
            reservedSSFacProvider = "";
        }
        Security.setProperty("ssl.ServerSocketFactory.provider", reservedSSFacProvider);
    }
}
Also used : ServerSocketFactory(javax.net.ServerSocketFactory) SSLServerSocketFactory(javax.net.ssl.SSLServerSocketFactory) SSLServerSocket(javax.net.ssl.SSLServerSocket)

Example 5 with ServerSocketFactory

use of javax.net.ServerSocketFactory in project geode by apache.

the class SocketCreator method createServerSocket.

private ServerSocket createServerSocket(int nport, int backlog, InetAddress bindAddr, int socketBufferSize, boolean sslConnection) throws IOException {
    printConfig();
    if (sslConnection) {
        if (this.sslContext == null) {
            throw new GemFireConfigException("SSL not configured correctly, Please look at previous error");
        }
        ServerSocketFactory ssf = this.sslContext.getServerSocketFactory();
        SSLServerSocket serverSocket = (SSLServerSocket) ssf.createServerSocket();
        serverSocket.setReuseAddress(true);
        // java.net.ServerSocket.setReceiverBufferSize javadocs)
        if (socketBufferSize != -1) {
            serverSocket.setReceiveBufferSize(socketBufferSize);
        }
        serverSocket.bind(new InetSocketAddress(bindAddr, nport), backlog);
        finishServerSocket(serverSocket);
        return serverSocket;
    } else {
        // log.info("Opening server socket on " + nport, new Exception("SocketCreation"));
        ServerSocket result = new ServerSocket();
        result.setReuseAddress(true);
        // java.net.ServerSocket.setReceiverBufferSize javadocs)
        if (socketBufferSize != -1) {
            result.setReceiveBufferSize(socketBufferSize);
        }
        try {
            result.bind(new InetSocketAddress(bindAddr, nport), backlog);
        } catch (BindException e) {
            BindException throwMe = new BindException(LocalizedStrings.SocketCreator_FAILED_TO_CREATE_SERVER_SOCKET_ON_0_1.toLocalizedString(new Object[] { bindAddr, Integer.valueOf(nport) }));
            throwMe.initCause(e);
            throw throwMe;
        }
        return result;
    }
}
Also used : GemFireConfigException(org.apache.geode.GemFireConfigException) ServerSocketFactory(javax.net.ServerSocketFactory) InetSocketAddress(java.net.InetSocketAddress) BindException(java.net.BindException) ServerSocket(java.net.ServerSocket) TransportFilterServerSocket(org.apache.geode.internal.cache.wan.TransportFilterServerSocket) SSLServerSocket(javax.net.ssl.SSLServerSocket) SSLServerSocket(javax.net.ssl.SSLServerSocket)

Aggregations

ServerSocketFactory (javax.net.ServerSocketFactory)9 ServerSocket (java.net.ServerSocket)6 IOException (java.io.IOException)4 SSLServerSocketFactory (javax.net.ssl.SSLServerSocketFactory)4 SSLServerSocket (javax.net.ssl.SSLServerSocket)3 BindException (java.net.BindException)2 InetSocketAddress (java.net.InetSocketAddress)2 SSLContext (javax.net.ssl.SSLContext)2 Field (java.lang.reflect.Field)1 SocketException (java.net.SocketException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 URI (java.net.URI)1 UnknownHostException (java.net.UnknownHostException)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 SocketFactory (javax.net.SocketFactory)1 KeyManager (javax.net.ssl.KeyManager)1 SSLContextSpi (javax.net.ssl.SSLContextSpi)1 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)1