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();
}
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));
}
}
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());
}
}
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());
}
}
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;
}
Aggregations