fixed reset of DispatcherType

This commit is contained in:
Greg Wilkins 2015-10-30 10:35:37 +11:00
parent 915a905df4
commit fa53b11850
2 changed files with 34 additions and 11 deletions

View File

@ -29,6 +29,7 @@ import java.nio.channels.ClosedChannelException;
import java.util.List; import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import javax.servlet.DispatcherType; import javax.servlet.DispatcherType;
import javax.servlet.RequestDispatcher; import javax.servlet.RequestDispatcher;
@ -264,6 +265,8 @@ public class HttpChannel implements Runnable, HttpOutput.Interceptor
handle(); handle();
} }
AtomicReference<Action> caller = new AtomicReference<>();
/** /**
* @return True if the channel is ready to continue handling (ie it is not suspended) * @return True if the channel is ready to continue handling (ie it is not suspended)
*/ */
@ -297,7 +300,6 @@ public class HttpChannel implements Runnable, HttpOutput.Interceptor
throw new IllegalStateException("state=" + _state); throw new IllegalStateException("state=" + _state);
_request.setHandled(false); _request.setHandled(false);
_response.getHttpOutput().reopen(); _response.getHttpOutput().reopen();
_request.setDispatcherType(DispatcherType.REQUEST);
List<HttpConfiguration.Customizer> customizers = _configuration.getCustomizers(); List<HttpConfiguration.Customizer> customizers = _configuration.getCustomizers();
if (!customizers.isEmpty()) if (!customizers.isEmpty())
@ -305,7 +307,15 @@ public class HttpChannel implements Runnable, HttpOutput.Interceptor
for (HttpConfiguration.Customizer customizer : customizers) for (HttpConfiguration.Customizer customizer : customizers)
customizer.customize(getConnector(), _configuration, _request); customizer.customize(getConnector(), _configuration, _request);
} }
try
{
_request.setDispatcherType(DispatcherType.REQUEST);
getServer().handle(this); getServer().handle(this);
}
finally
{
_request.setDispatcherType(null);
}
break; break;
} }
@ -313,8 +323,16 @@ public class HttpChannel implements Runnable, HttpOutput.Interceptor
{ {
_request.setHandled(false); _request.setHandled(false);
_response.getHttpOutput().reopen(); _response.getHttpOutput().reopen();
try
{
_request.setDispatcherType(DispatcherType.ASYNC); _request.setDispatcherType(DispatcherType.ASYNC);
getServer().handleAsync(this); getServer().handleAsync(this);
}
finally
{
_request.setDispatcherType(null);
}
break; break;
} }
@ -336,9 +354,17 @@ public class HttpChannel implements Runnable, HttpOutput.Interceptor
_request.setAttribute(ERROR_STATUS_CODE,code); _request.setAttribute(ERROR_STATUS_CODE,code);
_request.setHandled(false); _request.setHandled(false);
_response.getHttpOutput().reopen(); _response.getHttpOutput().reopen();
try
{
_request.setDispatcherType(DispatcherType.ERROR); _request.setDispatcherType(DispatcherType.ERROR);
getServer().handle(this); getServer().handle(this);
} }
finally
{
_request.setDispatcherType(null);
}
}
break; break;
} }
@ -390,10 +416,6 @@ public class HttpChannel implements Runnable, HttpOutput.Interceptor
else else
handleException(failure); handleException(failure);
} }
finally
{
_request.setDispatcherType(null);
}
action = _state.unhandle(); action = _state.unhandle();
} }

View File

@ -40,6 +40,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentLinkedQueue;
import javax.servlet.AsyncContext; import javax.servlet.AsyncContext;
import javax.servlet.AsyncListener; import javax.servlet.AsyncListener;