当前位置: 首页>>代码示例>>Java>>正文


Java RequestAttributes类代码示例

本文整理汇总了Java中org.springframework.web.context.request.RequestAttributes的典型用法代码示例。如果您正苦于以下问题:Java RequestAttributes类的具体用法?Java RequestAttributes怎么用?Java RequestAttributes使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RequestAttributes类属于org.springframework.web.context.request包,在下文中一共展示了RequestAttributes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getErrorAttributes

import org.springframework.web.context.request.RequestAttributes; //导入依赖的package包/类
@Override
public Map<String, Object> getErrorAttributes(RequestAttributes requestAttributes, boolean includeStackTrace) {
	Map<String, Object> errorAttributes = super.getErrorAttributes(requestAttributes, includeStackTrace);
	Throwable error = getError(requestAttributes);
	if (error != null) {
		// pass in name and version if ReleaseNotFoundException
		if (error instanceof ReleaseNotFoundException) {
			ReleaseNotFoundException e = ((ReleaseNotFoundException) error);
			if (e.getReleaseName() != null) {
				errorAttributes.put("releaseName", e.getReleaseName());
			}
			if (e.getReleaseVersion() != null) {
				errorAttributes.put("version", e.getReleaseVersion());
			}
		}
	}
	return errorAttributes;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-skipper,代码行数:19,代码来源:SkipperErrorAttributes.java

示例2: error

import org.springframework.web.context.request.RequestAttributes; //导入依赖的package包/类
@RequestMapping
@ResponseBody
public ResponseEntity<DataGateError> error(HttpServletRequest request) {
    HttpStatus status = getStatus(request);
    RequestAttributes requestAttributes = new ServletRequestAttributes(request);
    Map<String, Object> attributeMap = this.errorAttributes.getErrorAttributes(requestAttributes, false);
    DataGateError dataGateError = new DataGateError();
    if (attributeMap != null) {
        String message = (String) attributeMap.get("message");
        dataGateError.setMessage(message);
    } else {
        dataGateError.setMessage("Unknown error");
    }

    return new ResponseEntity<>(dataGateError, status);
}
 
开发者ID:dizitart,项目名称:nitrite-database,代码行数:17,代码来源:DataGateErrorController.java

示例3: errorPage

import org.springframework.web.context.request.RequestAttributes; //导入依赖的package包/类
@RequestMapping(produces = "text/html")
public String errorPage(HttpServletRequest request, Model model) {
    String message, error;
    HttpStatus status = getStatus(request);
    RequestAttributes requestAttributes = new ServletRequestAttributes(request);
    Map<String, Object> attributeMap = this.errorAttributes.getErrorAttributes(requestAttributes, false);

    if (attributeMap != null) {
        message = (String) attributeMap.get("message");
        error = (String) attributeMap.get("error");
        model.addAttribute("header", error);
        model.addAttribute("message", message);
    }

    if (status.is4xxClientError()){
        if(status.value() == 404) {
            model.addAttribute("header", "Sorry but we couldn't find this page");
            model.addAttribute("message", "This page you are looking for does not exist.");
        } else if (status.value() == 403) {
            model.addAttribute("header", "Access denied");
            model.addAttribute("message", "Full authentication is required to access this resource.");
        }
    } else if (status.value() == 500){
        model.addAttribute("header", "Internal Server Error");
        model.addAttribute("message",
                "If the problem persists feel free to create an issue in Github.");
    }
    model.addAttribute("number", status.value());
    return "errorPage";
}
 
开发者ID:dizitart,项目名称:nitrite-database,代码行数:31,代码来源:DataGateErrorController.java

示例4: signupForm

import org.springframework.web.context.request.RequestAttributes; //导入依赖的package包/类
@RequestMapping(value = "/signup", method = RequestMethod.GET)
public String signupForm(@ModelAttribute SocialUserDTO socialUserDTO, WebRequest request, Model model) {
    if (request.getUserPrincipal() != null)
        return "redirect:/";
    else {
        Connection<?> connection = providerSignInUtils.getConnectionFromSession(request);
        request.setAttribute("connectionSubheader",
                webUI.parameterizedMessage(MESSAGE_KEY_SOCIAL_SIGNUP,
                        StringUtils.capitalize(connection.getKey().getProviderId())),
                RequestAttributes.SCOPE_REQUEST);

        socialUserDTO = createSocialUserDTO(request, connection);

        ConnectionData connectionData = connection.createData();
        SignInUtils.setUserConnection(request, connectionData);

        model.addAttribute(MODEL_ATTRIBUTE_SOCIALUSER, socialUserDTO);
        return SIGNUP_VIEW;
    }
}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:21,代码来源:UserController.java

示例5: getCurrentRequest

import org.springframework.web.context.request.RequestAttributes; //导入依赖的package包/类
/**
 * Obtain the request through {@link RequestContextHolder}.
 * @return the active servlet request
 */
protected static HttpServletRequest getCurrentRequest() {
    RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
    Assert.state(requestAttributes != null, "Could not find current request via RequestContextHolder");
    Assert.isInstanceOf(ServletRequestAttributes.class, requestAttributes);
    HttpServletRequest servletRequest = ((ServletRequestAttributes) requestAttributes).getRequest();
    Assert.state(servletRequest != null, "Could not find current HttpServletRequest");
    return servletRequest;
}
 
开发者ID:jaschenk,项目名称:Your-Microservice,代码行数:13,代码来源:YourServletUriComponentsBuilder.java

示例6: interceptor

import org.springframework.web.context.request.RequestAttributes; //导入依赖的package包/类
@Override
public Object interceptor(ProceedingJoinPoint pjp) throws Throwable {
    TccTransactionContext tccTransactionContext;
    //如果不是本地反射调用补偿
    RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
    HttpServletRequest request = requestAttributes == null ? null : ((ServletRequestAttributes) requestAttributes).getRequest();
    String context = request == null ? null : request.getHeader(CommonConstant.TCC_TRANSACTION_CONTEXT);
    tccTransactionContext =
            GsonUtils.getInstance().fromJson(context, TccTransactionContext.class);

    return tccTransactionAspectService.invoke(tccTransactionContext, pjp);
}
 
开发者ID:yu199195,项目名称:happylifeplat-tcc,代码行数:13,代码来源:SpringCloudTxTransactionInterceptor.java

示例7: getLocaleUrl

import org.springframework.web.context.request.RequestAttributes; //导入依赖的package包/类
public String getLocaleUrl(String locale) throws Exception {
    UriComponentsBuilder builder = ServletUriComponentsBuilder.fromCurrentRequest().replaceQueryParam("locale", locale);
    RequestAttributes attributes = org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes();
    if (attributes instanceof ServletRequestAttributes) {
        int statusCode = ((ServletRequestAttributes) attributes).getResponse().getStatus();
        switch (statusCode) {
            case 200:
                break;
            case 404:
                builder.replacePath("" + statusCode);
                break;
            default:
                builder.replacePath("error");
        }
    }
    URI serverUri = new URI(this.casConfigurationProperties.getServer().getName());
    if ("https".equalsIgnoreCase(serverUri.getScheme())) {
        builder.port((serverUri.getPort() == -1) ? 443 : serverUri.getPort());
    }
    return builder.scheme(serverUri.getScheme()).host(serverUri.getHost()).build(true).toUriString();
}
 
开发者ID:e-gov,项目名称:TARA-Server,代码行数:22,代码来源:TaraProperties.java

示例8: interceptor

import org.springframework.web.context.request.RequestAttributes; //导入依赖的package包/类
@Override
public Object interceptor(ProceedingJoinPoint pjp) throws Throwable {
    MythTransactionContext mythTransactionContext = TransactionContextLocal.getInstance().get();
    if (Objects.nonNull(mythTransactionContext) &&
            mythTransactionContext.getRole() == MythRoleEnum.LOCAL.getCode()) {
        mythTransactionContext = TransactionContextLocal.getInstance().get();
    } else {
        RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
        HttpServletRequest request = requestAttributes == null ? null : ((ServletRequestAttributes) requestAttributes).getRequest();
        String context = request == null ? null : request.getHeader(CommonConstant.MYTH_TRANSACTION_CONTEXT);
        if (StringUtils.isNoneBlank(context)) {
            mythTransactionContext =
                    GsonUtils.getInstance().fromJson(context, MythTransactionContext.class);
        }
    }
    return mythTransactionAspectService.invoke(mythTransactionContext, pjp);
}
 
开发者ID:yu199195,项目名称:myth,代码行数:18,代码来源:SpringCloudMythTransactionInterceptor.java

示例9: findUser

import org.springframework.web.context.request.RequestAttributes; //导入依赖的package包/类
protected User findUser() {
    try {
        RequestAttributes reqAttr = RequestContextHolder.currentRequestAttributes();

        if (reqAttr instanceof ServletRequestAttributes) {

            ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) reqAttr;

            HttpServletRequest request = servletRequestAttributes.getRequest();

            if (request != null) {
                Object obj = request.getAttribute(User.class.getName());
                if (obj instanceof User) {
                    return (User) obj;
                }
            }
        }
    } catch (IllegalStateException e) {
        log.debug("Unable to obtain request context user via RequestContextHolder.", e);
    }

    return null;
}
 
