當前位置: 首頁>>代碼示例>>Java>>正文


Java NativeWebRequest.getAttribute方法代碼示例

本文整理匯總了Java中org.springframework.web.context.request.NativeWebRequest.getAttribute方法的典型用法代碼示例。如果您正苦於以下問題:Java NativeWebRequest.getAttribute方法的具體用法?Java NativeWebRequest.getAttribute怎麽用?Java NativeWebRequest.getAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.web.context.request.NativeWebRequest的用法示例。


在下文中一共展示了NativeWebRequest.getAttribute方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getRequestBody

import org.springframework.web.context.request.NativeWebRequest; //導入方法依賴的package包/類
private String getRequestBody(NativeWebRequest webRequest) {
    HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class);
    String body = (String) webRequest.getAttribute(JSON_BODY_ATTRIBUTE, NativeWebRequest.SCOPE_REQUEST);
    if (StringUtils.isBlank(body)) {
        try {
            body = IOUtils.toString(servletRequest.getInputStream(), Charset.forName("UTF-8"));
            webRequest.setAttribute(JSON_BODY_ATTRIBUTE, body, NativeWebRequest.SCOPE_REQUEST);
        } catch (IOException e) {
            throw new ParameterResolverException("參數解析失敗", e);
        }
    }
    return body;
}
 
開發者ID:guqiyao,項目名稱:fishing-village,代碼行數:14,代碼來源:JsonParameterResolver.java

示例2: resolveArgument

import org.springframework.web.context.request.NativeWebRequest; //導入方法依賴的package包/類
@Override
public Object resolveArgument(MethodParameter parameter,
		ModelAndViewContainer mavContainer, NativeWebRequest webRequest,
		WebDataBinderFactory binderFactory) throws Exception {
	if(Oauth2Token.class.equals(parameter.getParameterType())){
		return webRequest.getAttribute("Oauth2Token",  RequestAttributes.SCOPE_REQUEST);
	}
	
	if(SNSUserInfo.class.equals(parameter.getParameterType())){
		return webRequest.getAttribute("SNSUserInfo",  RequestAttributes.SCOPE_REQUEST);
	}
	
	return null;
}
 
開發者ID:tojaoomy,項目名稱:private-WeChat,代碼行數:15,代碼來源:SNSUserInfoArgumentResolver.java

示例3: resolveArgument

import org.springframework.web.context.request.NativeWebRequest; //導入方法依賴的package包/類
public Object resolveArgument(MethodParameter parameter,
		ModelAndViewContainer mavContainer, NativeWebRequest webRequest,
		WebDataBinderFactory binderFactory) throws Exception {
	if(Oauth2Token.class.equals(parameter.getParameterType())){
		return webRequest.getAttribute("Oauth2Token",  RequestAttributes.SCOPE_REQUEST);
	}
	
	if(SNSUserInfo.class.equals(parameter.getParameterType())){
		return webRequest.getAttribute("SNSUserInfo",  RequestAttributes.SCOPE_REQUEST);
	}
	
	return null;
}
 
開發者ID:tojaoomy,項目名稱:private-WeChat,代碼行數:14,代碼來源:SNSUserInfoArgumentResolver.java

示例4: resolveArgument

import org.springframework.web.context.request.NativeWebRequest; //導入方法依賴的package包/類
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer container,
                              NativeWebRequest request, WebDataBinderFactory factory) throws Exception {
    //獲取用戶ID
    Object object = request.getAttribute(AuthorizationInterceptor.LOGIN_USER_KEY, RequestAttributes.SCOPE_REQUEST);
    if(object == null){
        return null;
    }

    //獲取用戶信息
    UserEntity user = userService.queryObject((Long)object);

    return user;
}
 
開發者ID:zhaoqicheng,項目名稱:renren-fast,代碼行數:15,代碼來源:LoginUserHandlerMethodArgumentResolver.java

示例5: getRequestBody

