设置一个请求对象到这个包装器中， {@link PortalRequest} 将把这个请求对象关联给当前线程。
<p>

这个方法将由web容器(tomcat/resin等)调用
511158
public void setRequest(ServletRequest request) {
        if (request != null) {
            if (logger.isDebugEnabled()) {
                logger.debug(String.format("set request: %s", request));
            }
            this.threadLocalRequests.set((HttpServletRequest) request);
        } else {
            //if null, remove from threadLocalRequests
            // @see WindowTask#run 's finally
            if (logger.isDebugEnabled()) {
                HttpServletRequest tmpRequest = this.threadLocalRequests.get();
                logger.debug(String.format("remove request: %s", tmpRequest));
            }
            this.threadLocalRequests.remove();
        }
    }
1329367
public static int getPage(final HttpServletRequest request) {
        int ret = 1;
        final String p = request.getParameter("p");
        if (Strings.isNumeric(p)) {
            try {
                ret = Integer.parseInt(p);
            } catch (final Exception e) {
                // ignored
            }
        }

        if (1 > ret) {
            ret = 1;
        }

        return ret;
    }
915801
public static boolean isAjaxRequest(HttpServletRequest request) {
        String ajaxHeader = request.getHeader("X-Requested-With");
        return StringUtils.isNotBlank(ajaxHeader) && "XMLHttpRequest".equalsIgnoreCase(ajaxHeader);
    }
1136210
@SuppressWarnings("unchecked")
    protected Map<IPortletWindowId, IPortletRenderExecutionWorker> getPortletRenderingMap(
            HttpServletRequest request) {
        synchronized (PortalWebUtils.getRequestAttributeMutex(request)) {
            Map<IPortletWindowId, IPortletRenderExecutionWorker> portletRenderingMap =
                    (Map<IPortletWindowId, IPortletRenderExecutionWorker>)
                            request.getAttribute(PORTLET_RENDERING_MAP);
            if (portletRenderingMap == null) {
                portletRenderingMap =
                        new ConcurrentHashMap<IPortletWindowId, IPortletRenderExecutionWorker>();
                request.setAttribute(PORTLET_RENDERING_MAP, portletRenderingMap);
            }
            return portletRenderingMap;
        }
    }
288516
@Override
    public IUserInstance getUserInstance(HttpServletRequest request) throws PortalException {
        try {
            request = this.portalRequestUtils.getOriginalPortalRequest(request);
        } catch (IllegalArgumentException iae) {
            // ignore, just means that this isn't a wrapped request
        }

        // Use request attributes first for the fastest possible retrieval
        IUserInstance userInstance = (IUserInstance) request.getAttribute(KEY);
        if (userInstance != null) {
            return userInstance;
        }

        final IPerson person;
        try {
            // Retrieve the person object that is associated with the request
            person = this.personManager.getPerson(request);
        } catch (Exception e) {
            logger.error("Exception while retrieving IPerson!", e);
            throw new PortalSecurityException("Could not retrieve IPerson", e);
        }

        if (person == null) {
            throw new PortalSecurityException(
                    "PersonManager returned null person for this request.  With no user, there's no UserInstance.  Is PersonManager misconfigured?  RDBMS access misconfigured?");
        }

        final HttpSession session = request.getSession();
        if (session == null) {
            throw new IllegalStateException(
                    "HttpServletRequest.getSession() returned a null session for request: "
                            + request);
        }

        // Return the UserInstance object if it's in the session
        UserInstanceHolder userInstanceHolder = getUserInstanceHolder(session);
        if (userInstanceHolder != null) {
            userInstance = userInstanceHolder.getUserInstance();

            if (userInstance != null) {
                return userInstance;
            }
        }

        // Create either a UserInstance or a GuestUserInstance
        final LocaleManager localeManager = this.getLocaleManager(request, person);
        final String userAgent = this.getUserAgent(request);
        final IUserProfile userProfile =
                this.getUserProfile(request, person, localeManager, userAgent);

        // Create the user layout manager and user instance object
        IUserLayoutManager userLayoutManager =
                userLayoutManagerFactory.getUserLayoutManager(person, userProfile);

        final UserPreferencesManager userPreferencesManager =
                new UserPreferencesManager(person, userProfile, userLayoutManager);
        userInstance = new UserInstance(person, userPreferencesManager, localeManager);

        // Ensure the newly created UserInstance is cached in the session
        if (userInstanceHolder == null) {
            userInstanceHolder = new UserInstanceHolder();
        }
        userInstanceHolder.setUserInstance(userInstance);
        session.setAttribute(KEY, userInstanceHolder);
        request.setAttribute(KEY, userInstance);

        // Return the new UserInstance
        return userInstance;
    }
