Java Code Examples for org.springframework.web.context.request.RequestContextHolder#resetRequestAttributes()

The following examples show how to use org.springframework.web.context.request.RequestContextHolder#resetRequestAttributes() . 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: RequestContextDecorator.java    From Milkomeda with MIT License 6 votes vote down vote up
@Override
public Runnable decorate(Runnable runnable) {
    RequestAttributes context;
    try {
        context = RequestContextHolder.currentRequestAttributes();
    } catch (Exception e) {
        return runnable;
    }
    RequestAttributes finalContext = context;
    return () -> {
        try {
            RequestContextHolder.setRequestAttributes(finalContext);
            runnable.run();
        } finally {
            RequestContextHolder.resetRequestAttributes();
        }
    };
}
 
Example 2
Source File: ContextCopyingDecorator.java    From staffjoy with MIT License 5 votes vote down vote up
@Override
public Runnable decorate(Runnable runnable) {
    RequestAttributes context = RequestContextHolder.currentRequestAttributes();
    return () -> {
        try {
            RequestContextHolder.setRequestAttributes(context);
            runnable.run();
        } finally {
            RequestContextHolder.resetRequestAttributes();
        }
    };
}
 
Example 3
Source File: RequestAwareRunnable.java    From mogu_blog_v2 with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    try {
        RequestContextHolder.setRequestAttributes(requestAttributes);
        onRun();
    } finally {
        if (Thread.currentThread() != thread) {
            RequestContextHolder.resetRequestAttributes();
        }
        thread = null;
    }
}
 
Example 4
Source File: RequestAwareRunnable.java    From mogu_blog_v2 with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    try {
        RequestContextHolder.setRequestAttributes(requestAttributes);
        onRun();
    } finally {
        if (Thread.currentThread() != thread) {
            RequestContextHolder.resetRequestAttributes();
        }
        thread = null;
    }
}
 
Example 5
Source File: FeignHystrixConcurrencyStrategy.java    From sophia_scaffolding with Apache License 2.0 5 votes vote down vote up
@Override
public T call() throws Exception {
    try {
        RequestContextHolder.setRequestAttributes(requestAttributes);
        return target.call();
    } finally {
        RequestContextHolder.resetRequestAttributes();
    }
}
 
Example 6
Source File: RequestAttributeHystrixConcurrencyStrategy.java    From Taroco with Apache License 2.0 5 votes vote down vote up
@Override
public T call() throws Exception {
    try {
        RequestContextHolder.setRequestAttributes(requestAttributes);
        return target.call();
    }
    finally {
        RequestContextHolder.resetRequestAttributes();
    }
}
 
Example 7
Source File: RequestAttributeHystrixConcurrencyStrategy.java    From spring-cloud-yes with Apache License 2.0 5 votes vote down vote up
@Override
public T call() throws Exception {
    try {
        RequestContextHolder.setRequestAttributes(requestAttributes);
        return target.call();
    } finally {
        RequestContextHolder.resetRequestAttributes();
    }
}
 
Example 8
Source File: ServletTestExecutionListenerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * @since 4.3
 */
@Test
public void activateListenerWithoutExistingRequestAttributes() throws Exception {
	BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(NoAtWebAppConfigWebTestCase.class);
	given(testContext.getAttribute(ServletTestExecutionListener.ACTIVATE_LISTENER)).willReturn(true);

	RequestContextHolder.resetRequestAttributes();
	listener.beforeTestClass(testContext);
	assertRequestAttributesDoNotExist();

	assertWebAppConfigTestCase();
}
 
Example 9
Source File: RequestMappingHandlerAdapterIntegrationTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@After
public void teardown() {
	RequestContextHolder.resetRequestAttributes();
}
 
Example 10
Source File: ContentNegotiatingViewResolverTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@After
public void resetRequestContextHolder() {
	RequestContextHolder.resetRequestAttributes();
}
 
Example 11
Source File: ExpressionValueMethodArgumentResolverTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@After
public void teardown() {
	RequestContextHolder.resetRequestAttributes();
}
 
Example 12
Source File: ClassPathBeanDefinitionScannerScopeIntegrationTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@After
public void tearDown() throws Exception {
	RequestContextHolder.resetRequestAttributes();
}
 
Example 13
Source File: ClassPathBeanDefinitionScannerScopeIntegrationTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@After
public void tearDown() throws Exception {
	RequestContextHolder.resetRequestAttributes();
}
 
Example 14
Source File: RequestHeaderMethodArgumentResolverTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@After
public void reset() {
	RequestContextHolder.resetRequestAttributes();
}
 
Example 15
Source File: ExpressionValueMethodArgumentResolverTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@After
public void teardown() {
	RequestContextHolder.resetRequestAttributes();
}
 
Example 16
Source File: RequestContextFilter.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private void resetContextHolders() {
	LocaleContextHolder.resetLocaleContext();
	RequestContextHolder.resetRequestAttributes();
}
 
Example 17
Source File: MvcUriComponentsBuilderTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@After
public void reset() {
	RequestContextHolder.resetRequestAttributes();
}
 
Example 18
Source File: RequestMappingHandlerAdapterIntegrationTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@After
public void teardown() {
	RequestContextHolder.resetRequestAttributes();
}
 
Example 19
Source File: ContentNegotiatingViewResolverTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@After
public void resetRequestContextHolder() {
	RequestContextHolder.resetRequestAttributes();
}
 
Example 20
Source File: WebMvcUtilsTest.java    From spring-webmvc-support with GNU General Public License v3.0 3 votes vote down vote up
@Before
public void init() {

    servletContext = new MockServletContext();

    request = new MockHttpServletRequest(servletContext);

    RequestContextHolder.resetRequestAttributes();

}