本文整理汇总了Java中javax.servlet.DispatcherType类的典型用法代码示例。如果您正苦于以下问题:Java DispatcherType类的具体用法?Java DispatcherType怎么用?Java DispatcherType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DispatcherType类属于javax.servlet包,在下文中一共展示了DispatcherType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addApplication
import javax.servlet.DispatcherType; //导入依赖的package包/类
private void addApplication(final ServletContextHandler context, final MinijaxApplication application)
throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
// (0) Sort the resource methods by literal length
application.sortResourceMethods();
// (1) Add Minijax filter (must come before websocket!)
context.addFilter(new FilterHolder(new MinijaxFilter(application)), "/*", EnumSet.of(DispatcherType.REQUEST));
// (2) WebSocket endpoints
if (OptionalClasses.WEB_SOCKET_UTILS != null) {
OptionalClasses.WEB_SOCKET_UTILS
.getMethod("init", ServletContextHandler.class, MinijaxApplication.class)
.invoke(null, context, application);
}
// (3) Dynamic JAX-RS content
final MinijaxServlet servlet = new MinijaxServlet(application);
final ServletHolder servletHolder = new ServletHolder(servlet);
servletHolder.getRegistration().setMultipartConfig(new MultipartConfigElement(""));
context.addServlet(servletHolder, "/*");
}
示例2: putHeaders
import javax.servlet.DispatcherType; //导入依赖的package包/类
@Override
protected void putHeaders(HttpServletResponse response, HttpContent content, long contentLength) {
super.putHeaders(response, content, contentLength);
HttpFields fields = ((Response) response).getHttpFields();
if (requestHolder.get().getDispatcherType() == DispatcherType.ERROR) {
/*
* Do not cache error page and also makes sure that error page is not eligible for
* modification check. That is, error page will be always retrieved.
*/
fields.put(HttpHeader.CACHE_CONTROL, "must-revalidate,no-cache,no-store");
} else if (requestHolder.get().getRequestURI().equals("/favicon.ico")) {
/*
* Make sure favicon request is cached. Otherwise, it will be requested for every
* page request.
*/
fields.put(HttpHeader.CACHE_CONTROL, "max-age=86400,public");
}
}
示例3: handleRequest
import javax.servlet.DispatcherType; //导入依赖的package包/类
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
final ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
ServletRequest request = servletRequestContext.getServletRequest();
if (request.getDispatcherType() == DispatcherType.REQUEST) {
List<SingleConstraintMatch> constraints = servletRequestContext.getRequiredConstrains();
SecurityContext sc = exchange.getSecurityContext();
if (!authorizationManager.canAccessResource(constraints, sc.getAuthenticatedAccount(), servletRequestContext.getCurrentServlet().getManagedServlet().getServletInfo(), servletRequestContext.getOriginalRequest(), servletRequestContext.getDeployment())) {
HttpServletResponse response = (HttpServletResponse) servletRequestContext.getServletResponse();
response.sendError(StatusCodes.FORBIDDEN);
return;
}
}
next.handleRequest(exchange);
}
示例4: run
import javax.servlet.DispatcherType; //导入依赖的package包/类
@Override
public void run(@Nonnull final GraphiakConfiguration configuration,
@Nonnull final Environment environment) throws Exception {
// Enable CORS
final FilterRegistration.Dynamic cors = environment.servlets()
.addFilter("cors", CrossOriginFilter.class);
cors.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true,
"/*");
// get Riak client
final RiakClient client = configuration.getRiak().build();
final MetricStore store = new MetricStore(client);
environment.lifecycle().manage(new MetricStoreManager(store));
// Configure the Netty TCP server
configuration.getNetty().build(environment, store);
// Resources
environment.jersey().register(new DashboardResource());
environment.jersey().register(new MetricsResource(store));
environment.jersey().register(new EventsResource());
environment.jersey().register(new PingResource());
environment.jersey().register(new VersionResource());
}
示例5: setRequest
import javax.servlet.DispatcherType; //导入依赖的package包/类
/**
* Set the request that we are wrapping.
*
* @param request
* The new wrapped request
*/
void setRequest(HttpServletRequest request) {
super.setRequest(request);
// Initialize the attributes for this request
dispatcherType = (DispatcherType) request.getAttribute(Globals.DISPATCHER_TYPE_ATTR);
requestDispatcherPath = request.getAttribute(Globals.DISPATCHER_REQUEST_PATH_ATTR);
// Initialize the path elements for this request
contextPath = request.getContextPath();
pathInfo = request.getPathInfo();
queryString = request.getQueryString();
requestURI = request.getRequestURI();
servletPath = request.getServletPath();
}
示例6: getDispatcherNames
import javax.servlet.DispatcherType; //导入依赖的package包/类
public String[] getDispatcherNames() {
ArrayList<String> result = new ArrayList<String>();
if ((dispatcherMapping & FORWARD) > 0) {
result.add(DispatcherType.FORWARD.name());
}
if ((dispatcherMapping & INCLUDE) > 0) {
result.add(DispatcherType.INCLUDE.name());
}
if ((dispatcherMapping & REQUEST) > 0) {
result.add(DispatcherType.REQUEST.name());
}
if ((dispatcherMapping & ERROR) > 0) {
result.add(DispatcherType.ERROR.name());
}
if ((dispatcherMapping & ASYNC) > 0) {
result.add(DispatcherType.ASYNC.name());
}
return result.toArray(new String[result.size()]);
}
示例7: factory
import javax.servlet.DispatcherType; //导入依赖的package包/类
@Bean(name = "VIFilterRegistrationBeanNew")
public org.springframework.boot.web.servlet.FilterRegistrationBean factory() {
if(environment != null) {
String port = environment.getProperty("server.port");
if(port !=null) {
System.setProperty(SysKeys.SPRINGBOOTPORTKEY, port);
}
}
org.springframework.boot.web.servlet.FilterRegistrationBean filter =
new org.springframework.boot.web.servlet.FilterRegistrationBean();
filter.setFilter(new VIFilter());
filter.setName("vi-filter");
filter.addUrlPatterns(URLPATTERNS);
filter.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.FORWARD);
filter.setAsyncSupported(true);
filter.setOrder(Ordered.HIGHEST_PRECEDENCE);
return filter;
}
示例8: setDispatcher
import javax.servlet.DispatcherType; //导入依赖的package包/类
/**
*
* This method will be used to set the current state of the FilterMap
* representing the state of when filters should be applied.
*/
public void setDispatcher(String dispatcherString) {
String dispatcher = dispatcherString.toUpperCase(Locale.ENGLISH);
if (dispatcher.equals(DispatcherType.FORWARD.name())) {
// apply FORWARD to the global dispatcherMapping.
dispatcherMapping |= FORWARD;
} else if (dispatcher.equals(DispatcherType.INCLUDE.name())) {
// apply INCLUDE to the global dispatcherMapping.
dispatcherMapping |= INCLUDE;
} else if (dispatcher.equals(DispatcherType.REQUEST.name())) {
// apply REQUEST to the global dispatcherMapping.
dispatcherMapping |= REQUEST;
} else if (dispatcher.equals(DispatcherType.ERROR.name())) {
// apply ERROR to the global dispatcherMapping.
dispatcherMapping |= ERROR;
} else if (dispatcher.equals(DispatcherType.ASYNC.name())) {
// apply ERROR to the global dispatcherMapping.
dispatcherMapping |= ASYNC;
}
}
示例9: setAttribute
import javax.servlet.DispatcherType; //导入依赖的package包/类
/**
* Override the <code>setAttribute()</code> method of the wrapped request.
*
* @param name
* Name of the attribute to set
* @param value
* Value of the attribute to set
*/
@Override
public void setAttribute(String name, Object value) {
if (name.equals(Globals.DISPATCHER_TYPE_ATTR)) {
dispatcherType = (DispatcherType) value;
return;
} else if (name.equals(Globals.DISPATCHER_REQUEST_PATH_ATTR)) {
requestDispatcherPath = value;
return;
}
if (!setSpecial(name, value)) {
getRequest().setAttribute(name, value);
}
}
示例10: getDispatcherNames
import javax.servlet.DispatcherType; //导入依赖的package包/类
public String[] getDispatcherNames() {
ArrayList<String> result = new ArrayList<String>();
if ((dispatcherMapping & FORWARD) > 0) {
result.add(DispatcherType.FORWARD.name());
}
if ((dispatcherMapping & INCLUDE) > 0) {
result.add(DispatcherType.INCLUDE.name());
}
if ((dispatcherMapping & REQUEST) > 0) {
result.add(DispatcherType.REQUEST.name());
}
if ((dispatcherMapping & ERROR) > 0) {
result.add(DispatcherType.ERROR.name());
}
if ((dispatcherMapping & ASYNC) > 0) {
result.add(DispatcherType.ASYNC.name());
}
return result.toArray(new String[result.size()]);
}
示例11: setDispatcher
import javax.servlet.DispatcherType; //导入依赖的package包/类
/**
*
* This method will be used to set the current state of the FilterMap
* representing the state of when filters should be applied.
*/
public void setDispatcher(String dispatcherString) {
String dispatcher = dispatcherString.toUpperCase(Locale.ENGLISH);
if (dispatcher.equals(DispatcherType.FORWARD.name())) {
// apply FORWARD to the global dispatcherMapping.
dispatcherMapping |= FORWARD;
} else if (dispatcher.equals(DispatcherType.INCLUDE.name())) {
// apply INCLUDE to the global dispatcherMapping.
dispatcherMapping |= INCLUDE;
} else if (dispatcher.equals(DispatcherType.REQUEST.name())) {
// apply REQUEST to the global dispatcherMapping.
dispatcherMapping |= REQUEST;
} else if (dispatcher.equals(DispatcherType.ERROR.name())) {
// apply ERROR to the global dispatcherMapping.
dispatcherMapping |= ERROR;
} else if (dispatcher.equals(DispatcherType.ASYNC.name())) {
// apply ERROR to the global dispatcherMapping.
dispatcherMapping |= ASYNC;
}
}
示例12: flush
import javax.servlet.DispatcherType; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
public void flush() throws IOException {
//according to the servlet spec we ignore a flush from within an include
if (servletRequestContext.getOriginalRequest().getDispatcherType() == DispatcherType.INCLUDE ||
servletRequestContext.getOriginalResponse().isTreatAsCommitted()) {
return;
}
if (servletRequestContext.getDeployment().getDeploymentInfo().isIgnoreFlush() &&
servletRequestContext.getExchange().isRequestComplete() &&
servletRequestContext.getOriginalResponse().getHeader(Headers.TRANSFER_ENCODING_STRING) == null) {
//we mark the stream as flushed, but don't actually flush
//because in most cases flush just kills performance
//we only do this if the request is fully read, so that http tunneling scenarios still work
servletRequestContext.getOriginalResponse().setIgnoredFlushPerformed(true);
return;
}
flushInternal();
}
示例13: handleRequest
import javax.servlet.DispatcherType; //导入依赖的package包/类
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
final ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
ServletRequest request = servletRequestContext.getServletRequest();
ServletResponse response = servletRequestContext.getServletResponse();
DispatcherType dispatcher = servletRequestContext.getDispatcherType();
Boolean supported = asyncSupported.get(dispatcher);
if(supported != null && ! supported) {
exchange.putAttachment(AsyncContextImpl.ASYNC_SUPPORTED, false );
}
final List<ManagedFilter> filters = this.filters.get(dispatcher);
if(filters == null) {
next.handleRequest(exchange);
} else {
final FilterChainImpl filterChain = new FilterChainImpl(exchange, filters, next, allowNonStandardWrappers);
filterChain.doFilter(request, response);
}
}
示例14: buildRequest
import javax.servlet.DispatcherType; //导入依赖的package包/类
@Override
public MockHttpServletRequest buildRequest(ServletContext servletContext) {
MockHttpServletRequest request = this.result.getRequest();
request.setDispatcherType(DispatcherType.ERROR);
request.setRequestURI(this.path);
return request;
}
示例15: csrfFilterRegistrationBean
import javax.servlet.DispatcherType; //导入依赖的package包/类
/**
* @return CSRF protection filter bean
*/
@Bean
public FilterRegistrationBean csrfFilterRegistrationBean() {
String path = "/*";
logger.debug("Initializing CSRF filter [{}]...", path);
FilterRegistrationBean frb = new FilterRegistrationBean(new CsrfFilter());
frb.setDispatcherTypes(EnumSet.of(DispatcherType.REQUEST));
frb.setName("csrfFilter");
frb.setAsyncSupported(true);
frb.addUrlPatterns(path);
frb.setMatchAfter(false);
frb.setEnabled(true);
frb.setOrder(2);
return frb;
}