Java Code Examples for org.springframework.web.context.request.RequestAttributes#getAttribute()

The following examples show how to use org.springframework.web.context.request.RequestAttributes#getAttribute() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExceptionSupressingErrorAttributes.java    From restdocs-raml with MIT License 5 votes vote down vote up
@Override
public Map<String, Object> getErrorAttributes(RequestAttributes requestAttributes,
		boolean includeStackTrace) {
	Map<String, Object> errorAttributes = super.getErrorAttributes(requestAttributes, includeStackTrace);
	errorAttributes.remove("exception");
	Object message = requestAttributes.getAttribute("javax.servlet.error.message", RequestAttributes.SCOPE_REQUEST);
	if (message != null) {
		errorAttributes.put("message", message);
	}
	return errorAttributes;
}
 
Example 2
Source File: WxWebUtils.java    From FastBootWeixin with Apache License 2.0 5 votes vote down vote up
public static WxRequest getWxRequestFromRequest() {
    RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
    if (requestAttributes != null) {
        return (WxRequest) requestAttributes.getAttribute(WX_REQUEST_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);
    }
    return null;
}
 
Example 3
Source File: WxWebUtils.java    From FastBootWeixin with Apache License 2.0 5 votes vote down vote up
public static WxWebUser getWxWebUserFromSession() {
    RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
    if (requestAttributes != null) {
        return (WxWebUser) requestAttributes.getAttribute(WX_SESSION_USER, RequestAttributes.SCOPE_SESSION);
    }
    return null;
}
 
Example 4
Source File: AuthEnvs.java    From onetwo with Apache License 2.0 5 votes vote down vote up
public static AuthEnv getCurrent() {
	RequestAttributes req = RequestContextHolder.getRequestAttributes();
	if (req!=null) {
		return (AuthEnv) req.getAttribute(AUTH_ENV_KEY, RequestAttributes.SCOPE_REQUEST);
	} else {
		return CURRENT_ENVS.get();
	}
}
 
Example 5
Source File: ServletTestExecutionListenerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private void assertAttributeExists() {
	RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
	assertNotNull("request attributes should exist", requestAttributes);
	Object setUpOutsideOfStel = requestAttributes.getAttribute(SET_UP_OUTSIDE_OF_STEL,
		RequestAttributes.SCOPE_REQUEST);
	assertNotNull(SET_UP_OUTSIDE_OF_STEL + " should exist as a request attribute", setUpOutsideOfStel);
}
 
Example 6
Source File: ServletTestExecutionListenerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private void assertAttributeDoesNotExist() {
	RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
	assertNotNull("request attributes should exist", requestAttributes);
	Object setUpOutsideOfStel = requestAttributes.getAttribute(SET_UP_OUTSIDE_OF_STEL,
		RequestAttributes.SCOPE_REQUEST);
	assertNull(SET_UP_OUTSIDE_OF_STEL + " should NOT exist as a request attribute", setUpOutsideOfStel);
}
 
Example 7
Source File: CurrentTenantIdentifierResolverImpl.java    From multitenancy with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String resolveCurrentTenantIdentifier() {
	RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
	if (requestAttributes != null) {
		String identifier = (String) requestAttributes.getAttribute("CURRENT_TENANT_IDENTIFIER",RequestAttributes.SCOPE_REQUEST);
		if (identifier != null) {
			return identifier;
		}
	}
	return DEFAULT_TENANT_ID;
}
 
Example 8
Source File: RequestCorrelationUtils.java    From request-correlation-spring-cloud-starter with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the current request correlation id if present.
 *
 * @return the correlation id or {@code null}
 */
@SuppressWarnings("unchecked")
public static String getCurrentCorrelationId() {

    final RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
    if (requestAttributes != null) {
        Object correlationId = requestAttributes
                .getAttribute(RequestCorrelationConsts.ATTRIBUTE_NAME, RequestAttributes.SCOPE_REQUEST);

        if (correlationId instanceof RequestCorrelation) {
            return ((RequestCorrelation) correlationId).getRequestId();
        }
    }
    return null;
}
 
Example 9
Source File: PostBackManager.java    From sinavi-jfw with Apache License 2.0 4 votes vote down vote up
/**
 * 現在のリクエスト・スコープで有効な{@link PostBackManager}インスタンスを返却します。
 * @return 現在のリクエスト・スコープで有効な{@link PostBackManager}インスタンス
 */
public static PostBackManager getCurrentPostBackManager() {
    RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
    return (PostBackManager) requestAttributes.getAttribute(STORE_KEY_TO_REQUEST, RequestAttributes.SCOPE_REQUEST);
}
 
Example 10
Source File: ServletTestExecutionListenerTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private void assertSetUpOutsideOfStelAttributeExists() {
	RequestAttributes requestAttributes = assertRequestAttributesExist();
	Object setUpOutsideOfStel = requestAttributes.getAttribute(SET_UP_OUTSIDE_OF_STEL,
		RequestAttributes.SCOPE_REQUEST);
	assertNotNull(SET_UP_OUTSIDE_OF_STEL + " should exist as a request attribute", setUpOutsideOfStel);
}
 
