Search in sources :

Example 6 with RestLiSyntaxException

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);
    }
}
Also used : RoutingException(com.linkedin.restli.server.RoutingException) RequestExecutionReportBuilder(com.linkedin.restli.server.RequestExecutionReportBuilder) RestLiSyntaxException(com.linkedin.restli.internal.server.util.RestLiSyntaxException) RestLiArgumentBuilder(com.linkedin.restli.internal.server.methods.arguments.RestLiArgumentBuilder) URI(java.net.URI) RequestExecutionReport(com.linkedin.restli.server.RequestExecutionReport) RoutingResult(com.linkedin.restli.internal.server.RoutingResult) RestRequest(com.linkedin.r2.message.rest.RestRequest) RestRequestBuilder(com.linkedin.r2.message.rest.RestRequestBuilder) FilterRequestContext(com.linkedin.restli.server.filter.FilterRequestContext) RequestContext(com.linkedin.r2.message.RequestContext) ResourceContextImpl(com.linkedin.restli.internal.server.ResourceContextImpl) RestLiResponseAttachments(com.linkedin.restli.server.RestLiResponseAttachments) RestLiRequestData(com.linkedin.restli.server.RestLiRequestData)

Aggregations

RestLiSyntaxException (com.linkedin.restli.internal.server.util.RestLiSyntaxException)6 RoutingException (com.linkedin.restli.server.RoutingException)5 RequestExecutionReport (com.linkedin.restli.server.RequestExecutionReport)4 RestLiResponseAttachments (com.linkedin.restli.server.RestLiResponseAttachments)4 RequestContext (com.linkedin.r2.message.RequestContext)3 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)3 RestResponse (com.linkedin.r2.message.rest.RestResponse)3 RestLiAttachmentReader (com.linkedin.restli.common.attachments.RestLiAttachmentReader)3 RestLiCallback (com.linkedin.restli.internal.server.RestLiCallback)3 ServerResourceContext (com.linkedin.restli.internal.server.ServerResourceContext)3 FilterChainCallback (com.linkedin.restli.internal.server.filter.FilterChainCallback)3 RestLiArgumentBuilder (com.linkedin.restli.internal.server.methods.arguments.RestLiArgumentBuilder)3 ResourceModel (com.linkedin.restli.internal.server.model.ResourceModel)3 RequestExecutionCallback (com.linkedin.restli.server.RequestExecutionCallback)3 RequestExecutionReportBuilder (com.linkedin.restli.server.RequestExecutionReportBuilder)3 FilterRequestContext (com.linkedin.restli.server.filter.FilterRequestContext)3 EasyMock.anyObject (org.easymock.EasyMock.anyObject)3 Callback (com.linkedin.common.callback.Callback)2 ByteString (com.linkedin.data.ByteString)2 RestException (com.linkedin.r2.message.rest.RestException)2