Search in sources :

Example 6 with ConnectException

use of java.net.ConnectException in project hbase by apache.

the class TestIPCUtil method testWrapException.

@Test
public void testWrapException() throws Exception {
    final InetSocketAddress address = InetSocketAddress.createUnresolved("localhost", 0);
    assertTrue(wrapException(address, new ConnectException()) instanceof ConnectException);
    assertTrue(wrapException(address, new SocketTimeoutException()) instanceof SocketTimeoutException);
    assertTrue(wrapException(address, new ConnectionClosingException("Test AbstractRpcClient#wrapException")) instanceof ConnectionClosingException);
    assertTrue(wrapException(address, new CallTimeoutException("Test AbstractRpcClient#wrapException")).getCause() instanceof CallTimeoutException);
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) InetSocketAddress(java.net.InetSocketAddress) ConnectionClosingException(org.apache.hadoop.hbase.exceptions.ConnectionClosingException) ConnectException(java.net.ConnectException) Test(org.junit.Test)

Example 7 with ConnectException

use of java.net.ConnectException in project hbase by apache.

the class MetaTableLocator method verifyRegionLocation.

/**
   * Verify we can connect to <code>hostingServer</code> and that its carrying
   * <code>regionName</code>.
   * @param hostingServer Interface to the server hosting <code>regionName</code>
   * @param address The servername that goes with the <code>metaServer</code>
   * Interface.  Used logging.
   * @param regionName The regionname we are interested in.
   * @return True if we were able to verify the region located at other side of
   * the Interface.
   * @throws IOException
   */
// TODO: We should be able to get the ServerName from the AdminProtocol
// rather than have to pass it in.  Its made awkward by the fact that the
// HRI is likely a proxy against remote server so the getServerName needs
// to be fixed to go to a local method or to a cache before we can do this.
private boolean verifyRegionLocation(final ClusterConnection connection, AdminService.BlockingInterface hostingServer, final ServerName address, final byte[] regionName) throws IOException {
    if (hostingServer == null) {
        LOG.info("Passed hostingServer is null");
        return false;
    }
    Throwable t;
    HBaseRpcController controller = connection.getRpcControllerFactory().newController();
    try {
        // Try and get regioninfo from the hosting server.
        return ProtobufUtil.getRegionInfo(controller, hostingServer, regionName) != null;
    } catch (ConnectException e) {
        t = e;
    } catch (RetriesExhaustedException e) {
        t = e;
    } catch (RemoteException e) {
        IOException ioe = e.unwrapRemoteException();
        t = ioe;
    } catch (IOException e) {
        Throwable cause = e.getCause();
        if (cause != null && cause instanceof EOFException) {
            t = cause;
        } else if (cause != null && cause.getMessage() != null && cause.getMessage().contains("Connection reset")) {
            t = cause;
        } else {
            t = e;
        }
    }
    LOG.info("Failed verification of " + Bytes.toStringBinary(regionName) + " at address=" + address + ", exception=" + t.getMessage());
    return false;
}
Also used : HBaseRpcController(org.apache.hadoop.hbase.ipc.HBaseRpcController) RetriesExhaustedException(org.apache.hadoop.hbase.client.RetriesExhaustedException) EOFException(java.io.EOFException) IOException(java.io.IOException) RemoteException(org.apache.hadoop.ipc.RemoteException) ConnectException(java.net.ConnectException)

Example 8 with ConnectException

use of java.net.ConnectException in project tomcat by apache.

the class SetParentClassLoaderRule method stopServer.

public void stopServer(String[] arguments) {
    if (arguments != null) {
        arguments(arguments);
    }
    Server s = getServer();
    if (s == null) {
        // Create and execute our Digester
        Digester digester = createStopDigester();
        File file = configFile();
        try (FileInputStream fis = new FileInputStream(file)) {
            InputSource is = new InputSource(file.toURI().toURL().toString());
            is.setByteStream(fis);
            digester.push(this);
            digester.parse(is);
        } catch (Exception e) {
            log.error("Catalina.stop: ", e);
            System.exit(1);
        }
    } else {
        // Server object already present. Must be running as a service
        try {
            s.stop();
        } catch (LifecycleException e) {
            log.error("Catalina.stop: ", e);
        }
        return;
    }
    // Stop the existing server
    s = getServer();
    if (s.getPort() > 0) {
        try (Socket socket = new Socket(s.getAddress(), s.getPort());
            OutputStream stream = socket.getOutputStream()) {
            String shutdown = s.getShutdown();
            for (int i = 0; i < shutdown.length(); i++) {
                stream.write(shutdown.charAt(i));
            }
            stream.flush();
        } catch (ConnectException ce) {
            log.error(sm.getString("catalina.stopServer.connectException", s.getAddress(), String.valueOf(s.getPort())));
            log.error("Catalina.stop: ", ce);
            System.exit(1);
        } catch (IOException e) {
            log.error("Catalina.stop: ", e);
            System.exit(1);
        }
    } else {
        log.error(sm.getString("catalina.stopServer"));
        System.exit(1);
    }
}
Also used : InputSource(org.xml.sax.InputSource) LifecycleException(org.apache.catalina.LifecycleException) Server(org.apache.catalina.Server) OutputStream(java.io.OutputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) ConnectException(java.net.ConnectException) LifecycleException(org.apache.catalina.LifecycleException) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) Digester(org.apache.tomcat.util.digester.Digester) File(java.io.File) Socket(java.net.Socket) ConnectException(java.net.ConnectException)

