下面列出了org.springframework.web.context.request.RequestContextHolder#resetRequestAttributes ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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();
}
};
}
@Override
public Runnable decorate(Runnable runnable) {
RequestAttributes context = RequestContextHolder.currentRequestAttributes();
return () -> {
try {
RequestContextHolder.setRequestAttributes(context);
runnable.run();
} finally {
RequestContextHolder.resetRequestAttributes();
}
};
}
@Override
public T call() throws Exception {
try {
RequestContextHolder.setRequestAttributes(requestAttributes);
return target.call();
}
finally {
RequestContextHolder.resetRequestAttributes();
}
}
@Override
public T call() throws Exception {
try {
RequestContextHolder.setRequestAttributes(requestAttributes);
return target.call();
} finally {
RequestContextHolder.resetRequestAttributes();
}
}
/**
* @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();
}
@Override
public T call() throws Exception {
try {
RequestContextHolder.setRequestAttributes(requestAttributes);
return target.call();
} finally {
RequestContextHolder.resetRequestAttributes();
}
}
@Override
public void run() {
try {
RequestContextHolder.setRequestAttributes(requestAttributes);
onRun();
} finally {
if (Thread.currentThread() != thread) {
RequestContextHolder.resetRequestAttributes();
}
thread = null;
}
}
@Override
public void run() {
try {
RequestContextHolder.setRequestAttributes(requestAttributes);
onRun();
} finally {
if (Thread.currentThread() != thread) {
RequestContextHolder.resetRequestAttributes();
}
thread = null;
}
}
@After
public void resetRequestContextHolder() {
RequestContextHolder.resetRequestAttributes();
}
@After
public void teardown() {
RequestContextHolder.resetRequestAttributes();
}
@After
public void reset() {
RequestContextHolder.resetRequestAttributes();
}
private void resetContextHolders() {
LocaleContextHolder.resetLocaleContext();
RequestContextHolder.resetRequestAttributes();
}
@After
public void teardown() {
RequestContextHolder.resetRequestAttributes();
}
@After
public void reset() {
RequestContextHolder.resetRequestAttributes();
}
@After
public void tearDown() throws Exception {
RequestContextHolder.resetRequestAttributes();
}
@After
public void tearDown() throws Exception {
RequestContextHolder.resetRequestAttributes();
}
@After
public void teardown() {
RequestContextHolder.resetRequestAttributes();
}
@After
public void resetRequestContextHolder() {
RequestContextHolder.resetRequestAttributes();
}
@After
public void teardown() {
RequestContextHolder.resetRequestAttributes();
}
@Before
public void init() {
servletContext = new MockServletContext();
request = new MockHttpServletRequest(servletContext);
RequestContextHolder.resetRequestAttributes();
}