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(":"));
}
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);
}
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());
}
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));
}
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;
}
}
Aggregations