List of usage examples for java.io IOException getCause
public synchronized Throwable getCause()
From source file:org.apache.hadoop.ipc.TestIPC.java
public void testStandAloneClient() throws Exception { testParallel(10, false, 2, 4, 2, 4, 100); Client client = new Client(LongWritable.class, conf); InetSocketAddress address = new InetSocketAddress("127.0.0.1", 10); try {//w w w . j a va 2s . c o m client.call(new LongWritable(RANDOM.nextLong()), address, null, null, 0, conf); fail("Expected an exception to have been thrown"); } catch (IOException e) { String message = e.getMessage(); String addressText = address.toString(); assertTrue("Did not find " + addressText + " in " + message, message.contains(addressText)); Throwable cause = e.getCause(); assertNotNull("No nested exception in " + e, cause); String causeText = cause.getMessage(); assertTrue("Did not find " + causeText + " in " + message, message.contains(causeText)); } }
From source file:com.github.sardine.FunctionalSardineTest.java
@Test public void testDisallowLoadExternalDtd() throws Exception { final CountDownLatch entry = new CountDownLatch(1); Thread t = new Thread(new Runnable() { public void run() { try { String html = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" + "<html xmlns=\"http://www.w3.org/1999/xhtml\"></html>"; SardineUtil.unmarshal(new ByteArrayInputStream(html.getBytes())); fail("Expected parsing failure for invalid namespace"); } catch (IOException e) { // Success assertTrue(e.getCause() instanceof JAXBException); } finally { entry.countDown();/*from www .j a v a 2s .co m*/ } } }); t.start(); assertTrue( "Timeout for listing resources. Possibly the XML parser is trying to read the DTD in the response.", entry.await(5, TimeUnit.SECONDS)); }
From source file:eu.learnpad.core.rest.XWikiRestUtils.java
public String getEmailAddress(String wikiName, String username) throws LpRestExceptionXWikiImpl { String emailAddress = null;//from w w w .j ava2s.c om HttpClient httpClient = restResource.getClient(); // http://<server>/rest/wikis/xwiki/spaces/XWiki/pages/<username>/objects/XWiki.XWikiUsers/0/properties/email String uri = String.format("%s/wikis/%s/spaces/XWiki/pages/%s/objects/XWiki.XWikiUsers/0/properties/email", DefaultRestResource.REST_URI, wikiName, username); GetMethod getMethod = new GetMethod(uri); try { httpClient.executeMethod(getMethod); InputStream response = getMethod.getResponseBodyAsStream(); JAXBContext jaxbContext = JAXBContext.newInstance(Property.class); Property emailProperty = (Property) jaxbContext.createUnmarshaller().unmarshal(response); emailAddress = emailProperty.getValue(); } catch (IOException e) { String message = String.format("Unable to GET the email propery of '%s' on %s@%s'.", username, wikiName, DefaultRestResource.REST_URI); logger.error(message, e); throw new LpRestExceptionXWikiImpl(message, e.getCause()); } catch (JAXBException e) { String message = String.format("Unable to unmarshall the email propery of '%s' on %s@%s'.", username, wikiName, DefaultRestResource.REST_URI); logger.error(message, e); throw new LpRestExceptionXWikiImpl(message, e.getCause()); } return emailAddress; }
From source file:org.osaf.cosmo.atom.provider.TicketsCollectionAdapter.java
public ResponseContext postEntry(RequestContext request) { TicketsTarget target = (TicketsTarget) request.getTarget(); CollectionItem collection = target.getCollection(); ResponseContext frc = checkEntryWritePreconditions(request); if (frc != null) return frc; try {//from www. ja va 2s . com Ticket ticket = readTicket(request); ticket.setOwner(securityManager.getSecurityContext().getUser()); if (contentService.getTicket(collection, ticket.getKey()) != null) return ProviderHelper.conflict(request, "Ticket exists on " + collection.getDisplayName()); if (log.isDebugEnabled()) log.debug("creating ticket " + ticket.getKey() + " for collection " + collection.getDisplayName()); contentService.createTicket(collection, ticket); collection = contentService.updateCollection(collection); ServiceLocator locator = createServiceLocator(request); TicketsFeedGenerator generator = createTicketsFeedGenerator(locator); Entry entry = generator.generateEntry(collection, ticket); return created(request, entry, ticket, locator); } catch (IOException e) { String reason = "Unable to read request content: " + e.getMessage(); log.error(reason, e); return ProviderHelper.servererror(request, reason, e); } catch (ValidationException e) { String msg = "Invalid entry: " + e.getMessage(); if (e.getCause() != null) msg += e.getCause().getMessage(); return ProviderHelper.badrequest(request, msg); } catch (GeneratorException e) { String reason = "Unknown entry generation error: " + e.getMessage(); log.error(reason, e); return ProviderHelper.servererror(request, reason, e); } }
From source file:org.apache.blur.command.ShardCommandManagerTest.java
@Test public void testShardCommandManagerNormalWithCancel() throws IOException, TimeoutException, ExceptionCollector, BlurException, InterruptedException { String commandExecutionId = "TEST_COMMAND_ID1"; BlurObjectSerDe serDe = new BlurObjectSerDe(); WaitForSeconds waitForSeconds = new WaitForSeconds(); waitForSeconds.setTable("test"); waitForSeconds.setSeconds(5);//from w w w . ja v a 2 s .c o m waitForSeconds.setCommandExecutionId(commandExecutionId); Arguments arguments = CommandUtil.toArguments(waitForSeconds, serDe); BlurObject args = CommandUtil.toBlurObject(arguments); System.out.println(args.toString(1)); final ArgumentOverlay argumentOverlay = new ArgumentOverlay(args, serDe); final AtomicBoolean fail = new AtomicBoolean(); final AtomicBoolean running = new AtomicBoolean(true); new Thread(new Runnable() { @Override public void run() { TableContextFactory tableContextFactory = getTableContextFactory(); Long instanceExecutionId = null; while (true) { try { Response response; if (instanceExecutionId == null) { response = _manager.execute(tableContextFactory, "wait", argumentOverlay); } else { response = _manager.reconnect(instanceExecutionId); } fail.set(true); System.out.println(response); return; } catch (IOException e) { if (e.getCause() instanceof CancellationException) { return; } e.printStackTrace(); fail.set(true); return; } catch (TimeoutException e) { instanceExecutionId = e.getInstanceExecutionId(); } catch (Exception e) { e.printStackTrace(); fail.set(true); return; } finally { running.set(false); } } } }).start(); Thread.sleep(1000); _manager.cancelCommand(commandExecutionId); Thread.sleep(5000); if (fail.get() || running.get()) { fail("Fail [" + fail.get() + "] Running [" + running.get() + "]"); } }
From source file:org.apache.hadoop.tools.distcp2.mapred.CopyMapper.java
private void handleFailures(IOException exception, FileStatus sourceFileStatus, Path target, Context context) throws IOException, InterruptedException { LOG.error("Failure in copying " + sourceFileStatus.getPath() + " to " + target, exception); if (ignoreFailures && exception.getCause() instanceof RetriableFileCopyCommand.CopyReadException) { incrementCounter(context, Counter.FAIL, 1); incrementCounter(context, Counter.BYTESFAILED, sourceFileStatus.getLen()); context.write(null, new Text( "FAIL: " + sourceFileStatus.getPath() + " - " + StringUtils.stringifyException(exception))); } else//from ww w .ja v a 2 s . co m throw exception; }
From source file:DDTReporter.java
private void transformXmlFileToHtml(String fileSpecs, String resultsFolder) throws IOException, TransformerException { try {//from w w w . java2s .c o m String baseSpecs = DDTSettings.asValidOSPath(fileSpecs, true); String htmlFileSpecs = baseSpecs.replace(".xml", ".html"); String xslFileName = DDTSettings.asValidOSPath(settings.xslFileName(), false); String xslFileSpecs = DDTSettings.asValidOSPath(settings.resourcesFolder() + xslFileName, false); //String targetFolder = resultsFolder.endsWith(File.separator) ? resultsFolder : resultsFolder + File.separator; StringWriter sw = new StringWriter(); XSLTProcessor xsltProcessor = new XSLTProcessor(); xsltProcessor.setFile(xslFileSpecs); URL xmlURL = new File(baseSpecs).toURI().toURL(); //String xmlSystemId = xmlURL.toExternalForm(); URL xsltURL = new File(xslFileSpecs).toURI().toURL(); //String xsltSystemId = xsltURL.toExternalForm(); URL htmlURL = new File(htmlFileSpecs).toURI().toURL(); //String htmlSystemId = htmlURL.toExternalForm(); File xmlFile = new File(baseSpecs); File xsltFile = new File(xslFileSpecs); File htmlResult = new File(htmlFileSpecs); htmlResult.createNewFile(); OutputStream htmlOutputStream = new FileOutputStream(new File(htmlFileSpecs)); javax.xml.transform.Source xmlSource = new javax.xml.transform.stream.StreamSource(xmlFile); javax.xml.transform.Source xsltSource = new javax.xml.transform.stream.StreamSource(xsltFile); javax.xml.transform.Result result = new javax.xml.transform.stream.StreamResult(htmlOutputStream); javax.xml.transform.TransformerFactory transFact = javax.xml.transform.TransformerFactory.newInstance(); javax.xml.transform.Transformer trans = transFact.newTransformer(xsltSource); trans.transform(xmlSource, result); } catch (IOException e) { System.out.println(e.getCause().toString()); } catch (TransformerException e) { System.out.println(e.getCause().toString()); } }
From source file:eu.learnpad.core.impl.cw.XwikiCoreFacadeRestResource.java
@Override public Entities analyseText(String modelSetId, String contextArtifactId, String userId, String title, String text) throws LpRestException { HttpClient httpClient = this.getClient(); String uri = String.format("%s/learnpad/cw/corefacade/semantic/%s/analysetext", DefaultRestResource.REST_URI, modelSetId); PostMethod postMethod = new PostMethod(uri); postMethod.addRequestHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_XML); NameValuePair[] queryString = new NameValuePair[4]; queryString[0] = new NameValuePair("modelsetid", modelSetId); queryString[1] = new NameValuePair("contextArtifactId", contextArtifactId); queryString[2] = new NameValuePair("userid", userId); queryString[3] = new NameValuePair("title", title); postMethod.setQueryString(queryString); RequestEntity requestEntity;/*w w w.j av a2 s . com*/ InputStream entitiesAsStream = null; try { requestEntity = new StringRequestEntity(text, MediaType.APPLICATION_XML, "UTF-8"); postMethod.setRequestEntity(requestEntity); httpClient.executeMethod(postMethod); entitiesAsStream = postMethod.getResponseBodyAsStream(); } catch (IOException e) { throw new LpRestExceptionXWikiImpl(e.getMessage(), e.getCause()); } Entities entities = null; try { JAXBContext jc = JAXBContext.newInstance(Entities.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); entities = (Entities) unmarshaller.unmarshal(entitiesAsStream); } catch (JAXBException e) { throw new LpRestExceptionXWikiImpl(e.getMessage(), e.getCause()); } return entities; }
From source file:org.osaf.cosmo.atom.provider.PreferencesCollectionAdapter.java
public ResponseContext postEntry(RequestContext request) { PreferencesTarget target = (PreferencesTarget) request.getTarget(); User user = target.getUser();/*from www . jav a2 s .c om*/ ResponseContext frc = checkEntryWritePreconditions(request); if (frc != null) return frc; try { Preference pref = readPreference(request); if (user.getPreference(pref.getKey()) != null) return ProviderHelper.conflict(request, "Preference exists"); if (log.isDebugEnabled()) log.debug("creating preference " + pref.getKey() + " for user " + user.getUsername()); user.addPreference(pref); user = userService.updateUser(user); ServiceLocator locator = createServiceLocator(request); PreferencesFeedGenerator generator = createPreferencesFeedGenerator(locator); Entry entry = generator.generateEntry(pref); return created(request, entry, pref, locator); } catch (IOException e) { String reason = "Unable to read request content: " + e.getMessage(); log.error(reason, e); return ProviderHelper.servererror(request, reason, e); } catch (ValidationException e) { String msg = "Invalid entry: " + e.getMessage(); if (e.getCause() != null) msg += e.getCause().getMessage(); return ProviderHelper.badrequest(request, msg); } catch (GeneratorException e) { String reason = "Unknown entry generation error: " + e.getMessage(); log.error(reason, e); return ProviderHelper.servererror(request, reason, e); } }