Java Code Examples for javax.ws.rs.ProcessingException#getCause()
The following examples show how to use
javax.ws.rs.ProcessingException#getCause() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CircuitBreakerFailoverTest.java From cxf with Apache License 2.0 | 6 votes |
@Test public void testSequentialStrategyWithElapsingCircuitBreakerTimeout() throws Throwable { FailoverFeature feature = customizeFeature( new CircuitBreakerFailoverFeature(1, 3000), false, "http://localhost:" + NON_PORT + "/non-existent", "http://localhost:" + NON_PORT + "/non-existent2"); final BookStore bookStore = getBookStore( "http://localhost:" + NON_PORT + "/non-existent", feature); // First iteration is going to open all circuit breakers. The timeout at the end // should reset all circuit breakers and the URLs could be tried again. for (int i = 0; i < 2; ++i) { try { bookStore.getBook(1); fail("Exception expected"); } catch (ProcessingException ex) { if (!(ex.getCause() instanceof IOException)) { throw ex.getCause(); } } // Let's wait a bit more than circuit breaker timeout Thread.sleep(4000); } }
Example 2
Source File: CircuitBreakerFailoverTest.java From cxf with Apache License 2.0 | 6 votes |
@Test(expected = FailoverFailedException.class) public void testSequentialStrategyUnavailableAlternatives() throws Exception { FailoverFeature feature = getFeature(false, "http://localhost:" + NON_PORT + "/non-existent", "http://localhost:" + NON_PORT + "/non-existent2"); final BookStore bookStore = getBookStore( "http://localhost:" + NON_PORT + "/non-existent", feature); // First iteration is going to open all circuit breakers. // Second iteration should not call any URL as all targets are not available. for (int i = 0; i < 2; ++i) { try { bookStore.getBook(1); fail("Exception expected"); } catch (ProcessingException ex) { if (ex.getCause() instanceof FailoverFailedException) { throw (FailoverFailedException) ex.getCause(); } } } }
Example 3
Source File: JerseyDockerHttpClient.java From docker-java with Apache License 2.0 | 6 votes |
@Override public Response execute(Request request) { if (request.hijackedInput() != null) { throw new UnsupportedOperationException("Does not support hijacking"); } String url = sanitizeUrl(originalUri).toString(); if (url.endsWith("/") && request.path().startsWith("/")) { url = url.substring(0, url.length() - 1); } Invocation.Builder builder = client.target(url + request.path()).request(); request.headers().forEach(builder::header); try { return new JerseyResponse( builder.build(request.method(), toEntity(request)).invoke() ); } catch (ProcessingException e) { if (e.getCause() instanceof DockerException) { throw (DockerException) e.getCause(); } throw e; } }
Example 4
Source File: EdgeUtil.java From datacollector with Apache License 2.0 | 6 votes |
public static PipelineConfigurationJson getEdgePipeline(String edgeHttpUrl, String pipelineId) throws PipelineException { Response response = null; try { response = ClientBuilder.newClient() .target(edgeHttpUrl + "/rest/v1/pipeline/" + pipelineId) .request() .get(); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(PipelineConfigurationJson.class); } else { return null; } } catch (ProcessingException ex) { if (ex.getCause() instanceof ConnectException) { throw new PipelineException(ContainerError.CONTAINER_01602, edgeHttpUrl, ex); } throw ex; } finally { if (response != null) { response.close(); } } }
Example 5
Source File: EdgeUtil.java From datacollector with Apache License 2.0 | 6 votes |
public static List<PipelineInfoJson> getEdgePipelines(String edgeHttpUrl) throws PipelineException { Response response = null; try { response = ClientBuilder.newClient() .target(edgeHttpUrl + "/rest/v1/pipelines") .request() .get(); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return Arrays.asList(response.readEntity(PipelineInfoJson[].class)); } else { return Collections.emptyList(); } } catch (ProcessingException ex) { if (ex.getCause() instanceof ConnectException) { throw new PipelineException(ContainerError.CONTAINER_01602, edgeHttpUrl, ex); } throw ex; } finally { if (response != null) { response.close(); } } }
Example 6
Source File: EdgeUtil.java From datacollector with Apache License 2.0 | 5 votes |
public static void resetOffset(PipelineConfiguration pipelineConfiguration) throws PipelineException { String pipelineId = pipelineConfiguration.getPipelineId(); PipelineConfigBean pipelineConfigBean = PipelineBeanCreator.get() .create(pipelineConfiguration, new ArrayList<>(), null); if (!pipelineConfigBean.executionMode.equals(ExecutionMode.EDGE)) { throw new PipelineException(ContainerError.CONTAINER_01600, pipelineConfigBean.executionMode); } Response response = null; try { response = ClientBuilder.newClient() .target(pipelineConfigBean.edgeHttpUrl + "/rest/v1/pipeline/" + pipelineId + "/resetOffset") .request() .post(null); if (response.getStatus() != Response.Status.OK.getStatusCode()) { throw new PipelineException( ContainerError.CONTAINER_01604, response.getStatus(), response.readEntity(String.class) ); } } catch (ProcessingException ex) { if (ex.getCause() instanceof ConnectException) { throw new PipelineException(ContainerError.CONTAINER_01602, pipelineConfigBean.edgeHttpUrl, ex); } throw ex; } finally { if (response != null) { response.close(); } } }
Example 7
Source File: JAXRSClientServerBookTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testGetBookRelativeUriAutoRedirectNotAllowed() throws Exception { String address = "http://localhost:" + PORT + "/bookstore/redirect/relative?loop=true"; WebClient wc = WebClient.create(address); WebClient.getConfig(wc).getHttpConduit().getClient().setAutoRedirect(true); try { wc.get(); fail("relative Redirect is not allowed"); } catch (ProcessingException ex) { Throwable cause = ex.getCause(); assertTrue(cause.getMessage().contains("Relative Redirect detected on")); } }
Example 8
Source File: JAXRSClientServerBookTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testGetBookRelativeUriAutoRedirectLoop() throws Exception { String address = "http://localhost:" + PORT + "/bookstore/redirect/relative?loop=true"; WebClient wc = WebClient.create(address); WebClient.getConfig(wc).getRequestContext().put("http.redirect.relative.uri", "true"); WebClient.getConfig(wc).getHttpConduit().getClient().setAutoRedirect(true); try { wc.get(); fail("Redirect loop must be detected"); } catch (ProcessingException ex) { Throwable cause = ex.getCause(); assertTrue(cause.getMessage().contains("Redirect loop detected on")); } }
Example 9
Source File: JAXRSClientServerBookTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testGetBookDiffUriAutoRedirect() throws Exception { String address = "http://localhost:" + PORT + "/bookstore/redirect?sameuri=false"; WebClient wc = WebClient.create(address); WebClient.getConfig(wc).getRequestContext().put("http.redirect.same.host.only", "true"); WebClient.getConfig(wc).getHttpConduit().getClient().setAutoRedirect(true); try { wc.get(); fail("Redirect to different host is not allowed"); } catch (ProcessingException ex) { Throwable cause = ex.getCause(); assertTrue(cause.getMessage().contains("Different HTTP Scheme or Host Redirect detected on")); } }
Example 10
Source File: SchemaRegistryRestAPIClient.java From apicurio-registry with Apache License 2.0 | 5 votes |
private Response getResponse(Builder builder) throws Exception { try { return builder.header(HttpHeaders.AUTHORIZATION, "Bearer " + apiKey) .get(); } catch (ProcessingException pe) { logger.error("Failed to make API request", pe); Throwable cause = pe.getCause(); throw new Exception(cause != null ? cause : pe); } }
Example 11
Source File: EdgeUtil.java From datacollector with Apache License 2.0 | 5 votes |
public static MetricRegistryJson getEdgePipelineMetrics( PipelineConfiguration pipelineConfiguration ) throws PipelineException { String pipelineId = pipelineConfiguration.getPipelineId(); PipelineConfigBean pipelineConfigBean = PipelineBeanCreator.get() .create(pipelineConfiguration, new ArrayList<>(), null); if (!pipelineConfigBean.executionMode.equals(ExecutionMode.EDGE)) { throw new PipelineException(ContainerError.CONTAINER_01600, pipelineConfigBean.executionMode); } Response response = null; try { response = ClientBuilder.newClient() .target(pipelineConfigBean.edgeHttpUrl + "/rest/v1/pipeline/" + pipelineId + "/metrics") .request() .get(); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(MetricRegistryJson.class); } else { return null; } } catch (ProcessingException ex) { if (ex.getCause() instanceof ConnectException) { throw new PipelineException(ContainerError.CONTAINER_01602, pipelineConfigBean.edgeHttpUrl, ex); } throw ex; } finally { if (response != null) { response.close(); } } }
Example 12
Source File: EdgeUtil.java From datacollector with Apache License 2.0 | 5 votes |
public static PipelineStateJson stopEdgePipeline( PipelineConfiguration pipelineConfiguration, Map<String, Object> runtimeParameters ) throws PipelineException { String pipelineId = pipelineConfiguration.getPipelineId(); PipelineConfigBean pipelineConfigBean = PipelineBeanCreator.get() .create(pipelineConfiguration, new ArrayList<>(), runtimeParameters); if (!pipelineConfigBean.executionMode.equals(ExecutionMode.EDGE)) { throw new PipelineException(ContainerError.CONTAINER_01600, pipelineConfigBean.executionMode); } Response response = null; try { response = ClientBuilder.newClient() .target(pipelineConfigBean.edgeHttpUrl + "/rest/v1/pipeline/" + pipelineId + "/stop") .request() .post(Entity.json(runtimeParameters)); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(PipelineStateJson.class); } else { throw new PipelineException( ContainerError.CONTAINER_01603, response.getStatus(), response.readEntity(String.class) ); } } catch (ProcessingException ex) { if (ex.getCause() instanceof ConnectException) { throw new PipelineException(ContainerError.CONTAINER_01602, pipelineConfigBean.edgeHttpUrl, ex); } throw ex; } finally { if (response != null) { response.close(); } } }
Example 13
Source File: EdgeUtil.java From datacollector with Apache License 2.0 | 5 votes |
public static PipelineStateJson startEdgePipeline( PipelineConfiguration pipelineConfiguration, Map<String, Object> runtimeParameters ) throws PipelineException { String pipelineId = pipelineConfiguration.getPipelineId(); PipelineConfigBean pipelineConfigBean = PipelineBeanCreator.get() .create(pipelineConfiguration, new ArrayList<>(), runtimeParameters); if (!pipelineConfigBean.executionMode.equals(ExecutionMode.EDGE)) { throw new PipelineException(ContainerError.CONTAINER_01600, pipelineConfigBean.executionMode); } Response response = null; try { response = ClientBuilder.newClient() .target(pipelineConfigBean.edgeHttpUrl + "/rest/v1/pipeline/" + pipelineId + "/start") .request() .post(Entity.json(runtimeParameters)); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(PipelineStateJson.class); } else { throw new PipelineException( ContainerError.CONTAINER_01603, response.getStatus(), response.readEntity(String.class) ); } } catch (ProcessingException ex) { if (ex.getCause() instanceof ConnectException) { throw new PipelineException(ContainerError.CONTAINER_01602, pipelineConfigBean.edgeHttpUrl, ex); } throw ex; } finally { if (response != null) { response.close(); } } }
Example 14
Source File: EdgeUtil.java From datacollector with Apache License 2.0 | 5 votes |
public static PipelineStateJson getEdgePipelineState( PipelineConfiguration pipelineConfiguration ) throws PipelineException { String pipelineId = pipelineConfiguration.getPipelineId(); PipelineConfigBean pipelineConfigBean = PipelineBeanCreator.get() .create(pipelineConfiguration, new ArrayList<>(), null); if (!pipelineConfigBean.executionMode.equals(ExecutionMode.EDGE)) { throw new PipelineException(ContainerError.CONTAINER_01600, pipelineConfigBean.executionMode); } Response response = null; try { response = ClientBuilder.newClient() .target(pipelineConfigBean.edgeHttpUrl + "/rest/v1/pipeline/" + pipelineId + "/status") .request() .get(); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(PipelineStateJson.class); } else { return null; } } catch (ProcessingException ex) { if (ex.getCause() instanceof ConnectException) { throw new PipelineException(ContainerError.CONTAINER_01602, pipelineConfigBean.edgeHttpUrl, ex); } throw ex; } finally { if (response != null) { response.close(); } } }
Example 15
Source File: OAuth2ConfigBean.java From datacollector with Apache License 2.0 | 5 votes |
private Response sendRequest(Invocation.Builder builder) throws IOException, StageException { Response response; try { response = builder.property(ClientProperties.REQUEST_ENTITY_PROCESSING, transferEncoding) .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED + "; charset=utf-8") .post(generateRequestEntity()); } catch (ProcessingException ex) { if (ex.getCause() instanceof UnresolvedAddressException || ex.getCause() instanceof UnknownHostException) { throw new NotFoundException(ex.getCause()); } throw ex; } return response; }
Example 16
Source File: SigningTest.java From resteasy-examples with Apache License 2.0 | 5 votes |
/** * Test that expiration works * * @throws Exception */ @Test public void testExpiresFail() throws Exception { Verifier verifier = new Verifier(); Verification verification = verifier.addNew(); verification.setRepository(repository); WebTarget target = client.target("http://localhost:9095/signed/expires-short"); Invocation.Builder request = target.request(); request.property(Verifier.class.getName(), verifier); Response response = request.get(); System.out.println(response.getHeaderString(DKIMSignature.DKIM_SIGNATURE)); Assert.assertEquals(200, response.getStatus()); Thread.sleep(1500); try { String output = response.readEntity(String.class); Assert.fail(); } catch (ProcessingException pe) { UnauthorizedSignatureException e = (UnauthorizedSignatureException)pe.getCause(); System.out.println("Verification failed: " + e.getMessage()); } response.close(); }
Example 17
Source File: SigningTest.java From resteasy-examples with Apache License 2.0 | 5 votes |
@Test public void testFailedVerification() throws Exception { Verifier verifier = new Verifier(); Verification verification = verifier.addNew(); verification.setRepository(repository); WebTarget target = client.target("http://localhost:9095/signed/bad-signature"); Invocation.Builder request = target.request(); request.property(Verifier.class.getName(), verifier); Response response = request.get(); System.out.println(response.getHeaderString(DKIMSignature.DKIM_SIGNATURE)); Assert.assertEquals(200, response.getStatus()); // If you don't extract the entity, then verification will not happen try { System.out.println(response.readEntity(String.class)); Assert.fail(); } catch (ProcessingException pe) { UnauthorizedSignatureException e = (UnauthorizedSignatureException)pe.getCause(); System.out.println("We expect this failure: " + e.getMessage()); } response.close(); }