开发者ID:juiser,项目名称:juiser,代码行数:24,代码来源:RequestContextUser.java

示例10: getCurrentConnectionInformation

import org.springframework.web.context.request.RequestAttributes; //导入依赖的package包/类
/**
 * Returns current connection information, as derived from HTTP request stored in current thread.
 * May be null if the thread is not associated with any HTTP request (e.g. task threads, operations invoked from GUI but executing in background).
 */
public static HttpConnectionInformation getCurrentConnectionInformation() {
	RequestAttributes attr = RequestContextHolder.getRequestAttributes();
	if (!(attr instanceof ServletRequestAttributes)) {
		return null;
	}
	ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) attr;
	HttpServletRequest request = servletRequestAttributes.getRequest();
	if (request == null) {
		return null;
	}
	HttpConnectionInformation rv = new HttpConnectionInformation();
	HttpSession session = request.getSession(false);
	if (session != null) {
		rv.setSessionId(session.getId());
	}
	rv.setLocalHostName(request.getLocalName());
	rv.setRemoteHostAddress(getRemoteHostAddress(request));
	return rv;
}
 
开发者ID:Pardus-Engerek,项目名称:engerek,代码行数:24,代码来源:SecurityUtil.java

示例11: addErrorDetails

import org.springframework.web.context.request.RequestAttributes; //导入依赖的package包/类
private void addErrorDetails(Map<String, Object> errorAttributes,
		RequestAttributes requestAttributes, boolean includeStackTrace) {
	Throwable error = getError(requestAttributes);
	if (error != null) {
		while (error instanceof ServletException && error.getCause() != null) {
			error = ((ServletException) error).getCause();
		}
		errorAttributes.put("exception", error.getClass().getName());
		addErrorMessage(errorAttributes, error);
		if (includeStackTrace) {
			addStackTrace(errorAttributes, error);
		}
	}
	Object message = getAttribute(requestAttributes, "javax.servlet.error.message");
	if ((!StringUtils.isEmpty(message) || errorAttributes.get("message") == null)
			&& !(error instanceof BindingResult)) {
		errorAttributes.put("message",
				StringUtils.isEmpty(message) ? "No message available" : message);
	}
}
 