import org.springframework.web.context.request.NativeWebRequest; //導入方法依賴的package包/類
private String getRequestBody(NativeWebRequest webRequest) {
    HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class);

    String jsonBody = (String) webRequest.getAttribute(JSON_BODY_ATTRIBUTE, NativeWebRequest.SCOPE_REQUEST);
    if (jsonBody == null) {
        try {
            jsonBody = IOUtils.toString(servletRequest.getInputStream(), "UTF-8");
            webRequest.setAttribute(JSON_BODY_ATTRIBUTE, jsonBody, NativeWebRequest.SCOPE_REQUEST);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    return jsonBody;
}
 
開發者ID:mingzuozhibi,項目名稱:mzzb-server,代碼行數:15,代碼來源:JsonArgumentResolver.java

示例6: resolveArgument

import org.springframework.web.context.request.NativeWebRequest; //導入方法依賴的package包/類
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {

    //取出存入的用戶ID
    String currentUserId = (String) webRequest.getAttribute(Constant.CURRENT_USER_ID, RequestAttributes.SCOPE_REQUEST);
    if (currentUserId != null) {
        return userDao.findById(currentUserId);
    }
    return new MissingServletRequestPartException(Constant.CURRENT_USER_ID);
}
 
開發者ID:aollio,項目名稱:school-express-delivery,代碼行數:11,代碼來源:CurrentUserMethodArgumentResolver.java

示例7: resolveArgument

import org.springframework.web.context.request.NativeWebRequest; //導入方法依賴的package包/類
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer container,
                              NativeWebRequest request, WebDataBinderFactory factory) throws Exception {
    //獲取用戶ID
    Object object = request.getAttribute(AuthorizationInterceptor.LOGIN_USER_KEY, RequestAttributes.SCOPE_REQUEST);
    if (object == null) {
        return null;
    }
    //獲取用戶信息
    return userService.queryObject((Long) object);
}
 
開發者ID:davichi11,項目名稱:my-spring-boot-project,代碼行數:12,代碼來源:LoginUserHandlerMethodArgumentResolver.java

示例8: resolveArgument

import org.springframework.web.context.request.NativeWebRequest; //導入方法依賴的package包/類
/**
 * Construct new {@link AppSecret} object from the given Web request.
 * The authenticated user is available in the web request principal.
 */
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webReq, WebDataBinderFactory binderFactory) throws Exception {
    Authentication auth = (Authentication) webReq.getUserPrincipal();
    OneOpsUser user = (OneOpsUser) auth.getPrincipal();

    // Get the path variable.
    @SuppressWarnings("unchecked")
    Map<String, String> pathVars = (Map<String, String>) webReq.getAttribute(URI_TEMPLATE_VARIABLES_ATTRIBUTE, SCOPE_REQUEST);
    String group = pathVars != null ? pathVars.get(APP_NAME_PARAM) : "";
    String secret = pathVars != null ? pathVars.get(APP_SECRET_PARAM) : "";

    AppGroup appGroup = new AppGroup(user.getDomain(), group);
    return new AppSecret(secret, appGroup);
}
 
開發者ID:oneops,項目名稱:secrets-proxy,代碼行數:19,代碼來源:AppSecretArgResolver.java

示例9: resolveArgument

import org.springframework.web.context.request.NativeWebRequest; //導入方法依賴的package包/類
/**
 * Construct new {@link AppGroup} object from the given Web request.
 * The authenticated user is available in the web request principal.
 */
@Override
public AppGroup resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webReq, WebDataBinderFactory binderFactory) throws Exception {
    Authentication auth = (Authentication) webReq.getUserPrincipal();
    OneOpsUser user = (OneOpsUser) auth.getPrincipal();

    // Get the path variable.
    @SuppressWarnings("unchecked")
    Map<String, String> pathVars = (Map<String, String>) webReq.getAttribute(URI_TEMPLATE_VARIABLES_ATTRIBUTE, SCOPE_REQUEST);
    String group = pathVars != null ? pathVars.get(APP_NAME_PARAM) : "";
    return AppGroup.from(user.getDomain(), group);
}
 
開發者ID:oneops,項目名稱:secrets-proxy,代碼行數:16,代碼來源:AppGroupArgResolver.java

示例10: resolveArgument

import org.springframework.web.context.request.NativeWebRequest; //導入方法依賴的package包/類
@Override
public Object resolveArgument(MethodParameter parameter,
		ModelAndViewContainer mavContainer, NativeWebRequest webRequest,
		WebDataBinderFactory binderFactory) throws Exception {
	return webRequest.getAttribute("Oauth2Token",  RequestAttributes.SCOPE_REQUEST);
}
 
開發者ID:tojaoomy,項目名稱:private-WeChat,代碼行數:7,代碼來源:Oauth2TokenArgumentResolver.java

示例11: resolveArgument

import org.springframework.web.context.request.NativeWebRequest; //導入方法依賴的package包/類
public Object resolveArgument(MethodParameter parameter,
		ModelAndViewContainer mavContainer, NativeWebRequest webRequest,
		WebDataBinderFactory binderFactory) throws Exception {
	return webRequest.getAttribute("Oauth2Token",  RequestAttributes.SCOPE_REQUEST);
}
 
開發者ID:tojaoomy,項目名稱:private-WeChat,代碼行數:6,代碼來源:Oauth2TokenArgumentResolver.java


注:本文中的org.springframework.web.context.request.NativeWebRequest.getAttribute方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。