use of com.linkedin.r2.message.rest.RestResponseBuilder in project rest.li by linkedin.
the class TestRestLiServer method handleRequestWithCustomResponse.
private void handleRequestWithCustomResponse(final RequestExecutionCallback<RestResponse> callback, final String response) {
RestResponseBuilder responseBuilder = new RestResponseBuilder();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
IOUtils.write(response, outputStream);
} catch (IOException exc) {
//Test will fail later.
}
responseBuilder.setEntity(outputStream.toByteArray());
callback.onSuccess(responseBuilder.build(), null, null);
}
use of com.linkedin.r2.message.rest.RestResponseBuilder in project rest.li by linkedin.
the class ParseqTraceDebugRequestHandler method sendByteArrayAsResponse.
private void sendByteArrayAsResponse(final RequestExecutionCallback<RestResponse> callback, final byte[] responseBytes, final String mediaType) {
RestResponse staticContentResponse = new RestResponseBuilder().setStatus(HttpStatus.S_200_OK.getCode()).setHeader(RestConstants.HEADER_CONTENT_TYPE, mediaType).setEntity(responseBytes).build();
callback.onSuccess(staticContentResponse, null, null);
}
use of com.linkedin.r2.message.rest.RestResponseBuilder in project rest.li by linkedin.
the class MockClient method streamRequest.
@Override
public void streamRequest(StreamRequest request, RequestContext requestContext, Callback<StreamResponse> callback) {
TransportCallback<StreamResponse> adapter = HttpBridge.streamToHttpCallback(new TransportCallbackAdapter<>(callback), request);
RestResponse response = new RestResponseBuilder().setStatus(status()).setHeaders(headers()).setEntity(body()).build();
adapter.onResponse(TransportResponseImpl.success(Messages.toStreamResponse(response)));
}
use of com.linkedin.r2.message.rest.RestResponseBuilder 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);
}
use of com.linkedin.r2.message.rest.RestResponseBuilder in project rest.li by linkedin.
the class RestEchoServer method handleRequest.
public void handleRequest(RestRequest request, RequestContext requestContext, Callback<RestResponse> callback) {
final String msg;
try {
msg = IOUtil.toString(request.getEntity().asInputStream(), CHARSET.name());
} catch (IOException ex) {
callback.onError(ex);
return;
}
_echoService.echo(msg, new CallbackAdapter<RestResponse, String>(callback) {
@Override
protected RestResponse convertResponse(String responseMsg) {
return new RestResponseBuilder().setEntity(ByteString.copyString(responseMsg, CHARSET)).setHeader("Content-Type", "text/plain").build();
}
});
}
Aggregations