开发者ID:philwebb,项目名称:spring-boot-concourse,代码行数:21,代码来源:DefaultErrorAttributes.java

示例12: getError

import org.springframework.web.context.request.RequestAttributes; //导入依赖的package包/类
@Override
public Throwable getError(final RequestAttributes requestAttributes)
{
	Throwable exception = getAttribute(requestAttributes, REQUEST_ATTR_EXCEPTION);
	if (exception == null)
	{
		exception = getAttribute(requestAttributes, RequestDispatcher.ERROR_EXCEPTION);
	}

	if (exception != null)
	{
		exception = AdempiereException.extractCause(exception);
	}

	return exception;
}
 
开发者ID:metasfresh,项目名称:metasfresh-webui-api,代码行数:17,代码来源:WebuiExceptionHandler.java

示例13: listPhoto

import org.springframework.web.context.request.RequestAttributes; //导入依赖的package包/类
/**
    * 사진 목록 조회 Service interface 호출 및 결과를 반환한다.
    * 
    * @param photoVO
    */
@IncludedInfo(name = "사진 정보", order = 10050, gid = 100)
   @RequestMapping(value = "/mbl/com/mpa/listPhoto.do")
@Secured("ROLE_ADMIN")
   public String listPhoto(
   		@ModelAttribute PhotoVO photoVO,
           ModelMap model) {
   	
       PaginationInfo paginationInfo = new PaginationInfo();
       photoVO.getSearchVO().fillPageInfo(paginationInfo);

       model.addAttribute("resultList", photoService.selectPhotoList(photoVO));
       int totCnt = photoService.selectPhotoListCnt(photoVO);

       photoVO.getSearchVO().setTotalRecordCount(totCnt);
       paginationInfo.setTotalRecordCount(totCnt);

       model.addAttribute(paginationInfo);

	RequestContextHolder.getRequestAttributes().setAttribute("jspPrefix", "aramframework/mbl", RequestAttributes.SCOPE_REQUEST);
	return WebUtil.adjustViewName("/com/mpa/PhotoList");
   }
 
