Example usage for java.net NoRouteToHostException NoRouteToHostException

List of usage examples for java.net NoRouteToHostException NoRouteToHostException

Introduction

In this page you can find the example usage for java.net NoRouteToHostException NoRouteToHostException.

Prototype

public NoRouteToHostException(String msg) 

Source Link

Document

Constructs a new NoRouteToHostException with the specified detail message as to why the remote host cannot be reached.

Usage

From source file:org.apache.hadoop.log.TestLog4Json.java

@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// w  w w . j av  a2 s .c  om
            .toJson(new StringWriter(), "testException", timeStamp, "INFO", "quoted\"", "new line\n and {}", ti)
            .toString();
    println("testException", outcome);
}

From source file:org.smartfrog.services.json.log.test.Log4JsonTest.java

@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 = System.currentTimeMillis();
    String outcome = l4j// ww w.jav  a 2s.  co  m
            .toJson(new StringWriter(), "testException", timeStamp, "INFO", "quoted\"", "new line\n and {}", ti)
            .toString();
    println("testException", outcome);
}

From source file:org.apache.hadoop.log.TestLog4Json.java

@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.getTextValue();
    assertTrue("No '-' in " + dateText, dateText.contains("-"));
    assertTrue("No '-' in " + dateText, dateText.contains(":"));

}

From source file:org.smartfrog.services.json.log.test.Log4JsonTest.java

@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 = System.currentTimeMillis();
    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.getTextValue();
    assertTrue("No '-' in " + dateText, dateText.contains("-"));
    assertTrue("No '-' in " + dateText, dateText.contains(":"));

}

From source file:it.evilsocket.dsploit.net.Network.java

public Network(Context context) throws NoRouteToHostException, SocketException, UnknownHostException {
    mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    mConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    mInfo = mWifiManager.getDhcpInfo();/*from www.j av  a  2s  .  c  o  m*/
    mWifiInfo = mWifiManager.getConnectionInfo();
    mLocal = new IP4Address(mInfo.ipAddress);
    mGateway = new IP4Address(mInfo.gateway);
    mNetmask = getNetmask();
    mBase = new IP4Address(mInfo.netmask & mInfo.gateway);

    if (isConnected() == false)
        throw new NoRouteToHostException("Not connected to any WiFi access point.");

    else {
        try {
            mInterface = NetworkInterface.getByInetAddress(getLocalAddress());
            if (mInterface == null)
                throw new IllegalStateException("Error retrieving network interface.");
        } catch (SocketException e) {
            System.errorLogging(e);
            /*
             * Issue #26: Initialization error in ColdFusionX ROM
                 * 
                 * It seems it's a ROM issue which doesn't correctly populate device descriptors.
                 * This rom maps the default wifi interface to a generic usb device 
                 * ( maybe it's missing the specific interface driver ), which is obviously not, and
                 * it all goes shit, use an alternative method to obtain the interface object.
                 */
            mInterface = NetworkInterface.getByName(java.lang.System.getProperty("wifi.interface", "wlan0"));

            if (mInterface == null)
                throw e;
        }
    }
}

From source file:org.csploit.android.net.Network.java

public Network(Context context) throws SocketException, UnknownHostException {
    mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    mConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    mInfo = mWifiManager.getDhcpInfo();/* w  w  w.jav  a  2  s  .co m*/
    mWifiInfo = mWifiManager.getConnectionInfo();
    mLocal = new IP4Address(mInfo.ipAddress);
    mGateway = new IP4Address(mInfo.gateway);
    mNetmask = getNetmask();
    mBase = new IP4Address(mInfo.netmask & mInfo.gateway);

    if (isConnected() == false)
        throw new NoRouteToHostException("Not connected to any WiFi access point.");

    else {
        try {
            mInterface = NetworkInterface.getByInetAddress(getLocalAddress());
            if (mInterface == null)
                throw new IllegalStateException("Error retrieving network interface.");
        } catch (SocketException e) {
            System.errorLogging(e);
            /*
             * Issue #26: Initialization error in ColdFusionX ROM
                 * 
                 * It seems it's a ROM issue which doesn't correctly populate device descriptors.
                 * This rom maps the default wifi interface to a generic usb device 
                 * ( maybe it's missing the specific interface driver ), which is obviously not, and
                 * it all goes shit, use an alternative method to obtain the interface object.
                 */
            mInterface = NetworkInterface.getByName(java.lang.System.getProperty("wifi.interface", "wlan0"));

            if (mInterface == null)
                throw e;
        }
    }
}

From source file:com.daskiworks.ghwatch.backend.RemoteSystemClient.java

