use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.
the class WebAppClassLoader method addJars.
/* ------------------------------------------------------------ */
/** Add elements to the class path for the context from the jar and zip files found
* in the specified resource.
* @param lib the resource that contains the jar and/or zip files.
*/
public void addJars(Resource lib) {
if (lib.exists() && lib.isDirectory()) {
String[] files = lib.list();
for (int f = 0; files != null && f < files.length; f++) {
try {
Resource fn = lib.addPath(files[f]);
if (LOG.isDebugEnabled())
LOG.debug("addJar - {}", fn);
String fnlc = fn.getName().toLowerCase(Locale.ENGLISH);
// don't check if this is a directory, see Bug 353165
if (isFileSupported(fnlc)) {
String jar = fn.toString();
jar = StringUtil.replace(jar, ",", "%2C");
jar = StringUtil.replace(jar, ";", "%3B");
addClassPath(jar);
}
} catch (Exception ex) {
LOG.warn(Log.EXCEPTION, ex);
}
}
}
}
use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.
the class WebAppClassLoader method addClassPath.
/* ------------------------------------------------------------ */
/**
* @param classPath Comma or semicolon separated path of filenames or URLs
* pointing to directories or jar files. Directories should end
* with '/'.
* @throws IOException if unable to add classpath
*/
public void addClassPath(String classPath) throws IOException {
if (classPath == null)
return;
StringTokenizer tokenizer = new StringTokenizer(classPath, ",;");
while (tokenizer.hasMoreTokens()) {
Resource resource = _context.newResource(tokenizer.nextToken().trim());
if (LOG.isDebugEnabled())
LOG.debug("Path resource=" + resource);
// Add the resource
if (resource.isDirectory() && resource instanceof ResourceCollection)
addClassPath(resource);
else {
// Resolve file path if possible
File file = resource.getFile();
if (file != null) {
URL url = resource.getURI().toURL();
addURL(url);
} else if (resource.isDirectory()) {
addURL(resource.getURI().toURL());
} else {
if (LOG.isDebugEnabled())
LOG.debug("Check file exists and is not nested jar: " + resource);
throw new IllegalArgumentException("File not resolvable or incompatible with URLClassloader: " + resource);
}
}
}
}
use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.
the class WebAppContext method getResource.
/* ------------------------------------------------------------ */
@Override
public Resource getResource(String uriInContext) throws MalformedURLException {
if (uriInContext == null || !uriInContext.startsWith(URIUtil.SLASH))
throw new MalformedURLException(uriInContext);
IOException ioe = null;
Resource resource = null;
int loop = 0;
while (uriInContext != null && loop++ < 100) {
try {
resource = super.getResource(uriInContext);
if (resource != null && resource.exists())
return resource;
uriInContext = getResourceAlias(uriInContext);
} catch (IOException e) {
LOG.ignore(e);
if (ioe == null)
ioe = e;
}
}
if (ioe != null && ioe instanceof MalformedURLException)
throw (MalformedURLException) ioe;
return resource;
}
use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.
the class SslContextFactoryTest method testResourceTsResourceKs.
@Test
public void testResourceTsResourceKs() throws Exception {
Resource keystoreResource = Resource.newSystemResource("keystore");
Resource truststoreResource = Resource.newSystemResource("keystore");
cf.setKeyStoreResource(keystoreResource);
cf.setTrustStoreResource(truststoreResource);
cf.setKeyStorePassword("storepwd");
cf.setKeyManagerPassword("keypwd");
cf.setTrustStorePassword("storepwd");
cf.start();
assertTrue(cf.getSslContext() != null);
}
use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.
the class MetaData method resolve.
/**
* Resolve all servlet/filter/listener metadata from all sources: descriptors and annotations.
*
* @param context the context to resolve servlets / filters / listeners metadata from
* @throws Exception if unable to resolve metadata
*/
public void resolve(WebAppContext context) throws Exception {
LOG.debug("metadata resolve {}", context);
//Ensure origins is fresh
_origins.clear();
// Set the ordered lib attribute
List<Resource> orderedWebInfJars = null;
if (getOrdering() != null) {
orderedWebInfJars = getOrderedWebInfJars();
List<String> orderedLibs = new ArrayList<String>();
for (Resource webInfJar : orderedWebInfJars) {
//get just the name of the jar file
String fullname = webInfJar.getName();
int i = fullname.indexOf(".jar");
int j = fullname.lastIndexOf("/", i);
orderedLibs.add(fullname.substring(j + 1, i + 4));
}
context.setAttribute(ServletContext.ORDERED_LIBS, orderedLibs);
}
// set the webxml version
if (_webXmlRoot != null) {
context.getServletContext().setEffectiveMajorVersion(_webXmlRoot.getMajorVersion());
context.getServletContext().setEffectiveMinorVersion(_webXmlRoot.getMinorVersion());
}
for (DescriptorProcessor p : _descriptorProcessors) {
p.process(context, getWebDefault());
p.process(context, getWebXml());
for (WebDescriptor wd : getOverrideWebs()) {
LOG.debug("process {} {}", context, wd);
p.process(context, wd);
}
}
//get an apply the annotations that are not associated with a fragment (and hence for
//which no ordering applies
List<DiscoveredAnnotation> nonFragAnnotations = _annotations.get(NON_FRAG_RESOURCE);
if (nonFragAnnotations != null) {
for (DiscoveredAnnotation a : nonFragAnnotations) {
LOG.debug("apply {}", a);
a.apply();
}
}
//apply the annotations that are associated with a fragment, according to the
//established ordering
List<Resource> resources = null;
if (getOrdering() != null)
resources = orderedWebInfJars;
else
resources = getWebInfJars();
for (Resource r : resources) {
FragmentDescriptor fd = _webFragmentResourceMap.get(r);
if (fd != null) {
for (DescriptorProcessor p : _descriptorProcessors) {
LOG.debug("process {} {}", context, fd);
p.process(context, fd);
}
}
List<DiscoveredAnnotation> fragAnnotations = _annotations.get(r);
if (fragAnnotations != null) {
for (DiscoveredAnnotation a : fragAnnotations) {
LOG.debug("apply {}", a);
a.apply();
}
}
}
}
Aggregations