Package dk.brics.jwig

Examples of dk.brics.jwig.WebSite


            String websiteclass = config.getInitParameter("MainClass");
            if (websiteclass == null) {
                websiteclass = "Main";
            }
            final Object o = Dispatcher.class.getClassLoader().loadClass(websiteclass).newInstance();
            WebSite website;
            if (o instanceof WebApp) {
                website = new WebSite() {
                    @Override
                    public void init() {
                        add((WebApp) o);
                    }
                };
            } else if (o instanceof WebSite) {
                website = (WebSite) o;
            } else {
                throw new ServletException("JWIG main class does not extend dk.brics.jwig.WebSite or dk.brics.jwig.WebApp");
            }

            // set thread context, log4j properties, and Hibernate properties
            ThreadContext.setWebSite(website);
            String base_url = Config.get("jwig.base_url", (String) null);
            String base_url_secure = Config.get("jwig.base_url_secure", (String) null);
            boolean hibernate = Config.get("jwig.hibernate", false);
            Properties properties = new Properties();
            properties.putAll(website.getProperties());
            if (!Logger.getRootLogger().getAllAppenders().hasMoreElements()) {
                PropertyConfigurator.configure(properties);
            }
            log = Logger.getLogger(Dispatcher.class);
            log.info("Initializing {"
                     + "MainClass=" + websiteclass
                     + ", jwig.hibernate=" + hibernate
                     + (base_url != null ? ", jwig.base_url=" + base_url : "")
                     + (base_url_secure != null ? ", jwig.base_url_secure=" + base_url_secure : "")
                     + "}");
            website.getQuerier().preInit(properties);
            website.init();
            if (!Logger.getRootLogger().getAllAppenders().hasMoreElements()) {
                //Make absolutely sure that at least some logging can happen
                BasicConfigurator.configure();
                log.warn("Log4J logging not configured by the application. Initializing Log4J with a default setup.");
            }

            website.getQuerier().postInit();
            List<RequestManager> requestmanagers = new ArrayList<RequestManager>();
            ThreadContext.init(base_url, base_url_secure, website.getCache(), requestmanagers, new SessionManager(config.getServletContext()),
                               new DependencyMap(), config.getServletContext().getRealPath("/"), this);

            // register request manager for each web app
            for (WebApp app : website.getWebApps()) {
                requestmanagers.add(new RequestManager(app));
                addListener(app.getSecurityManager());
            }

            int fileupload_memory_threshold = Config.get("jwig.fileupload_memory_threshold", 100000);
            String fileupload_tmpdir = Config.get("jwig.fileupload_tmpdir", System.getProperty("java.io.tmpdir"));
            long multipart_maxsize = Config.get("jwig.multipart_maxsize", 100000000L);
            long fileupload_maxsize = Config.get("jwig.fileupload_maxsize", -1L);

            File repository = new File(fileupload_tmpdir);
            if (!repository.isAbsolute()) {
                repository = new File(ThreadContext.getServletHome(), fileupload_tmpdir);
            }
            fileupload = new ServletFileUpload(new DiskFileItemFactory(fileupload_memory_threshold, repository));
            fileupload.setSizeMax(multipart_maxsize);
            fileupload.setFileSizeMax(fileupload_maxsize);
            log.debug("Initializing {jwig.fileupload_memory_threshold=" + fileupload_memory_threshold +
                      ", jwig.fileupload_tmpdir=" + fileupload_tmpdir +
                      ", jwig.multipart_maxsize=" + multipart_maxsize +
                      ", jwig.fileupload_maxsize=" + fileupload_maxsize +
                      "}");

            website.postInit();
        } catch (Exception e) {
            if (log != null) {
                log.fatal("Exception in init", e);
            } else {
                e.printStackTrace();
View Full Code Here


                chain.doFilter(req, resp);
                return;
            }

            // handle error codes
            WebSite website = ThreadContext.getWebSite();
            Object sc = request.getAttribute("javax.servlet.error.status_code");
            if (sc != null) {
                int status_code = (Integer) sc;
                String error_url = (String) request.getAttribute("javax.servlet.error.request_uri");
                log.info("Status code " + status_code);
                ThreadContext.set(new ThreadContext(request, response, error_url));
                switch (status_code) { // TODO: need to cover more status codes? (should match web.xml)
                    case HttpServletResponse.SC_NOT_FOUND:
                        website.sendError(status_code, "The requested resource is not found: " + error_url);
                        ThreadContext.get().getResponse().write(request, response);
                        break;
                    case HttpServletResponse.SC_FORBIDDEN:
                        website.sendError(status_code, "Access to the requested resource is forbidden: " + error_url);
                        ThreadContext.get().getResponse().write(request, response);
                        break;
                    default:
                        log.error("Unexpected status code " + status_code);
                }
                return;
            }

            // first phase of parsing the request
            String url = getFullRequestURL(request);
            String method = request.getMethod();
            ThreadContext.set(new ThreadContext(request, response, url));
            log.info(method + " from " + getClient(request) + ": " + url);
            if (!ALLOWED_METHODS.contains(method)) {
                log.info("HTTP method not allowed: " + method);
                website.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "HTTP method " + method + " not allowed.");
                ThreadContext.get().getResponse().write(request, response);
                return;
            }
            //url = URLEncoding.decode(url);
            String path = request.getRequestURI().substring(request.getContextPath().length());
            ThreadContext context = new ThreadContext(request, response, url);
            ThreadContext.set(context);

            //Add all web methods that may answer to the URL provided
            SortedSet<RegisteredMethod> allMethods = new TreeSet<RegisteredMethod>();
            for (RequestManager r : ThreadContext.getRequestManagers()) {
                if (r.matches(path)) {
                    allMethods.addAll(r.getWebMethods());
                }
            }
            context.setMatchedWebMethods(new LinkedList<RegisteredMethod>(allMethods));

            // try all request managers until one takes the request

            if (process(path, url, request, response)) {
                if (!response.isCommitted()) {
                    log.error("No response generated");
                    website.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "No response.");
                    ThreadContext.get().getResponse().write(request, response);
                }
                log.info("Completed");
                return;
            }
View Full Code Here

TOP

Related Classes of dk.brics.jwig.WebSite

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.