当前位置: 首页>>代码示例>>Java>>正文


Java StatusLine.getReasonPhrase方法代码示例

本文整理汇总了Java中org.apache.http.StatusLine.getReasonPhrase方法的典型用法代码示例。如果您正苦于以下问题:Java StatusLine.getReasonPhrase方法的具体用法?Java StatusLine.getReasonPhrase怎么用?Java StatusLine.getReasonPhrase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.http.StatusLine的用法示例。


在下文中一共展示了StatusLine.getReasonPhrase方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doFormatStatusLine

import org.apache.http.StatusLine; //导入方法依赖的package包/类
/**
 * Actually formats a status line.
 * Called from {@link #formatStatusLine}.
 *
 * @param buffer    the empty buffer into which to format,
 *                  never <code>null</code>
 * @param statline  the status line to format, never <code>null</code>
 */
protected void doFormatStatusLine(final CharArrayBuffer buffer,
                                  final StatusLine statline) {

    int len = estimateProtocolVersionLen(statline.getProtocolVersion())
        + 1 + 3 + 1; // room for "HTTP/1.1 200 "
    final String reason = statline.getReasonPhrase();
    if (reason != null) {
        len += reason.length();
    }
    buffer.ensureCapacity(len);

    appendProtocolVersion(buffer, statline.getProtocolVersion());
    buffer.append(' ');
    buffer.append(Integer.toString(statline.getStatusCode()));
    buffer.append(' '); // keep whitespace even if reason phrase is empty
    if (reason != null) {
        buffer.append(reason);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:28,代码来源:BasicLineFormatter.java

示例2: toFeignResponse

import org.apache.http.StatusLine; //导入方法依赖的package包/类
Response toFeignResponse(HttpResponse httpResponse) throws IOException {
  StatusLine statusLine = httpResponse.getStatusLine();
  int statusCode = statusLine.getStatusCode();

  String reason = statusLine.getReasonPhrase();

  Map<String, Collection<String>> headers = new HashMap<String, Collection<String>>();
  for (Header header : httpResponse.getAllHeaders()) {
    String name = header.getName();
    String value = header.getValue();

    Collection<String> headerValues = headers.get(name);
    if (headerValues == null) {
      headerValues = new ArrayList<String>();
      headers.put(name, headerValues);
    }
    headerValues.add(value);
  }

  return Response.builder()
          .status(statusCode)
          .reason(reason)
          .headers(headers)
          .body(toFeignBody(httpResponse))
          .build();
}
 
开发者ID:wenwu315,项目名称:XXXX,代码行数:27,代码来源:ApacheHttpClient.java

示例3: doInBackground

import org.apache.http.StatusLine; //导入方法依赖的package包/类
@Override
protected String doInBackground(String... uri) {
    HttpClient httpclient = new DefaultHttpClient();
    HttpResponse response;
    String responseString = null;
    try {
        response = httpclient.execute(new HttpGet(uri[0]));
        StatusLine statusLine = response.getStatusLine();
        if (statusLine.getStatusCode() == 200) {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            response.getEntity().writeTo(out);
            responseString = out.toString();
            out.close();
        } else {
            // Close the connection.
            response.getEntity().getContent().close();
            throw new IOException(statusLine.getReasonPhrase());
        }
    } catch (Exception e) {
        return null;
    }
    return responseString;
}
 
开发者ID:KoreHuang,项目名称:WeChatLuckyMoney,代码行数:24,代码来源:UpdateTask.java

示例4: handleResponse

import org.apache.http.StatusLine; //导入方法依赖的package包/类
private ResponseStream handleResponse(HttpResponse response) throws HttpException, IOException {
    if (response == null) {
        throw new HttpException("response is null");
    }
    StatusLine status = response.getStatusLine();
    int statusCode = status.getStatusCode();
    if (statusCode < 300) {

        // Set charset from response header if it's exist.
        String responseCharset = OtherUtils.getCharsetFromHttpResponse(response);
        charset = TextUtils.isEmpty(responseCharset) ? charset : responseCharset;

        return new ResponseStream(response, charset, requestUrl, expiry);
    } else if (statusCode == 301 || statusCode == 302) {
        if (httpRedirectHandler == null) {
            httpRedirectHandler = new DefaultHttpRedirectHandler();
        }
        HttpRequestBase request = httpRedirectHandler.getDirectRequest(response);
        if (request != null) {
            return this.sendRequest(request);
        }
    } else if (statusCode == 416) {
        throw new HttpException(statusCode, "maybe the file has downloaded completely");
    } else {
        throw new HttpException(statusCode, status.getReasonPhrase());
    }
    return null;
}
 
开发者ID:SavorGit,项目名称:Hotspot-master-devp,代码行数:29,代码来源:SyncHttpHandler.java

示例5: assert2xx

import org.apache.http.StatusLine; //导入方法依赖的package包/类
private static void assert2xx(HttpResponse response)
        throws HttpResponseException {
    StatusLine statusLine = response.getStatusLine();
    if (statusLine.getStatusCode() >= 300) {
        String detail = null;
        try {
            String body = EntityUtils.toString(response.getEntity());
            detail = String.format("[%s] %s",
                                   statusLine.getReasonPhrase(), body);
        } catch (Exception e) {
            detail = statusLine.getReasonPhrase();
        }
        throw new HttpResponseException(statusLine.getStatusCode(), detail);
    }
}
 
开发者ID:openmicroscopy,项目名称:omero-ms-queue,代码行数:16,代码来源:JsonResponseHandlers.java

示例6: handleResponse

import org.apache.http.StatusLine; //导入方法依赖的package包/类
@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();
}
 
开发者ID:11590692,项目名称:Wechat-Group,代码行数:11,代码来源:InputStreamResponseHandler.java

示例7: handleResponse

import org.apache.http.StatusLine; //导入方法依赖的package包/类
@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);
}
 
