当前位置: 首页>>代码示例>>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;未经允许,请勿转载。