/**
   * Invokes the method with the specified callback and arguments built from the request.
   *
   * @param invocableMethod {@link RoutingResult}
   * @param request {@link RestRequest}
   * @param callback {@link RestLiCallback}
   * @param isDebugMode whether the invocation will be done as part of a debug request.
   * @param filterContext {@link FilterRequestContextInternal}
   */
  public void invoke(
      final RoutingResult invocableMethod,
      final RestRequest request,
      final RequestExecutionCallback<Object> callback,
      final boolean isDebugMode,
      final FilterRequestContextInternal filterContext) {
    RequestExecutionReportBuilder requestExecutionReportBuilder = null;

    if (isDebugMode) {
      requestExecutionReportBuilder = new RequestExecutionReportBuilder();
    }

    // Fast fail if the request headers are invalid.
    try {
      RestUtils.validateRequestHeadersAndUpdateResourceContext(
          request.getHeaders(), (ServerResourceContext) invocableMethod.getContext());
    } catch (RestLiServiceException e) {
      callback.onError(e, getRequestExecutionReport(requestExecutionReportBuilder));
      return;
    }
    // Request headers are valid. Proceed with the invocation of the filters and eventually the
    // resource.
    ResourceMethodDescriptor resourceMethodDescriptor = invocableMethod.getResourceMethod();

    RestLiArgumentBuilder adapter =
        _methodAdapterRegistry.getArgumentBuilder(resourceMethodDescriptor.getType());
    if (adapter == null) {
      throw new IllegalArgumentException(
          "Unsupported method type: " + resourceMethodDescriptor.getType());
    }
    RestLiRequestData requestData = adapter.extractRequestData(invocableMethod, request);
    filterContext.setRequestData(requestData);
    // Kick off the request filter iterator, which finally would invoke the resource.
    RestLiRequestFilterChainCallback restLiRequestFilterChainCallback =
        new RestLiRequestFilterChainCallbackImpl(
            invocableMethod, adapter, callback, requestExecutionReportBuilder);
    new RestLiRequestFilterChain(_requestFilters, restLiRequestFilterChainCallback)
        .onRequest(filterContext);
  }
 @Override
 public void onSuccess(RestLiRequestData requestData) {
   try {
     ResourceMethodDescriptor resourceMethodDescriptor = _invocableMethod.getResourceMethod();
     Object resource =
         _resourceFactory.create(resourceMethodDescriptor.getResourceModel().getResourceClass());
     if (BaseResource.class.isAssignableFrom(resource.getClass())) {
       ((BaseResource) resource).setContext(_invocableMethod.getContext());
     }
     Object[] args = _restLiArgumentBuilder.buildArguments(requestData, _invocableMethod);
     // Now invoke the resource implementation.
     doInvoke(
         resourceMethodDescriptor, _callback, _requestExecutionReportBuilder, resource, args);
   } catch (Exception e) {
     _callback.onError(
         e,
         _requestExecutionReportBuilder == null ? null : _requestExecutionReportBuilder.build());
   }
 }