Package org.apache.http

Examples of org.apache.http.StatusLine


           
            res.sampleEnd(); // Done with the sampling proper.
            currentRequest = null;

            // Now collect the results into the HTTPSampleResult:
            StatusLine statusLine = httpResponse.getStatusLine();
            int statusCode = statusLine.getStatusCode();
            res.setResponseCode(Integer.toString(statusCode));
            res.setResponseMessage(statusLine.getReasonPhrase());
            res.setSuccessful(isSuccessCode(statusCode));

            res.setResponseHeaders(getResponseHeaders(httpResponse));
            if (res.isRedirect()) {
                final Header headerLocation = httpResponse.getLastHeader(HTTPConstants.HEADER_LOCATION);
View Full Code Here


            }

            httpPost = initHttpPost(timeoutSec, jsonToSend);

            HttpResponse httpResponse = httpClient.execute(httpPost);
            StatusLine statusLine = httpResponse.getStatusLine();
            if (isAuthorizationFailureResponse(statusLine)) {
                throw new InvalidPluginConfigurationException(
                    createErrorMessageForAuthorizationFailureResponse(statusLine));
            }

            HttpEntity httpResponseEntity = httpResponse.getEntity();
            String responseBody = httpResponseEntity == null ? StringUtil.EMPTY_STRING : EntityUtils
                .toString(httpResponseEntity);
            if (verbose && statusLine.getStatusCode() >= 400) {
                logHttpError(operation, statusLine, responseBody);
            }

            JsonNode operationResult;
            if (!responseBody.isEmpty()) {
View Full Code Here

        return response;
    }

    private ClientResponse createResponse(ClientRequest request, final HttpResponse httpResponse) {
        final ClientResponseImpl response = new ClientResponseImpl();
        StatusLine statusLine = httpResponse.getStatusLine();
        response.setStatusCode(statusLine.getStatusCode());
        response.setMessage(statusLine.getReasonPhrase());
        response.getAttributes().putAll(request.getAttributes());
        response.setContentConsumer(new Runnable() {
           
            public void run() {
              HttpEntity entity = httpResponse.getEntity();
View Full Code Here

            httpContext = ensureContext(httpContext);
            applyAuthentication(asAbstractClient(httpClient), url, httpContext, authenticator);
            HttpResponse response = httpClient.execute(request, httpContext);

            // Response
            StatusLine statusLine = response.getStatusLine();
            int statusCode = statusLine.getStatusCode();
            if (HttpSC.isClientError(statusCode) || HttpSC.isServerError(statusCode)) {
                log.debug(format("[%d] %s %s", id, statusLine.getStatusCode(), statusLine.getReasonPhrase()));
                // Error responses can have bodies so it is important to clear up.
                EntityUtils.consume(response.getEntity());
                throw new HttpException(statusLine.getStatusCode(), statusLine.getReasonPhrase());
            }
            // Redirects are followed by HttpClient.
            if (handler != null)
                handler.handle(baseURI, response);
        } catch (IOException ex) {
View Full Code Here

           
            res.sampleEnd(); // Done with the sampling proper.
            currentRequest = null;

            // Now collect the results into the HTTPSampleResult:
            StatusLine statusLine = httpResponse.getStatusLine();
            int statusCode = statusLine.getStatusCode();
            res.setResponseCode(Integer.toString(statusCode));
            res.setResponseMessage(statusLine.getReasonPhrase());
            res.setSuccessful(isSuccessCode(statusCode));

            res.setResponseHeaders(getResponseHeaders(httpResponse));
            if (res.isRedirect()) {
                final Header headerLocation = httpResponse.getLastHeader(HTTPConstants.HEADER_LOCATION);
View Full Code Here

  protected Serializable transfer(HttpUriRequest request, String url,
      Serializable model) throws IOException {
    if (request instanceof HttpEntityEnclosingRequest)
      ((HttpEntityEnclosingRequest)request).setEntity(new SerializeEntity(serializer, model));
    HttpResponse response = httpClient.execute(request);
    StatusLine status = response.getStatusLine();
    assertSuccessStatusCode(status.getStatusCode(), status.getReasonPhrase());
    HttpEntity entity = response.getEntity();
    try {
      return serializer.deserialize(Serializable.class, entity.getContent());
    } finally {
      entity.consumeContent();
View Full Code Here

  public static HttpRequest createHttpRequest(String method, String uri) {
    return new BasicHttpRequest(method, uri);
  }
 
  public static HttpResponse createHttpResponse(int status, String reason) {
    StatusLine statusLine = new BasicStatusLine(
      new ProtocolVersion("HTTP",1,1), status, reason);
    return new BasicHttpResponse(statusLine);
  }
View Full Code Here

*/
public class TestBasicResponseHandler {

    @Test
    public void testSuccessfulResponse() throws Exception {
        final StatusLine sl = new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "OK");
        final HttpResponse response = Mockito.mock(HttpResponse.class);
        final HttpEntity entity = new StringEntity("stuff");
        Mockito.when(response.getStatusLine()).thenReturn(sl);
        Mockito.when(response.getEntity()).thenReturn(entity);

View Full Code Here

    public void testUnsuccessfulResponse() throws Exception {
        final InputStream instream = Mockito.mock(InputStream.class);
        final HttpEntity entity = Mockito.mock(HttpEntity.class);
        Mockito.when(entity.isStreaming()).thenReturn(true);
        Mockito.when(entity.getContent()).thenReturn(instream);
        final StatusLine sl = new BasicStatusLine(HttpVersion.HTTP_1_1, 404, "Not Found");
        final HttpResponse response = Mockito.mock(HttpResponse.class);
        Mockito.when(response.getStatusLine()).thenReturn(sl);
        Mockito.when(response.getEntity()).thenReturn(entity);

        final BasicResponseHandler handler = new BasicResponseHandler();
View Full Code Here

class ContentResponseHandler implements ResponseHandler<Content> {

    public Content handleResponse(
            final HttpResponse response) throws ClientProtocolException, IOException {
        final StatusLine statusLine = response.getStatusLine();
        final HttpEntity entity = response.getEntity();
        if (statusLine.getStatusCode() >= 300) {
            throw new HttpResponseException(statusLine.getStatusCode(),
                    statusLine.getReasonPhrase());
        }
        if (entity != null) {
            return new Content(
                    EntityUtils.toByteArray(entity),
                    ContentType.getOrDefault(entity));
View Full Code Here

TOP

Related Classes of org.apache.http.StatusLine

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.