use of javax.servlet.DispatcherType in project tomcat70 by apache.
the class ApplicationDispatcher method processRequest.
/**
* Prepare the request based on the filter configuration.
* @param request The servlet request we are processing
* @param response The servlet response we are creating
* @param state The RD state
*
* @exception IOException if an input/output error occurs
* @exception ServletException if a servlet error occurs
*/
private void processRequest(ServletRequest request, ServletResponse response, State state) throws IOException, ServletException {
DispatcherType disInt = (DispatcherType) request.getAttribute(Globals.DISPATCHER_TYPE_ATTR);
if (disInt != null) {
boolean doInvoke = true;
if (context.getFireRequestListenersOnForwards() && !context.fireRequestInitEvent(request)) {
doInvoke = false;
}
if (doInvoke) {
if (disInt != DispatcherType.ERROR) {
state.outerRequest.setAttribute(Globals.DISPATCHER_REQUEST_PATH_ATTR, getCombinedPath());
state.outerRequest.setAttribute(Globals.DISPATCHER_TYPE_ATTR, DispatcherType.FORWARD);
invoke(state.outerRequest, response, state);
} else {
invoke(state.outerRequest, response, state);
}
if (context.getFireRequestListenersOnForwards()) {
context.fireRequestDestroyEvent(request);
}
}
}
}
use of javax.servlet.DispatcherType in project tomcat70 by apache.
the class ApplicationFilterFactory method createFilterChain.
/**
* Construct and return a FilterChain implementation that will wrap the
* execution of the specified servlet instance. If we should not execute
* a filter chain at all, return <code>null</code>.
*
* @param request The servlet request we are processing
* @param servlet The servlet instance to be wrapped
*/
public ApplicationFilterChain createFilterChain(ServletRequest request, Wrapper wrapper, Servlet servlet) {
// get the dispatcher type
DispatcherType dispatcher = null;
if (request.getAttribute(Globals.DISPATCHER_TYPE_ATTR) != null) {
dispatcher = (DispatcherType) request.getAttribute(Globals.DISPATCHER_TYPE_ATTR);
}
String requestPath = null;
Object attribute = request.getAttribute(Globals.DISPATCHER_REQUEST_PATH_ATTR);
if (attribute != null) {
requestPath = attribute.toString();
}
// If there is no servlet to execute, return null
if (servlet == null)
return (null);
boolean comet = false;
// Create and initialize a filter chain object
ApplicationFilterChain filterChain = null;
if (request instanceof Request) {
Request req = (Request) request;
comet = req.isComet();
if (Globals.IS_SECURITY_ENABLED) {
// Security: Do not recycle
filterChain = new ApplicationFilterChain();
if (comet) {
req.setFilterChain(filterChain);
}
} else {
filterChain = (ApplicationFilterChain) req.getFilterChain();
if (filterChain == null) {
filterChain = new ApplicationFilterChain();
req.setFilterChain(filterChain);
}
}
} else {
// Request dispatcher in use
filterChain = new ApplicationFilterChain();
}
filterChain.setServlet(servlet);
filterChain.setSupport(((StandardWrapper) wrapper).getInstanceSupport());
// Acquire the filter mappings for this Context
StandardContext context = (StandardContext) wrapper.getParent();
FilterMap[] filterMaps = context.findFilterMaps();
// If there are no filter mappings, we are done
if ((filterMaps == null) || (filterMaps.length == 0))
return (filterChain);
// Acquire the information we will need to match filter mappings
String servletName = wrapper.getName();
// Add the relevant path-mapped filters to this filter chain
for (int i = 0; i < filterMaps.length; i++) {
if (!matchDispatcher(filterMaps[i], dispatcher)) {
continue;
}
if (!matchFiltersURL(filterMaps[i], requestPath))
continue;
ApplicationFilterConfig filterConfig = (ApplicationFilterConfig) context.findFilterConfig(filterMaps[i].getFilterName());
if (filterConfig == null) {
// FIXME - log configuration problem
continue;
}
boolean isCometFilter = false;
if (comet) {
try {
isCometFilter = filterConfig.getFilter() instanceof CometFilter;
} catch (Exception e) {
// Note: The try catch is there because getFilter has a lot of
// declared exceptions. However, the filter is allocated much
// earlier
Throwable t = ExceptionUtils.unwrapInvocationTargetException(e);
ExceptionUtils.handleThrowable(t);
}
if (isCometFilter) {
filterChain.addFilter(filterConfig);
}
} else {
filterChain.addFilter(filterConfig);
}
}
// Add filters that match on servlet name second
for (int i = 0; i < filterMaps.length; i++) {
if (!matchDispatcher(filterMaps[i], dispatcher)) {
continue;
}
if (!matchFiltersServlet(filterMaps[i], servletName))
continue;
ApplicationFilterConfig filterConfig = (ApplicationFilterConfig) context.findFilterConfig(filterMaps[i].getFilterName());
if (filterConfig == null) {
// FIXME - log configuration problem
continue;
}
boolean isCometFilter = false;
if (comet) {
try {
isCometFilter = filterConfig.getFilter() instanceof CometFilter;
} catch (Exception e) {
// Note: The try catch is there because getFilter has a lot of
// declared exceptions. However, the filter is allocated much
// earlier
}
if (isCometFilter) {
filterChain.addFilter(filterConfig);
}
} else {
filterChain.addFilter(filterConfig);
}
}
// Return the completed filter chain
return (filterChain);
}
use of javax.servlet.DispatcherType in project HttpApiJava by thevsk.
the class JettyStart method main.
public static void main(String[] args) {
String path = JettyStart.class.getProtectionDomain().getCodeSource().getLocation().getFile();
if (path == null) {
throw new RuntimeException("jar path can't find");
}
if (path.contains(".jar")) {
log.info("[服务] jar 环境");
path = path.substring(0, path.lastIndexOf(separator));
} else {
log.info("[服务] 非 jar 环境");
path = path.substring(0, path.length() - 1);
path = path.substring(0, path.lastIndexOf(separator));
}
path += separator + "config.properties";
File file = new File(path);
if (!file.exists()) {
throw new RuntimeException("properties can't find");
}
PropKit.use(file);
EnumSet<DispatcherType> all = EnumSet.of(DispatcherType.ASYNC, DispatcherType.ERROR, DispatcherType.FORWARD, DispatcherType.INCLUDE, DispatcherType.REQUEST);
int port = PropKit.getInt("server.port");
final Server server = new Server(port);
log.info("[服务] 端口 " + port);
try {
WebAppContext context = new WebAppContext("/", "/");
FilterHolder filter = new FilterHolder(new JFinalFilter());
filter.setInitParameter("configClass", PropKit.get("config.class.path"));
context.addFilter(filter, "/*", all);
server.setHandler(context);
server.start();
server.join();
} catch (Exception e) {
e.printStackTrace();
}
}
use of javax.servlet.DispatcherType in project druid by druid-io.
the class JettyTest method setupInjector.
@Override
protected Injector setupInjector() {
TLSServerConfig tlsConfig;
try {
File keyStore = new File(JettyTest.class.getClassLoader().getResource("server.jks").getFile());
Path tmpKeyStore = Files.copy(keyStore.toPath(), new File(folder.newFolder(), "server.jks").toPath());
File trustStore = new File(JettyTest.class.getClassLoader().getResource("truststore.jks").getFile());
Path tmpTrustStore = Files.copy(trustStore.toPath(), new File(folder.newFolder(), "truststore.jks").toPath());
PasswordProvider pp = () -> "druid123";
tlsConfig = new TLSServerConfig() {
@Override
public String getKeyStorePath() {
return tmpKeyStore.toString();
}
@Override
public String getKeyStoreType() {
return "jks";
}
@Override
public PasswordProvider getKeyStorePasswordProvider() {
return pp;
}
@Override
public PasswordProvider getKeyManagerPasswordProvider() {
return pp;
}
@Override
public String getTrustStorePath() {
return tmpTrustStore.toString();
}
@Override
public String getTrustStoreAlgorithm() {
return "PKIX";
}
@Override
public PasswordProvider getTrustStorePasswordProvider() {
return pp;
}
@Override
public String getCertAlias() {
return "druid";
}
@Override
public boolean isRequireClientCertificate() {
return false;
}
@Override
public boolean isRequestClientCertificate() {
return false;
}
@Override
public boolean isValidateHostnames() {
return false;
}
};
sslConfig = HttpClientConfig.builder().withSslContext(HttpClientInit.sslContextWithTrustedKeyStore(tmpTrustStore.toString(), pp.getPassword())).withWorkerCount(1).withReadTimeout(Duration.ZERO).build();
} catch (IOException e) {
throw new RuntimeException(e);
}
final int ephemeralPort = ThreadLocalRandom.current().nextInt(49152, 65535);
latchedRequestState = new LatchedRequestStateHolder();
injector = Initialization.makeInjectorWithModules(GuiceInjectors.makeStartupInjector(), ImmutableList.<Module>of(new Module() {
@Override
public void configure(Binder binder) {
JsonConfigProvider.bindInstance(binder, Key.get(DruidNode.class, Self.class), new DruidNode("test", "localhost", false, ephemeralPort, ephemeralPort + 1, true, true));
binder.bind(TLSServerConfig.class).toInstance(tlsConfig);
binder.bind(JettyServerInitializer.class).to(JettyServerInit.class).in(LazySingleton.class);
binder.bind(LatchedRequestStateHolder.class).toInstance(latchedRequestState);
Multibinder<ServletFilterHolder> multibinder = Multibinder.newSetBinder(binder, ServletFilterHolder.class);
multibinder.addBinding().toInstance(new ServletFilterHolder() {
@Override
public String getPath() {
return "/*";
}
@Override
public Map<String, String> getInitParameters() {
return null;
}
@Override
public Class<? extends Filter> getFilterClass() {
return DummyAuthFilter.class;
}
@Override
public Filter getFilter() {
return null;
}
@Override
public EnumSet<DispatcherType> getDispatcherType() {
return null;
}
});
Jerseys.addResource(binder, SlowResource.class);
Jerseys.addResource(binder, LatchedResource.class);
Jerseys.addResource(binder, ExceptionResource.class);
Jerseys.addResource(binder, DefaultResource.class);
Jerseys.addResource(binder, DirectlyReturnResource.class);
binder.bind(AuthorizerMapper.class).toInstance(AuthTestUtils.TEST_AUTHORIZER_MAPPER);
LifecycleModule.register(binder, Server.class);
}
}));
return injector;
}
use of javax.servlet.DispatcherType in project undertow by undertow-io.
the class ServletContextImpl method addMappingForUrlPatterns.
void addMappingForUrlPatterns(FilterInfo filterInfo, final EnumSet<DispatcherType> dispatcherTypes, final boolean isMatchAfter, final String... urlPatterns) {
DeploymentInfo deploymentInfo = deployment.getDeploymentInfo();
for (final String url : urlPatterns) {
if (isMatchAfter) {
if (dispatcherTypes == null || dispatcherTypes.isEmpty()) {
deploymentInfo.addFilterUrlMapping(filterInfo.getName(), url, DispatcherType.REQUEST);
} else {
for (final DispatcherType dispatcher : dispatcherTypes) {
deploymentInfo.addFilterUrlMapping(filterInfo.getName(), url, dispatcher);
}
}
} else {
if (dispatcherTypes == null || dispatcherTypes.isEmpty()) {
deploymentInfo.insertFilterUrlMapping(filterMappingUrlPatternInsertPosition++, filterInfo.getName(), url, DispatcherType.REQUEST);
} else {
for (final DispatcherType dispatcher : dispatcherTypes) {
deploymentInfo.insertFilterUrlMapping(filterMappingUrlPatternInsertPosition++, filterInfo.getName(), url, dispatcher);
}
}
}
}
deployment.getServletPaths().invalidate();
}
Aggregations