Example 9 with ConnectException

use of java.net.ConnectException in project head by mifos.

the class MifosExecutableWARBasicTest method testExecutableWARStartup.

@Test
public void testExecutableWARStartup() throws IOException, InterruptedException {
    // maven-dependency-plugin (see pom.xml) copied it:
    final File warFile = new File("target/dependency/mifos.war");
    assertTrue(warFile.toString() + " does not exist", warFile.exists());
    int httpPort = 4847;
    // Give it max. 5 min to start-up
    Long timeOut = 5 * 60 * 1000L;
    // Could have used http://commons.apache.org/exec/ instead here, but this seemed easier:
    long startTime = System.currentTimeMillis();
    final String execWARFilePath = warFile.getAbsolutePath();
    final String port = Integer.toString(httpPort);
    List<String> args = new ArrayList<String>();
    args.add("java");
    args.add("-jar");
    args.add("-Xmx512M");
    args.add("-XX:MaxPermSize=256m");
    if (System.getProperty("os.name").toLowerCase().contains("mac")) {
        args.add("-d32");
    }
    args.add(execWARFilePath);
    args.add(port);
    final ProcessBuilder processBuilder = new ProcessBuilder(args);
    processBuilder.redirectErrorStream(true);
    Process p = processBuilder.start();
    URL url = new URL("http://localhost:" + httpPort + "/mifos");
    // Now either wait until the server is up on httpPort OR timeOut is reached
    boolean keepGoing = true;
    InputStream is = p.getInputStream();
    do {
        // Pipe process output to console
        while (is.available() > 0) {
            System.out.write(is.read());
        }
        // Check if the server is up and running
        try {
            HttpURLConnection con = (HttpURLConnection) url.openConnection();
            int r = con.getResponseCode();
            if (r == 200 || r == 302) {
                // Yeah, we're up and running! So shutdown now.
                p.destroy();
                keepGoing = false;
            }
        } catch (ConnectException e) {
        // Oh well; not ready yet, never mind, ignore it and move on.
        }
        // Has the server died on it's own already may be?
        try {
            int exitValue = p.exitValue();
            if (exitValue != 0) {
                fail("Server Process died (unexpectedly), return code: " + exitValue);
            }
        } catch (IllegalThreadStateException e) {
        // Great, it's still running; so move on.
        }
        // Have we hit time out?
        if (System.currentTimeMillis() - startTime > timeOut) {
            p.destroy();
            fail("Giving up after " + timeOut + "ms; as Server Process is still not responding on " + url);
        }
        // Now have a rest before trying again
        Thread.sleep(1000);
    } while (keepGoing);
}
Also used : InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) URL(java.net.URL) HttpURLConnection(java.net.HttpURLConnection) File(java.io.File) ConnectException(java.net.ConnectException) Test(org.junit.Test)

Example 10 with ConnectException

use of java.net.ConnectException in project failsafe by jhalterman.

the class RetryPolicyTest method testCanAbortForFailurePredicate.

public void testCanAbortForFailurePredicate() {
    RetryPolicy policy = new RetryPolicy().abortOn(failure -> failure instanceof ConnectException);
    assertTrue(policy.canAbortFor(null, new ConnectException()));
    assertFalse(policy.canAbortFor(null, new IllegalArgumentException()));
}
Also used : RetryPolicy(net.jodah.failsafe.RetryPolicy) ConnectException(java.net.ConnectException)

Aggregations

ConnectException (java.net.ConnectException)521 IOException (java.io.IOException)211 Socket (java.net.Socket)84 SocketTimeoutException (java.net.SocketTimeoutException)69 Test (org.junit.Test)69 UnknownHostException (java.net.UnknownHostException)57 InetSocketAddress (java.net.InetSocketAddress)56 WebServiceException (javax.xml.ws.WebServiceException)48 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)48 ErrorCode (org.olat.modules.vitero.model.ErrorCode)48 FileNotFoundException (java.io.FileNotFoundException)39 URL (java.net.URL)36 InputStream (java.io.InputStream)33 NoRouteToHostException (java.net.NoRouteToHostException)33 SocketException (java.net.SocketException)33 ArrayList (java.util.ArrayList)31 InetAddress (java.net.InetAddress)29 InputStreamReader (java.io.InputStreamReader)28 OutputStream (java.io.OutputStream)28 HttpURLConnection (java.net.HttpURLConnection)28