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; }
@Override public boolean retryRequest(IOException exception, int executionCount, HttpContext context) { if (executionCount >= 3) { logger.info("Got too many exceptions"); // Do not retry if over max retry count return false; } if (exception instanceof InterruptedIOException) { // Timeout logger.info("Got interrupted exception"); return true; } if (exception instanceof SocketException) { logger.info("Got socket exception"); return true; } if (exception instanceof org.apache.http.NoHttpResponseException){ logger.warn("got no http response exception"); return true; } if (exception instanceof UnknownHostException) { // Unknown host return false; } if (exception instanceof ConnectTimeoutException) { // Connection refused return true; } if (exception instanceof SSLException) { // SSL handshake exception return false; } HttpClientContext clientContext = HttpClientContext.adapt(context); HttpRequest request = clientContext.getRequest(); boolean idempotent = !(request instanceof HttpEntityEnclosingRequest); if (idempotent) { // Retry if the request is considered idempotent return true; } return false; }
public static boolean isLocalProblem(RemoteException e) { if (e instanceof ConnectIOException) { return true; } else if (e instanceof ConnectException) { return true; } else if (e instanceof UnknownHostException) { return true; } return false; }
/** @see NetLayer#createNetSocket(Map, NetAddress, NetAddress) */ @Override public NetSocket createNetSocket(final Map<String, Object> localProperties, final NetAddress localAddress, final NetAddress remoteAddress) throws IOException { final TcpipNetAddress r = (TcpipNetAddress) remoteAddress; // read (optional) properties final Integer timeoutInMs = PropertiesUtil.getAsInteger(localProperties, TIMEOUT_IN_MS, DEFAULT_TIMEOUT); // create connection and open socket final Socket socket = SocketGlobalUtil.createOriginalSocket(); /*if (r.getIpaddress() != null) { final InetAddress remoteInetAddress = InetAddress.getByAddress(r.getIpaddress()); final InetSocketAddress remoteInetSocketAddress = new InetSocketAddress(remoteInetAddress, r.getPort()); socket.connect(remoteInetSocketAddress, timeoutInMs); } else { */ // use host name final InetSocketAddress remoteInetSocketAddress = new InetSocketAddress(r.getHostname(), r.getPort()); if (remoteInetSocketAddress.getAddress() == null) { throw new UnknownHostException("hostlookup didnt worked. for Hostname : " + r.getHostname()); } socket.connect(remoteInetSocketAddress, timeoutInMs); //} // convert and return result return new Socket2NetSocket(socket); }
private static void launchGui() { String args[] = { "localhost" , "59125" }; try { MaryGUIClient.main(args); } catch (UnknownHostException uhe) { Log.print(uhe); } catch (IOException ioe) { Log.print(ioe); } catch (Exception e) { Log.print(e); } }
/** * {@link java.rmi.UnknownHostException#UnknownHostException(java.lang.String, java.lang.Exception)}. */ public void testUnknownHostExceptionStringException() { NullPointerException npe = new NullPointerException(); UnknownHostException e = new UnknownHostException("fixture", npe); assertTrue(e.getMessage().indexOf("fixture") > -1); assertSame(npe, e.getCause()); assertSame(npe, e.detail); }
/** * {@link java.rmi.UnknownHostException#UnknownHostException(java.lang.String)}. */ public void testUnknownHostExceptionString() { UnknownHostException e = new UnknownHostException("fixture"); assertEquals("fixture", e.getMessage()); assertNull(e.getCause()); assertNull(e.detail); }
@Test public void rmiProxyFactoryBeanWithUnknownHostException() throws Exception { doTestRmiProxyFactoryBeanWithException(UnknownHostException.class); }
@Test public void rmiProxyFactoryBeanWithUnknownHostExceptionAndRefresh() throws Exception { doTestRmiProxyFactoryBeanWithExceptionAndRefresh(UnknownHostException.class); }
@Test public void rmiProxyFactoryBeanWithBusinessInterfaceAndUnknownHostException() throws Exception { doTestRmiProxyFactoryBeanWithBusinessInterfaceAndException( UnknownHostException.class, RemoteConnectFailureException.class); }
@Test public void rmiProxyFactoryBeanWithBusinessInterfaceAndUnknownHostExceptionAndRefresh() throws Exception { doTestRmiProxyFactoryBeanWithBusinessInterfaceAndExceptionAndRefresh( UnknownHostException.class, RemoteConnectFailureException.class); }
public void testRmiProxyFactoryBeanWithUnknownHostException() throws Exception { doTestRmiProxyFactoryBeanWithException(UnknownHostException.class); }
public void testRmiProxyFactoryBeanWithUnknownHostExceptionAndRefresh() throws Exception { doTestRmiProxyFactoryBeanWithExceptionAndRefresh(UnknownHostException.class); }
public void testRmiProxyFactoryBeanWithBusinessInterfaceAndUnknownHostException() throws Exception { doTestRmiProxyFactoryBeanWithBusinessInterfaceAndException( UnknownHostException.class, RemoteConnectFailureException.class); }
public void testRmiProxyFactoryBeanWithBusinessInterfaceAndUnknownHostExceptionAndRefresh() throws Exception { doTestRmiProxyFactoryBeanWithBusinessInterfaceAndExceptionAndRefresh( UnknownHostException.class, RemoteConnectFailureException.class); }
/** * Prepares a new {@link NamingException} wrapping the specified * {@link RemoteException} source exception. Source exception becomes a * {@linkplain NamingException#getCause() cause} of the generated exception. * * The particular subclass of {@link NamingException} returned depends on * the particular subclass of source {@link RemoteException}. * * If source exception is not of a specific class or is not a * {@link RemoteException} or is <code>null</code>, then plain * {@link NamingException} is returned. * * Note: {@link Throwable#fillInStackTrace()} should be called before * throwing the generated exception, to provide the proper (not including * this method) stack trace for the exception. * * Example of use: * * <code>try { * ... * } catch (RemoteException e) { * throw (NamingException) newNamingException(e).fillInStackTrace(); * }</code> * * @param e * Source {@link RemoteException}. * * @return Generated {@link NamingException} exception. */ @SuppressWarnings("deprecation") protected NamingException newNamingException(Throwable e) { NamingException ret = (e instanceof AccessException) ? new NoPermissionException() : (e instanceof ConnectException) ? new ServiceUnavailableException() : (e instanceof ConnectIOException) || (e instanceof ExportException) || (e instanceof MarshalException) || (e instanceof UnmarshalException) ? new CommunicationException() : (e instanceof ActivateFailedException) || (e instanceof NoSuchObjectException) || (e instanceof java.rmi.server.SkeletonMismatchException) || (e instanceof java.rmi.server.SkeletonNotFoundException) || (e instanceof StubNotFoundException) || (e instanceof UnknownHostException) ? new ConfigurationException() : (e instanceof ServerException) ? newNamingException(e .getCause()) : new NamingException(); if (ret.getCause() == null) { ret.initCause(e); } return ret; }
/** * @deprecated not used for registry stubs retrieval since Java v1.2 */ @Deprecated public Registry registryStub(String host, int port) throws RemoteException, UnknownHostException;
/** * Determine whether the given RMI exception indicates a connect failure. * <p>Treats RMI's ConnectException, ConnectIOException, UnknownHostException, * NoSuchObjectException and StubNotFoundException as connect failure. * @param ex the RMI exception to check * @return whether the exception should be treated as connect failure * @see java.rmi.ConnectException * @see java.rmi.ConnectIOException * @see java.rmi.UnknownHostException * @see java.rmi.NoSuchObjectException * @see java.rmi.StubNotFoundException */ public static boolean isConnectFailure(RemoteException ex) { return (ex instanceof ConnectException || ex instanceof ConnectIOException || ex instanceof UnknownHostException || ex instanceof NoSuchObjectException || ex instanceof StubNotFoundException || ex.getCause() instanceof SocketException || isCorbaConnectFailure(ex.getCause())); }
/** * Determine whether the given RMI exception indicates a connect failure. * <p>Treats RMI's ConnectException, ConnectIOException, UnknownHostException, * NoSuchObjectException and StubNotFoundException as connect failure, * as well as Oracle's OC4J {@code com.evermind.server.rmi.RMIConnectionException} * (which doesn't derive from from any well-known RMI connect exception). * @param ex the RMI exception to check * @return whether the exception should be treated as connect failure * @see java.rmi.ConnectException * @see java.rmi.ConnectIOException * @see java.rmi.UnknownHostException * @see java.rmi.NoSuchObjectException * @see java.rmi.StubNotFoundException */ public static boolean isConnectFailure(RemoteException ex) { return (ex instanceof ConnectException || ex instanceof ConnectIOException || ex instanceof UnknownHostException || ex instanceof NoSuchObjectException || ex instanceof StubNotFoundException || ex.getCause() instanceof SocketException || isCorbaConnectFailure(ex.getCause()) || ORACLE_CONNECTION_EXCEPTION.equals(ex.getClass().getName())); }
/** * Prepares a new {@link NamingException} wrapping the specified * {@link RemoteException} source exception. Source exception becomes a * {@linkplain NamingException#getCause() cause} of the generated exception. * * The particular subclass of {@link NamingException} returned depends * on the particular subclass of source {@link RemoteException}. * * If source exception is not of a specific class or is not * a {@link RemoteException} or is <code>null</code>, * then plain {@link NamingException} is returned. * * Note: {@link Throwable#fillInStackTrace()} should be called before * throwing the generated exception, to provide the proper * (not including this method) stack trace for the exception. * * Example of use: * * <code>try { * ... * } catch (RemoteException e) { * throw (NamingException) newNamingException(e).fillInStackTrace(); * }</code> * * @param e * Source {@link RemoteException}. * * @return Generated {@link NamingException} exception. */ @SuppressWarnings("deprecation") //$NON-NLS-1$ protected NamingException newNamingException(Throwable e) { NamingException ret = (e instanceof AccessException) ? new NoPermissionException() : (e instanceof ConnectException) ? new ServiceUnavailableException() : (e instanceof ConnectIOException) || (e instanceof ExportException) || (e instanceof MarshalException) || (e instanceof UnmarshalException) ? new CommunicationException() : (e instanceof ActivateFailedException) || (e instanceof NoSuchObjectException) || (e instanceof java.rmi.server.SkeletonMismatchException) || (e instanceof java.rmi.server.SkeletonNotFoundException) || (e instanceof StubNotFoundException) || (e instanceof UnknownHostException) ? new ConfigurationException() : (e instanceof ServerException) ? newNamingException(e.getCause()) : new NamingException(); if (ret.getCause() == null) { ret.initCause(e); } return ret; }
/** * Returns a "stub" for contacting a remote registry * on the specified host and port. * * @deprecated no replacement. As of the Java 2 platform v1.2, RMI no * longer uses the <code>RegistryHandler</code> to obtain the registry's * stub. * @param host name of remote registry host * @param port remote registry port * @return remote registry stub * @throws RemoteException if a remote error occurs * @throws UnknownHostException if unable to resolve given hostname */ @Deprecated Registry registryStub(String host, int port) throws RemoteException, UnknownHostException;