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");
}
}
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("/?$", "/*"));
}
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();
}
}
}
Aggregations