public static void main(String[] args) throws Exception { System.err.println("\nRegression test for bug 4924577\n"); RMISocketFactory.setFailureHandler(new RMIFailureHandler() { public boolean failure(Exception e) { return false; } }); tryWith(new IOException()); tryWith(new NullPointerException()); tryWith(new OutOfMemoryError()); tryWith(new NoClassDefFoundError()); tryWith(new InternalError()); tryWith(new Throwable()); System.err.println("TEST PASSED"); }
public static void main (String[] args) throws Exception { if (args.length > 0) { success = System.getSecurityManager() == null || args[0].equals("success"); } doTest(()->{ System.out.println("Verify URLConnection.setContentHandlerFactor()"); URLConnection.setContentHandlerFactory(null); }); doTest(()->{ System.out.println("Verify URL.setURLStreamHandlerFactory()"); URL.setURLStreamHandlerFactory(null); }); doTest(()->{ System.out.println("Verify ServerSocket.setSocketFactory()"); ServerSocket.setSocketFactory(null); }); doTest(()->{ System.out.println("Verify Socket.setSocketImplFactory()"); Socket.setSocketImplFactory(null); }); doTest(()->{ System.out.println("Verify RMISocketFactory.setSocketFactory()"); RMISocketFactory.setSocketFactory(null); }); }
public static void main(String[] args) throws Exception { System.setProperty(RMISocketFactoryImpl.RMI_HOSTNAME_KEY, "localhost"); RMISocketFactoryImpl impl = new RMISocketFactoryImpl(); RMISocketFactory.setSocketFactory(impl); if (args.length > 0) { } else { Test.requireNameServer(); Test.rebindTest(); IntegerRMI remoteInt = new IntegerRMI(); Test.rebind(TEST_INT_NAME, remoteInt); } Object o = Test.lookup(TEST_DATE_NAME); RemoteDate rd = (RemoteDate) o; System.out.println("The remote-date is: " + rd.getDate()); o = Test.lookup(TEST_INT_NAME); RemoteInteger ri = (RemoteInteger) o; System.out.println("The remote-int is: " + ri.getInt()); }
static final AbstractClientConnection getClientConnection(Endpoint ep) throws IOException, UnknownHostException, ConnectException, ConnectIOException { Socket sock = null; AbstractClientConnection ret; RMIClientSocketFactory csf = (ep.getCsf() != null) ? ep.getCsf() : RMISocketFactory.getSocketFactory(); if (csf == null) { csf = RMISocketFactory.getDefaultSocketFactory(); } sock = csf.createSocket(ep.getEndpointID().getHost(), ep.getPort()); if (SO_TIME_OUT != 0) { sock.setSoTimeout(SO_TIME_OUT); } sock.setTcpNoDelay(true); if (sock instanceof HttpSocketClientSide) { ret = new SingleOpClientConnection(sock, ep); } else { ret = new StreamClientConnection(sock, ep); } return ret; }
public static RMISocketFactory getSunSocketFactory(String type) { if (type.equalsIgnoreCase("default")) { System.out.println("No forced SocketFactory, enabled DefaultSocketFactory supporting Fallback mode"); return new RMIDirectSocketFactory(); } else if (type.equalsIgnoreCase("cgi")) { System.out.println("RMIToCGISocketFactory enabled..."); return new RMIHttpToCGISocketFactory(); } else if (type.equalsIgnoreCase("http")) { System.out.println("RMIHttpToPortSocketFactory enabled..."); return new RMIHttpToPortSocketFactory(); } else if (type.equalsIgnoreCase("direct")) { System.out.println("RMIDirectSocketFactory enabled..."); return new RMIDirectSocketFactory(); } return new RMIDirectSocketFactory(); // if null returns default socket factory }
/** * Remember a successful factory for connecting to host. * Currently, excess hosts are removed from the remembered list * using a Least Recently Created strategy. */ void rememberFactory(String host, RMISocketFactory factory) { synchronized (successTable) { while (hostList.size() >= MaxRememberedHosts) { successTable.remove(hostList.elementAt(0)); hostList.removeElementAt(0); } hostList.addElement(host); successTable.put(host, factory); } }
/** * Create a new asynchronous connector object. */ AsyncConnector(RMISocketFactory factory, String host, int port, AccessControlContext acc) { this.factory = factory; this.host = host; this.port = port; this.acc = acc; SecurityManager security = System.getSecurityManager(); if (security != null) { security.checkConnect(host, port); } }
private static RMISocketFactory chooseFactory() { RMISocketFactory sf = RMISocketFactory.getSocketFactory(); if (sf == null) { sf = TCPTransport.defaultSocketFactory; } return sf; }
/** * Returns true if the accept loop should continue after the * specified exception has been caught, or false if the accept * loop should terminate (closing the server socket). If * there is an RMIFailureHandler, this method returns the * result of passing the specified exception to it; otherwise, * this method always returns true, after sleeping to throttle * the accept loop if necessary. **/ private boolean continueAfterAcceptFailure(Throwable t) { RMIFailureHandler fh = RMISocketFactory.getFailureHandler(); if (fh != null) { return fh.failure(t instanceof Exception ? (Exception) t : new InvocationTargetException(t)); } else { throttleLoopOnException(); return true; } }
public ServerSocket createServerSocket(int port) throws IOException { RMISocketFactory sf = RMISocketFactory.getSocketFactory(); if (sf == null) { sf = RMISocketFactory.getDefaultSocketFactory(); } return sf.createServerSocket(port); }
public static void main(String args[]) { UnderscoreHost t = null; try { HostVerifyingSocketFactory hvf = new HostVerifyingSocketFactory(); RMISocketFactory.setSocketFactory(hvf); Registry r = TestLibrary.createRegistryOnUnusedPort(); int port = TestLibrary.getRegistryPort(r); t = new UnderscoreHost(); r.rebind(NAME, t); Naming.lookup("rmi://" + HOSTNAME + ":" + port + "/" + NAME); /* * This test is coded to pass whether java.net.URI obeys * RFC 2396 or RFC 3986 (see 5085902, 6394131, etc.). * * If java.net.URI obeys RFC 3986, so host names may * contain underscores, then the Naming.lookup invocation * should succeed-- but the host actually connected to * must equal HOSTNAME. */ if (!hvf.host.equals(HOSTNAME)) { throw new RuntimeException( "java.rmi.Naming Parsing error:" + hvf.host + ":" + HOSTNAME); } } catch (MalformedURLException e) { /* * If java.net.URI obeys RFC 2396, so host names must not * contain underscores, then the Naming.lookup invocation * should throw MalformedURLException-- so this is OK. */ } catch (IOException ioe) { TestLibrary.bomb(ioe); } catch (java.rmi.NotBoundException nbe) { TestLibrary.bomb(nbe); } finally { TestLibrary.unexport(t); } }
public static void main(String[] args) throws Exception { System.err.println("\nRegression test for bug 6269166\n"); RMISocketFactory.setSocketFactory(new SF()); Remote impl = new ReuseDefaultPort(); Remote stub = UnicastRemoteObject.exportObject(impl, 0); System.err.println("- exported object: " + stub); try { Registry registry = LocateRegistry.createRegistry(PORT); System.err.println("- exported registry: " + registry); System.err.println("TEST PASSED"); } finally { UnicastRemoteObject.unexportObject(impl, true); } }
public static void main(String args[]) { UnderscoreHost t = null; try { HostVerifyingSocketFactory hvf = new HostVerifyingSocketFactory(); RMISocketFactory.setSocketFactory(hvf); Registry r = TestLibrary.createRegistryOnEphemeralPort(); int port = TestLibrary.getRegistryPort(r); t = new UnderscoreHost(); r.rebind(NAME, t); Naming.lookup("rmi://" + HOSTNAME + ":" + port + "/" + NAME); /* * This test is coded to pass whether java.net.URI obeys * RFC 2396 or RFC 3986 (see 5085902, 6394131, etc.). * * If java.net.URI obeys RFC 3986, so host names may * contain underscores, then the Naming.lookup invocation * should succeed-- but the host actually connected to * must equal HOSTNAME. */ if (!hvf.host.equals(HOSTNAME)) { throw new RuntimeException( "java.rmi.Naming Parsing error:" + hvf.host + ":" + HOSTNAME); } } catch (MalformedURLException e) { /* * If java.net.URI obeys RFC 2396, so host names must not * contain underscores, then the Naming.lookup invocation * should throw MalformedURLException-- so this is OK. */ } catch (IOException ioe) { TestLibrary.bomb(ioe); } catch (java.rmi.NotBoundException nbe) { TestLibrary.bomb(nbe); } finally { TestLibrary.unexport(t); } }
public static void main(String[] args) throws Exception { System.err.println("\nRegression test for bug 6269166\n"); RMISocketFactory.setSocketFactory(new SF()); Remote impl = new ReuseDefaultPort(); Remote stub = UnicastRemoteObject.exportObject(impl, 0); System.err.println("- exported object: " + stub); try { Registry registry = LocateRegistry.createRegistry(rmiPort); System.err.println("- exported registry: " + registry); System.err.println("TEST PASSED"); } finally { UnicastRemoteObject.unexportObject(impl, true); } }
@Override public Socket createSocket(String host, int port) throws IOException { Socket socket = RMISocketFactory.getDefaultSocketFactory() .createSocket(host, port); InterposeSocket s = new InterposeSocket(socket, triggerBytes, matchBytes, replaceBytes); sockets.add(s); return s; }