Search in sources :

Example 11 with ServletHolder

use of org.mortbay.jetty.servlet.ServletHolder in project gradle by gradle.

the class JettyConfiguration method parseAnnotations.

public void parseAnnotations() throws Exception {
    String v = System.getProperty("java.version");
    String[] version = v.split("\\.");
    if (version == null) {
        Log.info("Unable to determine jvm version, annotations will not be supported");
        return;
    }
    int major = Integer.parseInt(version[0]);
    int minor = Integer.parseInt(version[1]);
    if ((major >= 1) && (minor >= 5)) {
        //TODO it would be nice to be able to re-use the parseAnnotations() method on
        //the org.mortbay.jetty.annotations.Configuration class, but it's too difficult?
        //able to use annotations on jdk1.5 and above
        Class<?> annotationParserClass = Thread.currentThread().getContextClassLoader().loadClass("org.mortbay.jetty.annotations.AnnotationParser");
        Method parseAnnotationsMethod = annotationParserClass.getMethod("parseAnnotations", WebAppContext.class, Class.class, RunAsCollection.class, InjectionCollection.class, LifeCycleCallbackCollection.class);
        //look thru _servlets
        Iterator itor = LazyList.iterator(_servlets);
        while (itor.hasNext()) {
            ServletHolder holder = (ServletHolder) itor.next();
            //TODO: Some paths within Jetty can acquire persistent file locks on the jars containing these classes.
            Class servlet = getWebAppContext().loadClass(holder.getClassName());
            parseAnnotationsMethod.invoke(null, getWebAppContext(), servlet, _runAsCollection, _injections, _callbacks);
        }
        //look thru _filters
        itor = LazyList.iterator(_filters);
        while (itor.hasNext()) {
            FilterHolder holder = (FilterHolder) itor.next();
            Class filter = getWebAppContext().loadClass(holder.getClassName());
            parseAnnotationsMethod.invoke(null, getWebAppContext(), filter, null, _injections, _callbacks);
        }
        //look thru _listeners
        itor = LazyList.iterator(_listeners);
        while (itor.hasNext()) {
            Object listener = itor.next();
            parseAnnotationsMethod.invoke(null, getWebAppContext(), listener.getClass(), null, _injections, _callbacks);
        }
    } else {
        Log.info("Annotations are not supported on jvms prior to jdk1.5");
    }
}
Also used : FilterHolder(org.mortbay.jetty.servlet.FilterHolder) ServletHolder(org.mortbay.jetty.servlet.ServletHolder) Iterator(java.util.Iterator) Method(java.lang.reflect.Method)

Example 12 with ServletHolder

use of org.mortbay.jetty.servlet.ServletHolder in project commons by twitter.

the class JettyHttpServerDispatch method registerHandler.

@Override
public synchronized void registerHandler(String path, HttpServlet handler, @Nullable Map<String, String> initParams, boolean silent) {
    Preconditions.checkNotNull(path);
    Preconditions.checkNotNull(handler);
    Preconditions.checkState(path.length() > 0);
    Preconditions.checkState(path.charAt(0) == '/');
    if (silent) {
        registeredEndpoints.remove(path);
    } else {
        registeredEndpoints.add(path);
    }
    ServletHolder servletHolder = new ServletHolder(handler);
    if (initParams != null) {
        servletHolder.setInitParameters(initParams);
    }
    getRootContext().addServlet(servletHolder, path.replaceFirst("/?$", "/*"));
}
Also used : ServletHolder(org.mortbay.jetty.servlet.ServletHolder)

Example 13 with ServletHolder

use of org.mortbay.jetty.servlet.ServletHolder in project jackrabbit by apache.

the class LitmusTest method testLitmus.

public void testLitmus() throws Exception {
    File dir = new File("target", "litmus");
    String litmus = System.getProperty("litmus", "litmus");
    if (Boolean.getBoolean("jackrabbit.test.integration") && isLitmusAvailable(litmus)) {
        final Repository repository = JcrUtils.getRepository("jcr-jackrabbit://" + Text.escapePath(dir.getCanonicalPath()));
        // for the TransientRepository
        Session session = repository.login();
        try {
            SocketConnector connector = new SocketConnector();
            connector.setHost("localhost");
            connector.setPort(Integer.getInteger("litmus.port", 0));
            Server server = new Server();
            server.addConnector(connector);
            ServletHolder holder = new ServletHolder(new SimpleWebdavServlet() {

                @Override
                public Repository getRepository() {
                    return repository;
                }
            });
            holder.setInitParameter("resource-config", "/config.xml");
            Context context = new Context(server, "/");
            context.setResourceBase("src/test/resources");
            context.addServlet(holder, "/*");
            server.addHandler(context);
            server.start();
            try {
                int port = connector.getLocalPort();
                String url = "http://localhost:" + port + "/default";
                ProcessBuilder builder = new ProcessBuilder(litmus, url, "admin", "admin");
                builder.directory(dir);
                builder.redirectErrorStream();
                assertLitmus(builder, "basic", 0);
                assertLitmus(builder, "http", 0);
                assertLitmus(builder, "props", 0);
                // FIXME: JCR-2637: WebDAV shallow copy test failure
                assertLitmus(builder, "copymove", 1);
                // FIXME: JCR-2638: Litmus locks test failures
                assertLitmus(builder, "locks", 1);
            } finally {
                server.stop();
            }
        } finally {
            session.logout();
        }
    }
}
Also used : Context(org.mortbay.jetty.servlet.Context) Repository(javax.jcr.Repository) Server(org.mortbay.jetty.Server) ServletHolder(org.mortbay.jetty.servlet.ServletHolder) File(java.io.File) SocketConnector(org.mortbay.jetty.bio.SocketConnector) Session(javax.jcr.Session)

Aggregations

ServletHolder (org.mortbay.jetty.servlet.ServletHolder)13 Server (org.mortbay.jetty.Server)9 Context (org.mortbay.jetty.servlet.Context)8 SelectChannelConnector (org.mortbay.jetty.nio.SelectChannelConnector)4 SocketConnector (org.mortbay.jetty.bio.SocketConnector)3 IOException (java.io.IOException)2 Repository (javax.jcr.Repository)2 FilterHolder (org.mortbay.jetty.servlet.FilterHolder)2 QueuedThreadPool (org.mortbay.thread.QueuedThreadPool)2 VoldemortServer (voldemort.server.VoldemortServer)2 TearDown (com.google.common.testing.TearDown)1 File (java.io.File)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 RepositoryException (javax.jcr.RepositoryException)1 Session (javax.jcr.Session)1 ServletException (javax.servlet.ServletException)1 Configuration (org.apache.hadoop.conf.Configuration)1 JcrRemotingServlet (org.apache.jackrabbit.server.remoting.davex.JcrRemotingServlet)1