Search in sources :

Example 1 with NoRouteToHostException

use of java.net.NoRouteToHostException in project hadoop by apache.

the class TestLog4Json method testNestedException.

@Test
public void testNestedException() throws Throwable {
    Exception e = new NoRouteToHostException("that box caught fire 3 years ago");
    Exception ioe = new IOException("Datacenter problems", e);
    ThrowableInformation ti = new ThrowableInformation(ioe);
    Log4Json l4j = new Log4Json();
    long timeStamp = Time.now();
    String outcome = l4j.toJson(new StringWriter(), "testNestedException", timeStamp, "INFO", "quoted\"", "new line\n and {}", ti).toString();
    println("testNestedException", outcome);
    ContainerNode rootNode = Log4Json.parse(outcome);
    assertEntryEquals(rootNode, Log4Json.LEVEL, "INFO");
    assertEntryEquals(rootNode, Log4Json.NAME, "testNestedException");
    assertEntryEquals(rootNode, Log4Json.TIME, timeStamp);
    assertEntryEquals(rootNode, Log4Json.EXCEPTION_CLASS, ioe.getClass().getName());
    JsonNode node = assertNodeContains(rootNode, Log4Json.STACK);
    assertTrue("Not an array: " + node, node.isArray());
    node = assertNodeContains(rootNode, Log4Json.DATE);
    assertTrue("Not a string: " + node, node.isTextual());
    //rather than try and make assertions about the format of the text
    //message equalling another ISO date, this test asserts that the hypen
    //and colon characters are in the string.
    String dateText = node.textValue();
    assertTrue("No '-' in " + dateText, dateText.contains("-"));
    assertTrue("No '-' in " + dateText, dateText.contains(":"));
}
Also used : StringWriter(java.io.StringWriter) ThrowableInformation(org.apache.log4j.spi.ThrowableInformation) ContainerNode(com.fasterxml.jackson.databind.node.ContainerNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) NoRouteToHostException(java.net.NoRouteToHostException) IOException(java.io.IOException) NoRouteToHostException(java.net.NoRouteToHostException) Test(org.junit.Test)

Example 2 with NoRouteToHostException

use of java.net.NoRouteToHostException in project hadoop by apache.

the class TestLog4Json method testException.

@Test
public void testException() throws Throwable {
    Exception e = new NoRouteToHostException("that box caught fire 3 years ago");
    ThrowableInformation ti = new ThrowableInformation(e);
    Log4Json l4j = new Log4Json();
    long timeStamp = Time.now();
    String outcome = l4j.toJson(new StringWriter(), "testException", timeStamp, "INFO", "quoted\"", "new line\n and {}", ti).toString();
    println("testException", outcome);
}
Also used : StringWriter(java.io.StringWriter) ThrowableInformation(org.apache.log4j.spi.ThrowableInformation) NoRouteToHostException(java.net.NoRouteToHostException) IOException(java.io.IOException) NoRouteToHostException(java.net.NoRouteToHostException) Test(org.junit.Test)

Example 3 with NoRouteToHostException

use of java.net.NoRouteToHostException in project android by cSploit.

the class CSploitApplication method onCreate.

