Package dk.brics.jwig.server

Examples of dk.brics.jwig.server.ThreadContext


    /**
     * Registers the current response object as dependent on the given object.
     */
    public void addResponseDependency(Object p) {
        Object proxy = getObject(p);
        ThreadContext context = ThreadContext.get();
        //The context may be null data is queried from the database by a thread that does not create a page
        if (context == null) {
            return;
        }
        String requestURL = context.getRequestURL();
        CacheObject c = new CacheObject(requestURL);
        XMLProducer producer = context.getProducer();
        if (producer != null) {
            c.setUrl(producer.getHandlerIdentifier());
            c.setHandler(true);
        }
        addDependency(c, proxy);
View Full Code Here


            return true;
        }
    }

    private CacheObject createAugmented(CacheObject o) {
        ThreadContext context = ThreadContext.get();
        if (!o.isHandler() && context.isCacheAugmented()) {
            String url = o.getUrl();
            url = url + "<|>" + WebApp.get().getWebSite().getCacheAugmentationString();
            o = new CacheObject(url);
        }
        return o;
View Full Code Here

        }
    }

    public boolean hasTransaction() {
        if (ThreadContext.isInRequestContext()) {
            ThreadContext threadContext = ThreadContext.get();
            return threadContext.getCurrentCacheTransaction() != null;
        } else {
            return false;
        }
    }
View Full Code Here

     *            HTTP status code
     * @param msg
     *            message document body
     */
    public XML sendError(int status_code, XML msg, boolean standalone) {
        ThreadContext c = ThreadContext.get();
        ThreadContext.getCache().remove(c.getRequestURL());
        HttpServletRequest request = c.getServletRequest();
        HttpServletResponse response = c.getServletResponse();
        if (response.isCommitted()) {
            log.warn("Response already committed, unable to send error message");
            return null;
        }
        Response error = ThreadContext.get().getResponse();
        if (error == null) {
            error = new Response();
            ThreadContext.get().setResponse(error);
        }
        String base = ThreadContext
                .getBaseURL(c.getServletRequest().isSecure());
        Pattern pattern = Pattern.compile("https?://([^:/]*).*");
        Matcher matcher = pattern.matcher(base);
        String host = request.getServerName();
        if (matcher.find()) {
            host = matcher.group(1);
View Full Code Here

     * Returns the <code>WebApp</code> object for the current thread.
     * This method makes it easy get access to the current <code>WebApp</code>
     * object from outside the <code>WebApp</code> subclass.
     */
    public static WebApp get() {
        ThreadContext threadContext = ThreadContext.get();
        return threadContext.getRequestManager().getWebApp();
    }
View Full Code Here

        if (classObjectMap == null) return false;
        return classObjectMap.containsKey(type);
    }

    private Map<Class<?>, Object> getRequestScopeMap() {
        ThreadContext threadContext = ThreadContext.get();
        HttpServletRequest servletRequest = threadContext.getServletRequest();
        Map<WebApp, Map<Class<?>, Object>> responseMap = (Map<WebApp, Map<Class<?>, Object>>) servletRequest.getAttribute(RES);
        if (responseMap == null) {
            responseMap = new HashMap<>();
            servletRequest.setAttribute(RES,responseMap);
        }
View Full Code Here

            for (Object obs : objs) {
                if (obs != null) {
                    ThreadContext.getDependencyMap().addDependency(this, obs);
                }
            }
            ThreadContext c = ThreadContext.get();
            Method m = getClass().getDeclaredMethod("run");
            XMLProducer previous = c.getProducer();
            c.setProducer(this);
            m.setAccessible(true);
            XML xml = (XML) m.invoke(this);
            c.setProducer(previous);
            return xml;
        } catch (NoSuchMethodException e) {
            throw new JWIGException(e);
        } catch (IllegalArgumentException e) {
            throw new JWIGException(e);
View Full Code Here

     * method has return type void, then the next web method in the chain is
     * invoked when the filter web method returns. Also used for producing a
     * temporary response and continuing execution.
     */
    public static void sendResponse() {
        ThreadContext c = ThreadContext.get();
        ThreadContext.getDispatcher().send(c.getResponse());
    }
View Full Code Here

    @TRACE
    @HEAD
    @OPTIONS
    public Object augment() {
        Object o = next();
        ThreadContext c = ThreadContext.get();
        RequestManager manager = c.getRequestManager();
        Response r = getResponse();
        if (o instanceof XML) {
            // log.debug("Augmenting: " + r.getETag());
            XML xml = (XML) o;
            String home = manager.getWebSiteURL(c.getServletRequest()
                    .isSecure());
            xml = xml
                    .prependContent(
                            "//xhtml:head",
                            XML.parseTemplate(
View Full Code Here

     */
    @Priority(MAX_PRIORITY - 1)
    @URLPattern("**")
    public void transportSessionHandlers() {
        next();
        ThreadContext c = ThreadContext.get();
        Set<Session> activeSessions = c.getResponse().getSessions();
        Response response = c.getResponse();
        Collection<AbstractHandler> responseHandlers = response.getHandlers();
        for (Session s : activeSessions) {
            Set<AbstractHandler> sessionHandlers = this.sessionHandlers.get(s);
            if (sessionHandlers == null) {
                sessionHandlers = new HashSet<AbstractHandler>();
                this.sessionHandlers.put(s, sessionHandlers);
            }
            for (AbstractHandler handler : sessionHandlers) {
                c.getResponse().setHandler(handler.getHandlerIdentifier(), handler);
            }
            sessionHandlers.addAll(responseHandlers);
        }
    }
View Full Code Here

TOP

Related Classes of dk.brics.jwig.server.ThreadContext

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.