Search in sources :

Example 1 with ResponseFutureImpl

use of com.linkedin.restli.internal.client.ResponseFutureImpl in project rest.li by linkedin.

the class MockFailedResponseFutureBuilder method buildWithErrorResponse.

private ResponseFuture<V> buildWithErrorResponse(ProtocolVersion protocolVersion) {
    int status = (_errorResponse.hasStatus()) ? _errorResponse.getStatus() : DEFAULT_HTTP_STATUS;
    // create a RestLiResponseException and wrap it in an ExecutionException that will be thrown by the ResponseFuture
    RestLiResponseException restLiResponseException = new MockRestliResponseExceptionBuilder().setErrorResponse(_errorResponse).setStatus(HttpStatus.fromCode(status)).setCookies(getCookies() == null ? Collections.emptyList() : getCookies()).setHeaders(getHeaders() == null ? new HashMap<>() : getHeaders()).build();
    ExecutionException executionException = new ExecutionException(restLiResponseException);
    Future<Response<V>> responseFuture = buildFuture(null, executionException);
    return new ResponseFutureImpl<>(responseFuture, _errorHandlingBehavior);
}
Also used : RestResponse(com.linkedin.r2.message.rest.RestResponse) Response(com.linkedin.restli.client.Response) ErrorResponse(com.linkedin.restli.common.ErrorResponse) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) ExecutionException(java.util.concurrent.ExecutionException) ResponseFutureImpl(com.linkedin.restli.internal.client.ResponseFutureImpl)

Example 2 with ResponseFutureImpl

use of com.linkedin.restli.internal.client.ResponseFutureImpl in project rest.li by linkedin.

the class MockFailedResponseFutureBuilder method buildWithEntity.

private ResponseFuture<V> buildWithEntity() {
    int status = getStatus();
    byte[] entity = mapToBytes(getEntity().data());
    Response<V> decodedResponse = new MockResponseBuilder<K, V>().setEntity(getEntity()).setStatus(status).setHeaders(getHeaders()).setCookies(getCookies()).setProtocolVersion(getProtocolVersion()).build();
    RestResponse restResponse = new RestResponseBuilder().setEntity(entity).setStatus(status).setHeaders(decodedResponse.getHeaders()).setCookies(CookieUtil.encodeCookies(decodedResponse.getCookies())).build();
    RestLiResponseException restLiResponseException = new RestLiResponseException(restResponse, decodedResponse, new ErrorResponse());
    ExecutionException executionException = new ExecutionException(restLiResponseException);
    Future<Response<V>> responseFuture = buildFuture(null, executionException);
    return new ResponseFutureImpl<>(responseFuture, _errorHandlingBehavior);
}
Also used : RestResponse(com.linkedin.r2.message.rest.RestResponse) RestResponseBuilder(com.linkedin.r2.message.rest.RestResponseBuilder) ErrorResponse(com.linkedin.restli.common.ErrorResponse) RestResponse(com.linkedin.r2.message.rest.RestResponse) Response(com.linkedin.restli.client.Response) ErrorResponse(com.linkedin.restli.common.ErrorResponse) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) ExecutionException(java.util.concurrent.ExecutionException) ResponseFutureImpl(com.linkedin.restli.internal.client.ResponseFutureImpl)

Aggregations

RestResponse (com.linkedin.r2.message.rest.RestResponse)2 Response (com.linkedin.restli.client.Response)2 RestLiResponseException (com.linkedin.restli.client.RestLiResponseException)2 ErrorResponse (com.linkedin.restli.common.ErrorResponse)2 ResponseFutureImpl (com.linkedin.restli.internal.client.ResponseFutureImpl)2 ExecutionException (java.util.concurrent.ExecutionException)2 RestResponseBuilder (com.linkedin.r2.message.rest.RestResponseBuilder)1