private static void decompressResponse(ClientResponse response) { InputStream entityInputStream = response.getEntityInputStream(); GZIPInputStream uncompressedIS; try { uncompressedIS = new GZIPInputStream(entityInputStream); } catch (IOException ex) { try { entityInputStream.close(); } catch (IOException ignored) { } throw new ClientHandlerException(ex); } response.setEntityInputStream(uncompressedIS); }
/** * Close the response. * <p> * The entity input stream is closed. * * @throws ClientHandlerException if there is an error closing the response. */ public void close() throws ClientHandlerException { try { entity.close(); } catch (IOException e) { throw new ClientHandlerException(e); } }
private URI getProxyUri(Object proxy) { if (proxy instanceof URI) { return (URI) proxy; } else if (proxy instanceof String) { return URI.create((String) proxy); } else { throw new ClientHandlerException("The proxy URI property MUST be an instance of String or URI"); } }
private static URI getProxyUri(final Object proxy) { if (proxy instanceof URI) { return (URI) proxy; } else if (proxy instanceof String) { return URI.create((String) proxy); } else { throw new ClientHandlerException("The proxy URI (" + ApacheHttpClient4Config.PROPERTY_PROXY_URI + ") property MUST be an instance of String or URI"); } } }
/** * Close the response. * <p> * The entity input stream is closed. * * @throws ClientHandlerException if there is an error closing the response. */ public void close() throws ClientHandlerException { try { entity.close(); } catch (IOException e) { throw new ClientHandlerException(e); } }
/** * Close the response. * <p> * The entity input stream is closed. * * @throws ClientHandlerException if there is an error closing the response. */ public void close() throws ClientHandlerException { try { entity.close(); } catch (IOException e) { throw new ClientHandlerException(e); } }
private static URI getProxyUri( final Object proxy ) { if ( proxy instanceof URI ) { return (URI) proxy; } else if ( proxy instanceof String ) { return URI.create( (String) proxy ); } else { throw new ClientHandlerException( "The proxy URI (" + ApacheHttpClient4Config.PROPERTY_PROXY_URI + ") property MUST be an instance of String or URI" ); } }
@Override public ClientResponse handle(final ClientRequest ro) { try { return doHandle(ro); } catch (Exception e) { throw new ClientHandlerException(e); } }
@Override public ClientResponse handle(final ClientRequest ro) { try { return doHandle(ro); } catch (Exception e) { throw new ClientHandlerException(e); } }
/** * ClientRequest handler. * * @param ro ClientRequest * @return Server response represented as ClientResponse */ public ClientResponse handle(ClientRequest ro) { try { return _invoke(ro); } catch (Exception ex) { throw new ClientHandlerException(ex); } }
/** * ClientRequest handler. * * @param ro ClientRequest * @return Server response represented as ClientResponse */ public ClientResponse handle(ClientRequest ro) { try { return _invoke(ro); } catch (Exception ex) { throw new ClientHandlerException(ex); } }
private byte[] writeRequestEntity(ClientRequest ro) { try { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); InPocessClientHandler.this.writeRequestEntity(ro, new RequestWriter.RequestEntityWriterListener() { public void onRequestEntitySize(long size) throws IOException { } public OutputStream onGetOutputStream() throws IOException { return baos; } }); return baos.toByteArray(); } catch (IOException ex) { throw new ClientHandlerException(ex); } }
private byte[] writeRequestEntity(ClientRequest ro) { try { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); InPocessClientHandler.this.writeRequestEntity(ro, new RequestWriter.RequestEntityWriterListener() { public void onRequestEntitySize(long size) throws IOException { // Not yet implemented } public OutputStream onGetOutputStream() throws IOException { return baos; } }); return baos.toByteArray(); } catch (IOException ex) { throw new ClientHandlerException(ex); } }
private static void decompressResponse(ClientResponse response) { InputStream entityInputStream = response.getEntityInputStream(); GZIPInputStream uncompressedIS; try { uncompressedIS = new GZIPInputStream(entityInputStream); } catch (IOException ex) { try { entityInputStream.close(); } catch (IOException ignored) { } throw new ClientHandlerException(ex); } response.setEntityInputStream(uncompressedIS); }
private String getEntity(final ClientResponse response) { final ByteArrayOutputStream out = new ByteArrayOutputStream(); final InputStream in = response.getEntityInputStream(); try { ReaderWriter.writeTo(in, out); final byte[] entity = out.toByteArray(); response.setEntityInputStream(new ByteArrayInputStream(entity)); return (entity.length != 0) ? new String(entity, UTF_8) : ""; } catch (final IOException ex) { throw new ClientHandlerException(ex); } }
@VisibleForTesting void handleInternal(ClientRequest clientRequest) throws ClientHandlerException { if (!clientRequest.getHeaders().containsKey(HttpHeaders.AUTHORIZATION)) { try { clientRequest.getHeaders().add(HttpHeaders.AUTHORIZATION, getAsapBearerToken()); } catch (CannotRetrieveKeyException | InvalidTokenException ex) { throw new ClientHandlerException("Exception generating ASAP token.", ex); } } }
@Override public ClientResponse handle(ClientRequest cr) throws ClientHandlerException { URIBuilder uriBuilder = new URIBuilder(cr.getURI()); String path = uriBuilder.getPath(); uriBuilder.setPath(converter.convertCommandPath(path)); try { cr.setURI(uriBuilder.build()); ClientResponse response = getNext().handle(cr); String newEntity = converter.convertResponse(path, response.getEntity(String.class)); response.setEntityInputStream(new ByteArrayInputStream(newEntity.getBytes())); return response; } catch (Exception ex) { throw new ClientHandlerException(ex); } }
private static ClientResponse mockDomainClientResponse( TimelineClientImpl client, ClientResponse.Status status, boolean hasRuntimeError) { ClientResponse response = mock(ClientResponse.class); if (hasRuntimeError) { doThrow(new ClientHandlerException(new ConnectException())).when(client) .doPostingObject(any(TimelineDomain.class), any(String.class)); return response; } doReturn(response).when(client) .doPostingObject(any(TimelineDomain.class), any(String.class)); when(response.getClientResponseStatus()).thenReturn(status); return response; }
private static ClientResponse mockDomainClientResponse( TimelineWriter spyTimelineWriter, ClientResponse.Status status, boolean hasRuntimeError) { ClientResponse response = mock(ClientResponse.class); if (hasRuntimeError) { doThrow(new ClientHandlerException(new ConnectException())).when( spyTimelineWriter).doPostingObject(any(TimelineDomain.class), any(String.class)); return response; } doReturn(response).when(spyTimelineWriter) .doPostingObject(any(TimelineDomain.class), any(String.class)); when(response.getStatusInfo()).thenReturn(status); return response; }
private static ClientResponse mockDomainClientResponse( TimelineWriter spyTimelineWriter, ClientResponse.Status status, boolean hasRuntimeError) { ClientResponse response = mock(ClientResponse.class); if (hasRuntimeError) { doThrow(new ClientHandlerException(new ConnectException())).when( spyTimelineWriter).doPostingObject(any(TimelineDomain.class), any(String.class)); return response; } doReturn(response).when(spyTimelineWriter) .doPostingObject(any(TimelineDomain.class), any(String.class)); when(response.getClientResponseStatus()).thenReturn(status); return response; }