Search in sources :

Example 1 with URISyntaxException

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));
}
Also used : Pattern(java.util.regex.Pattern) Resource(org.eclipse.jetty.util.resource.Resource) AntClassLoader(org.apache.tools.ant.AntClassLoader) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URL(java.net.URL) URLClassLoader(java.net.URLClassLoader) WebAppClassLoader(org.eclipse.jetty.webapp.WebAppClassLoader) AntClassLoader(org.apache.tools.ant.AntClassLoader) URLClassLoader(java.net.URLClassLoader) PatternMatcher(org.eclipse.jetty.util.PatternMatcher) File(java.io.File)

Example 2 with URISyntaxException

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()));
}
Also used : URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) Test(org.junit.Test)

Example 3 with URISyntaxException

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));
}
Also used : URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) Test(org.junit.Test)

Example 4 with URISyntaxException

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;
}
Also used : URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 5 with URISyntaxException

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);
        }
    };
}
Also used : Node(org.elasticsearch.node.Node) IOException(java.io.IOException) ElasticsearchException(org.elasticsearch.ElasticsearchException) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) LoggerContext(org.apache.logging.log4j.core.LoggerContext) NodeValidationException(org.elasticsearch.node.NodeValidationException) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) Settings(org.elasticsearch.common.settings.Settings) SecureSettings(org.elasticsearch.common.settings.SecureSettings)

Aggregations

URISyntaxException (java.net.URISyntaxException)4043 URI (java.net.URI)2496 IOException (java.io.IOException)1273 File (java.io.File)716 URL (java.net.URL)702 ArrayList (java.util.ArrayList)407 Test (org.junit.Test)274 MalformedURLException (java.net.MalformedURLException)270 InputStream (java.io.InputStream)224 HashMap (java.util.HashMap)212 Response (javax.ws.rs.core.Response)194 Test (org.testng.annotations.Test)175 Parameters (org.testng.annotations.Parameters)166 Builder (javax.ws.rs.client.Invocation.Builder)165 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)165 Map (java.util.Map)162 StorageException (com.microsoft.azure.storage.StorageException)142 Path (java.nio.file.Path)141 URIBuilder (org.apache.http.client.utils.URIBuilder)140 List (java.util.List)125