@Override
public void onCreate() {
    SharedPreferences themePrefs = getSharedPreferences("THEME", 0);
    Boolean isDark = themePrefs.getBoolean("isDark", false);
    if (isDark)
        setTheme(R.style.DarkTheme);
    else
        setTheme(R.style.AppTheme);
    super.onCreate();
    ACRA.init(this);
    Services.init(this);
    // initialize the system
    try {
        System.init(this);
    } catch (Exception e) {
        // ignore exception when the user has wifi off
        if (!(e instanceof NoRouteToHostException))
            System.errorLogging(e);
    }
    ACRA.setConfig(ACRA.getConfig().setApplicationLogFile(System.getCorePath() + "/cSploitd.log"));
    // load system modules even if the initialization failed
    System.registerPlugin(new RouterPwn());
    System.registerPlugin(new Traceroute());
    System.registerPlugin(new PortScanner());
    System.registerPlugin(new Inspector());
    System.registerPlugin(new ExploitFinder());
    System.registerPlugin(new LoginCracker());
    System.registerPlugin(new Sessions());
    System.registerPlugin(new MITM());
    System.registerPlugin(new PacketForger());
}
Also used : RouterPwn(org.csploit.android.plugins.RouterPwn) SharedPreferences(android.content.SharedPreferences) Traceroute(org.csploit.android.plugins.Traceroute) Sessions(org.csploit.android.plugins.Sessions) PacketForger(org.csploit.android.plugins.PacketForger) LoginCracker(org.csploit.android.plugins.LoginCracker) PortScanner(org.csploit.android.plugins.PortScanner) NoRouteToHostException(java.net.NoRouteToHostException) NoRouteToHostException(java.net.NoRouteToHostException) MITM(org.csploit.android.plugins.mitm.MITM) Inspector(org.csploit.android.plugins.Inspector) ExploitFinder(org.csploit.android.plugins.ExploitFinder)

Example 4 with NoRouteToHostException

use of java.net.NoRouteToHostException in project sonarqube by SonarSource.

the class DefaultHttpDownloaderTest method openStream_network_errors.

@Test(timeout = 10000)
public void openStream_network_errors() throws IOException, URISyntaxException {
    // non routable address
    String url = "http://10.255.255.1";
    thrown.expect(SonarException.class);
    thrown.expect(hasCause(new BaseMatcher<Exception>() {

        @Override
        public boolean matches(Object ex) {
            return // Java 8
            ex instanceof NoRouteToHostException || ex instanceof SocketException || // Java 7 or before
            ex instanceof SocketTimeoutException;
        }

        @Override
        public void describeTo(Description arg0) {
        }
    }));
    DefaultHttpDownloader downloader = new DefaultHttpDownloader(new MapSettings(), 10, 50000);
    downloader.openStream(new URI(url));
}
Also used : SocketException(java.net.SocketException) SocketTimeoutException(java.net.SocketTimeoutException) Description(org.hamcrest.Description) BaseMatcher(org.hamcrest.BaseMatcher) MapSettings(org.sonar.api.config.MapSettings) NoRouteToHostException(java.net.NoRouteToHostException) URI(java.net.URI) Test(org.junit.Test)

Example 5 with NoRouteToHostException

use of java.net.NoRouteToHostException in project platform_frameworks_base by android.

the class MediaHTTPConnection method seekTo.

