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


Java StatusLine类代码示例

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


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

示例1: sendResponseMessage

import org.apache.http.StatusLine; //导入依赖的package包/类
public void sendResponseMessage(HttpResponse response) throws IOException {
    if (!Thread.currentThread().isInterrupted()) {
        StatusLine status = response.getStatusLine();
        if (status.getStatusCode() == 416) {
            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) {
                this.append = false;
                this.current = 0;
            } else {
                Log.v(LOG_TAG, "Content-Range: " + header.getValue());
            }
            sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(),
                    getResponseData(response.getEntity()));
        }
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:27,代码来源:RangeFileAsyncHttpResponseHandler.java

示例2: postSubmission

import org.apache.http.StatusLine; //导入依赖的package包/类
private static void postSubmission(boolean passed, StepicWrappers.AttemptWrapper.Attempt attempt,
                                   ArrayList<StepicWrappers.SolutionFile> files) throws IOException {
  final HttpPost request = new HttpPost(EduStepicNames.STEPIC_API_URL + EduStepicNames.SUBMISSIONS);

  String requestBody = new Gson().toJson(new StepicWrappers.SubmissionWrapper(attempt.id, passed ? "1" : "0", files));
  request.setEntity(new StringEntity(requestBody, ContentType.APPLICATION_JSON));
  final CloseableHttpClient client = EduStepicAuthorizedClient.getHttpClient();
  if (client == null) return;
  final CloseableHttpResponse response = client.execute(request);
  final HttpEntity responseEntity = response.getEntity();
  final String responseString = responseEntity != null ? EntityUtils.toString(responseEntity) : "";
  final StatusLine line = response.getStatusLine();
  EntityUtils.consume(responseEntity);
  if (line.getStatusCode() != HttpStatus.SC_CREATED) {
    LOG.error("Failed to make submission " + responseString);
  }
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:18,代码来源:EduStepicConnector.java

示例3: doGet_should_return_string_response_since_httpClient_execute_returned_with_success

import org.apache.http.StatusLine; //导入依赖的package包/类
@Test(groups = "HttpUtils.doGet")
public void doGet_should_return_string_response_since_httpClient_execute_returned_with_success()
        throws ClientProtocolException, IOException {

    String succResponse = "Test Response";

    CloseableHttpResponse httpResponse = PowerMockito
            .mock(CloseableHttpResponse.class);
    StatusLine statusLine = PowerMockito.mock(StatusLine.class);

    StringEntity entity = new StringEntity(succResponse);

    PowerMockito.spy(HttpUtils.class);

    try {
        PowerMockito.doReturn(mockHttpClient).when(HttpUtils.class,
                "initialize");
    } catch (Exception e1) {
        Assert.fail("Couldn't mock the HttpUtils.initialize method!", e1);
    }

    // and:
    PowerMockito.when(statusLine.getStatusCode()).thenReturn(200);
    PowerMockito.when(httpResponse.getEntity()).thenReturn(entity);
    PowerMockito.when(httpResponse.getStatusLine()).thenReturn(statusLine);

    PowerMockito.when(mockHttpClient.execute(Mockito.any(HttpGet.class)))
            .thenReturn(httpResponse);
    HashMap<String, String> headers = new HashMap<String, String>();

    headers.put("test", "value");

    try {
        String response = HttpUtils.doGet("http://example.com", headers);

        Assert.assertEquals(response, succResponse);
    } catch (StockException e) {
        Assert.fail("Exception occured while calling HttpUtils.doGet!", e);
    }
}
 
开发者ID:adobe,项目名称:stock-api-sdk,代码行数:41,代码来源:HttpUtilsTest.java

示例4: sendResponseMessage

import org.apache.http.StatusLine; //导入依赖的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

示例5: folder_can_handle_empty_response_to_body_request

import org.apache.http.StatusLine; //导入依赖的package包/类
@Test
public void folder_can_handle_empty_response_to_body_request() throws MessagingException, IOException {
    setupStoreForMessageFetching();
    List<WebDavMessage> messages = setup25MessagesToFetch();

    when(mockHttpClient.executeOverride(any(HttpUriRequest.class), any(HttpContext.class))).thenAnswer(
            new Answer<HttpResponse>() {
                @Override
                public HttpResponse answer(InvocationOnMock invocation) throws Throwable {
                    HttpResponse httpResponse = mock(HttpResponse.class);
                    StatusLine statusLine = mock(StatusLine.class);
                    when(httpResponse.getStatusLine()).thenReturn(statusLine);
                    when(statusLine.getStatusCode()).thenReturn(200);
                    return httpResponse;
                }
            });

    FetchProfile profile = new FetchProfile();
    profile.add(FetchProfile.Item.BODY_SANE);
    folder.fetch(messages, profile, listener);
    verify(listener, times(25)).messageStarted(any(String.class), anyInt(), eq(25));
    verify(listener, times(25)).messageFinished(any(WebDavMessage.class), anyInt(), eq(25));
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:24,代码来源:WebDavFolderTest.java

示例6: sendResponseMessage

import org.apache.http.StatusLine; //导入依赖的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

示例7: getStatusCode

import org.apache.http.StatusLine; //导入依赖的package包/类
protected int getStatusCode() {

        StatusLine sl = null;
        try {
            sl = response.getStatusLine();
        }
        catch (Exception e) {
            // ignore
        }

        if (null == sl) {
            // as BAT REQUEST
            return 400;
        }

        return sl.getStatusCode();
    }
 
开发者ID:uavorg,项目名称:uavstack,代码行数:18,代码来源:AsyncReqProcWithHttpClientCallback.java

示例8: getEntity

import org.apache.http.StatusLine; //导入依赖的package包/类
private String getEntity(URI url) throws IOException {
    final HttpGet get = new HttpGet(url);
    get.setConfig(requestConfig);
    get.setHeader("Accept", "application/json");

    HttpClientBuilder clientBuilder = HttpClients.custom();
    if (sslContext != null) {
        clientBuilder.setSslcontext(sslContext);
    }

    try (CloseableHttpClient httpClient = clientBuilder.build()) {

        try (CloseableHttpResponse response = httpClient.execute(get)) {

            final StatusLine statusLine = response.getStatusLine();
            final int statusCode = statusLine.getStatusCode();
            if (200 != statusCode) {
                final String msg = String.format("Failed to get entity from %s, response=%d:%s",
                        get.getURI(), statusCode, statusLine.getReasonPhrase());
                throw new RuntimeException(msg);
            }
            final HttpEntity entity = response.getEntity();
            return EntityUtils.toString(entity);
        }
    }
}
 
开发者ID:bcgov,项目名称:nifi-atlas,代码行数:27,代码来源:NiFiApiClient.java

示例9: parseStatusLine

import org.apache.http.StatusLine; //导入依赖的package包/类
public final static
    StatusLine parseStatusLine(final String value,
                               LineParser parser)
    throws ParseException {

    if (value == null) {
        throw new IllegalArgumentException
            ("Value to parse may not be null.");
    }

    if (parser == null)
        parser = BasicLineParser.DEFAULT;

    CharArrayBuffer buffer = new CharArrayBuffer(value.length());
    buffer.append(value);
    ParserCursor cursor = new ParserCursor(0, value.length());
    return parser.parseStatusLine(buffer, cursor);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:BasicLineParser.java

示例10: 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

示例11: deleteTask

import org.apache.http.StatusLine; //导入依赖的package包/类
public static void deleteTask(@NotNull final Integer task, Project project) {
  final HttpDelete request = new HttpDelete(EduStepicNames.STEPIC_API_URL + EduStepicNames.STEP_SOURCES + task);
  ApplicationManager.getApplication().invokeLater(() -> {
    try {
      final CloseableHttpClient client = EduStepicAuthorizedClient.getHttpClient();
      if (client == null) return;
      final CloseableHttpResponse response = client.execute(request);
      final HttpEntity responseEntity = response.getEntity();
      final String responseString = responseEntity != null ? EntityUtils.toString(responseEntity) : "";
      EntityUtils.consume(responseEntity);
      final StatusLine line = response.getStatusLine();
      if (line.getStatusCode() != HttpStatus.SC_NO_CONTENT) {
        LOG.error("Failed to delete task " + responseString);
        showErrorNotification(project, "Failed to delete task ", responseString);
      }
    }
    catch (IOException e) {
      LOG.error(e.getMessage());
    }
  });
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:22,代码来源:CCStepicConnector.java

示例12: 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

示例13: testMap

import org.apache.http.StatusLine; //导入依赖的package包/类
@Test
public void testMap() throws Exception {
    assertEquals("Message. 500 reason. Please contact your web hosting service provider for assistance.", new SwiftExceptionMappingService().map(
            new GenericException("message", null, new StatusLine() {
                @Override
                public ProtocolVersion getProtocolVersion() {
                    throw new UnsupportedOperationException();
                }

                @Override
                public int getStatusCode() {
                    return 500;
                }

                @Override
                public String getReasonPhrase() {
                    return "reason";
                }
            })).getDetail());
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:21,代码来源:SwiftExceptionMappingServiceTest.java

示例14: 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

示例15: doGet_should_return_null_since_httpClient_execute_returned_with_unknown_response_code

import org.apache.http.StatusLine; //导入依赖的package包/类
@Test(groups = "HttpUtils.doGet")
public void doGet_should_return_null_since_httpClient_execute_returned_with_unknown_response_code()
        throws ClientProtocolException, IOException {

    String succResponse = "Test Response";

    CloseableHttpResponse httpResponse = PowerMockito
            .mock(CloseableHttpResponse.class);
    StatusLine statusLine = PowerMockito.mock(StatusLine.class);

    StringEntity entity = new StringEntity(succResponse);

    PowerMockito.spy(HttpUtils.class);

    try {
        PowerMockito.doReturn(mockHttpClient).when(HttpUtils.class,
                "initialize");
    } catch (Exception e1) {
        Assert.fail("Couldn't mock the HttpUtils.initialize method!", e1);
    }

    // and:
    PowerMockito.when(statusLine.getStatusCode()).thenReturn(600);
    PowerMockito.when(httpResponse.getEntity()).thenReturn(entity);
    PowerMockito.when(httpResponse.getStatusLine()).thenReturn(statusLine);

    PowerMockito.when(mockHttpClient.execute(Mockito.any(HttpGet.class)))
            .thenReturn(httpResponse);
    HashMap<String, String> headers = new HashMap<String, String>();

    headers.put("test", "value");

    try {
        String response = HttpUtils.doGet("http://example.com", headers);

        Assert.assertNull(response);
    } catch (StockException e) {
        Assert.fail("Exception occured while calling HttpUtils.doGet!", e);
    }
}
 
开发者ID:adobe,项目名称:stock-api-sdk,代码行数:41,代码来源:HttpUtilsTest.java


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