private static Response<String> readInternetDataGet(Context context, GHCredentials apiCredentials, String url,
        Map<String, String> headers) throws NoRouteToHostException, URISyntaxException, IOException,
        ClientProtocolException, AuthenticationException, UnsupportedEncodingException {
    if (!Utils.isInternetConnectionAvailable(context))
        throw new NoRouteToHostException("Network not available");

    URI uri = new URI(url);
    DefaultHttpClient httpClient = prepareHttpClient(uri, apiCredentials);

    HttpGet httpGet = new HttpGet(uri);

    setHeaders(httpGet, headers);// w  w w  .ja v a  2  s  . c o  m

    // create response object here to measure request duration
    Response<String> ret = new Response<String>();
    ret.requestStartTime = System.currentTimeMillis();

    HttpResponse httpResponse = httpClient.execute(httpGet);
    int code = httpResponse.getStatusLine().getStatusCode();

    parseResponseHeaders(context, httpResponse, ret);
    Log.d(TAG, "Response http code: " + code);
    if (code == HttpStatus.SC_NOT_MODIFIED) {
        ret.notModified = true;
        ret.snapRequestDuration();
        writeReponseInfo(ret, context);
        return ret;
    }
    processStandardHttpResponseCodes(httpResponse);

    ret.data = getResponseContentAsString(httpResponse);
    ret.snapRequestDuration();
    writeReponseInfo(ret, context);
    return ret;

}

From source file:com.daskiworks.ghwatch.backend.RemoteSystemClient.java

public static Response<?> postNoData(Context context, GHCredentials apiCredentials, String url,
        Map<String, String> headers) throws NoRouteToHostException, URISyntaxException, IOException,
        ClientProtocolException, AuthenticationException, UnsupportedEncodingException {
    if (!Utils.isInternetConnectionAvailable(context))
        throw new NoRouteToHostException("Network not available");

    URI uri = new URI(url);
    DefaultHttpClient httpClient = prepareHttpClient(uri, apiCredentials);

    HttpPost httpPost = new HttpPost(uri);

    setHeaders(httpPost, headers);// w w  w  .ja va 2  s  . co m

    // create response object here to measure request duration
    Response<String> ret = new Response<String>();
    ret.requestStartTime = System.currentTimeMillis();

    HttpResponse httpResponse = httpClient.execute(httpPost);
    parseResponseHeaders(context, httpResponse, ret);

    processStandardHttpResponseCodes(httpResponse);

    ret.snapRequestDuration();
    writeReponseInfo(ret, context);
    return ret;
}

From source file:com.daskiworks.ghwatch.backend.RemoteSystemClient.java

public static Response<String> putToURL(Context context, GHCredentials apiCredentials, String url,
        Map<String, String> headers, String content) throws NoRouteToHostException, URISyntaxException,
        IOException, ClientProtocolException, AuthenticationException {
    if (!Utils.isInternetConnectionAvailable(context))
        throw new NoRouteToHostException("Network not available");

    URI uri = new URI(url);
    DefaultHttpClient httpClient = prepareHttpClient(uri, apiCredentials);

    HttpPut httpPut = new HttpPut(uri);

    setHeaders(httpPut, headers);/*  w w  w  . j a v a 2s . com*/

    if (content != null)
        httpPut.setEntity(new StringEntity(content, "UTF-8"));

    // create response object here to measure request duration
    Response<String> ret = new Response<String>();
    ret.requestStartTime = System.currentTimeMillis();

    HttpResponse httpResponse = httpClient.execute(httpPut);

    parseResponseHeaders(context, httpResponse, ret);

    processStandardHttpResponseCodes(httpResponse);

    ret.data = getResponseContentAsString(httpResponse);

    ret.snapRequestDuration();
    writeReponseInfo(ret, context);
    return ret;
}

From source file:com.daskiworks.ghwatch.backend.RemoteSystemClient.java

public static Response<String> deleteToURL(Context context, GHCredentials apiCredentials, String url,
        Map<String, String> headers) throws NoRouteToHostException, URISyntaxException, IOException,
        ClientProtocolException, AuthenticationException {
    if (!Utils.isInternetConnectionAvailable(context))
        throw new NoRouteToHostException("Network not available");

    URI uri = new URI(url);
    DefaultHttpClient httpClient = prepareHttpClient(uri, apiCredentials);

    HttpDelete httpPut = new HttpDelete(uri);

    setHeaders(httpPut, headers);/*from   w  w w.j ava  2 s  . c om*/

    // create response object here to measure request duration
    Response<String> ret = new Response<String>();
    ret.requestStartTime = System.currentTimeMillis();

    HttpResponse httpResponse = httpClient.execute(httpPut);

    parseResponseHeaders(context, httpResponse, ret);

    processStandardHttpResponseCodes(httpResponse);

    ret.data = getResponseContentAsString(httpResponse);

    ret.snapRequestDuration();
    writeReponseInfo(ret, context);
    return ret;
}