當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpResponse.getStatusLine方法代碼示例

本文整理匯總了Java中org.apache.http.HttpResponse.getStatusLine方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpResponse.getStatusLine方法的具體用法?Java HttpResponse.getStatusLine怎麽用?Java HttpResponse.getStatusLine使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.http.HttpResponse的用法示例。


在下文中一共展示了HttpResponse.getStatusLine方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: Response

import org.apache.http.HttpResponse; //導入方法依賴的package包/類
/**
 * Constructor
 *
 * @param response the http response
 */
public Response( final HttpResponse response )
{
	this.status = response.getStatusLine( );
	this.headers = response.getAllHeaders( );

	try
	{
		this.entityContent = EntityUtils.toByteArray( response.getEntity( ) );
		// EntityUtils.consume( response.getEntity( ) );
	}
	catch ( IllegalArgumentException | IOException e )
	{
		// ok
	}
}
 
開發者ID:ApinautenGmbH,項目名稱:integration-test-helper,代碼行數:21,代碼來源:Response.java

示例2: sendResponseMessage

import org.apache.http.HttpResponse; //導入方法依賴的package包/類
@Override
public void sendResponseMessage(HttpResponse response) throws IOException {
    if (!Thread.currentThread().isInterrupted()) {
        StatusLine status = response.getStatusLine();
        if (status.getStatusCode() == HttpStatus.SC_REQUESTED_RANGE_NOT_SATISFIABLE) {
            //already finished
            if (!Thread.currentThread().isInterrupted())
                sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(), null);
        } else if (status.getStatusCode() >= 300) {
            if (!Thread.currentThread().isInterrupted())
                sendFailureMessage(status.getStatusCode(), response.getAllHeaders(), null, new HttpResponseException(status.getStatusCode(), status.getReasonPhrase()));
        } else {
            if (!Thread.currentThread().isInterrupted()) {
                Header header = response.getFirstHeader(AsyncHttpClient.HEADER_CONTENT_RANGE);
                if (header == null) {
                    append = false;
                    current = 0;
                } else {
                    Log.v(LOG_TAG, AsyncHttpClient.HEADER_CONTENT_RANGE + ": " + header.getValue());
                }
                sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(), getResponseData(response.getEntity()));
            }
        }
    }
}
 
開發者ID:yiwent,項目名稱:Mobike,代碼行數:26,代碼來源:RangeFileAsyncHttpResponseHandler.java

示例3: sendResponseMessage

import org.apache.http.HttpResponse; //導入方法依賴的package包/類
@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);
            }
        }
    }
}
 
開發者ID:LanguidSheep,項目名稱:sealtalk-android-master,代碼行數:18,代碼來源:AsyncHttpResponseHandler.java

示例4: sendResponseMessage

import org.apache.http.HttpResponse; //導入方法依賴的package包/類
@Override
public final void sendResponseMessage(HttpResponse response) throws IOException {
    StatusLine status = response.getStatusLine();
    Header[] contentTypeHeaders = response.getHeaders("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) {
        }
    }
    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);
}
 
開發者ID:zqHero,項目名稱:rongyunDemo,代碼行數:27,代碼來源:BinaryHttpResponseHandler.java

示例5: toFeignResponse

import org.apache.http.HttpResponse; //導入方法依賴的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

示例6: sendResponseMessage

import org.apache.http.HttpResponse; //導入方法依賴的package包/類
@Override
public void sendResponseMessage(HttpResponse response) throws IOException {
    if (!Thread.currentThread().isInterrupted()) {
        StatusLine status = response.getStatusLine();
        if (status.getStatusCode() == HttpStatus.SC_REQUESTED_RANGE_NOT_SATISFIABLE) {
            //already finished
            if (!Thread.currentThread().isInterrupted())
                sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(), null);
        } else if (status.getStatusCode() >= 300) {
            if (!Thread.currentThread().isInterrupted())
                sendFailureMessage(status.getStatusCode(), response.getAllHeaders(), null, new HttpResponseException(status.getStatusCode(), status.getReasonPhrase()));
        } else {
            if (!Thread.currentThread().isInterrupted()) {
                Header header = response.getFirstHeader(AsyncHttpClient.HEADER_CONTENT_RANGE);
                if (header == null) {
                    append = false;
                    current = 0;
                } else
                    Log.v(LOG_TAG, AsyncHttpClient.HEADER_CONTENT_RANGE + ": " + header.getValue());
                sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(), getResponseData(response.getEntity()));
            }
        }
    }
}
 
開發者ID:benniaobuguai,項目名稱:android-project-gallery,代碼行數:25,代碼來源:RangeFileAsyncHttpResponseHandler.java

示例7: saveBotCam

import org.apache.http.HttpResponse; //導入方法依賴的package包/類
public Long saveBotCam(BotCamera botCamera) {
    HttpEntity entity = MultipartEntityBuilder
            .create()
            .addPart("file", new ByteArrayBody(botCamera.getScreenShot(), "botSnapshot"))
            .build();

    Long idResponse = -1L;

    try {
        HttpPost httpPost = new HttpPost(apiUrl + BotCameraController.ENDPOINT_ROINT + "/" + botCamera.getPlayerBot().getName());
        httpPost.setEntity(entity);
        HttpResponse response = uploadHttpClient.execute(httpPost);
        ResponseHandler<String> handler = new BasicResponseHandler();

        if(response != null &&
            response.getStatusLine() != null &&
            response.getStatusLine().getStatusCode() == HttpStatus.OK.value()) {

            final String rawResult = handler.handleResponse(response);

            idResponse = Long.parseLong(rawResult);
        } else {
            log.error("Failed to upload pictar!");
            log.error("Headers received: " + Arrays.stream(response.getAllHeaders()).map(header -> new String(header.getName() + ": " + header.getValue()))
                                                                                    .reduce("", (result, next) -> System.lineSeparator() + next));
            log.error("Body received: " + System.lineSeparator() + handler.handleResponse(response));
        }
    } catch (IOException e) {
        log.error("Failed to upload pictar!");
        log.error(e.getMessage());
    }

    return idResponse;
}
 
