@Override public String toString() { return createSummaryString(Response.MAX_BODY_DISPLAY_LENGTH); }
@Override public Header getHeader(String headerName) { List<Header> matchingHeaders = getHeaders(headerName); if (matchingHeaders.isEmpty()) { return null; } if (matchingHeaders.size() > 1) { throw new IllegalStateException("Attempt to get single header '" + headerName + "' but more than one value found."); } return matchingHeaders.get(0); }
@Override public void bigDump() { System.out.println(this.toBigString()); }
/** * Constructor from apache HttpResponse. * * @param response the HttpResponse * @param responseTime time taken for the request in milliseconds */ public DefaultResponse(HttpResponse response, long responseTime) { this.protocolVersion = response.getStatusLine().getProtocolVersion().toString(); this.statusCode = response.getStatusLine().getStatusCode(); this.statusMessage = response.getStatusLine().getReasonPhrase(); this.binaryContent = binaryContentFromResponse(response); this.content = contentFromResponse(response, this.binaryContent); this.headers = headersFromResponse(response); this.responseTime = responseTime; }
@Override public void tinyDump() { System.out.println(this.toCompactString()); }
private String contentFromResponse(HttpResponse response, byte[] bytes) { // we have to take binary content as a param here because we can't read the inputstream twice. if (bytes == null) { return null; } InputStream stream = new ByteArrayInputStream(bytes); try { return readWithEncoding(stream, response.getEntity().getContentEncoding()); } catch (IOException e) { throw new RuntimeException("Error converting response entity to string", e); } }
@Override public Element asXml() { return XmlUtil.asXml(this.getContent()); }
long endTime = System.currentTimeMillis(); return new DefaultResponse(response, (endTime - startTime)); } catch (ClientProtocolException cpe) { throw new RuntimeClientProtocolException(cpe);
/** * Constructor from apache HttpResponse. * * @param response the HttpResponse * @param responseTime time taken for the request in milliseconds */ public DefaultResponse(HttpResponse response, long responseTime) { this.protocolVersion = response.getStatusLine().getProtocolVersion().toString(); this.statusCode = response.getStatusLine().getStatusCode(); this.statusMessage = response.getStatusLine().getReasonPhrase(); this.binaryContent = binaryContentFromResponse(response); this.content = contentFromResponse(response, this.binaryContent); this.headers = headersFromResponse(response); this.responseTime = responseTime; }
@Override public void tinyDump() { System.out.println(this.toCompactString()); }
private String contentFromResponse(HttpResponse response, byte[] bytes) { // we have to take binary content as a param here because we can't read the inputstream twice. if (bytes == null) { return null; } InputStream stream = new ByteArrayInputStream(bytes); try { return readWithEncoding(stream, response.getEntity().getContentEncoding()); } catch (IOException e) { throw new RuntimeException("Error converting response entity to string", e); } }
@Override public Element asXml() { return XmlUtil.asXml(this.getContent()); }
long endTime = System.currentTimeMillis(); return new DefaultResponse(response, (endTime - startTime)); } catch (ClientProtocolException cpe) { throw new RuntimeClientProtocolException(cpe);
@Override public String toString() { return createSummaryString(Response.MAX_BODY_DISPLAY_LENGTH); }
@Override public Header getHeader(String headerName) { List<Header> matchingHeaders = getHeaders(headerName); if (matchingHeaders.isEmpty()) { return null; } if (matchingHeaders.size() > 1) { throw new IllegalStateException("Attempt to get single header '" + headerName + "' but more than one value found."); } return matchingHeaders.get(0); }
@Override public void bigDump() { System.out.println(this.toBigString()); }
@Override public String toBigString() { return createSummaryString(this.content.length()); }
@Override public String toBigString() { return createSummaryString(this.content.length()); }