Package com.astamuse.asta4d.web

Examples of com.astamuse.asta4d.web.WebApplicationContext


            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.setData(KEY_CURRENT_RULE, rule);
        writePathVarToContext(context, rule.getExtraVarMap());
        retrieveFlashScopeData(request);

        List<ContentProvider<?>> requestResult = handleRequest(rule);
        ContentWriter cw;
View Full Code Here

    public static void addFlashScopeData(Map<String, Object> flashScopeData) {
        if (flashScopeData == null || flashScopeData.isEmpty()) {
            return;
        }
        WebApplicationContext context = Context.getCurrentThreadContext();
        List<Map<String, Object>> dataList = context.getData(FlashScopeDataListKey);
        if (dataList == null) {
            dataList = new LinkedList<>();
            context.setData(FlashScopeDataListKey, dataList);
        }
        dataList.add(flashScopeData);
    }
View Full Code Here

        Map<String, Object> flashScopeData = rd.getFlashScopeData();
        if (url == null) {
            addFlashScopeData(flashScopeData);
        } else {
            Map<String, Object> dataMap = new HashMap<String, Object>();
            WebApplicationContext context = Context.getCurrentThreadContext();
            List<Map<String, Object>> dataList = context.getData(FlashScopeDataListKey);
            if (dataList != null) {
                for (Map<String, Object> map : dataList) {
                    dataMap.putAll(map);
                }
            }
            if (flashScopeData != null) {
                dataMap.putAll(flashScopeData);
            }
            if (url.startsWith("/")) {
                url = context.getRequest().getContextPath() + url;
            }
            url = RedirectUtil.setFlashScopeData(url, dataMap);

            if (url.indexOf('\n') >= 0 || url.indexOf('\r') >= 0) {
                throw new RuntimeException("illegal redirct url:" + url);
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

    }

    @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

    }

    @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.setData(KEY_CURRENT_RULE, rule);
        writePathVarToContext(context, rule.getExtraVarMap());
        restoreFlashScopeData(context, request);

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

            dispatcher.dispatchAndProcess(createRuleList());
        }
    }

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

    public static void addFlashScopeData(Map<String, Object> flashScopeData) {
        if (flashScopeData == null || flashScopeData.isEmpty()) {
            return;
        }
        WebApplicationContext context = Context.getCurrentThreadContext();
        List<Map<String, Object>> dataList = context.getData(FlashScopeDataListKey);
        if (dataList == null) {
            dataList = new LinkedList<>();
            context.setData(FlashScopeDataListKey, dataList);
        }
        dataList.add(flashScopeData);
    }
View Full Code Here

        String url = targetPath;
        if (url == null) {
            addFlashScopeData(flashScopeData);
        } else {
            Map<String, Object> dataMap = new HashMap<String, Object>();
            WebApplicationContext context = Context.getCurrentThreadContext();
            List<Map<String, Object>> dataList = context.getData(FlashScopeDataListKey);
            if (dataList != null) {
                for (Map<String, Object> map : dataList) {
                    dataMap.putAll(map);
                }
            }
            if (flashScopeData != null) {
                dataMap.putAll(flashScopeData);
            }
            if (url.startsWith("/")) {
                url = context.getRequest().getContextPath() + url;
            }
            url = RedirectUtil.setFlashScopeData(url, dataMap);

            if (url.indexOf('\n') >= 0 || url.indexOf('\r') >= 0) {
                throw new RuntimeException("illegal redirct url:" + url);
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.