use of org.apache.http.client.HttpResponseException in project afinal by yangfuhai.
the class HttpHandler method handleResponse.
private void handleResponse(HttpResponse response) {
StatusLine status = response.getStatusLine();
if (status.getStatusCode() >= 300) {
String errorMsg = "response status error code:" + status.getStatusCode();
if (status.getStatusCode() == 416 && isResume) {
errorMsg += " \n maybe you have download complete.";
}
publishProgress(UPDATE_FAILURE, new HttpResponseException(status.getStatusCode(), status.getReasonPhrase()), status.getStatusCode(), errorMsg);
} else {
try {
HttpEntity entity = response.getEntity();
Object responseBody = null;
if (entity != null) {
time = SystemClock.uptimeMillis();
if (targetUrl != null) {
responseBody = mFileEntityHandler.handleEntity(entity, this, targetUrl, isResume);
} else {
responseBody = mStrEntityHandler.handleEntity(entity, this, charset);
}
}
publishProgress(UPDATE_SUCCESS, responseBody);
} catch (IOException e) {
publishProgress(UPDATE_FAILURE, e, 0, e.getMessage());
}
}
}
use of org.apache.http.client.HttpResponseException in project SmartAndroidSource by jaychou2012.
the class BinaryHttpResponseHandler method sendResponseMessage.
@Override
public final void sendResponseMessage(HttpResponse response) throws IOException {
StatusLine status = response.getStatusLine();
Header[] contentTypeHeaders = response.getHeaders(AsyncHttpClient.HEADER_CONTENT_TYPE);
if (contentTypeHeaders.length != 1) {
// malformed/ambiguous HTTP Header, ABORT!
sendFailureMessage(status.getStatusCode(), response.getAllHeaders(), null, new HttpResponseException(status.getStatusCode(), "None, or more than one, Content-Type Header found!"));
return;
}
Header contentTypeHeader = contentTypeHeaders[0];
boolean foundAllowedContentType = false;
for (String anAllowedContentType : getAllowedContentTypes()) {
try {
if (Pattern.matches(anAllowedContentType, contentTypeHeader.getValue())) {
foundAllowedContentType = true;
}
} catch (PatternSyntaxException e) {
Log.e("BinaryHttpResponseHandler", "Given pattern is not valid: " + anAllowedContentType, e);
}
}
if (!foundAllowedContentType) {
// Content-Type not in allowed list, ABORT!
sendFailureMessage(status.getStatusCode(), response.getAllHeaders(), null, new HttpResponseException(status.getStatusCode(), "Content-Type not allowed!"));
return;
}
super.sendResponseMessage(response);
}
use of org.apache.http.client.HttpResponseException in project openkit-android by OpenKit.
the class BinaryHttpResponseHandler method sendResponseMessage.
// Interface to AsyncHttpRequest
void sendResponseMessage(HttpResponse response) {
StatusLine status = response.getStatusLine();
Header[] contentTypeHeaders = response.getHeaders("Content-Type");
byte[] responseBody = null;
if (contentTypeHeaders.length != 1) {
// malformed/ambiguous HTTP Header, ABORT!
sendFailureMessage(new HttpResponseException(status.getStatusCode(), "None, or more than one, Content-Type Header found!"), responseBody);
return;
}
Header contentTypeHeader = contentTypeHeaders[0];
boolean foundAllowedContentType = false;
for (String anAllowedContentType : mAllowedContentTypes) {
if (anAllowedContentType.equals(contentTypeHeader.getValue())) {
foundAllowedContentType = true;
}
}
if (!foundAllowedContentType) {
// Content-Type not in allowed list, ABORT!
sendFailureMessage(new HttpResponseException(status.getStatusCode(), "Content-Type not allowed!"), responseBody);
return;
}
try {
HttpEntity entity = null;
HttpEntity temp = response.getEntity();
if (temp != null) {
entity = new BufferedHttpEntity(temp);
}
responseBody = EntityUtils.toByteArray(entity);
} catch (IOException e) {
sendFailureMessage(e, (byte[]) null);
}
if (status.getStatusCode() >= 300) {
sendFailureMessage(new HttpResponseException(status.getStatusCode(), status.getReasonPhrase()), responseBody);
} else {
sendSuccessMessage(status.getStatusCode(), responseBody);
}
}
use of org.apache.http.client.HttpResponseException in project openkit-android by OpenKit.
the class OKUserUtilities method checkIfErrorIsUnsubscribedUserError.
public static void checkIfErrorIsUnsubscribedUserError(Throwable e) {
if (e == null) {
return;
}
if (e instanceof HttpResponseException) {
HttpResponseException responseException = (HttpResponseException) e;
if (responseException.getStatusCode() == OKHTTPClient.UNSUBSCRIBED_USER_ERROR_CODE) {
// Logout current user if we get an unsubscribed user error
OKLog.v("Unsubscribed user, log out the user, error is: " + e);
OKManager.INSTANCE.logoutCurrentUserWithoutClearingFB();
}
}
}
use of org.apache.http.client.HttpResponseException in project stashbot by palantir.
the class JenkinsManager method synchronousTriggerBuild.
public void synchronousTriggerBuild(Repository repo, JobType jobType, PullRequest pullRequest) {
try {
String pullRequestId = pullRequest.getId().toString();
String hashToBuild = pullRequest.getToRef().getLatestChangeset();
RepositoryConfiguration rc = cpm.getRepositoryConfigurationForRepository(repo);
JenkinsServerConfiguration jsc = cpm.getJenkinsServerConfiguration(rc.getJenkinsServerName());
JobTemplate jt = jtm.getJobTemplate(jobType, rc);
String jenkinsBuildId = jt.getBuildNameFor(repo);
String url = jsc.getUrl();
String user = jsc.getUsername();
String password = jsc.getPassword();
log.info("Triggering jenkins build id " + jenkinsBuildId + " on hash " + hashToBuild + " (" + user + "@" + url + " pw: " + password.replaceAll(".", "*") + ")");
final JenkinsServer js = jenkinsClientManager.getJenkinsServer(jsc, rc);
Map<String, Job> jobMap = js.getJobs();
String key = jt.getBuildNameFor(repo);
if (!jobMap.containsKey(key)) {
throw new RuntimeException("Build doesn't exist: " + key);
}
Builder<String, String> builder = ImmutableMap.builder();
builder.put("repoId", repo.getId().toString());
if (pullRequest != null) {
log.debug("Determined pullRequestId " + pullRequestId);
builder.put("pullRequestId", pullRequestId);
// toRef is always present in the repo
builder.put("buildHead", pullRequest.getToRef().getLatestChangeset().toString());
// fromRef may be in a different repo
builder.put("mergeRef", pullRequest.getFromRef().getId());
builder.put("buildRef", pullRequest.getToRef().getId());
builder.put("mergeRefUrl", sub.buildCloneUrl(pullRequest.getFromRef().getRepository(), jsc));
builder.put("mergeHead", pullRequest.getFromRef().getLatestChangeset().toString());
}
jobMap.get(key).build(builder.build());
} catch (SQLException e) {
throw new RuntimeException(e);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
} catch (HttpResponseException e) {
// client
if (e.getStatusCode() == 302) {
// to some URL after the fact.
return;
}
// For other HTTP errors, log it for easier debugging
log.error("HTTP Error (resp code " + Integer.toString(e.getStatusCode()) + ")", e);
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Aggregations