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) {
}
}
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) {
}
}
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) {
}
}
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);
}
}
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;
}
}
Aggregations