List of usage examples for java.lang InterruptedException getCause
public synchronized Throwable getCause()
From source file:com.microsoft.azure.keyvault.cryptography.test.SymmetricKeyTest.java
@Test public void testSymmetricKeyAesKw256() { // Arrange/* w w w . ja v a 2s .c o m*/ byte[] KEK = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F }; byte[] CEK = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, (byte) 0x88, (byte) 0x99, (byte) 0xAA, (byte) 0xBB, (byte) 0xCC, (byte) 0xDD, (byte) 0xEE, (byte) 0xFF }; byte[] EK = { 0x64, (byte) 0xE8, (byte) 0xC3, (byte) 0xF9, (byte) 0xCE, 0x0F, 0x5B, (byte) 0xA2, 0x63, (byte) 0xE9, 0x77, 0x79, 0x05, (byte) 0x81, (byte) 0x8A, 0x2A, (byte) 0x93, (byte) 0xC8, 0x19, 0x1E, 0x7D, 0x6E, (byte) 0x8A, (byte) 0xE7 }; /* * This test using the default JCE provider depends on whether unlimited security * is installed or not. In the unlimited case, the full test should pass but in * the limited case, it should fail with InvalidKeyException. */ boolean unlimited = hasUnlimitedCrypto(); SymmetricKey key = new SymmetricKey("KEK", KEK, _provider); byte[] encrypted = null; try { encrypted = key.wrapKeyAsync(CEK, "A256KW").get().getLeft(); if (!unlimited) fail("Expected ExecutionException"); } catch (InterruptedException e) { fail("InterrupedException"); } catch (ExecutionException e) { // In the limited case, the failure should be InvalidKeyException // In the unlimited case, this should not fail if (!unlimited) { Throwable cause = e.getCause(); if (cause == null || !(cause instanceof InvalidKeyException)) fail("ExecutionException"); } else { fail("ExecutionException"); } } catch (NoSuchAlgorithmException e) { fail("NoSuchAlgorithmException"); } if (unlimited) { // Assert assertArrayEquals(EK, encrypted); byte[] decrypted = null; try { decrypted = key.unwrapKeyAsync(EK, "A256KW").get(); } catch (InterruptedException e) { fail("InterrupedException"); } catch (ExecutionException e) { fail("ExecutionException"); } catch (NoSuchAlgorithmException e) { fail("NoSuchAlgorithmException"); } // Assert assertArrayEquals(CEK, decrypted); } try { key.close(); } catch (IOException e) { fail("Key could not be closed"); } }
From source file:com.microsoft.azure.keyvault.cryptography.test.SymmetricKeyTest.java
@Test public void testSymmetricKeyAesKw256_ExcessKeyMaterial() { // Arrange// w w w . ja va 2 s .c o m byte[] KEK = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F }; byte[] CEK = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, (byte) 0x88, (byte) 0x99, (byte) 0xAA, (byte) 0xBB, (byte) 0xCC, (byte) 0xDD, (byte) 0xEE, (byte) 0xFF }; byte[] EK = { 0x64, (byte) 0xE8, (byte) 0xC3, (byte) 0xF9, (byte) 0xCE, 0x0F, 0x5B, (byte) 0xA2, 0x63, (byte) 0xE9, 0x77, 0x79, 0x05, (byte) 0x81, (byte) 0x8A, 0x2A, (byte) 0x93, (byte) 0xC8, 0x19, 0x1E, 0x7D, 0x6E, (byte) 0x8A, (byte) 0xE7 }; /* * This test using the default JCE provider depends on whether unlimited security * is installed or not. In the unlimited case, the full test should pass but in * the limited case, it should fail with InvalidKeyException. */ boolean unlimited = hasUnlimitedCrypto(); SymmetricKey key = new SymmetricKey("KEK", KEK, _provider); byte[] encrypted = null; try { encrypted = key.wrapKeyAsync(CEK, "A256KW").get().getLeft(); if (!unlimited) fail("Expected ExecutionException"); } catch (InterruptedException e) { fail("InterrupedException"); } catch (ExecutionException e) { // In the limited case, the failure should be InvalidKeyException // In the unlimited case, this should not fail if (!unlimited) { Throwable cause = e.getCause(); if (cause == null || !(cause instanceof InvalidKeyException)) fail("ExecutionException"); } else { fail("ExecutionException"); } } catch (NoSuchAlgorithmException e) { fail("NoSuchAlgorithmException"); } if (unlimited) { // Assert assertArrayEquals(EK, encrypted); byte[] decrypted = null; try { decrypted = key.unwrapKeyAsync(EK, "A256KW").get(); } catch (InterruptedException e) { fail("InterrupedException"); } catch (ExecutionException e) { fail("ExecutionException"); } catch (NoSuchAlgorithmException e) { fail("NoSuchAlgorithmException"); } // Assert assertArrayEquals(CEK, decrypted); } try { key.close(); } catch (IOException e) { fail("Key could not be closed"); } }
From source file:com.microsoft.azure.keyvault.cryptography.test.SymmetricKeyTest.java
@Test public void testSymmetricKeyDefaultAlgorithmAesKw256() { // Arrange// ww w . j a v a 2s. c o m byte[] KEK = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F }; byte[] CEK = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, (byte) 0x88, (byte) 0x99, (byte) 0xAA, (byte) 0xBB, (byte) 0xCC, (byte) 0xDD, (byte) 0xEE, (byte) 0xFF }; byte[] EK = { 0x64, (byte) 0xE8, (byte) 0xC3, (byte) 0xF9, (byte) 0xCE, 0x0F, 0x5B, (byte) 0xA2, 0x63, (byte) 0xE9, 0x77, 0x79, 0x05, (byte) 0x81, (byte) 0x8A, 0x2A, (byte) 0x93, (byte) 0xC8, 0x19, 0x1E, 0x7D, 0x6E, (byte) 0x8A, (byte) 0xE7 }; /* * This test using the default JCE provider depends on whether unlimited security * is installed or not. In the unlimited case, the full test should pass but in * the limited case, it should fail with InvalidKeyException. */ boolean unlimited = hasUnlimitedCrypto(); SymmetricKey key = new SymmetricKey("KEK", KEK, _provider); byte[] encrypted = null; String algorithm = null; try { Pair<byte[], String> result = key.wrapKeyAsync(CEK, null).get(); encrypted = result.getLeft(); algorithm = result.getRight(); if (!unlimited) fail("Expected ExecutionException"); } catch (InterruptedException e) { fail("InterrupedException"); } catch (ExecutionException e) { // In the limited case, the failure should be InvalidKeyException // In the unlimited case, this should not fail if (!unlimited) { Throwable cause = e.getCause(); if (cause == null || !(cause instanceof InvalidKeyException)) fail("ExecutionException"); } else { fail("ExecutionException"); } } catch (NoSuchAlgorithmException e) { fail("NoSuchAlgorithmException"); } if (unlimited) { // Assert assertEquals("A256KW", algorithm); assertArrayEquals(EK, encrypted); byte[] decrypted = null; try { decrypted = key.unwrapKeyAsync(EK, algorithm).get(); } catch (InterruptedException e) { fail("InterrupedException"); } catch (ExecutionException e) { fail("ExecutionException"); } catch (NoSuchAlgorithmException e) { fail("NoSuchAlgorithmException"); } // Assert assertArrayEquals(CEK, decrypted); } try { key.close(); } catch (IOException e) { fail("Key could not be closed"); } }
From source file:com.microsoft.azure.keyvault.cryptography.test.SymmetricKeyTest.java
@Test public void testSymmetricKeyDefaultAlgorithmAesKw192() { // Arrange/*from w w w .ja va 2 s .com*/ byte[] KEK = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 }; byte[] CEK = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, (byte) 0x88, (byte) 0x99, (byte) 0xAA, (byte) 0xBB, (byte) 0xCC, (byte) 0xDD, (byte) 0xEE, (byte) 0xFF }; byte[] EK = { (byte) 0x96, 0x77, (byte) 0x8B, 0x25, (byte) 0xAE, 0x6C, (byte) 0xA4, 0x35, (byte) 0xF9, 0x2B, 0x5B, (byte) 0x97, (byte) 0xC0, 0x50, (byte) 0xAE, (byte) 0xD2, 0x46, (byte) 0x8A, (byte) 0xB8, (byte) 0xA1, 0x7A, (byte) 0xD8, 0x4E, 0x5D }; /* * This test using the default JCE provider depends on whether unlimited security * is installed or not. In the unlimited case, the full test should pass but in * the limited case, it should fail with InvalidKeyException. */ boolean unlimited = hasUnlimitedCrypto(); SymmetricKey key = new SymmetricKey("KEK", KEK, _provider); byte[] encrypted = null; String algorithm = null; try { Pair<byte[], String> result = key.wrapKeyAsync(CEK, null).get(); encrypted = result.getLeft(); algorithm = result.getRight(); if (!unlimited) fail("Expected ExecutionException"); } catch (InterruptedException e) { fail("InterrupedException"); } catch (ExecutionException e) { // In the limited case, the failure should be InvalidKeyException // In the unlimited case, this should not fail if (!unlimited) { Throwable cause = e.getCause(); if (cause == null || !(cause instanceof InvalidKeyException)) fail("ExecutionException"); } else { fail("ExecutionException"); } } catch (NoSuchAlgorithmException e) { fail("NoSuchAlgorithmException"); } if (unlimited) { // Assert assertEquals("A192KW", algorithm); assertArrayEquals(EK, encrypted); byte[] decrypted = null; try { decrypted = key.unwrapKeyAsync(EK, algorithm).get(); } catch (InterruptedException e) { fail("InterrupedException"); } catch (ExecutionException e) { fail("ExecutionException"); } catch (NoSuchAlgorithmException e) { fail("NoSuchAlgorithmException"); } // Assert assertArrayEquals(CEK, decrypted); } try { key.close(); } catch (IOException e) { fail("Key could not be closed"); } }
From source file:org.apache.hadoop.hdfs.server.namenode.AbstractFileTree.java
public void buildUp(BlockStoragePolicySuite bsps) throws IOException { INode subtreeRoot = readSubtreeRoot(bsps); if (!subtreeRoot.isDirectory()) { return;//w ww . j a v a2s . c o m } collectChildren(newProjectedInode(subtreeRoot, 0), subtreeRootId.getDepth(), 2, subtreeRootDefaultEntries, bsps, inheritedStoragePolicy); while (true) { try { Future future = activeCollectors.poll(); if (future == null) { break; } future.get(); } catch (InterruptedException e) { LOG.info("FileTree builder was interrupted"); throw new BuildingUpFileTreeFailedException("Building the up the file tree was interrupted."); } catch (ExecutionException e) { if (e.getCause() instanceof RuntimeException) { throw new RuntimeException(e.getCause()); } else { // This should not happen as it is a Runnable String message = "FileTree.buildUp received an unexpected execution exception"; LOG.warn(message, e); throw new RetriableException(message); } } } if (exception != null) { throw exception; } }
From source file:org.apache.tez.runtime.task.TezTaskRunner.java
/** * @return false if a shutdown message was received during task execution * @throws TezException/*ww w .j a va2s . co m*/ * @throws IOException */ public boolean run() throws InterruptedException, IOException, TezException { waitingThread = Thread.currentThread(); taskRunning.set(true); taskReporter.registerTask(task, this); TaskRunnerCallable callable = new TaskRunnerCallable(); Throwable failureCause = null; taskFuture = executor.submit(callable); try { taskFuture.get(); // Task could signal a fatal error and return control, or a failure while registering success. failureCause = firstException; } catch (InterruptedException e) { LOG.info("Interrupted while waiting for task to complete. Interrupting task"); taskFuture.cancel(true); if (shutdownRequested.get()) { LOG.info("Shutdown requested... returning"); return false; } if (firstException != null) { failureCause = firstException; } else { // Interrupted for some other reason. failureCause = e; } } catch (ExecutionException e) { // Exception thrown by the run() method itself. Throwable cause = e.getCause(); if (cause instanceof FSError) { // Not immediately fatal, this is an error reported by Hadoop FileSystem failureCause = cause; } else if (cause instanceof Error) { LOG.error("Exception of type Error.", cause); sendFailure(cause, "Fatal Error cause TezChild exit."); throw new TezException("Fatal Error cause TezChild exit.", cause); } else { failureCause = cause; } } finally { // Clear the interrupted status of the blocking thread, in case it is set after the // InterruptedException was invoked. taskReporter.unregisterTask(task.getTaskAttemptID()); Thread.interrupted(); } if (failureCause != null) { if (failureCause instanceof FSError) { // Not immediately fatal, this is an error reported by Hadoop FileSystem LOG.info("Encountered an FSError while executing task: " + task.getTaskAttemptID(), failureCause); throw (FSError) failureCause; } else if (failureCause instanceof Error) { LOG.error("Exception of type Error.", failureCause); sendFailure(failureCause, "Fatal error cause TezChild exit."); throw new TezException("Fatal error cause TezChild exit.", failureCause); } else { if (failureCause instanceof IOException) { throw (IOException) failureCause; } else if (failureCause instanceof TezException) { throw (TezException) failureCause; } else if (failureCause instanceof InterruptedException) { throw (InterruptedException) failureCause; } else { throw new TezException(failureCause); } } } if (shutdownRequested.get()) { LOG.info("Shutdown requested... returning"); return false; } return true; }
From source file:burlov.ultracipher.swing.SwingGuiApplication.java
/** * @return 'true' wenn alles fehlerfrei lief */// w w w . java2 s . c o m private boolean downloadAndMergeData() { if (core.getSyncCredentials() == null) { // Nichts zu tun, aber kein Fehler return true; } if (core.getCurrentCryptor() == null) { /* * Beim Sync Passwort mit Bestaetigung abfragen, weil beim falsch * eingegebenem Passwort keine Fehlermeldung kommt sondern einfach * nur leere Daten */ if (!createNewCryptor(true)) { // Vorgang abgebrochen return false; } } final AtomicReference<SyncResult> incomingChanges = new AtomicReference<SyncResult>(SyncResult.NoData); Callable<String> callable = new Callable<String>() { @Override public String call() throws Exception { // Mit neuesten Daten vom Sync-Account mergen System.out.println("Download data from " + core.getSyncCredentials().getEmailaddress()); incomingChanges.set(core.syncDatabase(true)); synced = true; return null; } }; CallableTask<String> task = new CallableTask<String>(callable); WaitDialog dlg = new WaitDialog(getMainFrame(), "Download data", task, 0, 0); dlg.start(); try { task.get(); mainPanel.init(); if (incomingChanges.get() == SyncResult.NoData) { showInfo("No sync data found on the server"); } else if (!hasChanges && incomingChanges.get() == SyncResult.IncomingChanges) { setNeedSave(true); /* * Wenn lokale Aenderungen nur von gerade runtergeladenen Daten * kommen, dann die fusionierte Daten sofort lokal abspeichern */ setNeedSave(!localSaveData()); return !hasChanges; } if (incomingChanges.get() == SyncResult.OutgoingChanges) { /* * Es existieren lokale Daten die nicht auf dem sync-Server * bekannt sind. Speicher-Flag setzen damit das Upload nicht * vergessen wird */ setNeedSave(true); } return true; } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); showError("Sync failed", e.getCause()); } return false; }
From source file:io.druid.indexing.overlord.RemoteTaskRunner.java
@Override public Optional<ByteSource> streamTaskLog(final String taskId, final long offset) { final ZkWorker zkWorker = findWorkerRunningTask(taskId); if (zkWorker == null) { // Worker is not running this task, it might be available in deep storage return Optional.absent(); } else {//from ww w . j a v a2 s. com // Worker is still running this task final URL url = makeWorkerURL(zkWorker.getWorker(), String.format("/task/%s/log?offset=%d", taskId, offset)); return Optional.<ByteSource>of(new ByteSource() { @Override public InputStream openStream() throws IOException { try { return httpClient.go(new Request(HttpMethod.GET, url), new InputStreamResponseHandler()) .get(); } catch (InterruptedException e) { throw Throwables.propagate(e); } catch (ExecutionException e) { // Unwrap if possible Throwables.propagateIfPossible(e.getCause(), IOException.class); throw Throwables.propagate(e); } } }); } }
From source file:org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.java
@Override public EntityManagerFactory getNativeEntityManagerFactory() { if (this.nativeEntityManagerFactory != null) { return this.nativeEntityManagerFactory; } else {/*from ww w . j a v a 2s . com*/ Assert.state(this.nativeEntityManagerFactoryFuture != null, "No native EntityManagerFactory available"); try { return this.nativeEntityManagerFactoryFuture.get(); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); throw new IllegalStateException("Interrupted during initialization of native EntityManagerFactory", ex); } catch (ExecutionException ex) { throw new IllegalStateException( "Failed to asynchronously initialize native EntityManagerFactory: " + ex.getMessage(), ex.getCause()); } } }
From source file:com.funambol.tools.test.PostSyncML.java
public void syncAndTest() throws IOException, TestFailedException { ///*from www . ja v a 2s . co m*/ // First of all clean up! // clean(); SyncML response = null; String respURI = null; File responseFile = null; boolean firstMessage = false; File fb = new File(baseDir, "header.properties"); if (fb.exists()) { propsHeader = new Properties(); propsHeader.load(new FileInputStream(fb)); } existResponseProcessor(); int msgCount = 0; for (int i = 0; i < msgs.length; ++i) { msgCount++; firstMessage = msgs[i].indexOf("<MsgID>1</MsgID>") != -1; if (firstMessage) { try { Thread.currentThread().sleep(sessionsDelay); } catch (InterruptedException ex) { } } try { log.info("Trying to execute target: " + msgFiles[i]); AntUtil.runAntTarget(antProject, baseDir, xmlBuildFile, msgFiles[i]); log.info("Target " + msgFiles[i] + " executed"); } catch (Exception ex) { boolean isIn = containsException(ex.getCause(), ComparisonFailure.class.getName()); if (isIn) { try { log.info("Comparison Failure "); saveEndTestError("Actual Report different than expected.\n" + ex.getLocalizedMessage(), new File(errorDir, "msg-end-test-error.xml")); } catch (IOException e) { } } log.info("Error executing target " + msgFiles[i] + " (" + ex + ")"); //do nothing } // // Read ant properties // Properties prop = new Properties(); File f = new File(baseDir, msgFiles[i] + ".properties"); if (f.exists()) { prop.load(new FileInputStream(f)); } String propertiesValues = prop.getProperty("replace"); // // Replace value_N into message before sending response // if (propertiesValues != null) { StringTokenizer values = new StringTokenizer(propertiesValues, ","); int y = 1; while (values.hasMoreTokens()) { String v = values.nextToken(); msgs[i] = msgs[i].replaceAll("VALUE_" + y, v); y++; } } File header = new File(baseDir, "header" + msgCount + ".properties"); if (header.exists()) { propsHeader = new Properties(); propsHeader.load(new FileInputStream(header)); } log.info("Sending " + msgFiles[i]); if (firstMessage) { // // It is a first message so we can set the // respURI to empty string // log.info("Message with id 1. Start new session"); nextURL = initialURL; } try { response = postRequest(msgs[i]); } catch (RepresentationException e) { Timestamp t = new Timestamp(System.currentTimeMillis()); String message = "<!-- " + t.toString() + " -->\n" + e.getMessage(); IOTools.writeFile(message, new File(errorDir, msgFiles[i])); throw new TestFailedException("XML syntax error: " + e.getMessage(), e); } catch (Sync4jException e) { Timestamp t = new Timestamp(System.currentTimeMillis()); String message = "<!-- " + t.toString() + " -->\n" + e.getMessage(); IOTools.writeFile(message, new File(errorDir, msgFiles[i])); throw new TestFailedException("XML syntax error: " + e.getMessage(), e); } // // Write the messages responded by the server, than read the reference // and make the comparison (excluding the XPaths specified by // ignoreXPaths // responseFile = new File(responseDir, msgFiles[i]); log.info("Writing the response into " + responseFile); try { String xmlMsg = marshallSyncML(response); // Preprocess response message before comparing it with the // reference message if (preProcessResp) { xmlMsg = preProcessResponse(responseProcessor, xmlMsg); } IOTools.writeFile(xmlMsg, responseFile); } catch (Exception e) { e.printStackTrace(); throw new TestFailedException("XML syntax error: " + e.getMessage(), e); } compare(msgFiles[i]); respURI = response.getSyncHdr().getRespURI(); if (respURI != null) { nextURL = respURI; } } }