Search in sources :

Example 81 with ProcessingException

use of javax.ws.rs.ProcessingException in project jersey by jersey.

the class LoopBackConnector method bufferEntity.

private byte[] bufferEntity(final ClientRequest requestContext) {
    final ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
    requestContext.setStreamProvider(new OutboundMessageContext.StreamProvider() {

        @Override
        public OutputStream getOutputStream(final int contentLength) throws IOException {
            return baos;
        }
    });
    try {
        requestContext.writeEntity();
    } catch (final IOException ioe) {
        throw new ProcessingException("Error buffering the entity.", ioe);
    }
    return baos.toByteArray();
}
Also used : OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) OutboundMessageContext(org.glassfish.jersey.message.internal.OutboundMessageContext) ProcessingException(javax.ws.rs.ProcessingException)

Example 82 with ProcessingException

use of javax.ws.rs.ProcessingException in project jersey by jersey.

the class ResponseReadAndBufferEntityTest method testBufferEntityReadsOriginalStreamTest.

@Test
public void testBufferEntityReadsOriginalStreamTest() throws Exception {
    final WebTarget target = target("response/corrupted");
    final CorruptableInputStream cis = new CorruptableInputStream();
    target.register(new ClientResponseFilter() {

        @Override
        public void filter(final ClientRequestContext requestContext, final ClientResponseContext responseContext) {
            responseContext.setEntityStream(cis);
        }
    });
    final Response response = target.request().buildGet().invoke();
    try {
        cis.setCorruptRead(true);
        response.bufferEntity();
        fail("ProcessingException expected.");
    } catch (ProcessingException pe) {
        // expected
        assertThat(pe.getCause(), instanceOf(IOException.class));
    }
}
Also used : ClientRequestContext(javax.ws.rs.client.ClientRequestContext) Response(javax.ws.rs.core.Response) ClientResponseFilter(javax.ws.rs.client.ClientResponseFilter) WebTarget(javax.ws.rs.client.WebTarget) ClientResponseContext(javax.ws.rs.client.ClientResponseContext) ProcessingException(javax.ws.rs.ProcessingException) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 83 with ProcessingException

use of javax.ws.rs.ProcessingException in project jersey by jersey.

the class EmptyEntityTest method testReceiveEmptyJAXBElement.

@Test
public void testReceiveEmptyJAXBElement() {
    WebTarget target = target("empty/getempty");
    final Response response = target.request("application/xml").get();
    assertEquals(200, response.getStatus());
    try {
        response.readEntity(new GenericType<JAXBElement<String>>() {
        });
        fail("ProcessingException expected.");
    } catch (ProcessingException ex) {
        assertSame(NoContentException.class, ex.getCause().getClass());
    }
    try {
        target.request("application/xml").get(new GenericType<JAXBElement<String>>() {
        });
        fail("ResponseProcessingException expected.");
    } catch (ResponseProcessingException ex) {
        assertSame(NoContentException.class, ex.getCause().getClass());
    }
}
Also used : Response(javax.ws.rs.core.Response) ResponseProcessingException(javax.ws.rs.client.ResponseProcessingException) WebTarget(javax.ws.rs.client.WebTarget) JAXBElement(javax.xml.bind.JAXBElement) NoContentException(javax.ws.rs.core.NoContentException) ProcessingException(javax.ws.rs.ProcessingException) ResponseProcessingException(javax.ws.rs.client.ResponseProcessingException) Test(org.junit.Test)

Example 84 with ProcessingException

use of javax.ws.rs.ProcessingException in project jersey by jersey.

the class EmptyEntityTest method testReceiveEmptyBoolean.

@Test
public void testReceiveEmptyBoolean() {
    WebTarget target = target("empty/getempty");
    final Response response = target.request("text/plain").get();
    assertEquals(200, response.getStatus());
    try {
        response.readEntity(Boolean.class);
        fail("ProcessingException expected.");
    } catch (ProcessingException ex) {
        assertSame(NoContentException.class, ex.getCause().getClass());
    }
    try {
        target.request("text/plain").get(Boolean.class);
        fail("ResponseProcessingException expected.");
    } catch (ResponseProcessingException ex) {
        assertSame(NoContentException.class, ex.getCause().getClass());
    }
}
Also used : Response(javax.ws.rs.core.Response) ResponseProcessingException(javax.ws.rs.client.ResponseProcessingException) WebTarget(javax.ws.rs.client.WebTarget) NoContentException(javax.ws.rs.core.NoContentException) ProcessingException(javax.ws.rs.ProcessingException) ResponseProcessingException(javax.ws.rs.client.ResponseProcessingException) Test(org.junit.Test)

Example 85 with ProcessingException

use of javax.ws.rs.ProcessingException in project jersey by jersey.

the class AuthCodeGrantImpl method refreshAccessToken.

@Override
public TokenResult refreshAccessToken(final String refreshToken) {
    refreshTokenProperties.put(OAuth2Parameters.REFRESH_TOKEN, refreshToken);
    final Form form = new Form();
    for (final Map.Entry<String, String> entry : refreshTokenProperties.entrySet()) {
        form.param(entry.getKey(), entry.getValue());
    }
    final Response response = client.target(refreshTokenUri).request(MediaType.APPLICATION_JSON_TYPE).post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE));
    if (response.getStatus() != 200) {
        throw new ProcessingException(LocalizationMessages.ERROR_FLOW_REQUEST_REFRESH_TOKEN(response.getStatus()));
    }
    this.tokenResult = response.readEntity(TokenResult.class);
    return tokenResult;
}
Also used : Response(javax.ws.rs.core.Response) Form(javax.ws.rs.core.Form) HashMap(java.util.HashMap) Map(java.util.Map) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) ProcessingException(javax.ws.rs.ProcessingException)

Aggregations

ProcessingException (javax.ws.rs.ProcessingException)91 Test (org.junit.Test)32 IOException (java.io.IOException)26 Response (javax.ws.rs.core.Response)20 WebTarget (javax.ws.rs.client.WebTarget)19 JerseyTest (org.glassfish.jersey.test.JerseyTest)16 WebApplicationException (javax.ws.rs.WebApplicationException)11 CountDownLatch (java.util.concurrent.CountDownLatch)9 Client (javax.ws.rs.client.Client)9 ResponseProcessingException (javax.ws.rs.client.ResponseProcessingException)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 ClientRequest (org.glassfish.jersey.client.ClientRequest)8 ClientResponse (org.glassfish.jersey.client.ClientResponse)8 ByteArrayInputStream (java.io.ByteArrayInputStream)6 URI (java.net.URI)6 NoContentException (javax.ws.rs.core.NoContentException)6 OutputStream (java.io.OutputStream)5 Map (java.util.Map)5 CompletableFuture (java.util.concurrent.CompletableFuture)5 EventSource (org.glassfish.jersey.media.sse.EventSource)5