开发者ID:11590692,项目名称:Wechat-Group,代码行数:11,代码来源:Utf8ResponseHandler.java

示例8: ResponseImpl

import org.apache.http.StatusLine; //导入方法依赖的package包/类
public ResponseImpl(HttpResponse response, HttpRequestBase httpMethod)
{
	this.httpMethod = httpMethod;
	this.response = response;
	if( response != null )
	{
		final StatusLine statusLine = response.getStatusLine();
		this.code = statusLine.getStatusCode();
		this.message = statusLine.getReasonPhrase();
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:12,代码来源:HttpServiceImpl.java

示例9: validateResponse

import org.apache.http.StatusLine; //导入方法依赖的package包/类
/**
 * Validate the given response as contained in the HttpPost object,
 * throwing an exception if it does not correspond to a successful HTTP response.
 * <p>Default implementation rejects any HTTP status code beyond 2xx, to avoid
 * parsing the response body and trying to deserialize from a corrupted stream.
 * @param config the HTTP invoker configuration that specifies the target service
 * @param response the resulting HttpResponse to validate
 * @throws java.io.IOException if validation failed
 */
protected void validateResponse(HttpInvokerClientConfiguration config, HttpResponse response)
		throws IOException {

	StatusLine status = response.getStatusLine();
	if (status.getStatusCode() >= 300) {
		throw new NoHttpResponseException(
				"Did not receive successful HTTP response: status code = " + status.getStatusCode() +
				", status message = [" + status.getReasonPhrase() + "]");
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:HttpComponentsHttpInvokerRequestExecutor.java

示例10: handleResponse

import org.apache.http.StatusLine; //导入方法依赖的package包/类
/**
 * 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();
    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);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:BasicResponseHandler.java

示例11: handleResponse

import org.apache.http.StatusLine; //导入方法依赖的package包/类
@Override
public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
	final StatusLine statusLine = response.getStatusLine();
	int status = statusLine.getStatusCode();
	if (status >= 200 && status < 300) {
		HttpEntity entity = response.getEntity();
		return entity != null ? EntityUtils.toString(entity) : null;
	} else {
		throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase());
	}
}
 
开发者ID:Code4SocialGood,项目名称:c4sg-services,代码行数:12,代码来源:StringResponseHandler.java

示例12: handleResponse

import org.apache.http.StatusLine; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private ResponseInfo<T> handleResponse(HttpResponse response) throws HttpException, IOException {
    if (response == null) {
        throw new HttpException("response is null");
    }
    if (isCancelled()) return null;

    StatusLine status = response.getStatusLine();
    int statusCode = status.getStatusCode();
    if (statusCode < 300) {
        Object result = null;
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            isUploading = false;
            if (isDownloadingFile) {
                autoResume = autoResume && OtherUtils.isSupportRange(response);
                String responseFileName = autoRename ? OtherUtils.getFileNameFromHttpResponse(response) : null;
                result = mFileDownloadHandler.handleEntity(entity, this, fileSavePath, autoResume, responseFileName);
            } else {

                // Set charset from response header info if it's exist.
                String responseCharset = OtherUtils.getCharsetFromHttpResponse(response);
                charset = TextUtils.isEmpty(responseCharset) ? charset : responseCharset;

                result = mStringDownloadHandler.handleEntity(entity, this, charset);
                HttpUtils.sHttpGetCache.put(requestUrl, (String) result, expiry);
            }
        }
        return new ResponseInfo<T>(response, (T) result, false);
    } else if (statusCode == 301 || statusCode == 302) {
        if (httpRedirectHandler == null) {
            httpRedirectHandler = new DefaultHttpRedirectHandler();
        }
        HttpRequestBase request = httpRedirectHandler.getDirectRequest(response);
        if (request != null) {
            return this.sendRequest(request);
        }
    } else if (statusCode == 416) {
        throw new HttpException(statusCode, "maybe the file has downloaded completely");
    } else {
        throw new HttpException(statusCode, status.getReasonPhrase());
    }
    return null;
}
 
开发者ID:SavorGit,项目名称:Hotspot-master-devp,代码行数:45,代码来源:HttpHandler.java

示例13: adaptStatus

import org.apache.http.StatusLine; //导入方法依赖的package包/类
private StatusCodeLine adaptStatus(StatusLine statusLine) {
    return new StatusCodeLine(statusLine.getProtocolVersion().toString(),
            statusLine.getStatusCode(), statusLine.getReasonPhrase());
}
 
开发者ID:renatoathaydes,项目名称:rawhttp,代码行数:5,代码来源:RawHttpComponentsClient.java


注:本文中的org.apache.http.StatusLine.getReasonPhrase方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。