@SuppressWarnings("unchecked") public void clientErrorHandling(BaseClientResponse clientResponse, RuntimeException e) { for (ClientErrorInterceptor handler : interceptors) { try { // attempt to reset the stream in order to provide a fresh stream // to each ClientErrorInterceptor -- failing to reset the stream // could mean that an unusable stream will be passed to the // interceptor InputStream stream = clientResponse.getStreamFactory().getInputStream(); if (stream != null) { stream.reset(); } } catch (IOException e1) { // eat this exception since it's not really relevant for the client // response } handler.handle(clientResponse); } throw e; } }
public ClientResponse cacheIfPossible(ClientRequest request, BaseClientResponse response) throws Exception { String cc = (String) response.getResponseHeaders().getFirst(HttpHeaders.CACHE_CONTROL); String exp = (String) response.getResponseHeaders().getFirst(HttpHeaders.EXPIRES); int expires = -1; if (cc != null) { CacheControl cacheControl = CacheControl.valueOf(cc); if (cacheControl.isNoCache()) return response; expires = cacheControl.getMaxAge(); } else if (exp != null) { Date date = DateUtil.parseDate(exp); expires = (int) ((date.getTime() - System.currentTimeMillis()) / 1000); } String lastModified = (String) response.getResponseHeaders().getFirst(HttpHeaders.LAST_MODIFIED); String etag = (String) response.getResponseHeaders().getFirst(HttpHeaders.ETAG); String contentType = (String) response.getResponseHeaders().getFirst(HttpHeaders.CONTENT_TYPE); byte[] cached = ReadFromStream.readFromStream(1024, response.getStreamFactory().getInputStream()); response.getStreamFactory().performReleaseConnection(); MediaType mediaType = MediaType.valueOf(contentType); final BrowserCache.Entry entry = cache.put(request.getUri(), mediaType, response.getResponseHeaders(), cached, expires, etag, lastModified); response.setStreamFactory(new CachedStreamFactory(entry)); return response; }
is = base.streamFactory.getInputStream(); byte[] bytes = ReadFromStream.readFromStream(1024, is); is = new ByteArrayInputStream(bytes);
is = base.streamFactory.getInputStream(); if (is != null)
try InputStream is = streamFactory.getInputStream(); if (is == null)
try InputStream is = streamFactory.getInputStream(); if (is == null)
InputStream stream = r.getStreamFactory().getInputStream(); stream.reset();
InputStream stream = r.getStreamFactory().getInputStream(); stream.reset();
public ClientResponse cacheIfPossible(ClientRequest request, BaseClientResponse response) throws Exception { String cc = (String) response.getResponseHeaders().getFirst(HttpHeaders.CACHE_CONTROL); String exp = (String) response.getResponseHeaders().getFirst(HttpHeaders.EXPIRES); int expires = -1; if (cc != null) { CacheControl cacheControl = CacheControl.valueOf(cc); if (cacheControl.isNoCache()) return response; expires = cacheControl.getMaxAge(); } else if (exp != null) { Date date = DateUtil.parseDate(exp); expires = (int) ((date.getTime() - System.currentTimeMillis()) / 1000); } String lastModified = (String) response.getResponseHeaders().getFirst(HttpHeaders.LAST_MODIFIED); String etag = (String) response.getResponseHeaders().getFirst(HttpHeaders.ETAG); String contentType = (String) response.getResponseHeaders().getFirst(HttpHeaders.CONTENT_TYPE); byte[] cached = ReadFromStream.readFromStream(1024, response.getStreamFactory().getInputStream()); response.getStreamFactory().performReleaseConnection(); MediaType mediaType = MediaType.valueOf(contentType); final BrowserCache.Entry entry = cache.put(request.getUri(), mediaType, response.getResponseHeaders(), cached, expires, etag, lastModified); response.setStreamFactory(new CachedStreamFactory(entry)); return response; }
@Override public void handle(final ClientResponse<?> response) throws RuntimeException { try { final BaseClientResponse<?> r = (BaseClientResponse<?>) response; final InputStream stream = r.getStreamFactory().getInputStream(); stream.reset(); final Object entity = response.getEntity(Object.class); if (entity instanceof RuntimeException) { final RuntimeException exception = (RuntimeException) entity; throw exception; } if (entity instanceof Exception) { final Exception exception = (Exception) entity; throw new RESTBonitaRuntimeExceptionWrapper(exception); } if (Status.FORBIDDEN.getStatusCode() == response.getResponseStatus().getStatusCode()) { throw new BonitaRuntimeException("Forbidden returned"); } } catch (final IOException e) { new BonitaRuntimeException("Error while reading client response", e); } // RESTEasy will throw the original ClientResponseFailure }
@Override public void handle(final ClientResponse<?> response) throws RuntimeException { try { final BaseClientResponse<?> r = (BaseClientResponse<?>) response; final InputStream stream = r.getStreamFactory().getInputStream(); stream.reset(); final Object entity = response.getEntity(Object.class); if (entity instanceof RuntimeException) { final RuntimeException exception = (RuntimeException) entity; throw exception; } if (entity instanceof Exception) { final Exception exception = (Exception) entity; throw new RESTBonitaRuntimeExceptionWrapper(exception); } if (Status.FORBIDDEN.getStatusCode() == response.getResponseStatus().getStatusCode()) { throw new BonitaRuntimeException("Forbidden returned"); } } catch (final IOException e) { new BonitaRuntimeException("Error while reading client response", e); } // RESTEasy will throw the original ClientResponseFailure }
@SuppressWarnings("unchecked") public void clientErrorHandling(BaseClientResponse clientResponse, RuntimeException e) { for (ClientErrorInterceptor handler : interceptors) { try { // attempt to reset the stream in order to provide a fresh stream // to each ClientErrorInterceptor -- failing to reset the stream // could mean that an unusable stream will be passed to the // interceptor InputStream stream = clientResponse.getStreamFactory().getInputStream(); if (stream != null) { stream.reset(); } } catch (IOException e1) { // eat this exception since it's not really relevant for the client // response } handler.handle(clientResponse); } throw e; } }
@Override public void resetStream() { try { if (this.streamFactory.getInputStream().markSupported()) { this.streamFactory.getInputStream().reset(); } } catch (IOException e) { throw new RuntimeException(e); } }
@Override public void resetStream() { try { if (this.streamFactory.getInputStream().markSupported()) { this.streamFactory.getInputStream().reset(); } } catch (IOException e) { throw new RuntimeException(e); } }
public final void releaseConnection() { if (!wasReleased) { if (streamFactory != null) streamFactory.performReleaseConnection(); wasReleased = true; } }
public final void releaseConnection() { if (!wasReleased) { if (streamFactory != null) streamFactory.performReleaseConnection(); wasReleased = true; } }