use of com.linkedin.restli.internal.server.response.RestLiResponseException in project rest.li by linkedin.
the class TestRestLiServer method testHandleRequestWithRestLiResponseError.
@Test(dataProvider = "restOrStream")
public void testHandleRequestWithRestLiResponseError(final RestOrStream restOrStream) throws Exception {
final StatusCollectionResource statusResource = getMockResource(StatusCollectionResource.class);
EasyMock.expect(statusResource.get(eq(1L))).andReturn(null).once();
replay(statusResource);
Callback<RestLiResponse> restLiResponseCallback = new Callback<RestLiResponse>() {
@Override
public void onSuccess(RestLiResponse restLiResponse) {
fail("We should not get a success here. The server should have returned a 404!");
}
@Override
public void onError(Throwable e) {
RestLiResponseException restLiResponseException = (RestLiResponseException) e;
assertEquals(restLiResponseException.getRestLiResponse().getStatus(), HttpStatus.S_404_NOT_FOUND, "We should get a 404 back here!");
EasyMock.verify(statusResource);
EasyMock.reset(statusResource);
}
};
if (restOrStream == RestOrStream.REST) {
RestRequest request = new RestRequestBuilder(new URI("/statuses/1")).setHeader(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, AllProtocolVersions.BASELINE_PROTOCOL_VERSION.toString()).build();
_server.handleRequestWithRestLiResponse(request, new RequestContext(), restLiResponseCallback);
} else {
StreamRequest streamRequest = new StreamRequestBuilder(new URI("/statuses/1")).setHeader(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, AllProtocolVersions.BASELINE_PROTOCOL_VERSION.toString()).build(EntityStreams.emptyStream());
_server.handleRequestWithRestLiResponse(streamRequest, new RequestContext(), restLiResponseCallback);
}
}
use of com.linkedin.restli.internal.server.response.RestLiResponseException in project rest.li by linkedin.
the class FilterChainCallbackImpl method onError.
@Override
public void onError(Throwable th, final RestLiResponseData<?> responseData) {
markOnResponseTimings(_method.getContext().getRawRequestContext());
// The Throwable passed in is not used at all. However, before every invocation, the throwable is wrapped inside
// the RestLiResponseData parameter. This can potentially be refactored.
Throwable error;
try {
RestLiServiceException serviceException = responseData.getResponseEnvelope().getException();
final RestLiResponse response = _responseHandler.buildPartialResponse(_method, responseData);
error = new RestLiResponseException(serviceException, response);
} catch (Throwable throwable) {
LOGGER.error("Unexpected error when processing error response.", responseData.getResponseEnvelope().getException());
error = throwable;
}
_wrappedCallback.onError(error);
}
use of com.linkedin.restli.internal.server.response.RestLiResponseException in project rest.li by linkedin.
the class BaseRestLiServer method buildPreRoutingError.
protected RestLiResponseException buildPreRoutingError(Throwable throwable, Request request) {
Map<String, String> requestHeaders = request.getHeaders();
Map<String, String> headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
headers.put(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, ProtocolVersionUtil.extractProtocolVersion(requestHeaders).toString());
headers.put(HeaderUtil.getErrorResponseHeaderName(requestHeaders), RestConstants.HEADER_VALUE_ERROR);
RestLiServiceException restLiServiceException = RestLiServiceException.fromThrowable(throwable);
ErrorResponse errorResponse = _errorResponseBuilder.buildErrorResponse(restLiServiceException);
RestLiResponse restLiResponse = new RestLiResponse.Builder().status(restLiServiceException.getStatus()).entity(errorResponse).headers(headers).cookies(Collections.emptyList()).build();
return new RestLiResponseException(throwable, restLiResponse);
}
use of com.linkedin.restli.internal.server.response.RestLiResponseException in project rest.li by linkedin.
the class FilterChainCallbackImpl method onResponseSuccess.
@Override
public void onResponseSuccess(final RestLiResponseData<?> responseData) {
markOnResponseTimings(_method.getContext().getRawRequestContext());
RestLiResponse partialResponse;
try {
partialResponse = _responseHandler.buildPartialResponse(_method, responseData);
} catch (Throwable th) {
LOGGER.error("Unexpected error while building the success response. Converting to error response.", th);
_wrappedCallback.onError(new RestLiResponseException(th, buildErrorResponse(th, responseData)));
return;
}
_wrappedCallback.onSuccess(partialResponse);
}
Aggregations