5215
private HttpRequest buildHTTPRequest(final Query<?, ?> query) {
		final String url = API_ENDPOINT + query.getPath();

		HttpRequest request;
		switch (query.getHttpRequestMethod()) {
			case GET:
				request = Unirest.get(url);

				if ((query.getQueryParameters() != null) && !query.getQueryParameters().isEmpty()) {
					((GetRequest) request).queryString(query.getQueryParameters());
				}

				break;

			case POST:
				request = Unirest.post(url);

				if ((query.getQueryParameters() != null) && !query.getQueryParameters().isEmpty()) {
					((HttpRequestWithBody) request).fields(query.getQueryParameters());
				}

				break;

			default:
				request = Unirest.get(url);
		}

		/*
		 * Add any named route parameters to the request (i.e. elements used to build the URI, such as
		 * '/sound/{sound_id}' would have a parameter named 'sound_id').
		 */
		if ((query.getRouteParameters() != null) && !query.getRouteParameters().isEmpty()) {
			for (final Entry<String, String> routeParameter : query.getRouteParameters().entrySet()) {
				request.routeParam(routeParameter.getKey(), routeParameter.getValue());
			}
		}

		return request;
	}
469030
public void doGet (HttpServletRequest request,
            	   HttpServletResponse response)
    throws ServletException, IOException
    {
        String toAddr = request.getParameter("to");
        String fromAddr = request.getParameter("from");
        String bye = request.getParameter("bye");

        URI to = toAddr==null? null : sipFactory.createAddress(toAddr).getURI();
        URI from = fromAddr==null? null : sipFactory.createAddress(fromAddr).getURI();    

        CallStatusContainer calls = (CallStatusContainer) getServletContext().getAttribute("activeCalls");

        // Create app session and request
        SipApplicationSession appSession = 
        	((ConvergedHttpSession)request.getSession()).getApplicationSession();

        if(bye != null) {
        	if(bye.equals("all")) {
        		Iterator it = (Iterator) appSession.getSessions("sip");
        		while(it.hasNext()) {
        			SipSession session = (SipSession) it.next();
        			Call call = (Call) session.getAttribute("call");
        			if (call != null) call.end();
        			calls.removeCall(call);
        			notifyStatus("Received Bye All request");
        		}
        	} else {
        		// Someone wants to end an established call, send byes and clean up
        		Call call = calls.getCall(fromAddr, toAddr);
        		call.end();
        		calls.removeCall(call);
        		notifyStatus("Received Bye request");
        	}
        } else {
        	if(calls == null) {
        		calls = new CallStatusContainer();
        		getServletContext().setAttribute("activeCalls", calls);
        	}
        	
        	// Add the call in the active calls
        	Call call = calls.addCall(fromAddr, toAddr, "FFFF00");

        	SipServletRequest req = sipFactory.createRequest(appSession, "INVITE", from, to);

        	// Set some attribute
        	req.getSession().setAttribute("SecondPartyAddress", sipFactory.createAddress(fromAddr));
        	req.getSession().setAttribute("call", call);
        	
        	// This session will be used to send BYE
        	call.addSession(req.getSession());
        	
        	logger.info("Sending request" + req);
        	// Send the INVITE request            
        	req.send();
        	notifyStatus("Received Call request");
        }
        
        // Write the output html
    	PrintWriter	out;
        response.setContentType("text/html");
        out = response.getWriter();
        
        out.println("success");
        out.close();
    }
