Java Code Examples for com.squareup.okhttp.internal.http.HttpEngine#getResponseBody()

The following examples show how to use com.squareup.okhttp.internal.http.HttpEngine#getResponseBody() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Job.java    From L.TileLayer.Cordova with MIT License 4 votes vote down vote up
private Response execute() throws IOException {
  Connection connection = null;
  Response redirectedBy = null;

  while (true) {
    HttpEngine engine = newEngine(connection);

    Request.Body body = request.body();
    if (body != null) {
      MediaType contentType = body.contentType();
      if (contentType == null) throw new IllegalStateException("contentType == null");
      if (engine.getRequestHeaders().getContentType() == null) {
        engine.getRequestHeaders().setContentType(contentType.toString());
      }
    }

    engine.sendRequest();

    if (body != null) {
      body.writeTo(engine.getRequestBody());
    }

    engine.readResponse();

    int responseCode = engine.getResponseCode();
    Dispatcher.RealResponseBody responseBody = new Dispatcher.RealResponseBody(
        engine.getResponseHeaders(), engine.getResponseBody());

    Response response = new Response.Builder(request, responseCode)
        .rawHeaders(engine.getResponseHeaders().getHeaders())
        .body(responseBody)
        .redirectedBy(redirectedBy)
        .build();

    Request redirect = processResponse(engine, response);

    if (redirect == null) {
      engine.automaticallyReleaseConnectionToPool();
      return response;
    }

    // TODO: fail if too many redirects
    // TODO: fail if not following redirects
    // TODO: release engine

    connection = sameConnection(request, redirect) ? engine.getConnection() : null;
    redirectedBy = response;
    request = redirect;
  }
}
 
Example 2
Source File: Job.java    From IoTgo_Android_App with MIT License 4 votes vote down vote up
private Response execute() throws IOException {
  Connection connection = null;
  Response redirectedBy = null;

  while (true) {
    HttpEngine engine = newEngine(connection);

    Request.Body body = request.body();
    if (body != null) {
      MediaType contentType = body.contentType();
      if (contentType == null) throw new IllegalStateException("contentType == null");
      if (engine.getRequestHeaders().getContentType() == null) {
        engine.getRequestHeaders().setContentType(contentType.toString());
      }
    }

    engine.sendRequest();

    if (body != null) {
      body.writeTo(engine.getRequestBody());
    }

    engine.readResponse();

    int responseCode = engine.getResponseCode();
    Dispatcher.RealResponseBody responseBody = new Dispatcher.RealResponseBody(
        engine.getResponseHeaders(), engine.getResponseBody());

    Response response = new Response.Builder(request, responseCode)
        .rawHeaders(engine.getResponseHeaders().getHeaders())
        .body(responseBody)
        .redirectedBy(redirectedBy)
        .build();

    Request redirect = processResponse(engine, response);

    if (redirect == null) {
      engine.automaticallyReleaseConnectionToPool();
      return response;
    }

    // TODO: fail if too many redirects
    // TODO: fail if not following redirects
    // TODO: release engine

    connection = sameConnection(request, redirect) ? engine.getConnection() : null;
    redirectedBy = response;
    request = redirect;
  }
}
 
Example 3
Source File: Job.java    From bluemix-parking-meter with MIT License 4 votes vote down vote up
private Response execute() throws IOException {
  Connection connection = null;
  Response redirectedBy = null;

  while (true) {
    HttpEngine engine = newEngine(connection);

    Request.Body body = request.body();
    if (body != null) {
      MediaType contentType = body.contentType();
      if (contentType == null) throw new IllegalStateException("contentType == null");
      if (engine.getRequestHeaders().getContentType() == null) {
        engine.getRequestHeaders().setContentType(contentType.toString());
      }
    }

    engine.sendRequest();

    if (body != null) {
      body.writeTo(engine.getRequestBody());
    }

    engine.readResponse();

    int responseCode = engine.getResponseCode();
    Dispatcher.RealResponseBody responseBody = new Dispatcher.RealResponseBody(
        engine.getResponseHeaders(), engine.getResponseBody());

    Response response = new Response.Builder(request, responseCode)
        .rawHeaders(engine.getResponseHeaders().getHeaders())
        .body(responseBody)
        .redirectedBy(redirectedBy)
        .build();

    Request redirect = processResponse(engine, response);

    if (redirect == null) {
      engine.automaticallyReleaseConnectionToPool();
      return response;
    }

    // TODO: fail if too many redirects
    // TODO: fail if not following redirects
    // TODO: release engine

    connection = sameConnection(request, redirect) ? engine.getConnection() : null;
    redirectedBy = response;
    request = redirect;
  }
}
 
