Search in sources :

Example 1 with RestLiFilterResponseContextFactory

use of com.linkedin.restli.internal.server.filter.RestLiFilterResponseContextFactory in project rest.li by linkedin.

the class RestLiServer method respondWithPreRoutingError.

private void respondWithPreRoutingError(Throwable th, RestRequest request, RestLiAttachmentReader attachmentReader, RequestExecutionCallback<RestResponse> callback) {
    RestLiFilterResponseContextFactory<Object> filterResponseContextFactory = new RestLiFilterResponseContextFactory<Object>(request, null, _responseHandler);
    RestLiResponseData responseData = filterResponseContextFactory.fromThrowable(th).getResponseData();
    RestException restException = _responseHandler.buildRestException(th, _responseHandler.buildPartialResponse(null, responseData));
    callback.onError(restException, createEmptyExecutionReport(), attachmentReader, null);
}
Also used : RestLiFilterResponseContextFactory(com.linkedin.restli.internal.server.filter.RestLiFilterResponseContextFactory) RestException(com.linkedin.r2.message.rest.RestException)

Example 2 with RestLiFilterResponseContextFactory

use of com.linkedin.restli.internal.server.filter.RestLiFilterResponseContextFactory in project rest.li by linkedin.

the class RestLiServer method handleResourceRequest.

private void handleResourceRequest(final RestRequest request, final RequestContext requestContext, final RequestExecutionCallback<RestResponse> callback, final RestLiAttachmentReader attachmentReader, final boolean isDebugMode) {
    try {
        ensureRequestUsesValidRestliProtocol(request);
    } catch (RestLiServiceException e) {
        respondWithPreRoutingError(e, request, attachmentReader, callback);
        return;
    }
    final RoutingResult method;
    try {
        method = _router.process(request, requestContext, attachmentReader);
    } catch (Exception e) {
        respondWithPreRoutingError(e, request, attachmentReader, callback);
        return;
    }
    final RequestExecutionCallback<RestResponse> wrappedCallback = notifyInvokeAwares(method, callback);
    RequestExecutionReportBuilder requestExecutionReportBuilder = null;
    if (isDebugMode) {
        requestExecutionReportBuilder = new RequestExecutionReportBuilder();
    }
    final FilterRequestContextInternal filterContext = new FilterRequestContextInternalImpl((ServerResourceContext) method.getContext(), method.getResourceMethod());
    RestLiArgumentBuilder adapter;
    try {
        RestUtils.validateRequestHeadersAndUpdateResourceContext(request.getHeaders(), (ServerResourceContext) method.getContext());
        adapter = buildRestLiArgumentBuilder(method, _errorResponseBuilder);
        filterContext.setRequestData(adapter.extractRequestData(method, request));
    } catch (Exception e) {
        // would not trigger response filters because request filters haven't run yet
        wrappedCallback.onError(e, requestExecutionReportBuilder == null ? null : requestExecutionReportBuilder.build(), ((ServerResourceContext) method.getContext()).getRequestAttachmentReader(), null);
        return;
    }
    RestLiFilterResponseContextFactory<Object> filterResponseContextFactory = new RestLiFilterResponseContextFactory<Object>(request, method, _responseHandler);
    FilterChainCallback filterChainCallback = new FilterChainCallbackImpl(method, _methodInvoker, adapter, requestExecutionReportBuilder, attachmentReader, _responseHandler, wrappedCallback);
    RestLiFilterChain filterChain = new RestLiFilterChain(_filters, filterChainCallback);
    filterChain.onRequest(filterContext, filterResponseContextFactory);
}
Also used : FilterRequestContextInternalImpl(com.linkedin.restli.internal.server.filter.FilterRequestContextInternalImpl) RestResponse(com.linkedin.r2.message.rest.RestResponse) RestLiArgumentBuilder(com.linkedin.restli.internal.server.methods.arguments.RestLiArgumentBuilder) MultiPartIllegalFormatException(com.linkedin.multipart.exceptions.MultiPartIllegalFormatException) ParseException(javax.mail.internet.ParseException) RestException(com.linkedin.r2.message.rest.RestException) RestLiAttachmentReaderException(com.linkedin.restli.common.attachments.RestLiAttachmentReaderException) RestLiFilterChain(com.linkedin.restli.internal.server.filter.RestLiFilterChain) RoutingResult(com.linkedin.restli.internal.server.RoutingResult) FilterChainCallback(com.linkedin.restli.internal.server.filter.FilterChainCallback) RestLiFilterResponseContextFactory(com.linkedin.restli.internal.server.filter.RestLiFilterResponseContextFactory) FilterRequestContextInternal(com.linkedin.restli.internal.server.filter.FilterRequestContextInternal) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) FilterChainCallbackImpl(com.linkedin.restli.internal.server.filter.FilterChainCallbackImpl)

Aggregations

RestException (com.linkedin.r2.message.rest.RestException)2 RestLiFilterResponseContextFactory (com.linkedin.restli.internal.server.filter.RestLiFilterResponseContextFactory)2 MultiPartIllegalFormatException (com.linkedin.multipart.exceptions.MultiPartIllegalFormatException)1 RestResponse (com.linkedin.r2.message.rest.RestResponse)1 RestLiAttachmentReaderException (com.linkedin.restli.common.attachments.RestLiAttachmentReaderException)1 RoutingResult (com.linkedin.restli.internal.server.RoutingResult)1 ServerResourceContext (com.linkedin.restli.internal.server.ServerResourceContext)1 FilterChainCallback (com.linkedin.restli.internal.server.filter.FilterChainCallback)1 FilterChainCallbackImpl (com.linkedin.restli.internal.server.filter.FilterChainCallbackImpl)1 FilterRequestContextInternal (com.linkedin.restli.internal.server.filter.FilterRequestContextInternal)1 FilterRequestContextInternalImpl (com.linkedin.restli.internal.server.filter.FilterRequestContextInternalImpl)1 RestLiFilterChain (com.linkedin.restli.internal.server.filter.RestLiFilterChain)1 RestLiArgumentBuilder (com.linkedin.restli.internal.server.methods.arguments.RestLiArgumentBuilder)1 ParseException (javax.mail.internet.ParseException)1