Package org.grails.web.servlet.mvc

Examples of org.grails.web.servlet.mvc.GrailsWebRequest$DefaultEncodingStateRegistryLookup


            return;
        }

        RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
        boolean restoreOriginalRequestAttributes = false;
        final GrailsWebRequest webRequest;
        if (requestAttributes instanceof GrailsWebRequest) {
            webRequest = (GrailsWebRequest) requestAttributes;
            urlMappingInfo.configure(webRequest);
        }
        else {
            restoreOriginalRequestAttributes = true;
            webRequest = new GrailsWebRequest(request, response, getServletContext());
            RequestContextHolder.setRequestAttributes(webRequest);
            urlMappingInfo.configure(webRequest);
        }

        // don't reuse cached controller attribute
        webRequest.removeAttribute(GrailsApplicationAttributes.GRAILS_CONTROLLER_CLASS_AVAILABLE, WebRequest.SCOPE_REQUEST);
       
        HttpServletResponse originalResponse = WrappedResponseHolder.getWrappedResponse();

        try {
            WrappedResponseHolder.setWrappedResponse(response);
View Full Code Here


        return ConverterUtil.invokeOriginalAsTypeMethod(instance, clazz);
    }

    public ApplicationContext getApplicationContext() {
        if (applicationContext == null) {
            GrailsWebRequest webRequest = GrailsWebRequest.lookup();
            if (webRequest != null) {
                applicationContext = webRequest.getApplicationContext();
            }
        }
        return applicationContext;
    }