private void seekTo(long offset) throws IOException {
    teardownConnection();
    try {
        int response;
        int redirectCount = 0;
        URL url = mURL;
        // do not use any proxy for localhost (127.0.0.1)
        boolean noProxy = isLocalHost(url);
        while (true) {
            if (noProxy) {
                mConnection = (HttpURLConnection) url.openConnection(Proxy.NO_PROXY);
            } else {
                mConnection = (HttpURLConnection) url.openConnection();
            }
            mConnection.setConnectTimeout(CONNECT_TIMEOUT_MS);
            // handle redirects ourselves if we do not allow cross-domain redirect
            mConnection.setInstanceFollowRedirects(mAllowCrossDomainRedirect);
            if (mHeaders != null) {
                for (Map.Entry<String, String> entry : mHeaders.entrySet()) {
                    mConnection.setRequestProperty(entry.getKey(), entry.getValue());
                }
            }
            if (offset > 0) {
                mConnection.setRequestProperty("Range", "bytes=" + offset + "-");
            }
            response = mConnection.getResponseCode();
            if (response != HttpURLConnection.HTTP_MULT_CHOICE && response != HttpURLConnection.HTTP_MOVED_PERM && response != HttpURLConnection.HTTP_MOVED_TEMP && response != HttpURLConnection.HTTP_SEE_OTHER && response != HTTP_TEMP_REDIRECT) {
                // not a redirect, or redirect handled by HttpURLConnection
                break;
            }
            if (++redirectCount > MAX_REDIRECTS) {
                throw new NoRouteToHostException("Too many redirects: " + redirectCount);
            }
            String method = mConnection.getRequestMethod();
            if (response == HTTP_TEMP_REDIRECT && !method.equals("GET") && !method.equals("HEAD")) {
                // automatically redirect the request"
                throw new NoRouteToHostException("Invalid redirect");
            }
            String location = mConnection.getHeaderField("Location");
            if (location == null) {
                throw new NoRouteToHostException("Invalid redirect");
            }
            url = new URL(mURL, /* TRICKY: don't use url! */
            location);
            if (!url.getProtocol().equals("https") && !url.getProtocol().equals("http")) {
                throw new NoRouteToHostException("Unsupported protocol redirect");
            }
            boolean sameProtocol = mURL.getProtocol().equals(url.getProtocol());
            if (!mAllowCrossProtocolRedirect && !sameProtocol) {
                throw new NoRouteToHostException("Cross-protocol redirects are disallowed");
            }
            boolean sameHost = mURL.getHost().equals(url.getHost());
            if (!mAllowCrossDomainRedirect && !sameHost) {
                throw new NoRouteToHostException("Cross-domain redirects are disallowed");
            }
            if (response != HTTP_TEMP_REDIRECT) {
                // update effective URL, unless it is a Temporary Redirect
                mURL = url;
            }
        }
        if (mAllowCrossDomainRedirect) {
            // remember the current, potentially redirected URL if redirects
            // were handled by HttpURLConnection
            mURL = mConnection.getURL();
        }
        if (response == HttpURLConnection.HTTP_PARTIAL) {
            // Partial content, we cannot just use getContentLength
            // because what we want is not just the length of the range
            // returned but the size of the full content if available.
            String contentRange = mConnection.getHeaderField("Content-Range");
            mTotalSize = -1;
            if (contentRange != null) {
                // format is "bytes xxx-yyy/zzz
                // where "zzz" is the total number of bytes of the
                // content or '*' if unknown.
                int lastSlashPos = contentRange.lastIndexOf('/');
                if (lastSlashPos >= 0) {
                    String total = contentRange.substring(lastSlashPos + 1);
                    try {
                        mTotalSize = Long.parseLong(total);
                    } catch (NumberFormatException e) {
                    }
                }
            }
        } else if (response != HttpURLConnection.HTTP_OK) {
            throw new IOException();
        } else {
            mTotalSize = mConnection.getContentLength();
        }
        if (offset > 0 && response != HttpURLConnection.HTTP_PARTIAL) {
            // data from the start of the content.
            throw new ProtocolException();
        }
        mInputStream = new BufferedInputStream(mConnection.getInputStream());
        mCurrentOffset = offset;
    } catch (IOException e) {
        mTotalSize = -1;
        mInputStream = null;
        mConnection = null;
        mCurrentOffset = -1;
        throw e;
    }
}
Also used : ProtocolException(java.net.ProtocolException) BufferedInputStream(java.io.BufferedInputStream) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) NoRouteToHostException(java.net.NoRouteToHostException) URL(java.net.URL)

Aggregations

NoRouteToHostException (java.net.NoRouteToHostException)31 IOException (java.io.IOException)26 InterruptedIOException (java.io.InterruptedIOException)19 ConnectException (java.net.ConnectException)19 InetSocketAddress (java.net.InetSocketAddress)14 Socket (java.net.Socket)14 TimeoutTracker (org.opennms.core.utils.TimeoutTracker)13 InetAddress (java.net.InetAddress)12 PollStatus (org.opennms.netmgt.poller.PollStatus)11 InputStreamReader (java.io.InputStreamReader)7 BufferedInputStream (java.io.BufferedInputStream)6 BufferedReader (java.io.BufferedReader)6 URL (java.net.URL)6 ProtocolException (java.net.ProtocolException)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 Test (org.junit.Test)4 DatagramSocket (java.net.DatagramSocket)3 SocketTimeoutException (java.net.SocketTimeoutException)3 OutputStream (java.io.OutputStream)2