use of javax.net.ServerSocketFactory in project robovm by robovm.
the class SSLContextTest method test_SSLContext_getServerSocketFactory.
public void test_SSLContext_getServerSocketFactory() throws Exception {
for (String protocol : StandardNames.SSL_CONTEXT_PROTOCOLS) {
if (protocol.equals(StandardNames.SSL_CONTEXT_PROTOCOLS_DEFAULT)) {
SSLContext.getInstance(protocol).getServerSocketFactory();
} else {
try {
SSLContext.getInstance(protocol).getServerSocketFactory();
fail();
} catch (IllegalStateException expected) {
}
}
SSLContext sslContext = SSLContext.getInstance(protocol);
if (!protocol.equals(StandardNames.SSL_CONTEXT_PROTOCOLS_DEFAULT)) {
sslContext.init(null, null, null);
}
ServerSocketFactory ssf = sslContext.getServerSocketFactory();
assertNotNull(ssf);
assertTrue(SSLServerSocketFactory.class.isAssignableFrom(ssf.getClass()));
}
}
use of javax.net.ServerSocketFactory in project robovm by robovm.
the class MyServerSocketFactory method test_createServerSocket.
public final void test_createServerSocket() throws Exception {
ServerSocketFactory sf = ServerSocketFactory.getDefault();
ServerSocket ss = sf.createServerSocket();
assertNotNull(ss);
ss.close();
}
use of javax.net.ServerSocketFactory in project geode by apache.
the class SecurityTestUtils method clearStaticSSLContext.
/**
* This is a hack using reflection to clear the static objects in JSSE since otherwise changing
* the javax.* store related properties has no effect during the course of running dunit suite
* unless the VMs are restarted.
*/
protected static void clearStaticSSLContext() {
ServerSocketFactory defaultServerFact = SSLServerSocketFactory.getDefault();
// Get the class of this and use reflection to blank out any static SSLContext objects inside
Map<Field, Object> contextMap = getSSLFields(defaultServerFact, new Class[] { SSLContext.class, SSLContextSpi.class });
makeNullSSLFields(defaultServerFact, contextMap);
for (Iterator contextObjsIter = contextMap.values().iterator(); contextObjsIter.hasNext(); ) {
Object contextObj = contextObjsIter.next();
Map<Field, Object> contextObjsMap = getSSLFields(contextObj, new Class[] { TrustManager.class, KeyManager.class, TrustManager[].class, KeyManager[].class });
makeNullSSLFields(contextObj, contextObjsMap);
}
makeNullStaticField(SSLServerSocketFactory.class);
// Do the same for normal SSL socket factory
SocketFactory defaultFact = SSLSocketFactory.getDefault();
contextMap = getSSLFields(defaultFact, new Class[] { SSLContext.class, SSLContextSpi.class });
makeNullSSLFields(defaultFact, contextMap);
for (Iterator contextObjsIter = contextMap.values().iterator(); contextObjsIter.hasNext(); ) {
Object contextObj = contextObjsIter.next();
Map<Field, Object> contextObjsMap = getSSLFields(contextObj, new Class[] { TrustManager.class, KeyManager.class, TrustManager[].class, KeyManager[].class });
makeNullSSLFields(contextObj, contextObjsMap);
}
makeNullStaticField(SSLSocketFactory.class);
makeNullStaticField(SSLContext.class);
}
use of javax.net.ServerSocketFactory in project tomee by apache.
the class ServiceDaemon method start.
@Override
public void start() throws ServiceException {
synchronized (this) {
// Don't bother if we are already started/starting
if (this.socketListener != null) {
return;
}
this.next.start();
final ServerSocket serverSocket;
try {
if (this.secure) {
final ServerSocketFactory factory = SSLServerSocketFactory.getDefault();
serverSocket = factory.createServerSocket(this.port, this.backlog, this.inetAddress);
((SSLServerSocket) serverSocket).setEnabledCipherSuites(this.enabledCipherSuites);
} else {
serverSocket = new ServerSocket();
serverSocket.setReuseAddress(true);
try {
serverSocket.bind(new InetSocketAddress(this.inetAddress, this.port), this.backlog);
} catch (final BindException e) {
//One retry - Port may be closing
Thread.sleep(1000);
serverSocket.bind(new InetSocketAddress(this.inetAddress, this.port), this.backlog);
}
}
serverSocket.setSoTimeout(this.timeout);
int serverPort = serverSocket.getLocalPort();
if (this.port == 0 && next.getName() != null) {
SystemInstance.get().getProperties().put(next.getName() + ".port", Integer.toString(serverPort));
this.port = serverPort;
}
} catch (Exception e) {
throw new ServiceException("Service failed to open socket", e);
}
this.socketListener = new SocketListener(this.next, serverSocket);
final Thread thread = new Thread(this.socketListener);
thread.setName("Service." + this.getName() + "@" + this.socketListener.hashCode());
thread.setDaemon(true);
thread.start();
final DiscoveryAgent agent = SystemInstance.get().getComponent(DiscoveryAgent.class);
if (agent != null && this.discoveryUriFormat != null) {
final Map<String, String> map = new HashMap<String, String>();
// add all the properties that were used to construct this service
for (final Map.Entry<Object, Object> entry : this.props.entrySet()) {
map.put(entry.getKey().toString(), entry.getValue().toString());
}
map.put("port", Integer.toString(this.port));
String address = this.ip;
if ("0.0.0.0".equals(address)) {
try {
address = InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
log.error("Failed to resolve 0.0.0.0 to a routable address", e);
}
}
map.put("host", address);
map.put("bind", address);
final String uriString = this.discoveryUriFormat.apply(map);
try {
this.serviceUri = new URI(uriString);
agent.registerService(this.serviceUri);
} catch (Exception e) {
log.error("Cannot register service '" + this.getName() + "' with DiscoveryAgent.", e);
}
}
}
}
Aggregations