use of com.linkedin.restli.internal.server.util.RestLiSyntaxException in project rest.li by linkedin.
the class TestRestLiMethodInvocation method checkAsyncInvocation.
@SuppressWarnings({ "unchecked", "rawtypes" })
private void checkAsyncInvocation(BaseResource resource, RestLiCallback callback, ResourceMethodDescriptor methodDescriptor, String httpMethod, ProtocolVersion version, String uri, String entityBody, MutablePathKeys pathkeys, boolean isDebugMode) throws URISyntaxException {
try {
RestRequestBuilder builder = new RestRequestBuilder(new URI(uri)).setMethod(httpMethod).addHeaderValue("Accept", "application/x-pson").setHeader(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, version.toString());
if (entityBody != null) {
builder.setEntity(entityBody.getBytes(Data.UTF_8_CHARSET));
}
RestRequest request = builder.build();
RoutingResult routingResult = new RoutingResult(new ResourceContextImpl(pathkeys, request, new RequestContext()), methodDescriptor);
RequestExecutionReportBuilder requestExecutionReportBuilder = null;
if (isDebugMode) {
requestExecutionReportBuilder = new RequestExecutionReportBuilder();
}
RestLiArgumentBuilder adapter = _methodAdapterRegistry.getArgumentBuilder(methodDescriptor.getType());
RestLiRequestData requestData = adapter.extractRequestData(routingResult, request);
RestUtils.validateRequestHeadersAndUpdateResourceContext(request.getHeaders(), (ServerResourceContext) routingResult.getContext());
_invoker.invoke(requestData, routingResult, adapter, callback, requestExecutionReportBuilder);
EasyMock.verify(resource);
EasyMock.verify(callback);
Assert.assertEquals(((ServerResourceContext) routingResult.getContext()).getResponseMimeType(), "application/x-pson");
} catch (RestLiSyntaxException e) {
throw new RoutingException("syntax exception", 400);
} finally {
EasyMock.reset(callback, resource);
callback.onSuccess(EasyMock.anyObject(), isDebugMode ? EasyMock.isA(RequestExecutionReport.class) : EasyMock.<RequestExecutionReport>isNull(), EasyMock.anyObject(RestLiResponseAttachments.class));
EasyMock.expectLastCall().once();
EasyMock.replay(callback);
}
}
Aggregations