use of io.crnk.core.engine.internal.dispatcher.controller.BaseController in project crnk-framework by crnk-project.
the class HttpRequestProcessorImpl method dispatchRequest.
/**
* Dispatch the request from a client
*
* @param path built represents the URI sent in the request
* @param method type of the request e.g. POST, GET, PATCH
* @param parameterProvider repository method legacy provider
* @param requestBody deserialized body of the client request
* @return the response form the Crnk
*/
@Override
public Response dispatchRequest(String path, String method, Map<String, Set<String>> parameters, RepositoryMethodParameterProvider parameterProvider, Document requestBody) {
JsonPath jsonPath = new PathBuilder(moduleRegistry.getResourceRegistry()).build(path);
try {
BaseController controller = controllerRegistry.getController(jsonPath, method);
ResourceInformation resourceInformation = getRequestedResource(jsonPath);
QueryAdapter queryAdapter = queryAdapterBuilder.build(resourceInformation, parameters);
DefaultFilterRequestContext context = new DefaultFilterRequestContext(jsonPath, queryAdapter, parameterProvider, requestBody, method);
DefaultFilterChain chain = new DefaultFilterChain(controller);
return chain.doFilter(context);
} catch (Exception e) {
Optional<JsonApiExceptionMapper> exceptionMapper = exceptionMapperRegistry.findMapperFor(e.getClass());
if (exceptionMapper.isPresent()) {
// noinspection unchecked
logger.debug("dispatching exception to mapper", e);
return exceptionMapper.get().toErrorResponse(e).toResponse();
} else {
logger.error("failed to process request", e);
throw e;
}
}
}
Aggregations