Polishing
This commit is contained in:
parent
02195f5abf
commit
acf511ac0e
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -22,6 +22,7 @@ import java.util.concurrent.Future;
|
||||||
* Extend {@link Future} with the capability to accept completion callbacks.
|
* Extend {@link Future} with the capability to accept completion callbacks.
|
||||||
* If the future has completed when the callback is added, the callback is
|
* If the future has completed when the callback is added, the callback is
|
||||||
* triggered immediately.
|
* triggered immediately.
|
||||||
|
*
|
||||||
* <p>Inspired by {@code com.google.common.util.concurrent.ListenableFuture}.
|
* <p>Inspired by {@code com.google.common.util.concurrent.ListenableFuture}.
|
||||||
*
|
*
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
|
|
|
@ -32,7 +32,6 @@ import static org.mockito.Mockito.*;
|
||||||
* @author Mattias Severson
|
* @author Mattias Severson
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
|
||||||
public class SettableListenableFutureTests {
|
public class SettableListenableFutureTests {
|
||||||
|
|
||||||
private final SettableListenableFuture<String> settableListenableFuture = new SettableListenableFuture<>();
|
private final SettableListenableFuture<String> settableListenableFuture = new SettableListenableFuture<>();
|
||||||
|
@ -266,20 +265,20 @@ public class SettableListenableFutureTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cancelWithMayInterruptIfRunningTrueCallsOverriddenMethod() {
|
public void cancelWithMayInterruptIfRunningTrueCallsOverriddenMethod() {
|
||||||
InterruptableSettableListenableFuture tested = new InterruptableSettableListenableFuture();
|
InterruptibleSettableListenableFuture interruptibleFuture = new InterruptibleSettableListenableFuture();
|
||||||
assertTrue(tested.cancel(true));
|
assertTrue(interruptibleFuture.cancel(true));
|
||||||
assertTrue(tested.calledInterruptTask());
|
assertTrue(interruptibleFuture.calledInterruptTask());
|
||||||
assertTrue(tested.isCancelled());
|
assertTrue(interruptibleFuture.isCancelled());
|
||||||
assertTrue(tested.isDone());
|
assertTrue(interruptibleFuture.isDone());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cancelWithMayInterruptIfRunningFalseDoesNotCallOverriddenMethod() {
|
public void cancelWithMayInterruptIfRunningFalseDoesNotCallOverriddenMethod() {
|
||||||
InterruptableSettableListenableFuture tested = new InterruptableSettableListenableFuture();
|
InterruptibleSettableListenableFuture interruptibleFuture = new InterruptibleSettableListenableFuture();
|
||||||
assertTrue(tested.cancel(false));
|
assertTrue(interruptibleFuture.cancel(false));
|
||||||
assertFalse(tested.calledInterruptTask());
|
assertFalse(interruptibleFuture.calledInterruptTask());
|
||||||
assertTrue(tested.isCancelled());
|
assertTrue(interruptibleFuture.isCancelled());
|
||||||
assertTrue(tested.isDone());
|
assertTrue(interruptibleFuture.isDone());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -350,6 +349,7 @@ public class SettableListenableFutureTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||||
public void cancelDoesNotNotifyCallbacksOnSet() {
|
public void cancelDoesNotNotifyCallbacksOnSet() {
|
||||||
ListenableFutureCallback callback = mock(ListenableFutureCallback.class);
|
ListenableFutureCallback callback = mock(ListenableFutureCallback.class);
|
||||||
settableListenableFuture.addCallback(callback);
|
settableListenableFuture.addCallback(callback);
|
||||||
|
@ -366,6 +366,7 @@ public class SettableListenableFutureTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||||
public void cancelDoesNotNotifyCallbacksOnSetException() {
|
public void cancelDoesNotNotifyCallbacksOnSetException() {
|
||||||
ListenableFutureCallback callback = mock(ListenableFutureCallback.class);
|
ListenableFutureCallback callback = mock(ListenableFutureCallback.class);
|
||||||
settableListenableFuture.addCallback(callback);
|
settableListenableFuture.addCallback(callback);
|
||||||
|
@ -382,7 +383,7 @@ public class SettableListenableFutureTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class InterruptableSettableListenableFuture extends SettableListenableFuture<String> {
|
private static class InterruptibleSettableListenableFuture extends SettableListenableFuture<String> {
|
||||||
|
|
||||||
private boolean interrupted = false;
|
private boolean interrupted = false;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -154,7 +154,7 @@ public abstract class DataSourceUtils {
|
||||||
}
|
}
|
||||||
con.setReadOnly(true);
|
con.setReadOnly(true);
|
||||||
}
|
}
|
||||||
catch (SQLException ex) {
|
catch (SQLException | RuntimeException ex) {
|
||||||
Throwable exToCheck = ex;
|
Throwable exToCheck = ex;
|
||||||
while (exToCheck != null) {
|
while (exToCheck != null) {
|
||||||
if (exToCheck.getClass().getSimpleName().contains("Timeout")) {
|
if (exToCheck.getClass().getSimpleName().contains("Timeout")) {
|
||||||
|
@ -166,18 +166,6 @@ public abstract class DataSourceUtils {
|
||||||
// "read-only not supported" SQLException -> ignore, it's just a hint anyway
|
// "read-only not supported" SQLException -> ignore, it's just a hint anyway
|
||||||
logger.debug("Could not set JDBC Connection read-only", ex);
|
logger.debug("Could not set JDBC Connection read-only", ex);
|
||||||
}
|
}
|
||||||
catch (RuntimeException ex) {
|
|
||||||
Throwable exToCheck = ex;
|
|
||||||
while (exToCheck != null) {
|
|
||||||
if (exToCheck.getClass().getSimpleName().contains("Timeout")) {
|
|
||||||
// Assume it's a connection timeout that would otherwise get lost: e.g. from Hibernate
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
exToCheck = exToCheck.getCause();
|
|
||||||
}
|
|
||||||
// "read-only not supported" UnsupportedOperationException -> ignore, it's just a hint anyway
|
|
||||||
logger.debug("Could not set JDBC Connection read-only", ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply specific isolation level, if any.
|
// Apply specific isolation level, if any.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -226,8 +226,7 @@ public class JmsTransactionManager extends AbstractPlatformTransactionManager
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doResume(Object transaction, Object suspendedResources) {
|
protected void doResume(Object transaction, Object suspendedResources) {
|
||||||
JmsResourceHolder conHolder = (JmsResourceHolder) suspendedResources;
|
TransactionSynchronizationManager.bindResource(getConnectionFactory(), suspendedResources);
|
||||||
TransactionSynchronizationManager.bindResource(getConnectionFactory(), conHolder);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -144,7 +144,6 @@ public class OpenSessionInViewInterceptor implements AsyncWebRequestInterceptor
|
||||||
(SessionHolder) TransactionSynchronizationManager.unbindResource(getSessionFactory());
|
(SessionHolder) TransactionSynchronizationManager.unbindResource(getSessionFactory());
|
||||||
logger.debug("Closing Hibernate Session in OpenSessionInViewInterceptor");
|
logger.debug("Closing Hibernate Session in OpenSessionInViewInterceptor");
|
||||||
SessionFactoryUtils.closeSession(sessionHolder.getSession());
|
SessionFactoryUtils.closeSession(sessionHolder.getSession());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2015 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -374,14 +374,10 @@ public abstract class AbstractPlatformTransactionManager implements PlatformTran
|
||||||
prepareSynchronization(status, definition);
|
prepareSynchronization(status, definition);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
catch (RuntimeException ex) {
|
catch (RuntimeException | Error ex) {
|
||||||
resume(null, suspendedResources);
|
resume(null, suspendedResources);
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
catch (Error err) {
|
|
||||||
resume(null, suspendedResources);
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Create "empty" transaction: no actual transaction, but potentially synchronization.
|
// Create "empty" transaction: no actual transaction, but potentially synchronization.
|
||||||
|
@ -430,14 +426,10 @@ public abstract class AbstractPlatformTransactionManager implements PlatformTran
|
||||||
prepareSynchronization(status, definition);
|
prepareSynchronization(status, definition);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
catch (RuntimeException beginEx) {
|
catch (RuntimeException | Error beginEx) {
|
||||||
resumeAfterBeginException(transaction, suspendedResources, beginEx);
|
resumeAfterBeginException(transaction, suspendedResources, beginEx);
|
||||||
throw beginEx;
|
throw beginEx;
|
||||||
}
|
}
|
||||||
catch (Error beginErr) {
|
|
||||||
resumeAfterBeginException(transaction, suspendedResources, beginErr);
|
|
||||||
throw beginErr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (definition.getPropagationBehavior() == TransactionDefinition.PROPAGATION_NESTED) {
|
if (definition.getPropagationBehavior() == TransactionDefinition.PROPAGATION_NESTED) {
|
||||||
|
@ -589,16 +581,11 @@ public abstract class AbstractPlatformTransactionManager implements PlatformTran
|
||||||
return new SuspendedResourcesHolder(
|
return new SuspendedResourcesHolder(
|
||||||
suspendedResources, suspendedSynchronizations, name, readOnly, isolationLevel, wasActive);
|
suspendedResources, suspendedSynchronizations, name, readOnly, isolationLevel, wasActive);
|
||||||
}
|
}
|
||||||
catch (RuntimeException ex) {
|
catch (RuntimeException | Error ex) {
|
||||||
// doSuspend failed - original transaction is still active...
|
// doSuspend failed - original transaction is still active...
|
||||||
doResumeSynchronization(suspendedSynchronizations);
|
doResumeSynchronization(suspendedSynchronizations);
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
catch (Error err) {
|
|
||||||
// doSuspend failed - original transaction is still active...
|
|
||||||
doResumeSynchronization(suspendedSynchronizations);
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (transaction != null) {
|
else if (transaction != null) {
|
||||||
// Transaction active but no synchronization active.
|
// Transaction active but no synchronization active.
|
||||||
|
@ -650,14 +637,10 @@ public abstract class AbstractPlatformTransactionManager implements PlatformTran
|
||||||
try {
|
try {
|
||||||
resume(transaction, suspendedResources);
|
resume(transaction, suspendedResources);
|
||||||
}
|
}
|
||||||
catch (RuntimeException resumeEx) {
|
catch (RuntimeException | Error resumeEx) {
|
||||||
logger.error(exMessage, beginEx);
|
logger.error(exMessage, beginEx);
|
||||||
throw resumeEx;
|
throw resumeEx;
|
||||||
}
|
}
|
||||||
catch (Error resumeErr) {
|
|
||||||
logger.error(exMessage, beginEx);
|
|
||||||
throw resumeErr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -782,20 +765,13 @@ public abstract class AbstractPlatformTransactionManager implements PlatformTran
|
||||||
}
|
}
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
catch (RuntimeException ex) {
|
catch (RuntimeException | Error ex) {
|
||||||
if (!beforeCompletionInvoked) {
|
if (!beforeCompletionInvoked) {
|
||||||
triggerBeforeCompletion(status);
|
triggerBeforeCompletion(status);
|
||||||
}
|
}
|
||||||
doRollbackOnCommitException(status, ex);
|
doRollbackOnCommitException(status, ex);
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
catch (Error err) {
|
|
||||||
if (!beforeCompletionInvoked) {
|
|
||||||
triggerBeforeCompletion(status);
|
|
||||||
}
|
|
||||||
doRollbackOnCommitException(status, err);
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Trigger afterCommit callbacks, with an exception thrown there
|
// Trigger afterCommit callbacks, with an exception thrown there
|
||||||
// propagated to callers but the transaction still considered as committed.
|
// propagated to callers but the transaction still considered as committed.
|
||||||
|
@ -869,14 +845,10 @@ public abstract class AbstractPlatformTransactionManager implements PlatformTran
|
||||||
logger.debug("Should roll back transaction but cannot - no transaction available");
|
logger.debug("Should roll back transaction but cannot - no transaction available");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (RuntimeException ex) {
|
catch (RuntimeException | Error ex) {
|
||||||
triggerAfterCompletion(status, TransactionSynchronization.STATUS_UNKNOWN);
|
triggerAfterCompletion(status, TransactionSynchronization.STATUS_UNKNOWN);
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
catch (Error err) {
|
|
||||||
triggerAfterCompletion(status, TransactionSynchronization.STATUS_UNKNOWN);
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
triggerAfterCompletion(status, TransactionSynchronization.STATUS_ROLLED_BACK);
|
triggerAfterCompletion(status, TransactionSynchronization.STATUS_ROLLED_BACK);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
|
@ -906,16 +878,11 @@ public abstract class AbstractPlatformTransactionManager implements PlatformTran
|
||||||
doSetRollbackOnly(status);
|
doSetRollbackOnly(status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (RuntimeException rbex) {
|
catch (RuntimeException | Error rbex) {
|
||||||
logger.error("Commit exception overridden by rollback exception", ex);
|
logger.error("Commit exception overridden by rollback exception", ex);
|
||||||
triggerAfterCompletion(status, TransactionSynchronization.STATUS_UNKNOWN);
|
triggerAfterCompletion(status, TransactionSynchronization.STATUS_UNKNOWN);
|
||||||
throw rbex;
|
throw rbex;
|
||||||
}
|
}
|
||||||
catch (Error rberr) {
|
|
||||||
logger.error("Commit exception overridden by rollback exception", ex);
|
|
||||||
triggerAfterCompletion(status, TransactionSynchronization.STATUS_UNKNOWN);
|
|
||||||
throw rberr;
|
|
||||||
}
|
|
||||||
triggerAfterCompletion(status, TransactionSynchronization.STATUS_ROLLED_BACK);
|
triggerAfterCompletion(status, TransactionSynchronization.STATUS_ROLLED_BACK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -118,9 +118,7 @@ public class ContentNegotiationManager implements ContentNegotiationStrategy, Me
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<MediaType> resolveMediaTypes(NativeWebRequest request)
|
public List<MediaType> resolveMediaTypes(NativeWebRequest request) throws HttpMediaTypeNotAcceptableException {
|
||||||
throws HttpMediaTypeNotAcceptableException {
|
|
||||||
|
|
||||||
for (ContentNegotiationStrategy strategy : this.strategies) {
|
for (ContentNegotiationStrategy strategy : this.strategies) {
|
||||||
List<MediaType> mediaTypes = strategy.resolveMediaTypes(request);
|
List<MediaType> mediaTypes = strategy.resolveMediaTypes(request);
|
||||||
if (mediaTypes.isEmpty() || mediaTypes.equals(MEDIA_TYPE_ALL)) {
|
if (mediaTypes.isEmpty() || mediaTypes.equals(MEDIA_TYPE_ALL)) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -454,10 +454,13 @@ public abstract class ResponseEntityExceptionHandler {
|
||||||
HttpServletRequest request = servletRequest.getNativeRequest(HttpServletRequest.class);
|
HttpServletRequest request = servletRequest.getNativeRequest(HttpServletRequest.class);
|
||||||
HttpServletResponse response = servletRequest.getNativeResponse(HttpServletResponse.class);
|
HttpServletResponse response = servletRequest.getNativeResponse(HttpServletResponse.class);
|
||||||
if (response.isCommitted()) {
|
if (response.isCommitted()) {
|
||||||
logger.error("Async timeout for " + request.getMethod() + " [" + request.getRequestURI() + "]");
|
if (logger.isErrorEnabled()) {
|
||||||
|
logger.error("Async timeout for " + request.getMethod() + " [" + request.getRequestURI() + "]");
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return handleExceptionInternal(ex, null, headers, status, webRequest);
|
return handleExceptionInternal(ex, null, headers, status, webRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -87,7 +87,7 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
||||||
ThemeChangeInterceptor interceptor4 = new ThemeChangeInterceptor();
|
ThemeChangeInterceptor interceptor4 = new ThemeChangeInterceptor();
|
||||||
interceptor4.setParamName("theme2");
|
interceptor4.setParamName("theme2");
|
||||||
UserRoleAuthorizationInterceptor interceptor5 = new UserRoleAuthorizationInterceptor();
|
UserRoleAuthorizationInterceptor interceptor5 = new UserRoleAuthorizationInterceptor();
|
||||||
interceptor5.setAuthorizedRoles(new String[] {"role1", "role2"});
|
interceptor5.setAuthorizedRoles("role1", "role2");
|
||||||
|
|
||||||
List<Object> interceptors = new ArrayList<>();
|
List<Object> interceptors = new ArrayList<>();
|
||||||
interceptors.add(interceptor5);
|
interceptors.add(interceptor5);
|
||||||
|
@ -100,8 +100,7 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
||||||
interceptors.add(new MyWebRequestInterceptor());
|
interceptors.add(new MyWebRequestInterceptor());
|
||||||
|
|
||||||
MutablePropertyValues pvs = new MutablePropertyValues();
|
MutablePropertyValues pvs = new MutablePropertyValues();
|
||||||
pvs.add(
|
pvs.add("mappings", "/view.do=viewHandler\n/locale.do=localeHandler\nloc.do=anotherLocaleHandler");
|
||||||
"mappings", "/view.do=viewHandler\n/locale.do=localeHandler\nloc.do=anotherLocaleHandler");
|
|
||||||
pvs.add("interceptors", interceptors);
|
pvs.add("interceptors", interceptors);
|
||||||
registerSingleton("myUrlMapping1", SimpleUrlHandlerMapping.class, pvs);
|
registerSingleton("myUrlMapping1", SimpleUrlHandlerMapping.class, pvs);
|
||||||
|
|
||||||
|
@ -124,7 +123,7 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
||||||
registerSingleton("noviewController", NoViewController.class);
|
registerSingleton("noviewController", NoViewController.class);
|
||||||
|
|
||||||
pvs = new MutablePropertyValues();
|
pvs = new MutablePropertyValues();
|
||||||
pvs.add("order", new Integer(0));
|
pvs.add("order", 0);
|
||||||
pvs.add("basename", "org.springframework.web.servlet.complexviews");
|
pvs.add("basename", "org.springframework.web.servlet.complexviews");
|
||||||
registerSingleton("viewResolver", ResourceBundleViewResolver.class, pvs);
|
registerSingleton("viewResolver", ResourceBundleViewResolver.class, pvs);
|
||||||
|
|
||||||
|
@ -150,8 +149,8 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
||||||
pvs = new MutablePropertyValues();
|
pvs = new MutablePropertyValues();
|
||||||
pvs.add("order", "1");
|
pvs.add("order", "1");
|
||||||
pvs.add("exceptionMappings",
|
pvs.add("exceptionMappings",
|
||||||
"java.lang.IllegalAccessException=failed2\n" +
|
"java.lang.IllegalAccessException=failed2\n" +
|
||||||
"ServletRequestBindingException=failed3");
|
"ServletRequestBindingException=failed3");
|
||||||
pvs.add("defaultErrorView", "failed0");
|
pvs.add("defaultErrorView", "failed0");
|
||||||
registerSingleton("exceptionResolver1", SimpleMappingExceptionResolver.class, pvs);
|
registerSingleton("exceptionResolver1", SimpleMappingExceptionResolver.class, pvs);
|
||||||
|
|
||||||
|
@ -237,11 +236,11 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static interface MyHandler {
|
public interface MyHandler {
|
||||||
|
|
||||||
public void doSomething(HttpServletRequest request) throws ServletException, IllegalAccessException;
|
void doSomething(HttpServletRequest request) throws ServletException, IllegalAccessException;
|
||||||
|
|
||||||
public long lastModified();
|
long lastModified();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -259,7 +258,8 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object delegate)
|
public ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object delegate)
|
||||||
throws ServletException, IllegalAccessException {
|
throws ServletException, IllegalAccessException {
|
||||||
|
|
||||||
((MyHandler) delegate).doSomething(request);
|
((MyHandler) delegate).doSomething(request);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -295,7 +295,8 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
|
||||||
throws ServletException {
|
throws ServletException {
|
||||||
|
|
||||||
if (request.getAttribute("test2") != null) {
|
if (request.getAttribute("test2") != null) {
|
||||||
throw new ServletException("Wrong interceptor order");
|
throw new ServletException("Wrong interceptor order");
|
||||||
}
|
}
|
||||||
|
@ -309,6 +310,7 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
||||||
public void postHandle(
|
public void postHandle(
|
||||||
HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView)
|
HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView)
|
||||||
throws ServletException {
|
throws ServletException {
|
||||||
|
|
||||||
if (request.getAttribute("test2x") != null) {
|
if (request.getAttribute("test2x") != null) {
|
||||||
throw new ServletException("Wrong interceptor order");
|
throw new ServletException("Wrong interceptor order");
|
||||||
}
|
}
|
||||||
|
@ -322,9 +324,13 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
||||||
public void afterCompletion(
|
public void afterCompletion(
|
||||||
HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
|
HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
|
||||||
throws ServletException {
|
throws ServletException {
|
||||||
|
|
||||||
if (request.getAttribute("test2y") != null) {
|
if (request.getAttribute("test2y") != null) {
|
||||||
throw new ServletException("Wrong interceptor order");
|
throw new ServletException("Wrong interceptor order");
|
||||||
}
|
}
|
||||||
|
if (request.getAttribute("test1y") == null) {
|
||||||
|
throw new ServletException("afterCompletion invoked twice");
|
||||||
|
}
|
||||||
request.removeAttribute("test1y");
|
request.removeAttribute("test1y");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -334,7 +340,8 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
|
||||||
throws ServletException {
|
throws ServletException {
|
||||||
|
|
||||||
if (request.getAttribute("test1x") == null) {
|
if (request.getAttribute("test1x") == null) {
|
||||||
throw new ServletException("Wrong interceptor order");
|
throw new ServletException("Wrong interceptor order");
|
||||||
}
|
}
|
||||||
|
@ -351,6 +358,7 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
||||||
public void postHandle(
|
public void postHandle(
|
||||||
HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView)
|
HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView)
|
||||||
throws ServletException {
|
throws ServletException {
|
||||||
|
|
||||||
if (request.getParameter("noView") != null) {
|
if (request.getParameter("noView") != null) {
|
||||||
modelAndView.clear();
|
modelAndView.clear();
|
||||||
}
|
}
|
||||||
|
@ -367,9 +375,13 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
||||||
public void afterCompletion(
|
public void afterCompletion(
|
||||||
HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
|
HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
if (request.getAttribute("test1y") == null) {
|
if (request.getAttribute("test1y") == null) {
|
||||||
throw new ServletException("Wrong interceptor order");
|
throw new ServletException("Wrong interceptor order");
|
||||||
}
|
}
|
||||||
|
if (request.getAttribute("test2y") == null) {
|
||||||
|
throw new ServletException("afterCompletion invoked twice");
|
||||||
|
}
|
||||||
request.removeAttribute("test2y");
|
request.removeAttribute("test2y");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -60,6 +60,7 @@ public class ServletRequestMethodArgumentResolverTests {
|
||||||
|
|
||||||
private MockHttpServletRequest servletRequest;
|
private MockHttpServletRequest servletRequest;
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
method = getClass().getMethod("supportedParams", ServletRequest.class, MultipartRequest.class,
|
method = getClass().getMethod("supportedParams", ServletRequest.class, MultipartRequest.class,
|
||||||
|
@ -70,6 +71,7 @@ public class ServletRequestMethodArgumentResolverTests {
|
||||||
webRequest = new ServletWebRequest(servletRequest, new MockHttpServletResponse());
|
webRequest = new ServletWebRequest(servletRequest, new MockHttpServletResponse());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void servletRequest() throws Exception {
|
public void servletRequest() throws Exception {
|
||||||
MethodParameter servletRequestParameter = new MethodParameter(method, 0);
|
MethodParameter servletRequestParameter = new MethodParameter(method, 0);
|
||||||
|
|
Loading…
Reference in New Issue