Example usage for java.io IOException getCause

List of usage examples for java.io IOException getCause

Introduction

In this page you can find the example usage for java.io IOException getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:org.apache.hadoop.hbase.TestJMXConnectorServer.java

/**
 * This tests to validate the RegionServer's ConnectorServer after unauthorised stopRegionServer
 * call./*from  w  ww  . j av a 2  s.co  m*/
 */
@Test(timeout = 180000)
public void testRSConnectorServerWhenStopRegionServer() throws Exception {
    conf.set(CoprocessorHost.REGIONSERVER_COPROCESSOR_CONF_KEY,
            JMXListener.class.getName() + "," + MyAccessController.class.getName());
    conf.setInt("regionserver.rmi.registry.port", rmiRegistryPort);
    UTIL.startMiniCluster();
    admin = UTIL.getConnection().getAdmin();

    hasAccess = false;
    ServerName serverName = UTIL.getHBaseCluster().getRegionServer(0).getServerName();
    LOG.info("Stopping Region Server...");
    admin.stopRegionServer(serverName.getHostname() + ":" + serverName.getPort());

    // Check whether Region Sever JMX Connector server can be connected
    JMXConnector connector = null;
    try {
        connector = JMXConnectorFactory
                .connect(JMXListener.buildJMXServiceURL(rmiRegistryPort, rmiRegistryPort));
    } catch (IOException e) {
        if (e.getCause() instanceof ServiceUnavailableException) {
            Assert.fail("Can't connect to Region Server ConnectorServer.");
        }
    }
    Assert.assertNotNull("JMXConnector should not be null.", connector);
    connector.close();
}

From source file:eu.learnpad.core.impl.ca.XwikiBridgeInterfaceRestResource.java

@Override
public String getStatusCollaborativeContentVerifications(String contentID) throws LpRestException {

    HttpClient httpClient = this.getAnonymousClient();
    String uri = String.format("%s/learnpad/ca/bridge/validatecollaborativecontent/%s/status", this.restPrefix,
            contentID);/*w w w  .  j a  v  a 2 s .  co m*/
    GetMethod getMethod = new GetMethod(uri);

    try {
        httpClient.executeMethod(getMethod);
        return getMethod.getResponseBodyAsString();
    } catch (IOException e) {
        throw new LpRestExceptionXWikiImpl(e.getMessage(), e.getCause());
    }
}

From source file:eu.learnpad.core.impl.ca.XwikiBridgeInterfaceRestResource.java

@Override
public String getCollaborativeContentVerificationsView(String contentID) throws LpRestException {

    HttpClient httpClient = this.getAnonymousClient();
    String uri = String.format("%s/learnpad/ca/bridge/validatecollaborativecontent/%s/view", this.restPrefix,
            contentID);//from   w ww  .j  a  v a2  s .c o m
    GetMethod getMethod = new GetMethod(uri);

    try {
        httpClient.executeMethod(getMethod);
        return getMethod.getResponseBodyAsString();
    } catch (IOException e) {
        throw new LpRestExceptionXWikiImpl(e.getMessage(), e.getCause());
    }
}

From source file:net.yoomai.virgo.spider.Emulator.java

/**
 * ??/*from  w  ww  .j  av a  2s.  co m*/
 *
 * @param url
 * @param cookies
 */
public void getPage(String id, String filename, String url, String cookies) {
    HttpGet httpGet = new HttpGet(url);
    // cookie
    httpGet.setHeader("Cookie", cookies);
    // Content-Type
    String contentType = config.getString("spider" + id + ".content_type");
    if (contentType == null || "".equals(contentType.trim())) {
        contentType = "text/html;charset=gb2312";
    }
    httpGet.setHeader("Content-Type", contentType);
    // User-Agent
    String agent = config.getString("spider" + id + ".agent");
    if (agent != null && !"".equals(agent.trim())) {
        httpGet.setHeader("User-Agent", agent);
    }

    CloseableHttpClient httpClient = HttpClients.createDefault();
    CloseableHttpResponse response = null;
    try {
        response = httpClient.execute(httpGet);
    } catch (IOException e) {
        log.error(e.getMessage() + " : " + e.getCause());
        response = null;
    }

    if (response != null) {
        StatusLine statusLine = response.getStatusLine();
        if (statusLine.getStatusCode() == 200) {
            try {
                InputStream is = response.getEntity().getContent();
                // OutputStream outputStream = System.out;
                SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
                // ????
                OutputStream outputStream = FileUtils
                        .openOutputStream(new File(config.getString("spider" + id + ".store") + filename + "-"
                                + sdf.format(new Date()) + ".html"));

                byte[] bytes = new byte[1024];
                int count = 0;
                while ((count = is.read(bytes)) != -1) {
                    outputStream.write(bytes, 0, count);
                }
            } catch (IOException e) {
                log.error("??: " + e.getMessage() + " : " + e.getCause());
            }
        } else {
            log.info("????: " + statusLine.getStatusCode());
        }
    } else {
        log.error("GetPage???????.");
    }
}

