Package grails.web.mapping

Examples of grails.web.mapping.UrlMappingInfo


                request.setAttribute("exception", new GrailsWrappedRuntimeException(getServletContext(), t));
            }
        }

        final UrlMappingsHolder urlMappingsHolder = (UrlMappingsHolder)getBean(UrlMappingsHolder.BEAN_ID);
        UrlMappingInfo urlMappingInfo = null;
        if (t != null) {
//            stackFilterer.filter(t, true);
            urlMappingInfo = urlMappingsHolder.matchStatusCode(statusCode, t);
            if (urlMappingInfo == null) {
                urlMappingInfo = urlMappingsHolder.matchStatusCode(statusCode, GrailsExceptionResolver.getRootCause(t));
            }
        }

        if (urlMappingInfo == null) {
            urlMappingInfo = urlMappingsHolder.matchStatusCode(statusCode);
        }

        if (urlMappingInfo == null) {
            renderDefaultResponse(response, statusCode);
            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);
            String viewName = urlMappingInfo.getViewName();
            if (viewName == null || viewName.endsWith(GSP_SUFFIX) || viewName.endsWith(JSP_SUFFIX)) {
//                GrailsClass controller = UrlMappingUtils.passControllerForUrlMappingInfoInRequest(webRequest, urlMappingInfo,
//                        webRequest.getApplicationContext().getBean(UrlConverter.BEAN_NAME, UrlConverter.class),
//                        webRequest.getAttributes().getGrailsApplication());
//                if(controller != null) {
View Full Code Here


    }

    protected ModelAndView resolveViewOrForward(Exception ex, UrlMappingsHolder urlMappings, HttpServletRequest request,
            HttpServletResponse response, ModelAndView mv) {

        UrlMappingInfo info = matchStatusCode(ex, urlMappings);
        try {
            if (info != null && info.getViewName() != null) {
                resolveView(request, info, mv);
            }
            else if (info != null && info.getControllerName() != null) {
                String uri = determineUri(request);
                if (!response.isCommitted()) {
                    if(response instanceof GrailsContentBufferingResponse) {
                        // clear the output from sitemesh before rendering error page
                        ((GrailsContentBufferingResponse)response).deactivateSitemesh();
View Full Code Here

            mv.setView(v);
        }
    }

    protected UrlMappingInfo matchStatusCode(Exception ex, UrlMappingsHolder urlMappings) {
        UrlMappingInfo info = urlMappings.matchStatusCode(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ex);
        if (info == null) {
            info = urlMappings.matchStatusCode(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                    getRootCause(ex));
        }
        if (info == null) {
View Full Code Here

    /**
     * @see grails.web.mapping.UrlMappingsHolder#match(String)
     */
    public UrlMappingInfo match(String uri) {
        UrlMappingInfo info = null;
        if (cachedMatches.containsKey(uri)) {
            return cachedMatches.get(uri);
        }

        for (UrlMapping mapping : mappings) {
View Full Code Here

            for (UrlMapping mapping : mappings) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Attempting to match URI [" + uri + "] with pattern [" + mapping.getUrlData().getUrlPattern() + "]");
                }

                UrlMappingInfo current = mapping.match(uri);
                if (current != null) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("Matched URI [" + uri + "] with pattern [" + mapping.getUrlData().getUrlPattern() + "], adding to posibilities");
                    }

                    String mappingHttpMethod = current.getHttpMethod();
                    if (mappingHttpMethod == null || anyHttpMethod || mappingHttpMethod.equalsIgnoreCase(UrlMapping.ANY_HTTP_METHOD) || mappingHttpMethod.equalsIgnoreCase(httpMethod))
                        matchingUrls.add(current);
                }
            }
            cachedListMatches.put(cacheKey, matchingUrls);
View Full Code Here

            for (UrlMapping mapping : mappings) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Attempting to match URI [" + uri + "] with pattern [" + mapping.getUrlData().getUrlPattern() + "]");
                }

                UrlMappingInfo current = mapping.match(uri);
                if (current != null) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("Matched URI [" + uri + "] with pattern [" + mapping.getUrlData().getUrlPattern() + "], adding to posibilities");
                    }

                    String mappingHttpMethod = current.getHttpMethod();
                    String mappingVersion = current.getVersion();
                    boolean isValidHttpMethod = mappingHttpMethod == null || anyHttpMethod || mappingHttpMethod.equalsIgnoreCase(UrlMapping.ANY_HTTP_METHOD) || mappingHttpMethod.equalsIgnoreCase(httpMethod);
                    boolean isValidVersion = mappingVersion == null || anyVersion || mappingVersion.equals(UrlMapping.ANY_VERSION) || mappingVersion.equals(version);
                    if (isValidHttpMethod && isValidVersion) {
                        matchingUrls.add(current);
                    }
View Full Code Here

    public UrlMappingInfo matchStatusCode(int responseCode) {
        for (UrlMapping mapping : mappings) {
            if (mapping instanceof ResponseCodeUrlMapping) {
                ResponseCodeUrlMapping responseCodeUrlMapping = (ResponseCodeUrlMapping) mapping;
                if (responseCodeUrlMapping.getExceptionType() != null) continue;
                final UrlMappingInfo current = responseCodeUrlMapping.match(responseCode);
                if (current != null) return current;
            }
        }

        return null;
View Full Code Here

    public UrlMappingInfo matchStatusCode(int responseCode, Throwable e) {
        for (UrlMapping mapping : mappings) {
            if (mapping instanceof ResponseCodeUrlMapping) {
                ResponseCodeUrlMapping responseCodeUrlMapping = (ResponseCodeUrlMapping) mapping;
                final UrlMappingInfo current = responseCodeUrlMapping.match(responseCode);
                if (current != null) {
                    if (responseCodeUrlMapping.getExceptionType() != null &&
                            responseCodeUrlMapping.getExceptionType().isInstance(e)) {
                        return current;
                    }
View Full Code Here

     */
    public UrlMappingInfo match(String uri) {
        for (Pattern pattern : patterns) {
            Matcher m = pattern.matcher(uri);
            if (m.matches()) {
                UrlMappingInfo urlInfo = createUrlMappingInfo(uri, m);
                if (urlInfo != null) {
                    return urlInfo;
                }
            }
        }
View Full Code Here

        assertTrue(makeSureMatchesConstraintExistsOnId(mapping));

        GrailsWebRequest r = GrailsWebMockUtil.bindMockWebRequest();

        UrlMappingInfo info = mapping.match("/mycontroller");
        info.configure(r);

        assertEquals("mycontroller", info.getControllerName());
        assertNull(mapping.match("/mycontroller").getActionName());
        assertNull(mapping.match("/mycontroller").getId());

        UrlMappingInfo info2 = mapping.match("/mycontroller/test");
        info2.configure(r);
        assertEquals("test", info2.getActionName());
        assertNull(mapping.match("/mycontroller/test").getId());
        assertEquals("234", mapping.match("/blog/test/234").getId());
    }
View Full Code Here

TOP

Related Classes of grails.web.mapping.UrlMappingInfo

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.