Example 4
Source File: Job.java    From reader with MIT License 4 votes vote down vote up
private Response execute() throws IOException {
  Connection connection = null;
  Response redirectedBy = null;

  while (true) {
    HttpEngine engine = newEngine(connection);

    Request.Body body = request.body();
    if (body != null) {
      MediaType contentType = body.contentType();
      if (contentType == null) throw new IllegalStateException("contentType == null");
      if (engine.getRequestHeaders().getContentType() == null) {
        engine.getRequestHeaders().setContentType(contentType.toString());
      }
    }

    engine.sendRequest();

    if (body != null) {
      body.writeTo(engine.getRequestBody());
    }

    engine.readResponse();

    int responseCode = engine.getResponseCode();
    Dispatcher.RealResponseBody responseBody = new Dispatcher.RealResponseBody(
        engine.getResponseHeaders(), engine.getResponseBody());

    Response response = new Response.Builder(request, responseCode)
        .rawHeaders(engine.getResponseHeaders().getHeaders())
        .body(responseBody)
        .redirectedBy(redirectedBy)
        .build();

    Request redirect = processResponse(engine, response);

    if (redirect == null) {
      engine.automaticallyReleaseConnectionToPool();
      return response;
    }

    // TODO: fail if too many redirects
    // TODO: fail if not following redirects
    // TODO: release engine

    connection = sameConnection(request, redirect) ? engine.getConnection() : null;
    redirectedBy = response;
    request = redirect;
  }
}
 
Example 5
Source File: Job.java    From reader with MIT License 4 votes vote down vote up
private Response execute() throws IOException {
  Connection connection = null;
  Response redirectedBy = null;

  while (true) {
    HttpEngine engine = newEngine(connection);

    Request.Body body = request.body();
    if (body != null) {
      MediaType contentType = body.contentType();
      if (contentType == null) throw new IllegalStateException("contentType == null");
      if (engine.getRequestHeaders().getContentType() == null) {
        engine.getRequestHeaders().setContentType(contentType.toString());
      }
    }

    engine.sendRequest();

    if (body != null) {
      body.writeTo(engine.getRequestBody());
    }

    engine.readResponse();

    int responseCode = engine.getResponseCode();
    Dispatcher.RealResponseBody responseBody = new Dispatcher.RealResponseBody(
        engine.getResponseHeaders(), engine.getResponseBody());

    Response response = new Response.Builder(request, responseCode)
        .rawHeaders(engine.getResponseHeaders().getHeaders())
        .body(responseBody)
        .redirectedBy(redirectedBy)
        .build();

    Request redirect = processResponse(engine, response);

    if (redirect == null) {
      engine.automaticallyReleaseConnectionToPool();
      return response;
    }

    // TODO: fail if too many redirects
    // TODO: fail if not following redirects
    // TODO: release engine

    connection = sameConnection(request, redirect) ? engine.getConnection() : null;
    redirectedBy = response;
    request = redirect;
  }
}
 
Example 6
Source File: Job.java    From cordova-amazon-fireos with Apache License 2.0 4 votes vote down vote up
private Response execute() throws IOException {
  Connection connection = null;
  Response redirectedBy = null;

  while (true) {
    HttpEngine engine = newEngine(connection);

    Request.Body body = request.body();
    if (body != null) {
      MediaType contentType = body.contentType();
      if (contentType == null) throw new IllegalStateException("contentType == null");
      if (engine.getRequestHeaders().getContentType() == null) {
        engine.getRequestHeaders().setContentType(contentType.toString());
      }
    }

    engine.sendRequest();

    if (body != null) {
      body.writeTo(engine.getRequestBody());
    }

    engine.readResponse();

    int responseCode = engine.getResponseCode();
    Dispatcher.RealResponseBody responseBody = new Dispatcher.RealResponseBody(
        engine.getResponseHeaders(), engine.getResponseBody());

    Response response = new Response.Builder(request, responseCode)
        .rawHeaders(engine.getResponseHeaders().getHeaders())
        .body(responseBody)
        .redirectedBy(redirectedBy)
        .build();

    Request redirect = processResponse(engine, response);

    if (redirect == null) {
      engine.automaticallyReleaseConnectionToPool();
      return response;
    }

    // TODO: fail if too many redirects
    // TODO: fail if not following redirects
    // TODO: release engine

    connection = sameConnection(request, redirect) ? engine.getConnection() : null;
    redirectedBy = response;
    request = redirect;
  }
}
 
Example 7
Source File: Job.java    From phonegapbootcampsite with MIT License 4 votes vote down vote up
private Response execute() throws IOException {
  Connection connection = null;
  Response redirectedBy = null;

  while (true) {
    HttpEngine engine = newEngine(connection);

    Request.Body body = request.body();
    if (body != null) {
      MediaType contentType = body.contentType();
      if (contentType == null) throw new IllegalStateException("contentType == null");
      if (engine.getRequestHeaders().getContentType() == null) {
        engine.getRequestHeaders().setContentType(contentType.toString());
      }
    }

    engine.sendRequest();

    if (body != null) {
      body.writeTo(engine.getRequestBody());
    }

    engine.readResponse();

    int responseCode = engine.getResponseCode();
    Dispatcher.RealResponseBody responseBody = new Dispatcher.RealResponseBody(
        engine.getResponseHeaders(), engine.getResponseBody());

    Response response = new Response.Builder(request, responseCode)
        .rawHeaders(engine.getResponseHeaders().getHeaders())
        .body(responseBody)
        .redirectedBy(redirectedBy)
        .build();

    Request redirect = processResponse(engine, response);

    if (redirect == null) {
      engine.automaticallyReleaseConnectionToPool();
      return response;
    }

    // TODO: fail if too many redirects
    // TODO: fail if not following redirects
    // TODO: release engine

    connection = sameConnection(request, redirect) ? engine.getConnection() : null;
    redirectedBy = response;
    request = redirect;
  }
}
 
