use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.
the class AnnotationConfiguration method parseContainerPath.
/**
* Scan jars on container path.
*
* @param context the context for the scan
* @param parser the parser to scan with
* @throws Exception if unable to scan
*/
public void parseContainerPath(final WebAppContext context, final AnnotationParser parser) throws Exception {
//always parse for discoverable annotations as well as class hierarchy and servletcontainerinitializer related annotations
final Set<Handler> handlers = new HashSet<Handler>();
handlers.addAll(_discoverableAnnotationHandlers);
handlers.addAll(_containerInitializerAnnotationHandlers);
if (_classInheritanceHandler != null)
handlers.add(_classInheritanceHandler);
_containerPathStats = new CounterStatistic();
for (Resource r : context.getMetaData().getContainerResources()) {
//queue it up for scanning if using multithreaded mode
if (_parserTasks != null) {
ParserTask task = new ParserTask(parser, handlers, r);
_parserTasks.add(task);
_containerPathStats.increment();
if (LOG.isDebugEnabled())
task.setStatistic(new TimeStatistic());
}
}
}
use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.
the class AnnotationParser method parse.
/**
* Parse a given class
*
* @param handlers the set of handlers to find class
* @param className the class name to parse
* @throws Exception if unable to parse
*/
public void parse(Set<? extends Handler> handlers, String className) throws Exception {
if (className == null)
return;
if (!isParsed(className)) {
className = className.replace('.', '/') + ".class";
URL resource = Loader.getResource(className);
if (resource != null) {
Resource r = Resource.newResource(resource);
try (InputStream is = r.getInputStream()) {
scanClass(handlers, null, is);
}
}
}
}
use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.
the class AnnotationParser method parseDir.
/**
* Parse all classes in a directory
*
* @param handlers the set of handlers to look for classes in
* @param dir the resource directory to look for classes
* @throws Exception if unable to parse
*/
protected void parseDir(Set<? extends Handler> handlers, Resource dir) throws Exception {
// skip dirs whose name start with . (ie hidden)
if (!dir.isDirectory() || !dir.exists() || dir.getName().startsWith("."))
return;
if (LOG.isDebugEnabled()) {
LOG.debug("Scanning dir {}", dir);
}
;
MultiException me = new MultiException();
String[] files = dir.list();
for (int f = 0; files != null && f < files.length; f++) {
Resource res = dir.addPath(files[f]);
if (res.isDirectory())
parseDir(handlers, res);
else {
//we've already verified the directories, so just verify the class file name
File file = res.getFile();
if (isValidClassFileName((file == null ? null : file.getName()))) {
try {
String name = res.getName();
if (!isParsed(name)) {
Resource r = Resource.newResource(res.getURL());
if (LOG.isDebugEnabled()) {
LOG.debug("Scanning class {}", r);
}
;
try (InputStream is = r.getInputStream()) {
scanClass(handlers, dir, is);
}
}
} catch (Exception ex) {
if (LOG.isDebugEnabled())
LOG.debug("Error scanning file " + files[f], ex);
me.add(new RuntimeException("Error scanning file " + files[f], ex));
}
} else {
if (LOG.isDebugEnabled())
LOG.debug("Skipping scan on invalid file {}", res);
}
}
}
me.ifExceptionThrow();
}
use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.
the class JarServer method main.
public static void main(String[] args) throws Exception {
Server server = new Server(8080);
ServletContextHandler context = new ServletContextHandler();
Resource.setDefaultUseCaches(true);
Resource base = Resource.newResource("jar:file:src/main/resources/content.jar!/");
context.setBaseResource(base);
context.addServlet(new ServletHolder(new DefaultServlet()), "/");
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { context, new DefaultHandler() });
server.setHandler(handlers);
server.start();
server.join();
}
use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.
the class GlobalWebappConfigBinding method processBinding.
public void processBinding(Node node, App app) throws Exception {
ContextHandler handler = app.getContextHandler();
if (handler == null) {
throw new NullPointerException("No Handler created for App: " + app);
}
if (handler instanceof WebAppContext) {
WebAppContext context = (WebAppContext) handler;
if (LOG.isDebugEnabled()) {
LOG.debug("Binding: Configuring webapp context with global settings from: " + _jettyXml);
}
if (_jettyXml == null) {
LOG.warn("Binding: global context binding is enabled but no jetty-web.xml file has been registered");
}
Resource globalContextSettings = Resource.newResource(_jettyXml);
if (globalContextSettings.exists()) {
XmlConfiguration jettyXmlConfig = new XmlConfiguration(globalContextSettings.getInputStream());
Resource resource = Resource.newResource(app.getOriginId());
File file = resource.getFile();
jettyXmlConfig.getIdMap().put("Server", app.getDeploymentManager().getServer());
jettyXmlConfig.getProperties().put("jetty.home", System.getProperty("jetty.home", "."));
jettyXmlConfig.getProperties().put("jetty.base", System.getProperty("jetty.base", "."));
jettyXmlConfig.getProperties().put("jetty.webapp", file.getCanonicalPath());
jettyXmlConfig.getProperties().put("jetty.webapps", file.getParentFile().getCanonicalPath());
jettyXmlConfig.configure(context);
} else {
LOG.info("Binding: Unable to locate global webapp context settings: " + _jettyXml);
}
}
}
Aggregations