use of com.linkedin.r2.message.Response in project rest.li by linkedin.
the class RestClient method sendStreamRequestImpl.
/**
* Sends an untyped stream request using a callback.
*
* @param requestContext context for the request
* @param uri for resource
* @param method to perform
* @param dataMap request body entity
* @param headers additional headers to be added to the request
* @param cookies the cookies to be sent with the request
* @param methodName the method name (used for finders and actions)
* @param protocolVersion the version of the Rest.li protocol used to build this request
* @param requestOptions contains compression force on/off overrides, request content type and accept types
* @param callback to call on request completion. In the event of an error, the callback
* will receive a {@link com.linkedin.r2.RemoteInvocationException}. If a valid
* error response was received from the remote server, the callback will receive
* a {@link com.linkedin.r2.message.rest.RestException} containing the error details.
*/
private void sendStreamRequestImpl(RequestContext requestContext, URI uri, ResourceMethod method, DataMap dataMap, Map<String, String> headers, List<String> cookies, String methodName, ProtocolVersion protocolVersion, RestliRequestOptions requestOptions, List<Object> streamingAttachments, Callback<StreamResponse> callback) {
try {
final StreamRequest request = buildStreamRequest(uri, method, dataMap, headers, cookies, protocolVersion, requestOptions.getContentType(), requestOptions.getAcceptTypes(), requestOptions.getAcceptResponseAttachments(), streamingAttachments);
String operation = OperationNameGenerator.generate(method, methodName);
requestContext.putLocalAttr(R2Constants.OPERATION, operation);
requestContext.putLocalAttr(R2Constants.REQUEST_COMPRESSION_OVERRIDE, requestOptions.getRequestCompressionOverride());
requestContext.putLocalAttr(R2Constants.RESPONSE_COMPRESSION_OVERRIDE, requestOptions.getResponseCompressionOverride());
_client.streamRequest(request, requestContext, callback);
} catch (Exception e) {
// No need to wrap the exception; RestLiCallbackAdapter.onError() will take care of that
callback.onError(e);
}
}
use of com.linkedin.r2.message.Response in project rest.li by linkedin.
the class RestClient method sendRestRequestImpl.
/**
* Sends an untyped REST request using a callback.
*
* @param requestContext context for the request
* @param uri for resource
* @param method to perform
* @param dataMap request body entity
* @param headers additional headers to be added to the request
* @param cookies the cookies to be sent with the request
* @param methodName the method name (used for finders and actions)
* @param protocolVersion the version of the Rest.li protocol used to build this request
* @param requestOptions contains compression force on/off overrides, request content type and accept types
* @param callback to call on request completion. In the event of an error, the callback
* will receive a {@link com.linkedin.r2.RemoteInvocationException}. If a valid
* error response was received from the remote server, the callback will receive
* a {@link com.linkedin.r2.message.rest.RestException} containing the error details.
*/
private void sendRestRequestImpl(RequestContext requestContext, URI uri, ResourceMethod method, DataMap dataMap, Map<String, String> headers, List<String> cookies, String methodName, ProtocolVersion protocolVersion, RestliRequestOptions requestOptions, Callback<RestResponse> callback) {
try {
RestRequest request = buildRestRequest(uri, method, dataMap, headers, cookies, protocolVersion, requestOptions.getContentType(), requestOptions.getAcceptTypes(), false);
String operation = OperationNameGenerator.generate(method, methodName);
requestContext.putLocalAttr(R2Constants.OPERATION, operation);
requestContext.putLocalAttr(R2Constants.REQUEST_COMPRESSION_OVERRIDE, requestOptions.getRequestCompressionOverride());
requestContext.putLocalAttr(R2Constants.RESPONSE_COMPRESSION_OVERRIDE, requestOptions.getResponseCompressionOverride());
_client.restRequest(request, requestContext, callback);
} catch (Exception e) {
// No need to wrap the exception; RestLiCallbackAdapter.onError() will take care of that
callback.onError(e);
}
}
use of com.linkedin.r2.message.Response in project rest.li by linkedin.
the class MultiplexedCallback method buildIndividualRestResponse.
private static RestResponse buildIndividualRestResponse(Response<?> envelopeResponse, IndividualResponse individualResponse) throws IOException, MimeTypeParseException {
IndividualBody body = individualResponse.getBody(GetMode.NULL);
ByteString entity = (body != null) ? DataMapConverter.dataMapToByteString(individualResponse.getHeaders(), body.data()) : ByteString.empty();
return new RestResponseBuilder().setStatus(individualResponse.getStatus()).setHeaders(inheritHeaders(individualResponse, envelopeResponse)).setCookies(CookieUtil.encodeSetCookies(envelopeResponse.getCookies())).setEntity(entity).build();
}
use of com.linkedin.r2.message.Response in project rest.li by linkedin.
the class MultiplexedCallback method notifyIndividualCallbacks.
private void notifyIndividualCallbacks(Response<MultiplexedResponseContent> muxResponse) {
IndividualResponseMap individualResponses = muxResponse.getEntity().getResponses();
for (IndividualResponseMap.Entry<String, IndividualResponse> individualResponseMapEntry : individualResponses.entrySet()) {
Integer id = Integer.valueOf(individualResponseMapEntry.getKey());
IndividualResponse individualResponse = individualResponseMapEntry.getValue();
Callback<RestResponse> callback = _callbacks.get(id);
RestResponse individualRestResponse;
try {
individualRestResponse = buildIndividualRestResponse(muxResponse, individualResponse);
} catch (MimeTypeParseException e) {
callback.onError(new RestLiDecodingException("Could not convert IndividualResponse to individual RestRestponse due to an invalid content type, id=" + id, e));
return;
} catch (IOException e) {
callback.onError(new RestLiDecodingException("Could not convert IndividualResponse to individual RestRestponse, id=" + id, e));
return;
}
if (RestStatus.isOK(individualResponse.getStatus())) {
callback.onSuccess(individualRestResponse);
} else {
RestException exception = new RestException(individualRestResponse, "Received error " + individualRestResponse.getStatus());
callback.onError(exception);
}
}
}
use of com.linkedin.r2.message.Response in project rest.li by linkedin.
the class FilterUtil method fireStreamRequestResponse.
// Fires a request, saving the local attributes, and then fires a response with the local
// attributes.
public static void fireStreamRequestResponse(FilterChain fc, StreamRequest req, StreamResponse res) {
final RequestContext context = new RequestContext();
wrapFilterChain(fc).onStreamRequest(req, context, emptyWireAttrs());
wrapFilterChain(fc).onStreamResponse(res, context, emptyWireAttrs());
}
Aggregations