開發者ID:corydissinger,項目名稱:mtgo-best-bot,代碼行數:35,代碼來源:BotCameraService.java

示例8: handleResponse

import org.apache.http.HttpResponse; //導入方法依賴的package包/類
private R handleResponse(ResponseParser<R> parser, HttpResponse response) throws IOException
{
    StatusLine statusLine= response.getStatusLine();
    if (statusLine.getStatusCode() == HttpStatus.SC_OK)
    {
        HttpEntity entity = response.getEntity();
        if (entity != null)
        {
            Charset charset = ContentType.getOrDefault(entity).getCharset();
            Reader reader = new InputStreamReader(entity.getContent(), charset);
            return parser.parseResponse(reader);
        }
        throw new NextcloudApiException("Empty response received");
    }
    throw new NextcloudApiException(String.format("Request failed with %d %s", statusLine.getStatusCode(), statusLine.getReasonPhrase()));
}
 
開發者ID:a-schild,項目名稱:nextcloud-java-api,代碼行數:17,代碼來源:ConnectorCommon.java

示例9: handleResponse

import org.apache.http.HttpResponse; //導入方法依賴的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

示例10: HttpPost

import org.apache.http.HttpResponse; //導入方法依賴的package包/類
private boolean b044C044C044Cьь044C(String str, String str2, String str3, String str4) throws ClientProtocolException, IOException {
    this.b041BЛЛ041BЛ041B = b044Cьь044Cь044C(str3);
    HttpPost httpPost = new HttpPost(bЛ041BЛЛЛ041B);
    String generateSignature = new crrcrc().generateSignature(str2, this.b041BЛЛ041BЛ041B, str4);
    httpPost.setEntity(new StringEntity(str4, "UTF-8"));
    httpPost.setHeaders(this.b041BЛЛ041BЛ041B);
    Object bььь044Cь044C = bььь044Cь044C(str, generateSignature, httpPost);
    HttpResponse execute = new DefaultHttpClient().execute(bььь044Cь044C);
    Log.d(b041BЛЛЛЛ041B, "All POST request headers:");
    for (Header header : bььь044Cь044C.getAllHeaders()) {
        Log.d(b041BЛЛЛЛ041B, header.getName() + NetworkUtils.DELIMITER_COLON + header.getValue());
    }
    Log.d(b041BЛЛЛЛ041B, "HTTP Request body: " + str4);
    String str5 = b041BЛЛЛЛ041B;
    StringBuilder append = new StringBuilder().append("HTTP Response: ");
    StatusLine statusLine = execute.getStatusLine();
    int b0427ЧЧЧ0427Ч = b0427ЧЧЧ0427Ч();
    switch ((b0427ЧЧЧ0427Ч * (b04270427ЧЧ0427Ч + b0427ЧЧЧ0427Ч)) % bЧЧ0427Ч0427Ч) {
        case 0:
            break;
        default:
            b0427Ч0427Ч0427Ч = b0427ЧЧЧ0427Ч();
            bЧ0427ЧЧ0427Ч = b0427ЧЧЧ0427Ч();
            break;
    }
    Log.d(str5, append.append(statusLine.toString()).toString());
    Log.d(b041BЛЛЛЛ041B, "HTTP Response: " + EntityUtils.toString(execute.getEntity()));
    return execute.getStatusLine().getStatusCode() == 200;
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:30,代碼來源:rcccrr.java

示例11: HttpResponseWarcRecord

import org.apache.http.HttpResponse; //導入方法依賴的package包/類
private HttpResponseWarcRecord(final HeaderGroup warcHeaders, final URI targetURI, final HttpResponse response, final HttpEntityFactory hef) throws IOException {
	super(targetURI, warcHeaders);
	getWarcTargetURI(); // Check correct initialization
	this.warcHeaders.updateHeader(Type.warcHeader(Type.RESPONSE));
	this.warcHeaders.updateHeader(new WarcHeader(WarcHeader.Name.CONTENT_TYPE, HTTP_RESPONSE_MSGTYPE));
	this.protocolVersion = response.getProtocolVersion();
	this.statusLine = response.getStatusLine();
	this.setHeaders(response.getAllHeaders());
	this.entity = (hef == null ? IdentityHttpEntityFactory.INSTANCE : hef).newEntity(response.getEntity());
}
 
開發者ID:LAW-Unimi,項目名稱:BUbiNG,代碼行數:11,代碼來源:HttpResponseWarcRecord.java

示例12: ResponseImpl

import org.apache.http.HttpResponse; //導入方法依賴的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

示例13: handleResponse

import org.apache.http.HttpResponse; //導入方法依賴的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

示例14: simplify

import org.apache.http.HttpResponse; //導入方法依賴的package包/類
public static ResultResponse simplify(HttpResponse httpResponse, boolean compress) {
    StatusLine statusLine = httpResponse.getStatusLine();
    int statusCode = statusLine.getStatusCode();
    ResultResponse resultResponse = new ResultResponse(statusCode);
    resultResponse.httpResponse = httpResponse;
    resultResponse.compress = compress;
    return resultResponse;
}
 
開發者ID:aliyun,項目名稱:HiTSDB-Client,代碼行數:9,代碼來源:ResultResponse.java

示例15: handleResponse

import org.apache.http.HttpResponse; //導入方法依賴的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


注:本文中的org.apache.http.HttpResponse.getStatusLine方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。