use of org.apache.http.client.HttpResponseException in project SmartAndroidSource by jaychou2012.
the class AsyncHttpResponseHandler method sendResponseMessage.
@Override
public void sendResponseMessage(HttpResponse response) throws IOException {
// do not process if request has been cancelled
if (!Thread.currentThread().isInterrupted()) {
StatusLine status = response.getStatusLine();
byte[] responseBody;
responseBody = getResponseData(response.getEntity());
// additional cancellation check as getResponseData() can take non-zero time to process
if (!Thread.currentThread().isInterrupted()) {
if (status.getStatusCode() >= 300) {
sendFailureMessage(status.getStatusCode(), response.getAllHeaders(), responseBody, new HttpResponseException(status.getStatusCode(), status.getReasonPhrase()));
} else {
sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(), responseBody);
}
}
}
}
use of org.apache.http.client.HttpResponseException 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 org.apache.http.client.HttpResponseException in project musiccabinet by hakko.
the class AbstractWSGetClientTest method validatePackagingOfResponseCode404.
@Test
public void validatePackagingOfResponseCode404() throws ApplicationException, IOException {
final int errorCode = 404;
final String errorMessage = "Not found";
HttpResponseException hpe = new HttpResponseException(errorCode, errorMessage);
TestWSGetClient testWSClient = getTestWSClient(hpe);
WSResponse response = testWSClient.testCall();
Assert.assertTrue(response.wasCallAllowed());
Assert.assertFalse(response.wasCallSuccessful());
Assert.assertFalse(response.isErrorRecoverable());
Assert.assertEquals(errorCode, response.getErrorCode());
Assert.assertEquals(errorMessage, response.getErrorMessage());
}
use of org.apache.http.client.HttpResponseException in project musiccabinet by hakko.
the class MusicBrainzServiceTest method handlesArtistFailureDuringUpdate.
@Test
public void handlesArtistFailureDuringUpdate() throws ApplicationException {
final String revName = reverse(artistName);
submitFile(additionDao, getFile(revName, albumName, trackName));
Mockito.when(service.artistQueryClient.get(revName)).thenThrow(new ApplicationException("Fail", new HttpResponseException(503, "Overloaded")));
service.updateDiscography();
List<MBAlbum> albums = service.getMissingAlbums(artistName, asList(TYPE_EP), null, -1, 0);
Assert.assertEquals(2, albums.size());
assertEquals("Switchblade / Cult of Luna", albums.get(0).getTitle());
assertEquals("Bodies / Recluse", albums.get(1).getTitle());
}
use of org.apache.http.client.HttpResponseException in project musiccabinet by hakko.
the class AbstractMusicBrainzClient method executeWSRequest.
protected String executeWSRequest(WebserviceInvocation invocation, String path, List<NameValuePair> params) throws ApplicationException {
String response = null;
HttpGet httpGet = new HttpGet(getURI(path, params));
httpGet.setHeader(USER_AGENT, CLIENT_INFO);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
try {
long elapsedMs = -currentTimeMillis();
response = httpClient.execute(httpGet, responseHandler);
elapsedMs += currentTimeMillis();
sleep(Math.max(INTERVAL_MS - elapsedMs, 0));
} catch (HttpResponseException e) {
LOG.warn(format("MusicBrainz internal error: %d, %s", e.getStatusCode(), e.getMessage()));
throw new ApplicationException("MusicBrainz internal error!", e);
} catch (IOException e) {
throw new ApplicationException("MusicBrainz communication failed!", e);
} catch (InterruptedException e) {
LOG.warn("MusicBrainz sleep interrupted!", e);
}
webserviceHistoryService.logWebserviceInvocation(invocation);
return response;
}
Aggregations