63437
public static void serverReceived(NettyHttpRequest request) {
        try {
            SofaRequest sofaRequest = new SofaRequest();

            HttpHeaders headers = request.getHttpHeaders();
            String rpcTraceContext = headers.getHeaderString(RemotingConstants.NEW_RPC_TRACE_NAME);
            if (StringUtils.isNotBlank(rpcTraceContext)) {
                // 新格式
                sofaRequest.addRequestProp(RemotingConstants.NEW_RPC_TRACE_NAME, rpcTraceContext);
            } else {
                String traceIdKey = headers.getHeaderString(RemotingConstants.HTTP_HEADER_TRACE_ID_KEY);
                String rpcIdKey = headers.getHeaderString(RemotingConstants.HTTP_HEADER_RPC_ID_KEY);
                if (StringUtils.isEmpty(rpcIdKey)) {
                    rpcIdKey = request.getUri().getQueryParameters().getFirst(RemotingConstants.RPC_ID_KEY);
                }
                if (StringUtils.isEmpty(traceIdKey)) {
                    traceIdKey = request.getUri().getQueryParameters().getFirst(RemotingConstants.TRACE_ID_KEY);
                }

                if (StringUtils.isNotEmpty(traceIdKey) && StringUtils.isNotEmpty(rpcIdKey)) {
                    Map<String, String> map = new HashMap<String, String>();
                    map.put(RemotingConstants.TRACE_ID_KEY, traceIdKey);
                    map.put(RemotingConstants.RPC_ID_KEY, rpcIdKey);
                    String penAttrs = headers.getHeaderString(RemotingConstants.PEN_ATTRS_KEY);
                    map.put(RemotingConstants.PEN_ATTRS_KEY, penAttrs);
                    sofaRequest.addRequestProp(RemotingConstants.RPC_TRACE_NAME, map);
                }
            }
            Tracers.serverReceived(sofaRequest);
        } catch (Throwable t) {
            if (LOGGER.isWarnEnabled()) {
                LOGGER.warn("the process of rest tracer server receive occur error ", t);
            }
        }
    }
1179301
@Override
    public PortletEventQueue getPortletEventQueue(HttpServletRequest request) {
        request = this.portalRequestUtils.getOriginalPortalRequest(request);

        synchronized (PortalWebUtils.getRequestAttributeMutex(request)) {
            PortletEventQueue portletEventQueue =
                    (PortletEventQueue) request.getAttribute(PORTLET_EVENT_QUEUE);
            if (portletEventQueue == null) {
                portletEventQueue = new PortletEventQueue();
                request.setAttribute(PORTLET_EVENT_QUEUE, portletEventQueue);
            }
            return portletEventQueue;
        }
    }
484638
public static boolean isInternalRequest(HttpServletRequest request){
		//
		if(Boolean.parseBoolean(request.getHeader(WebConstants.HEADER_INTERNAL_REQUEST))){
			return true;
		}

		boolean isInner = IpUtils.isInnerIp(request.getServerName());
		String forwardHost = request.getHeader(WebConstants.HEADER_FORWARDED_HOST);
		//来源于网关
		if(StringUtils.isNotBlank(forwardHost)){
			isInner = IpUtils.isInnerIp(StringUtils.split(forwardHost, ":")[0]);
		}else{			
			if(!isInner){
				isInner = IpUtils.isInnerIp(IpUtils.getinvokerIpAddr(request));
			}
		}
		return isInner;
	}
682511
@Override
    public RequestCtx handleRequest(HttpServletRequest request,
                                    HttpServletResponse response)
            throws IOException, ServletException {
        LogUtil.statLog(request.getRemoteUser(),
                        Constants.ACTION.RI_FIND_OBJECTS.uri,
                        "FedoraRepository:ResourceIndex",
                        null);

        return null;
    }
