public JmxTransRMIClientSocketFactory(int timeoutMillis, boolean ssl){ this.timeoutMillis = timeoutMillis; this.rmiClientSocketFactory = ssl ? new SslRMIClientSocketFactory() : RMISocketFactory.getDefaultSocketFactory(); }
/** * Return the JVM-level configured {@code RMISocketFactory}. * <p> * If a global socket factory has been set via the * {@link RMISocketFactory#setSocketFactory(RMISocketFactory)} method then * that factory will be returned. Otherwise the default socket factory as * returned by {@link RMISocketFactory#getDefaultSocketFactory()} is used * instead. * * @return the configured @{code {@link RMISocketFactory} */ public static RMISocketFactory getConfiguredRMISocketFactory() { RMISocketFactory globalSocketFactory = RMISocketFactory.getSocketFactory(); if (globalSocketFactory == null) { return RMISocketFactory.getDefaultSocketFactory(); } else { return globalSocketFactory; } } }
/** * Create a client socket connected to the specified host and port. * <p> * If necessary this implementation can be changed to specify the outbound address to use * e.g. <code>Socket socket = new Socket(host, port, localInterface , 0);</code> * * @param host the host name * @param port the port number * @return a socket connected to the specified host and port. * @throws java.io.IOException if an I/O error occurs during socket creation * @since 1.2 */ public Socket createSocket(String host, int port) throws IOException { Socket socket = getConfiguredRMISocketFactory().createSocket(host, port); socket.setSoTimeout(socketTimeoutMillis); return socket; }
public Socket createSocket(String host, int port) throws IOException { Socket s = RMISocketFactory.getDefaultSocketFactory(). createSocket(this.host, this.port); return s; } public boolean equals(Object o) {
public void init() { try { RMISocketFactory currentFactory = RMISocketFactory.getSocketFactory(); if (currentFactory != null) { verifyCurrentFactory(currentFactory); } else { RMISocketFactory.setSocketFactory(this); } } catch (Exception e) { LOGGER.error("Exeception occurred during set socket factory form RMI protocol - note, that this can cause problem with RMI connection" + " - especially when firewall is running between client and server.", e); } }
public Socket createSocket(String host, int port) throws IOException { System.out.println("change host from " + host + " to " + server); return getFactory().createSocket(server, port); return getFactory().createServerSocket(port); return RMISocketFactory.getDefaultSocketFactory();
public ServerSocket createServerSocket(int port) throws IOException { ServerSocket ss = host == null ? RMISocketFactory.getDefaultSocketFactory(). createServerSocket(this.port) : new ServerSocket(this.port, 50, InetAddress.getByName(host)); if (host == null) { host = ss.getInetAddress().getHostAddress(); System.setProperty("java.rmi.server.hostname", host); } if (this.port == 0) this.port = ss.getLocalPort(); if (rcsf != null) { if (rcsf.host == null) rcsf.host = InetAddress.getLocalHost().getHostAddress(); if (rcsf.port == 0) rcsf.port = this.port; Remote.defaultServerHost = this.host; Remote.defaultServerPort = this.port; Remote.defaultClientHost = rcsf.host; Remote.defaultClientPort = rcsf.port; rcsf = null; } return ss; } public boolean equals(Object o) {
private static void configureRMI(final ClassLoader cl) throws IOException { if (m_rmiServerSocketFactory != null) { // socket already configured return; } final String host = System.getProperty("opennms.poller.server.serverHost", "localhost"); if ("localhost".equals(host) || "127.0.0.1".equals(host) || "::1".equals(host)) { if (System.getProperty("java.rmi.server.hostname") == null) { System.setProperty("java.rmi.server.hostname", host); } m_rmiServerSocketFactory = new HostRMIServerSocketFactory("localhost"); RMISocketFactory.setSocketFactory(m_rmiServerSocketFactory); } /** * This is necessary so the ProxyLoginModule can find the OpenNMSLoginModule because * otherwise we're at the mercy of which thread/context is the first to make a JAAS * request, since LoginModules are initialized statically. In my testing, attempting * to connect to JMX with jconsole would give a class not found while attempting to * locate the OpenNMSLoginModule without using a classloader like this. */ OpenNMSProxyLoginModule.setClassloader(cl); } }
/** * Build a new registry on a given port * @param port given port number * @throws RemoteException if the registry cannot be built */ private ManageableRegistry(int port) throws RemoteException { this(port, RMISocketFactory.getSocketFactory(), RMISocketFactory.getSocketFactory()); }
@Test(expected = NetworkReactiveAuditException.class) public void createServerSocket() throws Exception { TestTools.strict.commit(); RMISocketFactory factory = getRmiSocketFactory(); factory.createServerSocket(1); }
@Override public Socket createSocket(final String host, final int port) throws IOException { return RMISocketFactory.getDefaultSocketFactory().createSocket(host, port); }
private static void ensureRmiUseFixedPort(final int port) throws IOException, IllegalStateException { final RMISocketFactory prevSocketFactory = RMISocketFactory.getSocketFactory(); if(prevSocketFactory == null) { RMISocketFactory.setSocketFactory(new FixedPortRmiSocketFactory(port)); } else if(prevSocketFactory instanceof FixedPortRmiSocketFactory) { ((FixedPortRmiSocketFactory) prevSocketFactory).setFixedPort(port); } else { throw new IllegalStateException("Invalid RMI socket factory was set"); } }
RMISocketFactory.setSocketFactory(new RMISocketFactory() { public Socket createSocket(String host, int port) throws IOException {
public static RMIClientSocketFactory getDefaultClientSocketFactory() { return isTLSRequired() ? new SslRMIClientSocketFactory() : RMISocketFactory.getSocketFactory(); }
/** * Programmatically starts a JMX server. * * @param port * port server should listen on. * @param allowConnections * allows restriction of connections to those from "localhost" * only. */ public static void startLocalJMXServer(final int port, final AllowConnections allowConnections) throws IOException, MalformedURLException, RemoteException { final RMISocketFactory serverSocketFactory = allowConnections == AllowConnections.ALL ? RMISocketFactory.getDefaultSocketFactory() : new LocalhostRMIServerSocketFactory(); LocateRegistry.createRegistry(port, RMISocketFactory.getDefaultSocketFactory(), serverSocketFactory); final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); final JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:" + port + "/jmxrmi"); final JMXConnectorServer rmiServer = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs); rmiServer.start(); }
/** * Return the JVM-level configured {@code RMISocketFactory}. * <p> * If a global socket factory has been set via the * {@link RMISocketFactory#setSocketFactory(RMISocketFactory)} method then * that factory will be returned. Otherwise the default socket factory as * returned by {@link RMISocketFactory#getDefaultSocketFactory()} is used * instead. * * @return the configured @{code {@link RMISocketFactory} */ public static RMISocketFactory getConfiguredRMISocketFactory() { RMISocketFactory globalSocketFactory = RMISocketFactory.getSocketFactory(); if (globalSocketFactory == null) { return RMISocketFactory.getDefaultSocketFactory(); } else { return globalSocketFactory; } } }
@Override public Socket createSocket(final String host, final int port) throws IOException { return RMISocketFactory.getDefaultSocketFactory().createSocket(host, port); }
private static void ensureRmiUseFixedPort(final int port) throws IOException, IllegalStateException { final RMISocketFactory prevSocketFactory = RMISocketFactory.getSocketFactory(); if (prevSocketFactory == null) { RMISocketFactory.setSocketFactory(new FixedPortRmiSocketFactory(port)); } else if (prevSocketFactory instanceof FixedPortRmiSocketFactory) { ((FixedPortRmiSocketFactory) prevSocketFactory).setFixedPort(port); } else { throw new IllegalStateException("Invalid RMI socket factory was set"); } }
private static void configureRMI(final ClassLoader cl) throws IOException { if (m_rmiServerSocketFactory != null) { // socket already configured return; } final String host = System.getProperty("opennms.poller.server.serverHost", "localhost"); if ("localhost".equals(host) || "127.0.0.1".equals(host) || "::1".equals(host)) { if (System.getProperty("java.rmi.server.hostname") == null) { System.setProperty("java.rmi.server.hostname", host); } m_rmiServerSocketFactory = new HostRMIServerSocketFactory("localhost"); RMISocketFactory.setSocketFactory(m_rmiServerSocketFactory); } /** * This is necessary so the ProxyLoginModule can find the OpenNMSLoginModule because * otherwise we're at the mercy of which thread/context is the first to make a JAAS * request, since LoginModules are initialized statically. In my testing, attempting * to connect to JMX with jconsole would give a class not found while attempting to * locate the OpenNMSLoginModule without using a classloader like this. */ OpenNMSProxyLoginModule.setClassloader(cl); } }
/** * Create a client socket connected to the specified host and port. * <p/> * If necessary this implementation can be changed to specify the outbound address to use * e.g. <code>Socket socket = new Socket(host, port, localInterface , 0);</code> * * @param host the host name * @param port the port number * @return a socket connected to the specified host and port. * @throws java.io.IOException if an I/O error occurs during socket creation * @since 1.2 */ public Socket createSocket(String host, int port) throws IOException { Socket socket = getConfiguredRMISocketFactory().createSocket(host, port); socket.setSoTimeout(socketTimeoutMillis); return socket; }