List of usage examples for java.io IOException getCause
public synchronized Throwable getCause()
From source file:org.jboss.jbossset.CommandLineParser.java
private Map<String, String> getValidDomains(CommandLine cmd) throws ParseException { Properties properties = new Properties(); if (cmd.hasOption("domainFile")) { String url = cmd.getOptionValue("domainFile"); File file = new File(url); if (!file.exists()) throw new ParseException("The specified file does not exist"); try (InputStream in = new FileInputStream(file)) { properties.load(in);/*from ww w. jav a 2s .com*/ } catch (IOException e) { throw new ParseException(e.getMessage() + ": " + e.getCause()); } if (properties.isEmpty()) throw new ParseException("The specified file does not contain any domain pairs"); } else { try (InputStream in = JiraReporter.class.getClassLoader().getResourceAsStream("domains")) { properties.load(in); } catch (IOException e) { throw new ParseException("Default domains file could not be read: " + e); } } @SuppressWarnings("unchecked") Map<String, String> map = (Map) properties; return map; }
From source file:org.apache.solr.client.solrj.io.stream.eval.TemporalEvaluatorsTest.java
@Test public void testInvalidExpression() throws Exception { StreamEvaluator evaluator;/* w ww.ja v a2 s .c om*/ try { evaluator = factory.constructEvaluator("week()"); StreamContext streamContext = new StreamContext(); evaluator.setStreamContext(streamContext); assertTrue(false); } catch (IOException e) { assertTrue(e.getCause().getCause().getMessage().contains("Invalid expression week()")); } try { evaluator = factory.constructEvaluator("week(a, b)"); StreamContext streamContext = new StreamContext(); evaluator.setStreamContext(streamContext); assertTrue(false); } catch (IOException e) { assertTrue(e.getCause().getCause().getMessage().contains("expecting one value but found 2")); } try { evaluator = factory.constructEvaluator("Week()"); StreamContext streamContext = new StreamContext(); evaluator.setStreamContext(streamContext); assertTrue(false); } catch (IOException e) { assertTrue(e.getMessage().contains("Invalid evaluator expression Week() - function 'Week' is unknown")); } }
From source file:com.splunk.shuttl.archiver.archive.ArchiveRestHandler.java
private void logIOExceptionGenereratedByDoingArchiveBucketRequest(IOException e, Bucket bucket) { logger.error(did("Sent archive bucket request", "got IOException", "request to succeed", "exception", e, "bucket_name", bucket.getName(), "cause", e.getCause())); }
From source file:eu.learnpad.core.impl.sim.XwikiBridgeInterfaceRestResource.java
@Override public String addProcessInstance(ProcessInstanceData data) throws LpRestException { HttpClient httpClient = this.getAnonymousClient(); String uri = String.format("%s/learnpad/sim/bridge/instances", this.restPrefix); PostMethod postMethod = new PostMethod(uri); postMethod.addRequestHeader("Content-Type", "application/json"); try {//from www .ja va 2 s .c om // Not fully tested, but is looks working for our purposes -- Gulyx String mashelledData = objectWriter.writeValueAsString(data); RequestEntity requestEntity = new StringRequestEntity(mashelledData, "application/json", "UTF-8"); postMethod.setRequestEntity(requestEntity); httpClient.executeMethod(postMethod); // Not fully tested, but is looks working for our purposes -- Gulyx return objectReaderString.readValue(postMethod.getResponseBodyAsStream()); } catch (IOException e) { throw new LpRestExceptionXWikiImpl(e.getMessage(), e.getCause()); } }
From source file:com.redblackit.war.AppSecurityHttpTest.java
/** * Test GET using supplied URL, expectedTitle (to identify login or welcome page), and an indication of whether we * should authenticate OK, or not.//from www . ja v a 2s . co m * * @param url * @param expectedTitle * @param badClientCertificate * @throws Exception */ private void testGetUrl(final String url, final String expectedTitle, final boolean badClientCertificate) throws Exception { StringBuilder sb = new StringBuilder(); sb.append(":url=").append(url).append(":expectedTitle=").append(expectedTitle) .append(":badClientCertificate=").append(badClientCertificate).append(":clientAuthMandatory=") .append(clientAuthMandatory); final String[] spropkeys = { "user.name", "clientAuthMandatory", "javax.net.ssl.keyStore", "javax.net.ssl.keyStorePassword", "javax.net.ssl.trustStore", "javax.net.ssl.trustStorePassword" }; for (String spropkey : spropkeys) { sb.append("\n [").append(spropkey).append("]=").append(System.getProperty(spropkey)); } WebConversation conversation = new WebConversation(); WebResponse response = null; try { response = conversation.getResponse(url); if (clientAuthMandatory && badClientCertificate) { Assert.fail("expected exception for bad certificate:but got response=" + response + sb); } else { Assert.assertNotNull("response" + sb, response); logger.info(response); String respUrl = response.getURL().toString(); Assert.assertTrue("URL should start with '" + baseHttpsUrl + "' ... but was '" + respUrl + "'", respUrl.startsWith(baseHttpsUrl)); Assert.assertEquals("Title for response page" + sb, expectedTitle, response.getTitle().trim()); } } catch (IOException se) { if (clientAuthMandatory && se instanceof SocketException) { logger.debug("expected exception" + sb, se); Throwable t = se.getCause(); while (t instanceof SocketException) { t = t.getCause(); } if (t != null) { logger.debug("root cause exception" + sb, t); } } else { logger.fatal("unexpected exception:" + sb, se); throw new RuntimeException("unexpected exception" + sb, se); } } }
From source file:org.apache.hadoop.hbase.master.ZKClusterStateRecovery.java
/** * Read znode path as part of scanning the unassigned directory. * @param regionName the region name to read the unassigned znode for * @return znode data or null if the znode no longer exists * @throws IOException in case of a ZK error *///from ww w. ja v a 2 s. c om private byte[] getUnassignedZNodeAndSetWatch(String regionName) throws IOException { final String znodePath = zkw.getZNode(unassignedZNode, regionName); try { return zkw.readUnassignedZNodeAndSetWatch(znodePath); } catch (IOException ex) { if (ex.getCause() instanceof KeeperException) { KeeperException ke = (KeeperException) ex.getCause(); if (ke.code() == KeeperException.Code.NONODE) { LOG.warn("Unassigned node is missing: " + znodePath + ", ignoring"); return null; } } throw ex; } }
From source file:org.apache.hadoop.ipc.TestIPC.java
public void testErrorClient() throws Exception { // start server Server server = new TestServer(1, false); InetSocketAddress addr = NetUtils.getConnectAddress(server); server.start();// w ww.j av a 2 s . c om // start client Client client = new Client(LongErrorWritable.class, conf); try { client.call(new LongErrorWritable(RANDOM.nextLong()), addr, null, null, 0, conf); fail("Expected an exception to have been thrown"); } catch (IOException e) { // check error Throwable cause = e.getCause(); assertTrue(cause instanceof IOException); assertEquals(LongErrorWritable.ERR_MSG, cause.getMessage()); } }
From source file:org.apache.flink.runtime.state.DuplicatingCheckpointOutputStreamTest.java
/** * Tests that an exception from interacting with the secondary stream does not effect duplicating to the primary * stream, but is reflected later when we want the secondary state handle. *///from w w w . j a va 2 s .co m private void testFailingSecondaryStream(DuplicatingCheckpointOutputStream duplicatingStream, StreamTestMethod testMethod) throws Exception { testMethod.call(); duplicatingStream.write(42); FailingCheckpointOutStream secondary = (FailingCheckpointOutStream) duplicatingStream .getSecondaryOutputStream(); Assert.assertTrue(secondary.isClosed()); long pos = duplicatingStream.getPos(); StreamStateHandle primaryHandle = duplicatingStream.closeAndGetPrimaryHandle(); if (primaryHandle != null) { Assert.assertEquals(pos, primaryHandle.getStateSize()); } try { duplicatingStream.closeAndGetSecondaryHandle(); Assert.fail(); } catch (IOException ioEx) { Assert.assertEquals(ioEx.getCause(), duplicatingStream.getSecondaryStreamException()); } }
From source file:eu.learnpad.core.impl.sim.XwikiBridgeInterfaceRestResource.java
@Override public Collection<String> addProcessDefinition(String processDefinitionFileURL, String modelSetId) throws LpRestException { HttpClient httpClient = this.getAnonymousClient(); String uri;/*w w w .j a va2s . co m*/ if (modelSetId != null) { uri = String.format("%s/learnpad/sim/bridge/processes?modelsetartifactid=%s", this.restPrefix, modelSetId); } else { uri = String.format("%s/learnpad/sim/bridge/processes", this.restPrefix); } PostMethod postMethod = new PostMethod(uri); postMethod.addRequestHeader("Content-Type", "application/json"); try { RequestEntity requestEntity = new StringRequestEntity(processDefinitionFileURL, "application/json", "UTF-8"); postMethod.setRequestEntity(requestEntity); httpClient.executeMethod(postMethod); // Not fully tested, but is looks working for our purposes -- Gulyx return this.objectReaderCollection.readValue(postMethod.getResponseBodyAsStream()); } catch (IOException e) { throw new LpRestExceptionXWikiImpl(e.getMessage(), e.getCause()); } }
From source file:eu.learnpad.core.impl.sim.XwikiBridgeInterfaceRestResource.java
@Override public String addProcessInstance(String processId, Collection<UserData> potentialUsers, String currentUser) throws LpRestException { HttpClient httpClient = this.getAnonymousClient(); String uri = String.format("%s/learnpad/sim/bridge/instances/%s", this.restPrefix, processId); PostMethod postMethod = new PostMethod(uri); postMethod.addRequestHeader("Content-Type", "application/json"); NameValuePair[] queryString = new NameValuePair[1]; queryString[0] = new NameValuePair("currentuser", currentUser); postMethod.setQueryString(queryString); StringRequestEntity requestEntity = null; String potentialUsersJson = "[]"; try {/*from ww w.j av a 2 s . com*/ potentialUsersJson = this.objectWriter.writeValueAsString(potentialUsers); requestEntity = new StringRequestEntity(potentialUsersJson, "application/json", "UTF-8"); postMethod.setRequestEntity(requestEntity); httpClient.executeMethod(postMethod); return IOUtils.toString(postMethod.getResponseBodyAsStream()); } catch (IOException e) { throw new LpRestExceptionXWikiImpl(e.getMessage(), e.getCause()); } }