use of javax.ws.rs.ProcessingException in project jersey by jersey.
the class JettyConnector method translateRequest.
private Request translateRequest(final ClientRequest clientRequest) {
final HttpMethod method = HttpMethod.fromString(clientRequest.getMethod());
if (method == null) {
throw new ProcessingException(LocalizationMessages.METHOD_NOT_SUPPORTED(clientRequest.getMethod()));
}
final URI uri = clientRequest.getUri();
final Request request = client.newRequest(uri);
request.method(method);
request.followRedirects(clientRequest.resolveProperty(ClientProperties.FOLLOW_REDIRECTS, true));
final Object readTimeout = clientRequest.getConfiguration().getProperties().get(ClientProperties.READ_TIMEOUT);
if (readTimeout != null && readTimeout instanceof Integer && (Integer) readTimeout > 0) {
request.timeout((Integer) readTimeout, TimeUnit.MILLISECONDS);
}
return request;
}
use of javax.ws.rs.ProcessingException in project jersey by jersey.
the class TimeoutTest method testSlow.
@Test
public void testSlow() {
final URI u = target().getUri();
ClientConfig config = new ClientConfig().property(ClientProperties.READ_TIMEOUT, 1000);
config.connectorProvider(new JettyConnectorProvider());
Client c = ClientBuilder.newClient(config);
WebTarget t = c.target(u);
try {
t.path("test/timeout").request().get();
fail("Timeout expected.");
} catch (ProcessingException e) {
assertThat("Unexpected processing exception cause", e.getCause(), instanceOf(TimeoutException.class));
} finally {
c.close();
}
}
use of javax.ws.rs.ProcessingException in project jersey by jersey.
the class OutboundJaxrsResponse method bufferEntity.
@Override
public boolean bufferEntity() throws ProcessingException {
if (closed) {
throw new IllegalStateException(LocalizationMessages.RESPONSE_CLOSED());
}
if (!context.hasEntity() || !InputStream.class.isAssignableFrom(context.getEntityClass())) {
return false;
}
if (buffered) {
// already buffered
return true;
}
final InputStream in = InputStream.class.cast(context.getEntity());
final ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len;
try {
while ((len = in.read(buffer)) != -1) {
out.write(buffer, 0, len);
}
} catch (IOException ex) {
throw new ProcessingException(ex);
} finally {
try {
in.close();
} catch (IOException ex) {
throw new ProcessingException(ex);
}
}
context.setEntity(new ByteArrayInputStream(out.toByteArray()));
buffered = true;
return true;
}
use of javax.ws.rs.ProcessingException in project jersey by jersey.
the class WriterInterceptorExecutor method proceed.
/**
* Starts the interceptor chain execution.
*/
@Override
@SuppressWarnings("unchecked")
public void proceed() throws IOException {
final WriterInterceptor nextInterceptor = getNextInterceptor();
if (nextInterceptor == null) {
throw new ProcessingException(LocalizationMessages.ERROR_INTERCEPTOR_WRITER_PROCEED());
}
traceBefore(nextInterceptor, MsgTraceEvent.WI_BEFORE);
try {
nextInterceptor.aroundWriteTo(this);
} finally {
processedCount++;
traceAfter(nextInterceptor, MsgTraceEvent.WI_AFTER);
}
}
use of javax.ws.rs.ProcessingException in project jersey by jersey.
the class EntityInputStream method isEmpty.
/**
* Check if the underlying entity stream is empty.
* <p>
* Note that the operation may need to block until a first byte (or EOF) is available in the stream.
* </p>
*
* @return {@code true} if the entity stream is empty, {@code false} otherwise.
*/
public boolean isEmpty() {
ensureNotClosed();
final InputStream in = input;
if (in == null) {
return true;
}
try {
// Try #markSupported first - #available on WLS waits until socked timeout is reached when chunked encoding is used.
if (in.markSupported()) {
in.mark(1);
int i = in.read();
in.reset();
return i == -1;
} else {
try {
if (in.available() > 0) {
return false;
}
} catch (IOException ioe) {
// NOOP. Try other approaches as this can fail on WLS.
}
int b = in.read();
if (b == -1) {
return true;
}
PushbackInputStream pbis;
if (in instanceof PushbackInputStream) {
pbis = (PushbackInputStream) in;
} else {
pbis = new PushbackInputStream(in, 1);
input = pbis;
}
pbis.unread(b);
return false;
}
} catch (IOException ex) {
throw new ProcessingException(ex);
}
}
Aggregations