Example 11
Source File: Location.java    From bearchoke with Apache License 2.0 4 votes vote down vote up
/**
 * Get the location of the user associated with the current request, if resolvable.
 */
public static Location getCurrentLocation() {
	RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
	return attributes != null ? (Location) attributes.getAttribute(UserLocationHandlerInterceptor.USER_LOCATION_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST) : null;
}
 
Example 12
Source File: PostBackManager.java    From sinavi-jfw with Apache License 2.0 4 votes vote down vote up
/**
 * 現在のリクエスト・スコープで有効な{@link BindingResult}インスタンスを返却します。
 * @return 現在のリクエスト・スコープで有効な{@link BindingResult}インスタンス
 */
public static BindingResult getCurrentBindingResult() {
    RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
    return (BindingResult) requestAttributes.getAttribute(BINDING_RESULT_KEY, RequestAttributes.SCOPE_REQUEST);
}
 
Example 13
Source File: PostBackManager.java    From sinavi-jfw with Apache License 2.0 4 votes vote down vote up
/**
 * 現在のリクエスト・スコープで有効な{@link MessageContext}インスタンスを返却します。
 * @return 現在のリクエスト・スコープで有効な{@link MessageContext}インスタンス
 */
public static MessageContext getMessageContext() {
    RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
    return (MessageContext) requestAttributes.getAttribute(MessageContext.MESSAGE_CONTEXT_ATTRIBUTE_KEY, RequestAttributes.SCOPE_REQUEST);
}
 
Example 14
Source File: WebuiExceptionHandler.java    From metasfresh-webui-api-legacy with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private static <T> T getAttribute(final RequestAttributes requestAttributes, final String name)
{
	return (T)requestAttributes.getAttribute(name, RequestAttributes.SCOPE_REQUEST);
}
 
Example 15
Source File: ServletTestExecutionListenerTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
private void assertSetUpOutsideOfStelAttributeDoesNotExist() {
	RequestAttributes requestAttributes = assertRequestAttributesExist();
	Object setUpOutsideOfStel = requestAttributes.getAttribute(SET_UP_OUTSIDE_OF_STEL,
		RequestAttributes.SCOPE_REQUEST);
	assertNull(SET_UP_OUTSIDE_OF_STEL + " should NOT exist as a request attribute", setUpOutsideOfStel);
}
 
Example 16
Source File: ServletTestExecutionListenerTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
private void assertSetUpOutsideOfStelAttributeExists() {
	RequestAttributes requestAttributes = assertRequestAttributesExist();
	Object setUpOutsideOfStel = requestAttributes.getAttribute(SET_UP_OUTSIDE_OF_STEL,
		RequestAttributes.SCOPE_REQUEST);
	assertNotNull(SET_UP_OUTSIDE_OF_STEL + " should exist as a request attribute", setUpOutsideOfStel);
}
 
Example 17
Source File: MyErrorController.java    From spring-cloud-yes with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private <T> T getAttribute(RequestAttributes requestAttributes, String name) {
    return (T) requestAttributes.getAttribute(name, RequestAttributes.SCOPE_REQUEST);
}
 
Example 18
Source File: ServletTestExecutionListenerTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private void assertSetUpOutsideOfStelAttributeDoesNotExist() {
	RequestAttributes requestAttributes = assertRequestAttributesExist();
	Object setUpOutsideOfStel = requestAttributes.getAttribute(SET_UP_OUTSIDE_OF_STEL,
		RequestAttributes.SCOPE_REQUEST);
	assertNull(SET_UP_OUTSIDE_OF_STEL + " should NOT exist as a request attribute", setUpOutsideOfStel);
}
 
Example 19
Source File: PostBackManager.java    From sinavi-jfw with Apache License 2.0 2 votes vote down vote up
/**
 * <p>
 * ポストバック処理をトリガーする例外でるかどうかを判定します。<br/>
 * </p>
 * @param t コントローラのハンドラ・メソッドがスローした例外
 * @return ポストバック処理をトリガーする例外である場合 {@code true}
 */
public static boolean isPostBackTargetException(Throwable t) {
    RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
    PostBackManager instance = (PostBackManager) requestAttributes.getAttribute(STORE_KEY_TO_REQUEST, RequestAttributes.SCOPE_REQUEST);
    return instance.isTargetException(t);
}
 
Example 20
Source File: PostBackManager.java    From sinavi-jfw with Apache License 2.0 2 votes vote down vote up
/**
 * 現在のリクエストに対応するコントローラのハンドラーメソッドに設定されている例外発生時のアクション定義({@link PostBack#Action}注釈)
 * から、指定した例外に対応するアクションが定義を検索し返却します。
 * @param t 例外
 * @return 例外発生時のアクション定義({@link PostBack#Action}注釈)
 */
public static PostBack.Action getPostBackAction(Throwable t) {
    RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
    PostBackManager instance = (PostBackManager) requestAttributes.getAttribute(STORE_KEY_TO_REQUEST, RequestAttributes.SCOPE_REQUEST);
    return instance.getInternalPostBackAction(t);
}