本文整理汇总了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);
}
}
示例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();
}
示例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;
}
示例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;
}
示例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);
}
}
示例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();
}
示例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);
}
示例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();
}
}
示例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() + "]");
}
}
示例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);
}
示例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());
}
}
示例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;
}
示例13: adaptStatus
import org.apache.http.StatusLine; //导入方法依赖的package包/类
private StatusCodeLine adaptStatus(StatusLine statusLine) {
return new StatusCodeLine(statusLine.getProtocolVersion().toString(),
statusLine.getStatusCode(), statusLine.getReasonPhrase());
}