use of java.net.URISyntaxException in project jetty.project by eclipse.
the class AntWebInfConfiguration method preConfigure.
@Override
public void preConfigure(final WebAppContext context) throws Exception {
//Make a temp directory for the webapp if one is not already set
resolveTempDirectory(context);
//Extract webapp if necessary
unpack(context);
//Apply an initial ordering to the jars which governs which will be scanned for META-INF
//info and annotations. The ordering is based on inclusion patterns.
String tmp = (String) context.getAttribute(WEBINF_JAR_PATTERN);
Pattern webInfPattern = (tmp == null ? null : Pattern.compile(tmp));
tmp = (String) context.getAttribute(CONTAINER_JAR_PATTERN);
Pattern containerPattern = (tmp == null ? null : Pattern.compile(tmp));
//Apply ordering to container jars - if no pattern is specified, we won't
//match any of the container jars
PatternMatcher containerJarNameMatcher = new PatternMatcher() {
public void matched(URI uri) throws Exception {
context.getMetaData().addContainerResource(Resource.newResource(uri));
}
};
ClassLoader loader = context.getClassLoader();
if (loader != null) {
loader = loader.getParent();
if (loader != null) {
URI[] containerUris = null;
if (loader instanceof URLClassLoader) {
URL[] urls = ((URLClassLoader) loader).getURLs();
if (urls != null) {
containerUris = new URI[urls.length];
int i = 0;
for (URL u : urls) {
try {
containerUris[i] = u.toURI();
} catch (URISyntaxException e) {
containerUris[i] = new URI(u.toString().replaceAll(" ", "%20"));
}
i++;
}
}
} else if (loader instanceof AntClassLoader) {
AntClassLoader antLoader = (AntClassLoader) loader;
String[] paths = antLoader.getClasspath().split(new String(new char[] { File.pathSeparatorChar }));
if (paths != null) {
containerUris = new URI[paths.length];
int i = 0;
for (String p : paths) {
File f = new File(p);
containerUris[i] = f.toURI();
i++;
}
}
}
containerJarNameMatcher.match(containerPattern, containerUris, false);
}
}
//Apply ordering to WEB-INF/lib jars
PatternMatcher webInfJarNameMatcher = new PatternMatcher() {
@Override
public void matched(URI uri) throws Exception {
context.getMetaData().addWebInfJar(Resource.newResource(uri));
}
};
List<Resource> jars = findJars(context);
//Convert to uris for matching
URI[] uris = null;
if (jars != null) {
uris = new URI[jars.size()];
int i = 0;
for (Resource r : jars) {
uris[i++] = r.getURI();
}
}
//null is inclusive, no pattern == all jars match
webInfJarNameMatcher.match(webInfPattern, uris, true);
//No pattern to appy to classes, just add to metadata
context.getMetaData().setWebInfClassesDirs(findClassDirs(context));
}
use of java.net.URISyntaxException in project jetty.project by eclipse.
the class HttpURIParseTest method testCompareToJavaNetURI.
@Test
public void testCompareToJavaNetURI() throws Exception {
URI javaUri = null;
try {
javaUri = new URI(input);
assumeNotNull(javaUri);
} catch (URISyntaxException e) {
// Ignore, as URI is invalid anyway
assumeNoException(e);
}
HttpURI httpUri = new HttpURI(javaUri);
assertThat("[" + input + "] .scheme", httpUri.getScheme(), is(javaUri.getScheme()));
assertThat("[" + input + "] .host", httpUri.getHost(), is(javaUri.getHost()));
assertThat("[" + input + "] .port", httpUri.getPort(), is(javaUri.getPort()));
assertThat("[" + input + "] .path", httpUri.getPath(), is(javaUri.getRawPath()));
// Not Relevant for java.net.URI -- assertThat("["+input+"] .param", httpUri.getParam(), is(param));
assertThat("[" + input + "] .query", httpUri.getQuery(), is(javaUri.getRawQuery()));
assertThat("[" + input + "] .fragment", httpUri.getFragment(), is(javaUri.getFragment()));
assertThat("[" + input + "] .toString", httpUri.toString(), is(javaUri.toASCIIString()));
}
use of java.net.URISyntaxException in project jetty.project by eclipse.
the class HttpURIParseTest method testParseURI.
@Test
public void testParseURI() throws Exception {
URI javaUri = null;
try {
javaUri = new URI(input);
assumeNotNull(javaUri);
} catch (URISyntaxException e) {
// Ignore, as URI is invalid anyway
assumeNoException(e);
}
HttpURI httpUri = new HttpURI(javaUri);
assertThat("[" + input + "] .scheme", httpUri.getScheme(), is(scheme));
assertThat("[" + input + "] .host", httpUri.getHost(), is(host));
assertThat("[" + input + "] .port", httpUri.getPort(), is(port == null ? -1 : Integer.parseInt(port)));
assertThat("[" + input + "] .path", httpUri.getPath(), is(path));
assertThat("[" + input + "] .param", httpUri.getParam(), is(param));
assertThat("[" + input + "] .query", httpUri.getQuery(), is(query));
assertThat("[" + input + "] .fragment", httpUri.getFragment(), is(fragment));
assertThat("[" + input + "] .toString", httpUri.toString(), is(input));
}
use of java.net.URISyntaxException in project jetty.project by eclipse.
the class AttributeNormalizer method toCanonicalURI.
private static URI toCanonicalURI(URI uri) {
uri = uri.normalize();
String ascii = uri.toASCIIString();
if (ascii.endsWith("/")) {
try {
uri = new URI(ascii.substring(0, ascii.length() - 1));
} catch (URISyntaxException e) {
throw new IllegalArgumentException(e);
}
}
return uri;
}
use of java.net.URISyntaxException in project elasticsearch by elastic.
the class Bootstrap method setup.
private void setup(boolean addShutdownHook, Environment environment) throws BootstrapException {
Settings settings = environment.settings();
try {
spawner.spawnNativePluginControllers(environment);
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
try {
spawner.close();
} catch (IOException e) {
throw new ElasticsearchException("Failed to destroy spawned controllers", e);
}
}
});
} catch (IOException e) {
throw new BootstrapException(e);
}
initializeNatives(environment.tmpFile(), BootstrapSettings.MEMORY_LOCK_SETTING.get(settings), BootstrapSettings.SYSTEM_CALL_FILTER_SETTING.get(settings), BootstrapSettings.CTRLHANDLER_SETTING.get(settings));
// initialize probes before the security manager is installed
initializeProbes();
if (addShutdownHook) {
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
try {
IOUtils.close(node);
LoggerContext context = (LoggerContext) LogManager.getContext(false);
Configurator.shutdown(context);
} catch (IOException ex) {
throw new ElasticsearchException("failed to stop node", ex);
}
}
});
}
try {
// look for jar hell
JarHell.checkJarHell();
} catch (IOException | URISyntaxException e) {
throw new BootstrapException(e);
}
// Log ifconfig output before SecurityManager is installed
IfConfig.logIfNecessary();
// install SM after natives, shutdown hooks, etc.
try {
Security.configure(environment, BootstrapSettings.SECURITY_FILTER_BAD_DEFAULTS_SETTING.get(settings));
} catch (IOException | NoSuchAlgorithmException e) {
throw new BootstrapException(e);
}
node = new Node(environment) {
@Override
protected void validateNodeBeforeAcceptingRequests(final Settings settings, final BoundTransportAddress boundTransportAddress, List<BootstrapCheck> checks) throws NodeValidationException {
BootstrapChecks.check(settings, boundTransportAddress, checks);
}
};
}
Aggregations