600163
@SuppressWarnings("unused")
	public static <T> String getRequestPayload(Request<T> request) {
		Class<?> referenceClazz = request.getClass();
		List<Field> fields = ClassUtil.getAnnotatedFields(referenceClazz, Body.class);
		List<String> objects = new LinkedList<String>();
		for (Field field : fields) {
			Body body = field.getAnnotation(Body.class);

			String asString = ClassUtil.getValueOf(field, request, referenceClazz, String.class);
			return (asString != null ? asString : "");
			// what if there are more bodies?!
		}
		return EMPTY;
	}
1087606
public void feedRequest(final CrawlRequest request, final boolean isCrawlSeed) {
        if (config.isOffsiteRequestFilteringEnabled()) {
            boolean inCrawlDomain = false;

            for (CrawlDomain allowedCrawlDomain : config.getAllowedCrawlDomains()) {
                if (allowedCrawlDomain.contains(request.getDomain())) {
                    inCrawlDomain = true;
                    break;
                }
            }

            if (!inCrawlDomain) {
                return;
            }
        }

        if (config.isDuplicateRequestFilteringEnabled()) {
            String urlFingerprint = createFingerprintForUrl(request.getRequestUrl());

            if (urlFingerprints.contains(urlFingerprint)) {
                return;
            }

            urlFingerprints.add(urlFingerprint);
        }

        CrawlCandidateBuilder builder = new CrawlCandidateBuilder(request);

        if (!isCrawlSeed) {
            int crawlDepthLimit = config.getMaximumCrawlDepth();
            int nextCrawlDepth = currentCandidate.getCrawlDepth() + 1;

            if (crawlDepthLimit != 0 && nextCrawlDepth > crawlDepthLimit) {
                return;
            }

            builder = builder
                    .setRefererUrl(currentCandidate.getRequestUrl())
                    .setCrawlDepth(nextCrawlDepth);
        }

        candidates.add(builder.build());
    }
83866
public void extractHttpRequestInfo(HttpServletRequest httpRequest) {
		
		putUnlessNull(REQUEST_REFERER_URL, httpRequest.getHeader("REFERER"));
		
		String remoteAddr = httpRequest.getHeader("X-Forwarded-For");
		remoteAddr = (remoteAddr == null) ? 
			httpRequest.getRemoteAddr() :
			remoteAddr + ", " + httpRequest.getRemoteAddr();
		
		putUnlessNull(REQUEST_REMOTE_ADDRESS, remoteAddr);
		
		// Check for AJAX
		String x_req_with = httpRequest.getHeader("X-Requested-With");
		if (x_req_with != null) {
			if (x_req_with.equals("XMLHttpRequest")) {
				this.setAjaxRequest(true);
			}
		} else if (this.getRefererUrl() != null && httpRequest.getParameter("ajaxpipe") != null) {
			this.setAjaxRequest(true);
		}
		
		if (isMementoEnabled()) {
			// Check for Memento Accept-Datetime
			String acceptDateTime = httpRequest.getHeader(MementoUtils.ACCEPT_DATETIME);
			if (acceptDateTime != null) {
				this.setMementoAcceptDatetime(true);
			}
		}
		
		putUnlessNull(REQUEST_WAYBACK_HOSTNAME, httpRequest.getLocalName());
		putUnlessNull(REQUEST_AUTH_TYPE, httpRequest.getAuthType());
		putUnlessNull(REQUEST_REMOTE_USER, httpRequest.getRemoteUser());
		
		putUnlessNull(REQUEST_AUTHORIZATION,
				httpRequest.getHeader(REQUEST_AUTHORIZATION));
		putUnlessNull(REQUEST_WAYBACK_PORT, 
				String.valueOf(httpRequest.getLocalPort()));
		putUnlessNull(REQUEST_WAYBACK_CONTEXT, httpRequest.getContextPath());

		Locale l = null;
		if (accessPoint != null) {
			l = accessPoint.getLocale();
		}
		if (l == null) {
			l = httpRequest.getLocale();
		}
		//setLocale(l);
		this.locale = l;

		putUnlessNull(REQUEST_LOCALE_LANG,l.getDisplayLanguage());

		Cookie[] cookies = httpRequest.getCookies();
		if(cookies != null) {
			for(Cookie cookie : cookies) {
				String name = cookie.getName();
				String value = cookie.getValue();
				String oldVal = get(name);
				if(oldVal == null || oldVal.length() == 0) {
					put(name,value);
				}
			}
		}
	}
