Search in sources :

Example 1 with RequestImpl

use of core.framework.impl.web.request.RequestImpl in project core-ng-project by neowu.

the class HTTPServerHandler method handle.

private void handle(String path, HttpServerExchange exchange) {
    ActionLog actionLog = logManager.begin("=== http transaction begin ===");
    RequestImpl request = new RequestImpl(exchange, requestBeanMapper);
    try {
        // initialize webContext at beginning, the customerErrorHandler in errorHandler may use it if any exception
        webContext.initialize(request);
        requestParser.parse(request, exchange, actionLog);
        request.session = sessionManager.load(request);
        HeaderMap headers = exchange.getRequestHeaders();
        String client = headers.getFirst(HTTPServerHandler.HEADER_CLIENT);
        if (client != null)
            actionLog.context("client", client);
        actionLog.refId(headers.getFirst(HTTPServerHandler.HEADER_REF_ID));
        ControllerHolder controller = route.get(path, request.method(), request.pathParams, actionLog);
        actionLog.action(controller.action);
        actionLog.context("controller", controller.controllerInfo);
        logger.debug("controllerClass={}", controller.controller.getClass().getCanonicalName());
        // trigger trace after action is determined due to trace log use action as part of path, is there better way?
        if ("true".equals(headers.getFirst(HEADER_TRACE))) {
            actionLog.trace = true;
        }
        Response response = new InvocationImpl(controller, interceptors, request, webContext).proceed();
        sessionManager.save(request, response);
        responseHandler.render((ResponseImpl) response, exchange, actionLog);
    } catch (Throwable e) {
        logManager.logError(e);
        errorHandler.handleError(e, exchange, request, actionLog);
    } finally {
        webContext.cleanup();
        logManager.end("=== http transaction end ===");
    }
}
Also used : Response(core.framework.web.Response) HeaderMap(io.undertow.util.HeaderMap) HttpString(io.undertow.util.HttpString) ActionLog(core.framework.impl.log.ActionLog) RequestImpl(core.framework.impl.web.request.RequestImpl)

Aggregations

ActionLog (core.framework.impl.log.ActionLog)1 RequestImpl (core.framework.impl.web.request.RequestImpl)1 Response (core.framework.web.Response)1 HeaderMap (io.undertow.util.HeaderMap)1 HttpString (io.undertow.util.HttpString)1