From source file:org.atilika.kuromoji.server.KuromojiServer.java

private String getViterbiSVG(String dot) {
    Process process = null;/*  w  ww . j  a  v a 2 s.c o  m*/
    try {
        log.info("Running " + DOT_COMMAND);
        process = Runtime.getRuntime().exec(DOT_COMMAND);
        process.getOutputStream().write(dot.getBytes("utf-8"));
        process.getOutputStream().close();

        InputStream input = process.getInputStream();
        String svg = new Scanner(input, "utf-8").useDelimiter("\\A").next();

        int exitValue = process.exitValue();

        log.debug("Read " + svg.getBytes("utf-8").length + " bytes of SVG output");
        log.info("Process exited with exit value " + exitValue);
        return svg;
    } catch (IOException e) {
        log.error("Error running process " + process, e.getCause());
        return null;
    } finally {
        if (process != null) {
            log.info("Destroying process " + process);
            process.destroy();
        }
    }
}

From source file:com.vmware.identity.idm.server.ClientCertTestUtils.java

private KeyStore loadKeyStoreWithType(String keyStoreFile, String pass, String storeType) {
    KeyStore ks = null;/*  w ww  . j  a  va 2 s  .  c o m*/
    try {
        ks = KeyStore.getInstance(storeType);
        ks.load(getClass().getClassLoader().getResourceAsStream(keyStoreFile), pass.toCharArray());
    } catch (FileNotFoundException fnfe) {
        throw new IllegalArgumentException(String.format("keystore file [%s] not found", keyStoreFile), fnfe);
    } catch (IOException ioe) {
        String errMsg = ioe.getCause() instanceof UnrecoverableKeyException ? "Wrong keystore password" : "";
        throw new IllegalArgumentException(errMsg, ioe);
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
    return ks;
}

From source file:ste.web.beanshell.jetty.BugFreeBeanShellUtils.java

@Test
public void bodyAsCorruptedJSONObject() throws Exception {
    TestRequest request = new TestRequest();
    request.setUri(new HttpURI(TEST_URI_PARAMETERS));
    request.setAttribute(TEST_REQ_ATTR_NAME1, TEST_VALUE1);
    request.setSession(new TestSession());
    request.setContentType("application/json");

    Interpreter i = new Interpreter();
    for (String s : TEST_JSON_ERRORS) {
        request.setContent(s);/*  ww w.  j  ava  2s.  co m*/
        try {
            BeanShellUtils.setup(i, request, new TestResponse());
            fail("JSONException not thrown for <" + s + ">");
        } catch (IOException x) {
            then(x.getCause()).isNotNull().isInstanceOf(JSONException.class);
        }
    }
}

From source file:org.geotools.data.couchdb.CouchDBDataStoreTest.java

@Test
public void testBrokenHost() {
    store.setCouchURL("http://thisshouldnotexistandifitdoesihateyou.org");
    try {/*from   w  ww .j  a v a 2s .c  o m*/
        store.getFeatureSource("foo");
        fail("expected exception");
    } catch (IOException ex) {
        assertEquals("HTTP error", ex.getMessage());
        assertTrue(ex.getCause() instanceof UnknownHostException);
    }
}

From source file:com.codefollower.lealone.omid.tso.TestClientHandler.java

@Override
protected void processMessage(TSOMessage msg) {
    if (msg instanceof CommitResponse) {
        CommitResponse cr = (CommitResponse) msg;
        if (!cr.committed && autoFullAbort) {
            try {
                completeAbort(cr.startTimestamp, new SyncAbortCompleteCallback());
            } catch (IOException e) {
                LOG.error("Could not send Abort Complete mesagge.", e.getCause());
            }//from  ww w.ja v  a  2s  .  co m
        }
    }
    messageQueue.add(msg);
}

From source file:ste.web.http.beanshell.BugFreeBeanShellUtils.java

@Test
public void bodyAsCorruptedJSONObject() throws Exception {
    BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("get", TEST_URI_PARAMETERS);
    HttpSessionContext context = new HttpSessionContext();
    context.setAttribute(HttpCoreContext.HTTP_CONNECTION, getConnection());
    request.addHeader(HTTP.CONTENT_TYPE, CONTENT_TYPE_JSON);

    Interpreter i = new Interpreter();
    for (String s : TEST_JSON_ERRORS) {
        request.setEntity(new StringEntity(s));
        try {//from   w w  w  .j av  a2s .com
            BeanShellUtils.setup(i, request, RESPONSE_OK, context);
            fail("JSONException not thrown for <" + s + ">");
        } catch (IOException x) {
            then(x.getCause()).isNotNull().isInstanceOf(JSONException.class);
        }
    }
}