本文整理了Java中org.apache.http.client.HttpResponseException.
方法的一些代码示例,展示了HttpResponseException.
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponseException.
方法的具体详情如下:
包路径:org.apache.http.client.HttpResponseException
类名称:HttpResponseException
方法名:
暂无
代码示例来源:origin: chanjarster/weixin-java-tools
public InputStream handleResponse(final HttpResponse response) throws HttpResponseException, IOException {
final StatusLine statusLine = response.getStatusLine();
final HttpEntity entity = response.getEntity();
if (statusLine.getStatusCode() >= 300) {
EntityUtils.consume(entity);
throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase());
}
return entity == null ? null : entity.getContent();
}
代码示例来源:origin: chanjarster/weixin-java-tools
public String handleResponse(final HttpResponse response) throws HttpResponseException, IOException {
final StatusLine statusLine = response.getStatusLine();
final HttpEntity entity = response.getEntity();
if (statusLine.getStatusCode() >= 300) {
EntityUtils.consume(entity);
throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase());
}
return entity == null ? null : EntityUtils.toString(entity, Consts.UTF_8);
}
代码示例来源:origin: robovm/robovm
/**
* Returns the response body as a String if the response was successful (a
* 2xx status code). If no response body exists, this returns null. If the
* response was unsuccessful (>= 300 status code), throws an
* {@link HttpResponseException}.
*/
public String handleResponse(final HttpResponse response)
throws HttpResponseException, IOException {
StatusLine statusLine = response.getStatusLine();
if (statusLine.getStatusCode() >= 300) {
throw new HttpResponseException(statusLine.getStatusCode(),
statusLine.getReasonPhrase());
}
HttpEntity entity = response.getEntity();
return entity == null ? null : EntityUtils.toString(entity);
}
代码示例来源:origin: azkaban/azkaban
/**
* Implementing the parseResponse function to return de-serialized Json object.
*
* @param response the returned response from the HttpClient.
* @return de-serialized object from Json or null if the response doesn't have a body.
*/
@Override
protected String parseResponse(final HttpResponse response)
throws HttpResponseException, IOException {
final StatusLine statusLine = response.getStatusLine();
final String respOnseBody= response.getEntity() != null ?
EntityUtils.toString(response.getEntity()) : "";
if (statusLine.getStatusCode() >= 300) {
logger.error(String.format("unable to parse response as the response status is %s",
statusLine.getStatusCode()));
throw new HttpResponseException(statusLine.getStatusCode(), responseBody);
}
return responseBody;
}
}
代码示例来源:origin: azkaban/azkaban
@Override
protected String parseResponse(final HttpResponse response) throws IOException {
final StatusLine statusLine = response.getStatusLine();
if (statusLine.getStatusCode() >= 300) {
throw new HttpResponseException(statusLine.getStatusCode(),
statusLine.getReasonPhrase());
}
return EntityUtils.toString(response.getEntity());
}
代码示例来源:origin: mttkay/ignition
@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;
}
}
代码示例来源:origin: rnewson/couchdb-lucene
public String handleResponse(final HttpResponse response) throws HttpResponseException, IOException {
final StatusLine statusLine = response.getStatusLine();
final HttpEntity entity = response.getEntity();
final String str = entity == null ? null : EntityUtils.toString(entity, "UTF-8");
if (statusLine.getStatusCode() >= 300) {
throw new HttpResponseException(statusLine.getStatusCode(), str);
}
return str;
}
代码示例来源:origin: egzosn/pay-java-parent
@Override
public T handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
final StatusLine statusLine = response.getStatusLine();
final HttpEntity entity = response.getEntity();
String[] value = null;
if (null == entity.getContentType()){
value = new String[]{"application/x-www-form-urlencoded"};
}else {
value = entity.getContentType().getValue().split(";");
}
//这里进行特殊处理,如果状态码非正常状态,但内容类型匹配至对应的结果也进行对应的响应类型转换
if (statusLine.getStatusCode() >= 300 && statusLine.getStatusCode() != 304) {
if (isJson(value[0], "") || isXml(value[0], "") ){
return toBean(entity, value);
}
EntityUtils.consume(entity);
throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase());
}
if (null == responseType){
respOnseType= (Class
}
return toBean(entity, value);
}
代码示例来源:origin: codebutler/android-websockets
throw new HttpException("Received no reply from server.");
} else if (statusLine.getStatusCode() != HttpStatus.SC_SWITCHING_PROTOCOLS) {
throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase());
代码示例来源:origin: jenkinsci/java-client-api
public void validateResponse(HttpResponse response) throws HttpResponseException {
int status = response.getStatusLine().getStatusCode();
if (status <200 || status >= 400) {
throw new HttpResponseException(status, response.getStatusLine().getReasonPhrase());
}
}
}
代码示例来源:origin: com.offbytwo.jenkins/jenkins-client
public void validateResponse(HttpResponse response) throws HttpResponseException {
int status = response.getStatusLine().getStatusCode();
if (status <200 || status >= 400) {
throw new HttpResponseException(status, response.getStatusLine().getReasonPhrase());
}
}
}
代码示例来源:origin: org.eclipse.aether/aether-transport-http
private void handleStatus( HttpResponse response )
throws HttpResponseException
{
int status = response.getStatusLine().getStatusCode();
if ( status >= 300 )
{
throw new HttpResponseException( status, response.getStatusLine().getReasonPhrase() + " (" + status + ")" );
}
}
代码示例来源:origin: com.github.binarywang/weixin-java-common
@Override
public String handleResponse(final HttpResponse response) throws IOException {
final StatusLine statusLine = response.getStatusLine();
final HttpEntity entity = response.getEntity();
if (statusLine.getStatusCode() >= 300) {
EntityUtils.consume(entity);
throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase());
}
return entity == null ? null : EntityUtils.toString(entity, Consts.UTF_8);
}
代码示例来源:origin: me.chanjar/weixin-java-common
public String handleResponse(final HttpResponse response) throws HttpResponseException, IOException {
final StatusLine statusLine = response.getStatusLine();
final HttpEntity entity = response.getEntity();
if (statusLine.getStatusCode() >= 300) {
EntityUtils.consume(entity);
throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase());
}
return entity == null ? null : EntityUtils.toString(entity, Consts.UTF_8);
}
代码示例来源:origin: com.centit.support/centit-utils
@Override
public InputStream handleResponse(final HttpResponse response) throws IOException {
final StatusLine statusLine = response.getStatusLine();
final HttpEntity entity = response.getEntity();
if (statusLine.getStatusCode() >= 300) {
EntityUtils.consume(entity);
throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase());
}
return entity == null ? null : entity.getContent();
}
代码示例来源:origin: com.cognifide.aet/client-core
@Override
public T handleResponse(HttpResponse httpResponse) throws IOException {
StatusLine statusLine = httpResponse.getStatusLine();
if (statusLine.getStatusCode() == 200) {
String result = EntityUtils.toString(httpResponse.getEntity(), MIME.UTF8_CHARSET);
Gson gson = new Gson();
return gson.fromJson(result, resultClass);
} else {
throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase());
}
}
}
代码示例来源:origin: com.centit.support/centit-utils
@Override
public String handleResponse(final HttpResponse response) throws IOException {
final StatusLine statusLine = response.getStatusLine();
final HttpEntity entity = response.getEntity();
if (statusLine.getStatusCode() >= 300) {
EntityUtils.consume(entity);
throw new HttpResponseException(statusLine.getStatusCode(), "Error Code : "+
String.valueOf(statusLine.getStatusCode())+", " +statusLine.getReasonPhrase()+"。");
}
return entity == null ? null : EntityUtils.toString(entity, Consts.UTF_8);
}
代码示例来源:origin: iterate-ch/cyberduck
@Override
public void onFailure(final GoogleJsonError e, final HttpHeaders responseHeaders) {
log.warn(String.format("Failure deleting %s. %s", file, e.getMessage()));
failures.add(new HttpResponseExceptionMappingService().map(
new HttpResponseException(e.getCode(), e.getMessage())));
}
代码示例来源:origin: iterate-ch/cyberduck
@Override
public BackgroundException map(final MantaClientHttpResponseException failure) {
switch(failure.getStatusCode()) {
case 403:
final StringBuilder buffer = new StringBuilder();
this.append(buffer, failure.getStatusMessage());
return new LoginFailureException(buffer.toString(), failure);
}
return new HttpResponseExceptionMappingService().map(new HttpResponseException(failure.getStatusCode(), failure.getStatusMessage()));
}
}
代码示例来源:origin: com.atlassian.addon.connect.hercules/hercules-ac
private List
{
LOGGER.debug("Getting comments for the issue {}", issue.getKey());
final WS.WSRequestHolder url = AC.url("/rest/api/2/issue/" + issue.getKey() + "/comment", acHost, Option.none()).setContentType("application/json");
final WS.Response respOnse= url.get().get(30, TimeUnit.SECONDS);
if (response.getStatus() != 200)
{
LOGGER.error("Comments by issue {} are not available, [{}] {}", issue.getKey(), response.getStatus(), response.getStatusText());
throw new HttpResponseException(response.getStatus(), response.getStatusText());
}
return JsonCommentFactory.toComments(response.asJson());
}