/** * Returns the contents of the response as a String. Inflates the response if it is in one of the * gzip formats. * * @throws IOException if unable to read the response contents */ public String getAsString() throws IOException { InputStream inputStream = isGzipped() ? new GZIPInputStream(getInputStream()) : getInputStream(); return Streams.readAll(inputStream, rawResponse.getCharset()); }
/** * Returns the contents of the response as a String. Inflates the response if it is in one of the * gzip formats. * * @throws IOException if unable to read the response contents */ public String getAsString() throws IOException { InputStream inputStream = isGzipped() ? new GZIPInputStream(getInputStream()) : getInputStream(); return Streams.readAll(inputStream, rawResponse.getCharset()); }
} else { try { responseText = Streams.readAll(rawResponse.getInputStream(), rawResponse.getCharset()); } catch (IOException e1) { throw new ReportDownloadResponseException(rawResponse.getHttpStatus(), e1); Map<String, String> fields = xmlFieldExtractor.extract( new ByteArrayInputStream(responseText.getBytes(rawResponse.getCharset())), new String[] {"fieldPath", "trigger", "type"}); exception.setFieldPath(fields.get("fieldPath"));
} else { try { responseText = Streams.readAll(rawResponse.getInputStream(), rawResponse.getCharset()); } catch (IOException e1) { throw new ReportDownloadResponseException(rawResponse.getHttpStatus(), e1); Map<String, String> fields = xmlFieldExtractor.extract( new ByteArrayInputStream(responseText.getBytes(rawResponse.getCharset())), new String[] {"fieldPath", "trigger", "type"}); exception.setFieldPath(fields.get("fieldPath"));
/** * Tests that the helper will properly capture an internal server error (500) status returned by * the mock HTTP server. */ @Test public void testDownloadReportWithServerErrorStatus() throws Exception { when(reportRequest.getRequestType()).thenReturn(RequestType.AWQL); String awqlString = "SELECT BadField1 FROM NOT_A_REPORT DURING NOT_A_TIME_PERIOD"; when(reportRequest.getReportRequestString()).thenReturn(awqlString); // Do not set the next response body on the test server. This will trigger an error // (500) from the test server. RawReportDownloadResponse response = helper.downloadReport(reportRequest); assertEquals("Response status code not failure", 500, response.getHttpStatus()); assertEquals("", Streams.readAll(response.getInputStream(), response.getCharset())); }
"Response charset incorrect", REPORT_CHARSET, response.getCharset()); assertEquals( "Response contents incorrect", "test", Streams.readAll(response.getInputStream(), response.getCharset())); } else { ReportDownloadResponse response = helper.downloadReport(reportRequest, exceptionBuilder);
"Response charset incorrect", REPORT_CHARSET, response.getCharset()); assertEquals( "Response contents incorrect", "test", Streams.readAll(response.getInputStream(), response.getCharset())); } else { ReportDownloadResponse response = helper.downloadReport(reportRequest, exceptionBuilder);