Package com.astamuse.asta4d.web

Examples of com.astamuse.asta4d.web.WebApplicationContext


        if (templateContext == null) {
            templateContext = applicationContext.getBean(WebApplicationContext.class);
            Context.setCurrentThreadContext(templateContext);
        }
        templateContext.init();
        WebApplicationContext webContext = (WebApplicationContext) templateContext;
        webContext.setRequest(request);
        webContext.setResponse(response);
        return true;
    }
View Full Code Here


    public AbstractGenericPathHandler(String basePath) {
        this._basePath = basePath;
    }

    public String convertPath(HttpServletRequest request, UrlMappingRule currentRule) {
        WebApplicationContext context = Context.getCurrentThreadContext();
        String uri = context.getAccessURI();

        String targetPath = genericMapResult.get(uri);
        if (targetPath != null) {
            return targetPath;
        } else {
            String basePath = context.getData(WebApplicationContext.SCOPE_PATHVAR, VAR_BASEPATH);
            if (basePath == null) {
                basePath = _basePath;
            }

            if (basePath == null) {// default from web context root
View Full Code Here

     * @return the time of last modified time in millisecond unit(In http
     *         protocol, the time unit should be second, but we will cope with
     *         this matter)
     */
    protected long getLastModifiedTime(String path) {
        WebApplicationContext context = Context.getCurrentThreadContext();
        Long varLastModified = context.getData(WebApplicationContext.SCOPE_PATHVAR, VAR_LAST_MODIFIED);
        if (varLastModified != null) {
            return varLastModified;
        } else {
            long retrieveTime = BinaryDataUtil.retrieveLastModifiedByPath(context.getServletContext(), this.getClass().getClassLoader(),
                    path);
            if (retrieveTime == 0L) {
                return DefaultLastModified;
            } else {
                return retrieveTime;
View Full Code Here

        return "";
    }

    @Override
    public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
        WebApplicationContext context = Context.getCurrentThreadContext();
        for (Entry<String, ?> entry : model.entrySet()) {
            context.setData(entry.getKey(), entry.getValue());
        }
        templateProvider.produce(dummyRule, response);
    }
View Full Code Here

        return new WebApplicatoinConfigurationInitializer();
    }

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        WebApplicationContext asta4dContext = WebApplicationContext.getCurrentThreadContext();
        if (asta4dContext == null) {
            asta4dContext = new WebApplicationContext();
            Context.setCurrentThreadContext(asta4dContext);
        }
        asta4dContext.init();
        asta4dContext.setRequest(request);
        asta4dContext.setResponse(response);
        asta4dContext.setServletContext(servletContext);
        return true;
    }
View Full Code Here

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Context templateContext = Context.getCurrentThreadContext();
        if (templateContext == null) {
            templateContext = new WebApplicationContext();
            Context.setCurrentThreadContext(templateContext);
        }
        templateContext.init();
        WebApplicationContext webContext = (WebApplicationContext) templateContext;
        webContext.setRequest(request);
        webContext.setResponse(response);
        webContext.setServletContext(servletContext);
        return true;
    }
View Full Code Here

    }

    @Override
    protected final void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        logger.debug("access for:{}", req.getRequestURI());
        WebApplicationContext context = null;
        try {
            context = Context.getCurrentThreadContext();
            if (context == null) {
                context = createAsta4dContext();
                Context.setCurrentThreadContext(context);
            }
            context.init();
            context.setRequest(req);
            context.setResponse(res);
            context.setServletContext(getServletContext());

            service();

        } catch (Exception e) {
            throw new ServletException(e);
        } finally {
            if (context != null) {
                context.clear();
            }
        }
    }
View Full Code Here

            dispatcher.dispatchAndProcess(createRuleList());
        }
    }

    protected WebApplicationContext createAsta4dContext() {
        WebApplicationContext context = new WebApplicationContext();
        return context;
    }
View Full Code Here

    }

    @SuppressWarnings({ "unchecked", "rawtypes" })
    public void dispatchAndProcess(List<UrlMappingRule> ruleList) throws Exception {
        WebApplicationConfiguration conf = WebApplicationConfiguration.getWebApplicationConfiguration();
        WebApplicationContext context = (WebApplicationContext) Context.getCurrentThreadContext();
        HttpServletRequest request = context.getRequest();
        HttpServletResponse response = context.getResponse();

        HttpMethod method = HttpMethod.valueOf(request.getMethod().toUpperCase());
        String uri = context.getAccessURI();
        if (uri == null) {
            uri = URLDecoder.decode(request.getRequestURI(), "UTF-8");
            String contextPath = request.getContextPath();
            uri = uri.substring(contextPath.length());
            context.setAccessURI(uri);
        }

        String queryString = request.getQueryString();

        UrlMappingResult result = conf.getRuleExtractor().findMappedRule(ruleList, method, uri, queryString);

        // if not found result, we do not need return 404, instead of user
        // defining all match rule

        if (result == null) {
            logger.warn("There is no matched rule found, we will simply return a 404. You should define your own matching all rule for this case.");
            response.setStatus(404);
            return;
        }

        if (logger.isDebugEnabled()) {
            logger.debug("apply rule at :" + result.getRule());
        }

        writePathVarToContext(context, result.getPathVarMap());

        UrlMappingRule rule = result.getRule();
        context.setCurrentRule(rule);
        writePathVarToContext(context, rule.getExtraVarMap());
        restoreFlashScopeData(context, request);

        List<ContentProvider> requestResult = handleRequest(rule);
        for (ContentProvider cp : requestResult) {
View Full Code Here

    }

    @Override
    protected final void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        logger.debug("access for:{}", req.getRequestURI());
        WebApplicationContext context = null;
        try {
            context = Context.getCurrentThreadContext();
            if (context == null) {
                context = createAsta4dContext();
                Context.setCurrentThreadContext(context);
            }

            context.setRequest(req);
            context.setResponse(res);
            context.setServletContext(getServletContext());

            service();

        } catch (Exception e) {
            throw new ServletException(e);
        } finally {
            if (context != null) {
                context.clear();
            }
        }
    }
View Full Code Here

TOP

Related Classes of com.astamuse.asta4d.web.WebApplicationContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.