Example 8
Source File: Job.java    From CordovaYoutubeVideoPlayer with MIT License 4 votes vote down vote up
private Response execute() throws IOException {
  Connection connection = null;
  Response redirectedBy = null;

  while (true) {
    HttpEngine engine = newEngine(connection);

    Request.Body body = request.body();
    if (body != null) {
      MediaType contentType = body.contentType();
      if (contentType == null) throw new IllegalStateException("contentType == null");
      if (engine.getRequestHeaders().getContentType() == null) {
        engine.getRequestHeaders().setContentType(contentType.toString());
      }
    }

    engine.sendRequest();

    if (body != null) {
      body.writeTo(engine.getRequestBody());
    }

    engine.readResponse();

    int responseCode = engine.getResponseCode();
    Dispatcher.RealResponseBody responseBody = new Dispatcher.RealResponseBody(
        engine.getResponseHeaders(), engine.getResponseBody());

    Response response = new Response.Builder(request, responseCode)
        .rawHeaders(engine.getResponseHeaders().getHeaders())
        .body(responseBody)
        .redirectedBy(redirectedBy)
        .build();

    Request redirect = processResponse(engine, response);

    if (redirect == null) {
      engine.automaticallyReleaseConnectionToPool();
      return response;
    }

    // TODO: fail if too many redirects
    // TODO: fail if not following redirects
    // TODO: release engine

    connection = sameConnection(request, redirect) ? engine.getConnection() : null;
    redirectedBy = response;
    request = redirect;
  }
}
 
Example 9
Source File: Job.java    From wildfly-samples with MIT License 4 votes vote down vote up
private Response execute() throws IOException {
  Connection connection = null;
  Response redirectedBy = null;

  while (true) {
    HttpEngine engine = newEngine(connection);

    Request.Body body = request.body();
    if (body != null) {
      MediaType contentType = body.contentType();
      if (contentType == null) throw new IllegalStateException("contentType == null");
      if (engine.getRequestHeaders().getContentType() == null) {
        engine.getRequestHeaders().setContentType(contentType.toString());
      }
    }

    engine.sendRequest();

    if (body != null) {
      body.writeTo(engine.getRequestBody());
    }

    engine.readResponse();

    int responseCode = engine.getResponseCode();
    Dispatcher.RealResponseBody responseBody = new Dispatcher.RealResponseBody(
        engine.getResponseHeaders(), engine.getResponseBody());

    Response response = new Response.Builder(request, responseCode)
        .rawHeaders(engine.getResponseHeaders().getHeaders())
        .body(responseBody)
        .redirectedBy(redirectedBy)
        .build();

    Request redirect = processResponse(engine, response);

    if (redirect == null) {
      engine.automaticallyReleaseConnectionToPool();
      return response;
    }

    // TODO: fail if too many redirects
    // TODO: fail if not following redirects
    // TODO: release engine

    connection = sameConnection(request, redirect) ? engine.getConnection() : null;
    redirectedBy = response;
    request = redirect;
  }
}
 
Example 10
Source File: Job.java    From crosswalk-cordova-android with Apache License 2.0 4 votes vote down vote up
private Response execute() throws IOException {
  Connection connection = null;
  Response redirectedBy = null;

  while (true) {
    HttpEngine engine = newEngine(connection);

    Request.Body body = request.body();
    if (body != null) {
      MediaType contentType = body.contentType();
      if (contentType == null) throw new IllegalStateException("contentType == null");
      if (engine.getRequestHeaders().getContentType() == null) {
        engine.getRequestHeaders().setContentType(contentType.toString());
      }
    }

    engine.sendRequest();

    if (body != null) {
      body.writeTo(engine.getRequestBody());
    }

    engine.readResponse();

    int responseCode = engine.getResponseCode();
    Dispatcher.RealResponseBody responseBody = new Dispatcher.RealResponseBody(
        engine.getResponseHeaders(), engine.getResponseBody());

    Response response = new Response.Builder(request, responseCode)
        .rawHeaders(engine.getResponseHeaders().getHeaders())
        .body(responseBody)
        .redirectedBy(redirectedBy)
        .build();

    Request redirect = processResponse(engine, response);

    if (redirect == null) {
      engine.automaticallyReleaseConnectionToPool();
      return response;
    }

    // TODO: fail if too many redirects
    // TODO: fail if not following redirects
    // TODO: release engine

    connection = sameConnection(request, redirect) ? engine.getConnection() : null;
    redirectedBy = response;
    request = redirect;
  }
}