Search in sources :

Example 6 with ServletHolder

use of org.eclipse.jetty.servlet.ServletHolder in project jetty.project by eclipse.

the class RunAsAnnotationHandler method doHandle.

public void doHandle(Class clazz) {
    if (!Servlet.class.isAssignableFrom(clazz))
        return;
    javax.annotation.security.RunAs runAs = (javax.annotation.security.RunAs) clazz.getAnnotation(javax.annotation.security.RunAs.class);
    if (runAs != null) {
        String role = runAs.value();
        if (role != null) {
            ServletHolder holder = getServletHolderForClass(clazz);
            if (holder != null) {
                MetaData metaData = _context.getMetaData();
                Descriptor d = metaData.getOriginDescriptor(holder.getName() + ".servlet.run-as");
                //let the annotation override it
                if (d == null) {
                    metaData.setOrigin(holder.getName() + ".servlet.run-as", runAs, clazz);
                    org.eclipse.jetty.plus.annotation.RunAs ra = new org.eclipse.jetty.plus.annotation.RunAs();
                    ra.setTargetClassName(clazz.getCanonicalName());
                    ra.setRoleName(role);
                    RunAsCollection raCollection = (RunAsCollection) _context.getAttribute(RunAsCollection.RUNAS_COLLECTION);
                    if (raCollection == null) {
                        raCollection = new RunAsCollection();
                        _context.setAttribute(RunAsCollection.RUNAS_COLLECTION, raCollection);
                    }
                    raCollection.add(ra);
                }
            }
        } else
            LOG.warn("Bad value for @RunAs annotation on class " + clazz.getName());
    }
}
Also used : ServletHolder(org.eclipse.jetty.servlet.ServletHolder) RunAsCollection(org.eclipse.jetty.plus.annotation.RunAsCollection) MetaData(org.eclipse.jetty.webapp.MetaData) Servlet(javax.servlet.Servlet) Descriptor(org.eclipse.jetty.webapp.Descriptor)

Example 7 with ServletHolder

use of org.eclipse.jetty.servlet.ServletHolder in project jetty.project by eclipse.

the class ProxyServletTest method startServer.

private void startServer(HttpServlet servlet) throws Exception {
    QueuedThreadPool serverPool = new QueuedThreadPool();
    serverPool.setName("server");
    server = new Server(serverPool);
    serverConnector = new ServerConnector(server);
    server.addConnector(serverConnector);
    ServletContextHandler appCtx = new ServletContextHandler(server, "/", true, false);
    ServletHolder appServletHolder = new ServletHolder(servlet);
    appCtx.addServlet(appServletHolder, "/*");
    server.start();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Server(org.eclipse.jetty.server.Server) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 8 with ServletHolder

use of org.eclipse.jetty.servlet.ServletHolder in project jetty.project by eclipse.

the class ReverseProxyTest method startServer.

private void startServer(HttpServlet servlet) throws Exception {
    server = new Server();
    serverConnector = new ServerConnector(server);
    server.addConnector(serverConnector);
    ServletContextHandler appCtx = new ServletContextHandler(server, "/", true, false);
    ServletHolder appServletHolder = new ServletHolder(servlet);
    appCtx.addServlet(appServletHolder, "/*");
    server.start();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 9 with ServletHolder

use of org.eclipse.jetty.servlet.ServletHolder in project jetty.project by eclipse.

the class ProxyServletTest method startProxy.

private void startProxy(Map<String, String> initParams) throws Exception {
    QueuedThreadPool proxyPool = new QueuedThreadPool();
    proxyPool.setName("proxy");
    proxy = new Server(proxyPool);
    HttpConfiguration configuration = new HttpConfiguration();
    configuration.setSendDateHeader(false);
    configuration.setSendServerVersion(false);
    String value = initParams.get("outputBufferSize");
    if (value != null)
        configuration.setOutputBufferSize(Integer.valueOf(value));
    proxyConnector = new ServerConnector(proxy, new HttpConnectionFactory(configuration));
    proxy.addConnector(proxyConnector);
    proxyContext = new ServletContextHandler(proxy, "/", true, false);
    ServletHolder proxyServletHolder = new ServletHolder(proxyServlet);
    proxyServletHolder.setInitParameters(initParams);
    proxyContext.addServlet(proxyServletHolder, "/*");
    proxy.start();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 10 with ServletHolder

use of org.eclipse.jetty.servlet.ServletHolder in project jetty.project by eclipse.

the class ProxyServletFailureTest method prepareProxy.

private void prepareProxy(Map<String, String> initParams) throws Exception {
    QueuedThreadPool executor = new QueuedThreadPool();
    executor.setName("proxy");
    proxy = new Server(executor);
    proxyConnector = new ServerConnector(proxy);
    proxy.addConnector(proxyConnector);
    proxyConnector.getConnectionFactory(HttpConnectionFactory.class).getHttpConfiguration().setDelayDispatchUntilContent(false);
    ServletContextHandler proxyCtx = new ServletContextHandler(proxy, "/", true, false);
    ServletHolder proxyServletHolder = new ServletHolder(proxyServlet);
    proxyServletHolder.setInitParameters(initParams);
    proxyCtx.addServlet(proxyServletHolder, "/*");
    proxy.start();
    client = prepareClient();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Server(org.eclipse.jetty.server.Server) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Aggregations

ServletHolder (org.eclipse.jetty.servlet.ServletHolder)473 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)255 Server (org.eclipse.jetty.server.Server)177 Test (org.junit.Test)81 FilterHolder (org.eclipse.jetty.servlet.FilterHolder)74 ServerConnector (org.eclipse.jetty.server.ServerConnector)67 HttpServletRequest (javax.servlet.http.HttpServletRequest)47 IOException (java.io.IOException)44 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)36 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)33 File (java.io.File)32 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)32 ServletContainer (org.glassfish.jersey.servlet.ServletContainer)30 DefaultServlet (org.eclipse.jetty.servlet.DefaultServlet)27 HttpServletResponse (javax.servlet.http.HttpServletResponse)26 HttpClient (org.eclipse.jetty.client.HttpClient)24 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)24 CountDownLatch (java.util.concurrent.CountDownLatch)23 ServletException (javax.servlet.ServletException)23 ServletHandler (org.eclipse.jetty.servlet.ServletHandler)23