本文整理匯總了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;
}
示例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);
}
示例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";
}
示例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;
}
}
示例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;
}
示例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);
}
示例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();
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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");
}
示例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);
}
示例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;
}
};
}