use of io.undertow.servlet.api.DeploymentInfo in project undertow by undertow-io.
the class DispatcherIncludeTestCase method setup.
@BeforeClass
public static void setup() throws ServletException {
final PathHandler root = new PathHandler();
final ServletContainer container = ServletContainer.Factory.newInstance();
DeploymentInfo builder = new DeploymentInfo().setClassLoader(SimpleServletTestCase.class.getClassLoader()).setContextPath("/servletContext").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").setResourceManager(new TestResourceLoader(DispatcherIncludeTestCase.class)).addServlet(new ServletInfo("include", MessageServlet.class).addInitParam(MessageServlet.MESSAGE, "included").addMapping("/include")).addServlet(new ServletInfo("dispatcher", IncludeServlet.class).addMapping("/dispatch")).addServlet(new ServletInfo("pathTest", PathTestServlet.class).addMapping("/path")).addFilter(new FilterInfo("notIncluded", MessageFilter.class).addInitParam(MessageFilter.MESSAGE, "Not Included")).addFilter(new FilterInfo("inc", MessageFilter.class).addInitParam(MessageFilter.MESSAGE, "Path!")).addFilter(new FilterInfo("nameFilter", MessageFilter.class).addInitParam(MessageFilter.MESSAGE, "Name!")).addFilterUrlMapping("notIncluded", "/include", DispatcherType.REQUEST).addFilterUrlMapping("inc", "/include", DispatcherType.INCLUDE).addFilterServletNameMapping("nameFilter", "include", DispatcherType.INCLUDE);
DeploymentManager manager = container.addDeployment(builder);
manager.deploy();
root.addPrefixPath(builder.getContextPath(), manager.start());
DefaultServer.setRootHandler(root);
}
use of io.undertow.servlet.api.DeploymentInfo 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();
}
use of io.undertow.servlet.api.DeploymentInfo in project undertow by undertow-io.
the class ServletContextImpl method addMappingForServletNames.
void addMappingForServletNames(FilterInfo filterInfo, final EnumSet<DispatcherType> dispatcherTypes, final boolean isMatchAfter, final String... servletNames) {
DeploymentInfo deploymentInfo = deployment.getDeploymentInfo();
for (final String servlet : servletNames) {
if (isMatchAfter) {
if (dispatcherTypes == null || dispatcherTypes.isEmpty()) {
deploymentInfo.addFilterServletNameMapping(filterInfo.getName(), servlet, DispatcherType.REQUEST);
} else {
for (final DispatcherType dispatcher : dispatcherTypes) {
deploymentInfo.addFilterServletNameMapping(filterInfo.getName(), servlet, dispatcher);
}
}
} else {
if (dispatcherTypes == null || dispatcherTypes.isEmpty()) {
deploymentInfo.insertFilterServletNameMapping(filterMappingServletNameInsertPosition++, filterInfo.getName(), servlet, DispatcherType.REQUEST);
} else {
for (final DispatcherType dispatcher : dispatcherTypes) {
deploymentInfo.insertFilterServletNameMapping(filterMappingServletNameInsertPosition++, filterInfo.getName(), servlet, dispatcher);
}
}
}
}
deployment.getServletPaths().invalidate();
}
use of io.undertow.servlet.api.DeploymentInfo in project undertow by undertow-io.
the class AnnotatedAutobahnServer method run.
public void run() {
Xnio xnio = Xnio.getInstance();
try {
XnioWorker worker = xnio.createWorker(OptionMap.builder().set(Options.WORKER_WRITE_THREADS, 4).set(Options.WORKER_READ_THREADS, 4).set(Options.CONNECTION_HIGH_WATER, 1000000).set(Options.CONNECTION_LOW_WATER, 1000000).set(Options.WORKER_TASK_CORE_THREADS, 10).set(Options.WORKER_TASK_MAX_THREADS, 12).set(Options.TCP_NODELAY, true).set(Options.CORK, true).getMap());
OptionMap serverOptions = OptionMap.builder().set(Options.WORKER_ACCEPT_THREADS, 4).set(Options.TCP_NODELAY, true).set(Options.REUSE_ADDRESSES, true).getMap();
DefaultByteBufferPool pool = new DefaultByteBufferPool(true, 8024);
HttpOpenListener openListener = new HttpOpenListener(pool);
ChannelListener acceptListener = ChannelListeners.openListenerAdapter(openListener);
AcceptingChannel<StreamConnection> server = worker.createStreamConnectionServer(new InetSocketAddress(port), acceptListener, serverOptions);
server.resumeAccepts();
final ServletContainer container = ServletContainer.Factory.newInstance();
DeploymentInfo builder = new DeploymentInfo().setClassLoader(AnnotatedAutobahnServer.class.getClassLoader()).setContextPath("/").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo().setBuffers(pool).setWorker(worker).addEndpoint(AutobahnAnnotatedEndpoint.class).setDispatchToWorkerThread(true).addExtension(new PerMessageDeflateHandshake())).addFilter(new FilterInfo("filter", JsrWebSocketFilter.class)).addFilterUrlMapping("filter", "/*", DispatcherType.REQUEST);
DeploymentManager manager = container.addDeployment(builder);
manager.deploy();
openListener.setRootHandler(manager.start());
} catch (Exception e) {
log.error("failed to start server", e);
}
}
use of io.undertow.servlet.api.DeploymentInfo in project undertow by undertow-io.
the class ProgramaticAutobahnServer method run.
public void run() {
Xnio xnio = Xnio.getInstance();
try {
XnioWorker worker = xnio.createWorker(OptionMap.builder().set(Options.CONNECTION_HIGH_WATER, 1000000).set(Options.CONNECTION_LOW_WATER, 1000000).set(Options.WORKER_TASK_CORE_THREADS, 10).set(Options.WORKER_TASK_MAX_THREADS, 12).set(Options.TCP_NODELAY, true).set(Options.CORK, true).getMap());
OptionMap serverOptions = OptionMap.builder().set(Options.TCP_NODELAY, true).set(Options.REUSE_ADDRESSES, true).getMap();
DefaultByteBufferPool pool = new DefaultByteBufferPool(true, 8192);
HttpOpenListener openListener = new HttpOpenListener(pool);
ChannelListener acceptListener = ChannelListeners.openListenerAdapter(openListener);
AcceptingChannel<StreamConnection> server = worker.createStreamConnectionServer(new InetSocketAddress(port), acceptListener, serverOptions);
server.resumeAccepts();
final ServletContainer container = ServletContainer.Factory.newInstance();
DeploymentInfo builder = new DeploymentInfo().setClassLoader(ProgramaticAutobahnServer.class.getClassLoader()).setContextPath("/").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").addFilter(new FilterInfo("filter", JsrWebSocketFilter.class)).addFilterUrlMapping("filter", "/*", DispatcherType.REQUEST).addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo().setBuffers(pool).setWorker(worker).setDispatchToWorkerThread(true).addEndpoint(new ServerEndpointConfigImpl(ProgramaticAutobahnEndpoint.class, "/")).addExtension(new PerMessageDeflateHandshake()));
DeploymentManager manager = container.addDeployment(builder);
manager.deploy();
openListener.setRootHandler(manager.start());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations