use of com.github.ignition.support.http.cache.CachedHttpResponse.ResponseData in project ignition by mttkay.
the class IgnitedHttpRequestBase method handleResponse.
@Override
public IgnitedHttpResponse handleResponse(HttpResponse response) throws IOException {
int status = response.getStatusLine().getStatusCode();
if (expectedStatusCodes != null && !expectedStatusCodes.isEmpty() && !expectedStatusCodes.contains(status)) {
throw new HttpResponseException(status, "Unexpected status code: " + status);
}
IgnitedHttpResponse bhttpr = new IgnitedHttpResponseImpl(response);
HttpResponseCache responseCache = ignitedHttp.getResponseCache();
if (responseCache != null && bhttpr.getResponseBody() != null) {
ResponseData responseData = new ResponseData(status, bhttpr.getResponseBodyAsBytes());
responseCache.put(getRequestUrl(), responseData);
}
return bhttpr;
}
use of com.github.ignition.support.http.cache.CachedHttpResponse.ResponseData in project ignition by mttkay.
the class HttpResponseCache method readValueFromDisk.
@Override
protected ResponseData readValueFromDisk(File file) throws IOException {
BufferedInputStream istream = new BufferedInputStream(new FileInputStream(file));
long fileSize = file.length();
if (fileSize > Integer.MAX_VALUE) {
throw new IOException("Cannot read files larger than " + Integer.MAX_VALUE + " bytes");
}
// first byte is the status code
int statusCode = istream.read();
// the remainder is the response data
int responseDataLength = (int) fileSize - 1;
byte[] responseBody = new byte[responseDataLength];
istream.read(responseBody, 0, responseDataLength);
istream.close();
return new ResponseData(statusCode, responseBody);
}
Aggregations