View Full Code Here

    }

    private static GrailsDomainClass getDomainClass(Object instance) {
        GrailsDomainClass domainClass = GrailsMetaClassUtils.getPropertyIfExists(instance, GrailsDomainClassProperty.DOMAIN_CLASS, GrailsDomainClass.class);
        if (domainClass == null) {
            GrailsWebRequest webRequest = GrailsWebRequest.lookup();
            if (webRequest != null) {
                ApplicationContext applicationContext = webRequest.getApplicationContext();
                if(applicationContext != null) {
                    GrailsApplication grailsApplication = applicationContext.containsBean(GrailsApplication.APPLICATION_ID) ?
                        applicationContext.getBean(GrailsApplication.APPLICATION_ID, GrailsApplication.class) : null;
                    if (grailsApplication != null) {
                        domainClass = (GrailsDomainClass) grailsApplication.getArtefact(DomainClassArtefactHandler.TYPE, instance.getClass().getName());
View Full Code Here

        if (argMap.isEmpty()) {
            throw new MissingMethodException("redirect",target.getClass(),new Object[]{ argMap });
        }

        GrailsWebRequest webRequest = (GrailsWebRequest)RequestContextHolder.currentRequestAttributes();

        if(target instanceof GroovyObject) {
            GroovyObject controller = (GroovyObject)target;

            // if there are errors add it to the list of errors
            Errors controllerErrors = (Errors)controller.getProperty(ControllerDynamicMethods.ERRORS_PROPERTY);
            Errors errors = (Errors)argMap.get(ControllerDynamicMethods.ERRORS_PROPERTY);
            if (controllerErrors != null && errors != null) {
                controllerErrors.addAllErrors(errors);
            }
            else {
                controller.setProperty(ControllerDynamicMethods.ERRORS_PROPERTY, errors);
            }
            Object action = argMap.get(GrailsControllerClass.ACTION);
            if (action != null) {
                argMap.put(GrailsControllerClass.ACTION, establishActionName(action,controller));
            }
            if (!argMap.containsKey(GrailsControllerClass.NAMESPACE_PROPERTY)) {
                // this could be made more efficient if we had a reference to the GrailsControllerClass object, which
                // has the namespace property accessible without needing reflection
                argMap.put(GrailsControllerClass.NAMESPACE_PROPERTY, GrailsClassUtils.getStaticFieldValue(controller.getClass(), GrailsControllerClass.NAMESPACE_PROPERTY));
            }
        }

        ResponseRedirector redirector = new ResponseRedirector(getLinkGenerator(webRequest));
        redirector.setRedirectListeners(redirectListeners);
        redirector.setRequestDataValueProcessor(initRequestDataValueProcessor());
        redirector.setUseJessionId(useJessionId);
        redirector.redirect(webRequest.getRequest(), webRequest.getResponse(), argMap);
        return null;
    }
View Full Code Here

    /**
     * getter to obtain RequestDataValueProcessor from
     */
    private RequestDataValueProcessor initRequestDataValueProcessor() {
        GrailsWebRequest webRequest = (GrailsWebRequest)RequestContextHolder.currentRequestAttributes();
        ApplicationContext applicationContext = webRequest.getApplicationContext();
        if (requestDataValueProcessor == null && applicationContext.containsBean("requestDataValueProcessor")) {
            requestDataValueProcessor = applicationContext.getBean("requestDataValueProcessor", RequestDataValueProcessor.class);
        }
        return requestDataValueProcessor;
    }
View Full Code Here

     * @param response The HttpServletResponse
     * @return The created java.io.Writer
     */
    protected GSPResponseWriter createResponseWriter(HttpServletResponse response) {
        GSPResponseWriter out = GSPResponseWriter.getInstance(response);
        GrailsWebRequest webRequest =  (GrailsWebRequest) RequestContextHolder.currentRequestAttributes();
        webRequest.setOut(out);
        return out;
    }
View Full Code Here

    @Test
    public void testCodecAndNoCodecGRAILS8405() throws IOException {
        FastStringWriter target = new FastStringWriter();

        GrailsWebRequest webRequest = bindMockHttpRequest();

        // Initialize out and codecOut as it is done in GroovyPage.initRun
        OutputEncodingStack outputStack = OutputEncodingStack.currentStack(true, target, false, true);
        GrailsPrintWriter out = outputStack.getOutWriter();
        webRequest.setOut(out);
        GrailsPrintWriter codecOut = new CodecPrintWriter(out, getEncoder(new MockGrailsApplication(), CodecWithClosureProperties.class), registry);

        // print some output
        codecOut.print("hola");
        codecOut.flush();
View Full Code Here

    }

    private GrailsWebRequest bindMockHttpRequest() {
        GrailsMockHttpServletRequest mockRequest=new GrailsMockHttpServletRequest();
        GrailsMockHttpServletResponse mockResponse=new GrailsMockHttpServletResponse();
        GrailsWebRequest webRequest = new GrailsWebRequest(mockRequest, mockResponse, mockRequest.getServletContext());
        mockRequest.setAttribute(GrailsApplicationAttributes.WEB_REQUEST, webRequest);
        RequestContextHolder.setRequestAttributes(webRequest);
        return webRequest;
    }
View Full Code Here

        resource = super.findResourceForURI(pluginUri);
        return resource;
    }

    private TemplateVariableBinding findBindingInWebRequest() {
        GrailsWebRequest webRequest = GrailsWebRequest.lookup();
        if (webRequest != null) {
            return (TemplateVariableBinding) webRequest.getAttribute(GrailsApplicationAttributes.PAGE_SCOPE, RequestAttributes.SCOPE_REQUEST);
        }
        return null;
    }
View Full Code Here

     * @return The Template instance
     */
    @Override
    public Template createTemplate(Resource resource, final boolean cacheable) {
        if (resource == null) {
            GrailsWebRequest webRequest = getWebRequest();
            throw new GroovyPagesException("No Groovy page found for URI: " + getCurrentRequestUri(webRequest.getCurrentRequest()));
        }
        //Yags: Because, "pageName" was sent as null originally, it is never go in pageCache, but will force to compile the String again and till the time this request
        // is getting executed, it will occupy space in PermGen space. So if there are 1000 request for the same resource at a particular instance, there will be 1000 instance
        // class in PermGen instead of ideally being 1 as they as essentially same resource.
        //we will cache metaInfo only is Developer wants-to. Developer will make sure that he creates unique key for every unique pages s/he wants to put in cache
View Full Code Here

TOP

Related Classes of org.grails.web.servlet.mvc.GrailsWebRequest$DefaultEncodingStateRegistryLookup

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.