jersey访问路径是如何匹配并访问的(二)

本文深入探讨了Jersey框架如何匹配并访问请求。从DispatcherServlet的doService方法开始,详细阐述了请求的处理流程,包括ResteasyHandlerMapping的使用、请求路径的匹配逻辑,以及如何根据类和方法的@Path注解找到合适的控制器和方法。通过具体例子解释了为何某些路径可以成功访问而某些路径会返回404错误。
摘要由CSDN通过智能技术生成

上一篇说明了jersey是怎么通过@path去初始化一些相关类的,那么继续看源码,看请求是如何去匹配并访问的。

那么开始从请求的入口DispatcherServlet的doService方法开始吧

protected void doService(HttpServletRequest request, HttpServletResponse response)
        throws Exception
    {
        if(logger.isDebugEnabled())
        {
            String resumed = WebAsyncUtils.getAsyncManager(request).hasConcurrentResult() ? " resumed" : "";
            logger.debug((new StringBuilder()).append("DispatcherServlet with name '").append(getServletName()).append("'").append(resumed).append(" processing ").append(request.getMethod()).append(" request for [").append(getRequestUri(request)).append("]").toString());
        }
        Map attributesSnapshot = null;
        if(WebUtils.isIncludeRequest(request))
        {
            attributesSnapshot = new HashMap();
            Enumeration attrNames = request.getAttributeNames();
            do
            {
                if(!attrNames.hasMoreElements())
                    break;
                String attrName = (String)attrNames.nextElement();
                if(cleanupAfterInclude || attrName.startsWith("org.springframework.web.servlet"))
                    attributesSnapshot.put(attrName, request.getAttribute(attrName));
            } while(true);
        }
        request.setAttribute(WEB_APPLICATION_CONTEXT_ATTRIBUTE, getWebApplicationContext());
        request.setAttribute(LOCALE_RESOLVER_ATTRIBUTE, localeResolver);
        request.setAttribute(THEME_RESOLVER_ATTRIBUTE, themeResolver);
        request.setAttribute(THEME_SOURCE_ATTRIBUTE, getThemeSource());
        FlashMap inputFlashMap = flashMapManager.retrieveAndUpdate(request, response);
        if(inputFlashMap != null)
            request.setAttribute(INPUT_FLASH_MAP_ATTRIBUTE, Collections.unmodifiableMap(inputFlashMap));
        request.setAttribute(OUTPUT_FLASH_MAP_ATTRIBUTE, new FlashMap());
        request.setAttribute(FLASH_MAP_MANAGER_ATTRIBUTE, flashMapManager);
        try
        {
            doDispatch(request, response);
        }
        finally
        {
            if(WebAsyncUtils.getAsyncManager(request).isConcurrentHandlingStarted())
                return;
            if(attributesSnapshot != null)
                restoreAttributesAfterInclude(request, attributesSnapshot);
        }
    }

没啥好说的,就是set一些值,点开doDispatch(request, response);

protected void doDispatch(HttpServletRequest request, HttpServletResponse response)
        throws Exception
    {
        HttpServletRequest processedRequest;
        HandlerExecutionChain mappedHandler;
        boolean multipartRequestParsed;
        WebAsyncManager asyncManager;
        processedRequest = request;
        mappedHandler = null;
        multipartRequestParsed = false;
        asyncManager = WebAsyncUtils.getAsyncManager(request);
        ModelAndView mv;
        Exception dispatchException;
        mv = null;
        dispatchException = null;
        processedRequest = checkMultipart(request);
        multipartRequestParsed = processedRequest != request;
        mappedHandler = getHandler(processedRequest, false);
        if(mappedHandler != null && mappedHandler.getHandler() != null)
            break MISSING_BLOCK_LABEL_69;
        noHandlerFound(processedRequest, response);
        return;
        HandlerAdapter ha;
        boole
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值