use of com.linkedin.restli.internal.server.methods.arguments.RestLiArgumentBuilder in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testAction_BadArrayElements.
@Test
public void testAction_BadArrayElements() throws Exception {
ResourceModel accountsResourceModel = buildResourceModel(TwitterAccountsResource.class);
ResourceMethodDescriptor methodDescriptor;
// #1 no defaults provided
methodDescriptor = accountsResourceModel.findActionMethod("spamTweets", ResourceLevel.COLLECTION);
String jsonEntityBody = RestLiTestHelper.doubleQuote("{'statuses':[1,2,3]}");
RestRequest request = new RestRequestBuilder(new URI("/accounts?action=spamTweets")).setMethod("POST").setEntity(jsonEntityBody.getBytes(Data.UTF_8_CHARSET)).setHeader(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, version.toString()).build();
RoutingResult routingResult = new RoutingResult(new ResourceContextImpl(null, request, new RequestContext()), methodDescriptor);
final FilterRequestContextInternal filterContext = new FilterRequestContextInternalImpl((ServerResourceContext) routingResult.getContext(), routingResult.getResourceMethod());
RestLiArgumentBuilder adapter = _methodAdapterRegistry.getArgumentBuilder(methodDescriptor.getType());
try {
RestUtils.validateRequestHeadersAndUpdateResourceContext(request.getHeaders(), (ServerResourceContext) routingResult.getContext());
filterContext.setRequestData(adapter.extractRequestData(routingResult, request));
_invoker.invoke(filterContext.getRequestData(), routingResult, _methodAdapterRegistry.getArgumentBuilder(methodDescriptor.getMethodType()), null, null);
Assert.fail("expected routing exception");
} catch (RoutingException e) {
Assert.assertEquals(e.getStatus(), 400);
}
}
use of com.linkedin.restli.internal.server.methods.arguments.RestLiArgumentBuilder in project rest.li by linkedin.
the class RestLiServerUtils method buildRestLiArgumentBuilder.
/**
* Builds a RestLiArgument builder
*
* @param method
* {@link RoutingResult}
* @param errorResponseBuilder
* {@link ErrorResponseBuilder}
* @return
*/
public static RestLiArgumentBuilder buildRestLiArgumentBuilder(RoutingResult method, ErrorResponseBuilder errorResponseBuilder) {
ResourceMethodDescriptor resourceMethodDescriptor = method.getResourceMethod();
RestLiArgumentBuilder adapter = new MethodAdapterRegistry(errorResponseBuilder).getArgumentBuilder(resourceMethodDescriptor.getType());
if (adapter == null) {
throw new IllegalArgumentException("Unsupported method type: " + resourceMethodDescriptor.getType());
}
return adapter;
}
use of com.linkedin.restli.internal.server.methods.arguments.RestLiArgumentBuilder 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