use of java.rmi.server.RMIClientSocketFactory in project tomcat by apache.
the class JmxRemoteLifecycleListener method lifecycleEvent.
@Override
public void lifecycleEvent(LifecycleEvent event) {
// When the server starts, configure JMX/RMI
if (Lifecycle.START_EVENT.equals(event.getType())) {
// Configure using standard jmx system properties
init();
// Prevent an attacker guessing the RMI object ID
System.setProperty("java.rmi.server.randomIDs", "true");
// Create the environment
HashMap<String, Object> env = new HashMap<>();
RMIClientSocketFactory registryCsf = null;
RMIServerSocketFactory registrySsf = null;
RMIClientSocketFactory serverCsf = null;
RMIServerSocketFactory serverSsf = null;
// Configure registry socket factories
if (rmiRegistrySSL) {
registryCsf = new SslRMIClientSocketFactory();
if (rmiBindAddress == null) {
registrySsf = new SslRMIServerSocketFactory(ciphers, protocols, clientAuth);
} else {
registrySsf = new SslRmiServerBindSocketFactory(ciphers, protocols, clientAuth, rmiBindAddress);
}
} else {
if (rmiBindAddress != null) {
registrySsf = new RmiServerBindSocketFactory(rmiBindAddress);
}
}
// Configure server socket factories
if (rmiServerSSL) {
serverCsf = new SslRMIClientSocketFactory();
if (rmiBindAddress == null) {
serverSsf = new SslRMIServerSocketFactory(ciphers, protocols, clientAuth);
} else {
serverSsf = new SslRmiServerBindSocketFactory(ciphers, protocols, clientAuth, rmiBindAddress);
}
} else {
if (rmiBindAddress != null) {
serverSsf = new RmiServerBindSocketFactory(rmiBindAddress);
}
}
// the configured address.
if (rmiBindAddress != null) {
System.setProperty("java.rmi.server.hostname", rmiBindAddress);
}
// Force the use of local ports if required
if (useLocalPorts) {
registryCsf = new RmiClientLocalhostSocketFactory(registryCsf);
serverCsf = new RmiClientLocalhostSocketFactory(serverCsf);
}
env.put("jmx.remote.rmi.server.credential.types", new String[] { String[].class.getName(), String.class.getName() });
// Populate the env properties used to create the server
if (serverCsf != null) {
env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, serverCsf);
env.put("com.sun.jndi.rmi.factory.socket", registryCsf);
}
if (serverSsf != null) {
env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, serverSsf);
}
// Configure authentication
if (authenticate) {
env.put("jmx.remote.x.password.file", passwordFile);
env.put("jmx.remote.x.access.file", accessFile);
env.put("jmx.remote.x.login.config", loginModuleName);
}
// Create the Platform server
csPlatform = createServer("Platform", rmiBindAddress, rmiRegistryPortPlatform, rmiServerPortPlatform, env, registryCsf, registrySsf, serverCsf, serverSsf);
} else if (Lifecycle.STOP_EVENT.equals(event.getType())) {
destroyServer("Platform", csPlatform);
}
}
use of java.rmi.server.RMIClientSocketFactory in project felix by apache.
the class RMIResolver method createRMIServer.
protected RMIServerImpl createRMIServer(JMXServiceURL url, Map environment) throws IOException {
int port = url.getPort();
RMIClientSocketFactory clientFactory = (RMIClientSocketFactory) environment.get(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE);
RMIServerSocketFactory serverFactory = (RMIServerSocketFactory) environment.get(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE);
return new RMIJRMPServerImpl(port, clientFactory, serverFactory, environment);
}
use of java.rmi.server.RMIClientSocketFactory in project jdk8u_jdk by JetBrains.
the class TCPEndpoint method newSocket.
/**
* Open and return new client socket connection to endpoint.
*/
Socket newSocket() throws RemoteException {
if (TCPTransport.tcpLog.isLoggable(Log.VERBOSE)) {
TCPTransport.tcpLog.log(Log.VERBOSE, "opening socket to " + this);
}
Socket socket;
try {
RMIClientSocketFactory clientFactory = csf;
if (clientFactory == null) {
clientFactory = chooseFactory();
}
socket = clientFactory.createSocket(host, port);
} catch (java.net.UnknownHostException e) {
throw new java.rmi.UnknownHostException("Unknown host: " + host, e);
} catch (java.net.ConnectException e) {
throw new java.rmi.ConnectException("Connection refused to host: " + host, e);
} catch (IOException e) {
// We might have simply run out of file descriptors
try {
TCPEndpoint.shedConnectionCaches();
// REMIND: should we retry createSocket?
} catch (OutOfMemoryError | Exception mem) {
// don't quit if out of memory
// or shed fails non-catastrophically
}
throw new ConnectIOException("Exception creating connection to: " + host, e);
}
// TBD: should this be left up to socket factory instead?
try {
socket.setTcpNoDelay(true);
} catch (Exception e) {
// if we fail to set this, ignore and proceed anyway
}
// fix 4187495: explicitly set SO_KEEPALIVE to prevent client hangs
try {
socket.setKeepAlive(true);
} catch (Exception e) {
// ignore and proceed
}
return socket;
}
use of java.rmi.server.RMIClientSocketFactory in project jdk8u_jdk by JetBrains.
the class TCPEndpoint method read.
/**
* Get the endpoint from the input stream.
* @param in the input stream
* @exception IOException If id could not be read (due to stream failure)
*/
public static TCPEndpoint read(ObjectInput in) throws IOException, ClassNotFoundException {
String host;
int port;
RMIClientSocketFactory csf = null;
byte format = in.readByte();
switch(format) {
case FORMAT_HOST_PORT:
host = in.readUTF();
port = in.readInt();
break;
case FORMAT_HOST_PORT_FACTORY:
host = in.readUTF();
port = in.readInt();
csf = (RMIClientSocketFactory) in.readObject();
break;
default:
throw new IOException("invalid endpoint format");
}
return new TCPEndpoint(host, port, csf, null);
}
use of java.rmi.server.RMIClientSocketFactory in project jdk8u_jdk by JetBrains.
the class RMIConnectorServer method newJRMPServer.
private static RMIServerImpl newJRMPServer(Map<String, ?> env, int port) throws IOException {
RMIClientSocketFactory csf = (RMIClientSocketFactory) env.get(RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE);
RMIServerSocketFactory ssf = (RMIServerSocketFactory) env.get(RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE);
return new RMIJRMPServerImpl(port, csf, ssf, env);
}
Aggregations