Search in sources :

Example 6 with FilterInfo

use of io.undertow.servlet.api.FilterInfo in project undertow by undertow-io.

the class ServletContextImpl method addFilter.

@Override
public FilterRegistration.Dynamic addFilter(final String filterName, final Filter filter) {
    ensureNotProgramaticListener();
    ensureNotInitialized();
    if (deploymentInfo.getFilters().containsKey(filterName)) {
        return null;
    }
    FilterInfo f = new FilterInfo(filterName, filter.getClass(), new ImmediateInstanceFactory<>(filter));
    deploymentInfo.addFilter(f);
    deployment.getFilters().addFilter(f);
    return new FilterRegistrationImpl(f, deployment, this);
}
Also used : FilterInfo(io.undertow.servlet.api.FilterInfo)

Example 7 with FilterInfo

use of io.undertow.servlet.api.FilterInfo 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);
    }
}
Also used : ChannelListener(org.xnio.ChannelListener) DefaultByteBufferPool(io.undertow.server.DefaultByteBufferPool) DeploymentManager(io.undertow.servlet.api.DeploymentManager) XnioWorker(org.xnio.XnioWorker) InetSocketAddress(java.net.InetSocketAddress) StreamConnection(org.xnio.StreamConnection) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) Xnio(org.xnio.Xnio) OptionMap(org.xnio.OptionMap) ServletContainer(io.undertow.servlet.api.ServletContainer) PerMessageDeflateHandshake(io.undertow.websockets.extensions.PerMessageDeflateHandshake) HttpOpenListener(io.undertow.server.protocol.http.HttpOpenListener) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) FilterInfo(io.undertow.servlet.api.FilterInfo)

Example 8 with FilterInfo

use of io.undertow.servlet.api.FilterInfo 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);
    }
}
Also used : ChannelListener(org.xnio.ChannelListener) DefaultByteBufferPool(io.undertow.server.DefaultByteBufferPool) DeploymentManager(io.undertow.servlet.api.DeploymentManager) XnioWorker(org.xnio.XnioWorker) InetSocketAddress(java.net.InetSocketAddress) ServerEndpointConfigImpl(io.undertow.websockets.jsr.ServerEndpointConfigImpl) StreamConnection(org.xnio.StreamConnection) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) Xnio(org.xnio.Xnio) JsrWebSocketFilter(io.undertow.websockets.jsr.JsrWebSocketFilter) OptionMap(org.xnio.OptionMap) ServletContainer(io.undertow.servlet.api.ServletContainer) PerMessageDeflateHandshake(io.undertow.websockets.extensions.PerMessageDeflateHandshake) HttpOpenListener(io.undertow.server.protocol.http.HttpOpenListener) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) FilterInfo(io.undertow.servlet.api.FilterInfo)

Example 9 with FilterInfo

use of io.undertow.servlet.api.FilterInfo in project undertow by undertow-io.

the class JsrWebSocketServer07Test method deployServlet.

private ServletContext deployServlet(final ServerWebSocketContainer deployment) throws ServletException {
    final DeploymentInfo builder;
    builder = new DeploymentInfo().setClassLoader(getClass().getClassLoader()).setContextPath("/").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("websocket.war").addFilter(new FilterInfo("filter", JsrWebSocketFilter.class)).addFilterUrlMapping("filter", "/*", DispatcherType.REQUEST).addServletContextAttribute(javax.websocket.server.ServerContainer.class.getName(), deployment);
    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());
    DefaultServer.setRootHandler(root);
    return manager.getDeployment().getServletContext();
}
Also used : DeploymentManager(io.undertow.servlet.api.DeploymentManager) ServletContainer(io.undertow.servlet.api.ServletContainer) PathHandler(io.undertow.server.handlers.PathHandler) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) FilterInfo(io.undertow.servlet.api.FilterInfo)

Example 10 with FilterInfo

use of io.undertow.servlet.api.FilterInfo in project undertow by undertow-io.

the class RequestPathTestCase method setup.

@BeforeClass
public static void setup() throws ServletException {
    final PathHandler pathHandler = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    DeploymentInfo builder = new DeploymentInfo().setClassLoader(SimpleServletTestCase.class.getClassLoader()).setContextPath("/servletContext").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").addServlets(new ServletInfo("request", RequestPathServlet.class).addMapping("/req/*"), new ServletInfo("DefaultServlet", RequestPathServlet.class).addMapping("/"), new ServletInfo("ExactServlet", RequestPathServlet.class).addMapping("/exact"), new ServletInfo("ExactTxtServlet", RequestPathServlet.class).addMapping("/exact.txt"), new ServletInfo("HtmlServlet", RequestPathServlet.class).addMapping("*.html")).addFilters(new FilterInfo("header", SetHeaderFilter.class).addInitParam("header", "Filter").addInitParam("value", "true"), new FilterInfo("all", SetHeaderFilter.class).addInitParam("header", "all").addInitParam("value", "true")).addFilterUrlMapping("header", "*.txt", DispatcherType.REQUEST).addFilterUrlMapping("all", "/*", DispatcherType.REQUEST);
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    try {
        pathHandler.addPrefixPath(builder.getContextPath(), manager.start());
    } catch (ServletException e) {
        throw new RuntimeException(e);
    }
    DefaultServer.setRootHandler(pathHandler);
}
Also used : ServletInfo(io.undertow.servlet.api.ServletInfo) ServletException(javax.servlet.ServletException) DeploymentManager(io.undertow.servlet.api.DeploymentManager) ServletContainer(io.undertow.servlet.api.ServletContainer) PathHandler(io.undertow.server.handlers.PathHandler) SetHeaderFilter(io.undertow.servlet.test.util.SetHeaderFilter) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) FilterInfo(io.undertow.servlet.api.FilterInfo) BeforeClass(org.junit.BeforeClass)

Aggregations

FilterInfo (io.undertow.servlet.api.FilterInfo)24 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)19 DeploymentManager (io.undertow.servlet.api.DeploymentManager)16 ServletContainer (io.undertow.servlet.api.ServletContainer)16 ServletInfo (io.undertow.servlet.api.ServletInfo)15 PathHandler (io.undertow.server.handlers.PathHandler)14 BeforeClass (org.junit.BeforeClass)6 Test (org.junit.Test)6 TestResourceLoader (io.undertow.servlet.test.util.TestResourceLoader)5 TestHttpClient (io.undertow.testutils.TestHttpClient)5 WebSocketDeploymentInfo (io.undertow.websockets.jsr.WebSocketDeploymentInfo)4 LoginConfig (io.undertow.servlet.api.LoginConfig)3 PerMessageDeflateHandshake (io.undertow.websockets.extensions.PerMessageDeflateHandshake)3 DefaultByteBufferPool (io.undertow.server.DefaultByteBufferPool)2 HandlerWrapper (io.undertow.server.HandlerWrapper)2 HttpHandler (io.undertow.server.HttpHandler)2 HttpOpenListener (io.undertow.server.protocol.http.HttpOpenListener)2 ServletExtension (io.undertow.servlet.ServletExtension)2 ErrorPage (io.undertow.servlet.api.ErrorPage)2 ListenerInfo (io.undertow.servlet.api.ListenerInfo)2