List of usage examples for java.util.concurrent ExecutionException getCause
public synchronized Throwable getCause()
From source file:org.eel.kitchen.jsonschema.ref.SchemaRegistry.java
/** * Get a schema container from the given URI * * <p>Note that if the URI is relative, it will be resolved against this * registry's namespace, if any.</p> * * @param uri the URI/*from ww w.ja v a 2 s . com*/ * @return a schema container * @throws JsonSchemaException impossible to get content at this URI */ public SchemaContainer get(final URI uri) throws JsonSchemaException { final URI realURI = namespace.resolve(JsonRef.fromURI(uri)).toURI(); try { return cache.get(realURI); } catch (ExecutionException e) { final Message.Builder msg = Domain.REF_RESOLVING.newMessage().setKeyword("N/A") .setMessage("failed to get content from URI").addInfo("uri", realURI) .addInfo("exception-class", e.getCause().getClass().getName()) .addInfo("exception-message", e.getCause().getMessage()); throw new JsonSchemaException(msg.build()); } }
From source file:com.microsoft.aad.adal4jsample.BasicFilter.java
private AuthenticationResult getAccessTokenFromRefreshToken(String refreshToken) throws Throwable { AuthenticationContext context;/*from w w w .java2s .co m*/ AuthenticationResult result = null; ExecutorService service = null; try { service = Executors.newFixedThreadPool(1); context = new AuthenticationContext(authority + tenant + "/", true, service); Future<AuthenticationResult> future = context.acquireTokenByRefreshToken(refreshToken, new ClientCredential(clientId, clientSecret), null, null); result = future.get(); } catch (ExecutionException e) { throw e.getCause(); } finally { service.shutdown(); } if (result == null) { throw new ServiceUnavailableException("authentication result was null"); } return result; }
From source file:com.cloudera.livy.client.local.rpc.TestRpc.java
@Test public void testClientServer() throws Exception { RpcServer server = autoClose(new RpcServer(emptyConfig)); Rpc[] rpcs = createRpcConnection(server); Rpc serverRpc = rpcs[0];/* w w w . j a va 2 s . com*/ Rpc client = rpcs[1]; TestMessage outbound = new TestMessage("Hello World!"); Future<TestMessage> call = client.call(outbound, TestMessage.class); TestMessage reply = call.get(10, TimeUnit.SECONDS); assertEquals(outbound.message, reply.message); TestMessage another = new TestMessage("Hello again!"); Future<TestMessage> anotherCall = client.call(another, TestMessage.class); TestMessage anotherReply = anotherCall.get(10, TimeUnit.SECONDS); assertEquals(another.message, anotherReply.message); String errorMsg = "This is an error."; try { client.call(new ErrorCall(errorMsg)).get(10, TimeUnit.SECONDS); } catch (ExecutionException ee) { assertTrue(ee.getCause() instanceof RpcException); assertTrue(ee.getCause().getMessage().indexOf(errorMsg) >= 0); } // Test from server to client too. TestMessage serverMsg = new TestMessage("Hello from the server!"); Future<TestMessage> serverCall = serverRpc.call(serverMsg, TestMessage.class); TestMessage serverReply = serverCall.get(10, TimeUnit.SECONDS); assertEquals(serverMsg.message, serverReply.message); }
From source file:org.jboss.as.test.clustering.cluster.web.ClusteredWebSimpleTestCase.java
private void abstractGracefulServe(URL baseURL1, boolean undeployOnly) throws Exception { final DefaultHttpClient client = HttpClientUtils.relaxedCookieHttpClient(); String url1 = baseURL1.toString() + "simple"; // Make sure a normal request will succeed HttpResponse response = client.execute(new HttpGet(url1)); Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); response.getEntity().getContent().close(); // Send a long request - in parallel String longRunningUrl = url1 + "?" + SimpleServlet.REQUEST_DURATION_PARAM + "=" + REQUEST_DURATION; ExecutorService executor = Executors.newSingleThreadExecutor(); Future<HttpResponse> future = executor.submit(new RequestTask(client, longRunningUrl)); // Make sure long request has started Thread.sleep(1000);//from w w w . j a v a2 s . com if (undeployOnly) { // Undeploy the app only. undeploy(DEPLOYMENT_1); } else { // Shutdown server. stop(CONTAINER_1); } // Get result of long request // This request should succeed since it initiated before server shutdown try { response = future.get(); Assert.assertEquals("Request should succeed since it initiated before undeply or shutdown.", HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); response.getEntity().getContent().close(); } catch (ExecutionException e) { e.printStackTrace(System.err); Assert.fail(e.getCause().getMessage()); } if (undeployOnly) { // If we are only undeploying, then subsequent requests should return 404. response = client.execute(new HttpGet(url1)); Assert.assertEquals("If we are only undeploying, then subsequent requests should return 404.", HttpServletResponse.SC_NOT_FOUND, response.getStatusLine().getStatusCode()); response.getEntity().getContent().close(); } }
From source file:com.microsoft.aad.adal4jsample.BasicFilter.java
private AuthenticationResult getAccessToken(AuthorizationCode authorizationCode, String currentUri) throws Throwable { String authCode = authorizationCode.getValue(); ClientCredential credential = new ClientCredential(clientId, clientSecret); AuthenticationContext context;/*from ww w.j a va2s . c om*/ AuthenticationResult result = null; ExecutorService service = null; try { service = Executors.newFixedThreadPool(1); context = new AuthenticationContext(authority + tenant + "/", true, service); Future<AuthenticationResult> future = context.acquireTokenByAuthorizationCode(authCode, new URI(currentUri), credential, null); result = future.get(); } catch (ExecutionException e) { throw e.getCause(); } finally { service.shutdown(); } if (result == null) { throw new ServiceUnavailableException("authentication result was null"); } return result; }
From source file:com.pliu.powerbiintegrate.BasicFilter.java
private AuthenticationResult getAccessToken(AuthorizationCode authorizationCode, String currentUri) throws Throwable { String authCode = authorizationCode.getValue(); ClientCredential credential = new ClientCredential(clientId, clientSecret); AuthenticationContext context;//from ww w .ja va2s .c om AuthenticationResult result = null; ExecutorService service = null; try { service = Executors.newFixedThreadPool(1); context = new AuthenticationContext(authority + tenant + "/", true, service); Future<AuthenticationResult> future = context.acquireTokenByAuthorizationCode(authCode, new URI(currentUri), credential, "https://analysis.windows.net/powerbi/api", null); result = future.get(); } catch (ExecutionException e) { throw e.getCause(); } finally { service.shutdown(); } if (result == null) { throw new ServiceUnavailableException("authentication result was null"); } return result; }
From source file:com.yahoo.pulsar.client.impl.ConsumerBase.java
@Override public void acknowledge(MessageId messageId) throws PulsarClientException { try {/*www . j a v a2 s. c o m*/ acknowledgeAsync(messageId).get(); } catch (ExecutionException e) { Throwable t = e.getCause(); if (t instanceof PulsarClientException) { throw (PulsarClientException) t; } else { throw new PulsarClientException(t); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new PulsarClientException(e); } }
From source file:com.yahoo.pulsar.client.impl.ConsumerBase.java
@Override public void acknowledgeCumulative(MessageId messageId) throws PulsarClientException { try {//from w ww. jav a 2s . c om acknowledgeCumulativeAsync(messageId).get(); } catch (ExecutionException e) { Throwable t = e.getCause(); if (t instanceof PulsarClientException) { throw (PulsarClientException) t; } else { throw new PulsarClientException(t); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new PulsarClientException(e); } }
From source file:com.yahoo.pulsar.client.impl.ConsumerBase.java
@Override public void unsubscribe() throws PulsarClientException { try {//from w ww . ja va2 s . c o m unsubscribeAsync().get(); } catch (ExecutionException e) { Throwable t = e.getCause(); if (t instanceof PulsarClientException) { throw (PulsarClientException) t; } else { throw new PulsarClientException(t); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new PulsarClientException(e); } }
From source file:com.yahoo.pulsar.client.impl.ConsumerBase.java
@Override public void close() throws PulsarClientException { try {//from w w w . j a va 2 s. co m closeAsync().get(); } catch (ExecutionException e) { Throwable t = e.getCause(); if (t instanceof PulsarClientException) { throw (PulsarClientException) t; } else { throw new PulsarClientException(t); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new PulsarClientException(e); } }