use of com.linkedin.restli.client.RestLiDecodingException 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.restli.client.RestLiDecodingException in project rest.li by linkedin.
the class TestMultiplexedCallback method testError.
@Test
public void testError() throws Exception {
FutureCallback<RestResponse> callback1 = new FutureCallback<RestResponse>();
FutureCallback<RestResponse> callback2 = new FutureCallback<RestResponse>();
ImmutableMap<Integer, Callback<RestResponse>> individualCallbacks = ImmutableMap.<Integer, Callback<RestResponse>>of(ID1, callback1, ID2, callback2);
FutureCallback<MultiplexedResponse> aggregatedCallback = new FutureCallback<MultiplexedResponse>();
MultiplexedCallback multiplexedCallback = new MultiplexedCallback(individualCallbacks, aggregatedCallback);
RestLiDecodingException exception = new RestLiDecodingException(null, null);
multiplexedCallback.onError(exception);
Assert.assertSame(getError(callback1), exception);
Assert.assertSame(getError(callback2), exception);
Assert.assertSame(getError(aggregatedCallback), exception);
}
use of com.linkedin.restli.client.RestLiDecodingException in project rest.li by linkedin.
the class ExceptionUtil method exceptionForThrowable.
public static RemoteInvocationException exceptionForThrowable(Throwable e, RestResponseDecoder<?> responseDecoder) {
if (e instanceof RestException) {
final RestException re = (RestException) e;
final RestResponse response = re.getResponse();
final ErrorResponse errorResponse;
// decode the response body when HEADER_RESTLI_ERROR_RESPONSE header is set.
try {
errorResponse = getErrorResponse(response);
} catch (RestLiDecodingException decodingException) {
return new RemoteInvocationException(e.getMessage(), decodingException);
}
Response<?> decodedResponse = null;
final String header = HeaderUtil.getErrorResponseHeaderValue(response.getHeaders());
if (header == null) {
// This is purely to handle case #2 commented above.
try {
decodedResponse = responseDecoder.decodeResponse(response);
} catch (RestLiDecodingException decodingException) {
return new RemoteInvocationException(e.getMessage(), e);
}
}
return new RestLiResponseException(response, decodedResponse, errorResponse, e);
}
if (e instanceof RemoteInvocationException) {
return (RemoteInvocationException) e;
}
return new RemoteInvocationException(e);
}
use of com.linkedin.restli.client.RestLiDecodingException in project rest.li by linkedin.
the class ExceptionUtil method wrapThrowable.
static RemoteInvocationException wrapThrowable(Throwable e) {
if (e instanceof RestLiResponseException) {
final RestLiResponseException restliException = (RestLiResponseException) e;
final ErrorResponse errorResponse;
try {
errorResponse = getErrorResponse(restliException.getResponse());
} catch (RestLiDecodingException decodingException) {
return new RemoteInvocationException(decodingException);
}
return new RestLiResponseException(restliException.getResponse(), restliException.getDecodedResponse(), errorResponse, restliException);
}
return new RemoteInvocationException(e);
}
use of com.linkedin.restli.client.RestLiDecodingException in project rest.li by linkedin.
the class RestResponseDecoder method createResponse.
private ResponseImpl<T> createResponse(Map<String, String> headers, int status, ByteString entity, List<String> cookies) throws RestLiDecodingException {
ResponseImpl<T> response = new ResponseImpl<T>(status, headers, CookieUtil.decodeSetCookies(cookies));
try {
DataMap dataMap = (entity.isEmpty()) ? null : DataMapConverter.bytesToDataMap(headers, entity);
response.setEntity(wrapResponse(dataMap, headers, ProtocolVersionUtil.extractProtocolVersion(response.getHeaders())));
return response;
} catch (MimeTypeParseException e) {
throw new RestLiDecodingException("Could not decode REST response", e);
} catch (IOException e) {
throw new RestLiDecodingException("Could not decode REST response", e);
} catch (InstantiationException e) {
throw new IllegalStateException(e);
} catch (IllegalAccessException e) {
throw new IllegalStateException(e);
} catch (InvocationTargetException e) {
throw new IllegalStateException(e);
} catch (NoSuchMethodException e) {
throw new IllegalStateException(e);
}
}
Aggregations