80428
protected IPortalCookie getOrCreatePortalCookie(HttpServletRequest request) {
        IPortalCookie result = null;

        // first check in request
        final Cookie cookie = this.getCookieFromRequest(this.cookieName, request);
        if (cookie != null) {
            // found a potential cookie, call off to the dao
            final String value = cookie.getValue();
            result = this.portletCookieDao.getPortalCookie(value);
        }

        // still null? check in the session
        if (result == null) {
            result = locatePortalCookieInSession(request.getSession());
        }
        // if by this point we still haven't found the portal cookie, create one
        if (result == null) {
            result = this.portletCookieDao.createPortalCookie(this.maxAge);
            // store the portal cookie value value in the session
            HttpSession session = request.getSession();
            synchronized (WebUtils.getSessionMutex(session)) {
                session.setAttribute(SESSION_ATTRIBUTE__PORTAL_COOKIE_ID, result.getValue());
            }
        }

        return result;
    }
289676
@Override
    @SuppressWarnings("deprecation")
    public RequestCtx handleRequest(HttpServletRequest request,
                                    HttpServletResponse response)
            throws IOException, ServletException {
        if (request.getPathInfo() != null) {
            logger.error("Bad request: " + request.getRequestURI());
            throw new ServletException("Bad request: "
                    + request.getRequestURI());
        }

        RequestCtx req = null;

        String pid = request.getParameter("PID");
        String dissID = "sDefPID";
        String methodName = request.getParameter("methodName");
        String dateTime = request.getParameter("asOfDateTime");

        if (logger.isDebugEnabled()) {
            logger.debug("PID: {} sDefPID {} methodName {}", pid, dissID, methodName);
        }

        Map<URI, AttributeValue> actions = new HashMap<URI, AttributeValue>();
        Map<URI, AttributeValue> resAttr;

        String logAction = null;

        // Starting assumption is that we are doing a GetObjectProfile
        actions.put(Constants.ACTION.ID.getURI(),
                    Constants.ACTION.GET_DISSEMINATION
                            .getStringAttribute());
        logAction =
                Constants.ACTION.GET_DISSEMINATION.uri;

        try {
            resAttr = ResourceAttributes.getResources(pid);
            
            if (dissID != null && !dissID.isEmpty()) {
                resAttr.put(Constants.DISSEMINATOR.ID.getURI(),
                            new StringAttribute(dissID));
            }
            if (methodName != null && !methodName.isEmpty()) {
                resAttr.put(Constants.DISSEMINATOR.METHOD.getURI(),
                            new StringAttribute(methodName));
            }
            if (dateTime != null && !dateTime.isEmpty()) {
                resAttr.put(Constants.DATASTREAM.AS_OF_DATETIME.getURI(),
                            DateTimeAttribute.getInstance(dateTime));
            }

            actions.put(Constants.ACTION.API.getURI(),
                        Constants.ACTION.APIA.getStringAttribute());

            req =
                    getContextHandler().buildRequest(getSubjects(request),
                                                     actions,
                                                     resAttr,
                                                     getEnvironment(request));

            LogUtil.statLog(request.getRemoteUser(), logAction, pid, dissID);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            throw new ServletException(e);
        }

        return req;
    }
186936
public HttpServletRequest getRequest() {
        HttpServletRequest request = threadLocalRequests.get();
        return request == null ? orginal : request;
    }