开发者ID:aramsoft,项目名称:aramcomp,代码行数:27,代码来源:PhotoController.java

示例14: setDirectUrlToModel

import org.springframework.web.context.request.RequestAttributes; //导入依赖的package包/类
private void setDirectUrlToModel(BoardVO boardVO, ModelMap model) {
	
	RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();

	String trgetId = (String) requestAttributes.getAttribute("curTrgetId", RequestAttributes.SCOPE_REQUEST);
	String contextUrl = (String) requestAttributes.getAttribute("contextUrl", RequestAttributes.SCOPE_REQUEST);
	String directUrl = "";
	if( trgetId != null 
			&& trgetId != "" 
			&& trgetId.indexOf("CMMNTY_") != -1) {
		String cmmntyId = WebUtil.getPathId(trgetId);
		directUrl = contextUrl + "/content/apps/"+cmmntyId+"/board/"+boardVO.getPathId()+"/article/"+boardVO.getNttId();
	} else {
		directUrl = contextUrl + "/content/board/"+boardVO.getPathId()+"/article/"+ boardVO.getNttId();
	}
	model.addAttribute("directUrl", directUrl);
}
 
开发者ID:aramsoft,项目名称:aramcomp,代码行数:18,代码来源:BBSBoardController.java

示例15: errorAttributes

import org.springframework.web.context.request.RequestAttributes; //导入依赖的package包/类
/**
 * 自定义ErrorAttributes,存储{@link com.easycodebox.common.error.CodeMsg} 属性
 */
@Bean
public ErrorAttributes errorAttributes() {
	return new DefaultErrorAttributes() {
		@Override
		public Map<String, Object> getErrorAttributes(RequestAttributes requestAttributes, boolean includeStackTrace) {
			Map<String, Object> attributes = super.getErrorAttributes(requestAttributes, includeStackTrace);
			Throwable error = getError(requestAttributes);
			if (error instanceof ErrorContext) {
				ErrorContext ec = (ErrorContext) error;
				if (ec.getError() != null) {
					attributes.put("code", ec.getError().getCode());
					attributes.put("msg", ec.getError().getMsg());
					attributes.put("data", ec.getError().getData());
				}
			}
			return attributes;
		}
	};
}
 
开发者ID:easycodebox,项目名称:easycode,代码行数:23,代码来源:SpringMvcConfig.java


注:本文中的org.springframework.web.context.request.RequestAttributes类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。