Search in sources :

Example 91 with URISyntaxException

use of java.net.URISyntaxException in project camel by apache.

the class HttpsRouteTest method configureSslContextFactory.

protected void configureSslContextFactory(SslContextFactory sslContextFactory) {
    sslContextFactory.setKeyManagerPassword(pwd);
    sslContextFactory.setKeyStorePassword(pwd);
    URL keyStoreUrl = this.getClass().getClassLoader().getResource("jsse/localhost.ks");
    try {
        sslContextFactory.setKeyStorePath(keyStoreUrl.toURI().getPath());
    } catch (URISyntaxException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
    sslContextFactory.setTrustStoreType("JKS");
}
Also used : URISyntaxException(java.net.URISyntaxException) URL(java.net.URL)

Example 92 with URISyntaxException

use of java.net.URISyntaxException in project camel by apache.

the class RestDefinition method asRouteApiDefinition.

/**
     * Transforms the rest api configuration into a {@link org.apache.camel.model.RouteDefinition} which
     * Camel routing engine uses to service the rest api docs.
     */
public static RouteDefinition asRouteApiDefinition(CamelContext camelContext, RestConfiguration configuration) {
    RouteDefinition answer = new RouteDefinition();
    // create the from endpoint uri which is using the rest-api component
    String from = "rest-api:" + configuration.getApiContextPath();
    // append options
    Map<String, Object> options = new HashMap<String, Object>();
    String routeId = configuration.getApiContextRouteId();
    if (routeId == null) {
        routeId = answer.idOrCreate(camelContext.getNodeIdFactory());
    }
    options.put("routeId", routeId);
    if (configuration.getComponent() != null && !configuration.getComponent().isEmpty()) {
        options.put("componentName", configuration.getComponent());
    }
    if (configuration.getApiContextIdPattern() != null) {
        options.put("contextIdPattern", configuration.getApiContextIdPattern());
    }
    if (!options.isEmpty()) {
        String query;
        try {
            query = URISupport.createQueryString(options);
        } catch (URISyntaxException e) {
            throw ObjectHelper.wrapRuntimeCamelException(e);
        }
        from = from + "?" + query;
    }
    // we use the same uri as the producer (so we have a little route for the rest api)
    String to = from;
    answer.fromRest(from);
    answer.id(routeId);
    answer.to(to);
    return answer;
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition) HashMap(java.util.HashMap) URISyntaxException(java.net.URISyntaxException)

Example 93 with URISyntaxException

use of java.net.URISyntaxException in project camel by apache.

the class DefaultPackageScanClassResolver method find.

protected void find(PackageScanFilter test, String packageName, ClassLoader loader, Set<Class<?>> classes) {
    if (log.isTraceEnabled()) {
        log.trace("Searching for: {} in package: {} using classloader: {}", new Object[] { test, packageName, loader.getClass().getName() });
    }
    Enumeration<URL> urls;
    try {
        urls = getResources(loader, packageName);
        if (!urls.hasMoreElements()) {
            log.trace("No URLs returned by classloader");
        }
    } catch (IOException ioe) {
        log.warn("Cannot read package: " + packageName, ioe);
        return;
    }
    while (urls.hasMoreElements()) {
        URL url = null;
        try {
            url = urls.nextElement();
            log.trace("URL from classloader: {}", url);
            url = customResourceLocator(url);
            String urlPath = url.getFile();
            urlPath = URLDecoder.decode(urlPath, "UTF-8");
            if (log.isTraceEnabled()) {
                log.trace("Decoded urlPath: {} with protocol: {}", urlPath, url.getProtocol());
            }
            // If it's a file in a directory, trim the stupid file: spec
            if (urlPath.startsWith("file:")) {
                // to remedy this then create new path without using the URLDecoder
                try {
                    urlPath = new URI(url.getFile()).getPath();
                } catch (URISyntaxException e) {
                // fallback to use as it was given from the URLDecoder
                // this allows us to work on Windows if users have spaces in paths
                }
                if (urlPath.startsWith("file:")) {
                    urlPath = urlPath.substring(5);
                }
            }
            // osgi bundles should be skipped
            if (url.toString().startsWith("bundle:") || urlPath.startsWith("bundle:")) {
                log.trace("Skipping OSGi bundle: {}", url);
                continue;
            }
            // bundle resource should be skipped
            if (url.toString().startsWith("bundleresource:") || urlPath.startsWith("bundleresource:")) {
                log.trace("Skipping bundleresource: {}", url);
                continue;
            }
            // Else it's in a JAR, grab the path to the jar
            if (urlPath.indexOf('!') > 0) {
                urlPath = urlPath.substring(0, urlPath.indexOf('!'));
            }
            log.trace("Scanning for classes in: {} matching criteria: {}", urlPath, test);
            File file = new File(urlPath);
            if (file.isDirectory()) {
                log.trace("Loading from directory using file: {}", file);
                loadImplementationsInDirectory(test, packageName, file, classes);
            } else {
                InputStream stream;
                if (urlPath.startsWith("http:") || urlPath.startsWith("https:") || urlPath.startsWith("sonicfs:") || isAcceptableScheme(urlPath)) {
                    // load resources using http/https, sonicfs and other acceptable scheme
                    // sonic ESB requires to be loaded using a regular URLConnection
                    log.trace("Loading from jar using url: {}", urlPath);
                    URL urlStream = new URL(urlPath);
                    URLConnection con = urlStream.openConnection();
                    // disable cache mainly to avoid jar file locking on Windows
                    con.setUseCaches(false);
                    stream = con.getInputStream();
                } else {
                    log.trace("Loading from jar using file: {}", file);
                    stream = new FileInputStream(file);
                }
                loadImplementationsInJar(test, packageName, stream, urlPath, classes, jarCache);
            }
        } catch (IOException e) {
            // use debug logging to avoid being to noisy in logs
            log.debug("Cannot read entries in url: " + url, e);
        }
    }
}
Also used : JarInputStream(java.util.jar.JarInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) File(java.io.File) URL(java.net.URL) URLConnection(java.net.URLConnection) FileInputStream(java.io.FileInputStream)

Example 94 with URISyntaxException

use of java.net.URISyntaxException in project camel by apache.

the class HttpHelper method createMethod.

/**
     * Creates the HttpMethod to use to call the remote server, often either its GET or POST.
     *
     * @param exchange  the exchange
     * @return the created method
     * @throws URISyntaxException
     */
public static HttpMethods createMethod(Exchange exchange, HttpCommonEndpoint endpoint, boolean hasPayload) throws URISyntaxException {
    // is a query string provided in the endpoint URI or in a header (header overrules endpoint)
    String queryString = exchange.getIn().getHeader(Exchange.HTTP_QUERY, String.class);
    // We need also check the HTTP_URI header query part
    String uriString = exchange.getIn().getHeader(Exchange.HTTP_URI, String.class);
    // resolve placeholders in uriString
    try {
        uriString = exchange.getContext().resolvePropertyPlaceholders(uriString);
    } catch (Exception e) {
        throw new RuntimeExchangeException("Cannot resolve property placeholders with uri: " + uriString, exchange, e);
    }
    if (uriString != null) {
        // in case the URI string contains unsafe characters
        uriString = UnsafeUriCharactersEncoder.encodeHttpURI(uriString);
        URI uri = new URI(uriString);
        queryString = uri.getQuery();
    }
    if (queryString == null) {
        queryString = endpoint.getHttpUri().getRawQuery();
    }
    HttpMethods answer;
    if (endpoint.getHttpMethod() != null) {
        // endpoint configured take precedence
        answer = endpoint.getHttpMethod();
    } else {
        // compute what method to use either GET or POST (header take precedence)
        HttpMethods m = exchange.getIn().getHeader(Exchange.HTTP_METHOD, HttpMethods.class);
        if (m != null) {
            // always use what end-user provides in a header
            answer = m;
        } else if (queryString != null) {
            // if a query string is provided then use GET
            answer = HttpMethods.GET;
        } else {
            // fallback to POST if we have payload, otherwise GET
            answer = hasPayload ? HttpMethods.POST : HttpMethods.GET;
        }
    }
    return answer;
}
Also used : RuntimeExchangeException(org.apache.camel.RuntimeExchangeException) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) ProtocolException(java.net.ProtocolException) RuntimeExchangeException(org.apache.camel.RuntimeExchangeException)

Example 95 with URISyntaxException

use of java.net.URISyntaxException in project camel by apache.

the class HttpMethodHelper method createMethod.

/**
     * Creates the HttpMethod to use to call the remote server, often either its GET or POST.
     *
     * @param exchange the exchange
     * @return the created method
     * @throws URISyntaxException 
     */
public static HttpMethods createMethod(Exchange exchange, HttpEndpoint endpoint, boolean hasPayload) throws URISyntaxException {
    // is a query string provided in the endpoint URI or in a header (header
    // overrules endpoint)
    String queryString = exchange.getIn().getHeader(Exchange.HTTP_QUERY, String.class);
    // We need also check the HTTP_URI header query part
    String uriString = exchange.getIn().getHeader(Exchange.HTTP_URI, String.class);
    // resolve placeholders in uriString
    try {
        uriString = exchange.getContext().resolvePropertyPlaceholders(uriString);
    } catch (Exception e) {
        throw new RuntimeExchangeException("Cannot resolve property placeholders with uri: " + uriString, exchange, e);
    }
    if (uriString != null) {
        // in case the URI string contains unsafe characters
        uriString = UnsafeUriCharactersEncoder.encodeHttpURI(uriString);
        URI uri = new URI(uriString);
        queryString = uri.getQuery();
    }
    if (queryString == null) {
        queryString = endpoint.getHttpUri().getRawQuery();
    }
    // compute what method to use either GET or POST
    HttpMethods answer;
    if (endpoint.getHttpMethod() != null) {
        // endpoint configured take precedence
        answer = HttpMethods.valueOf(endpoint.getHttpMethod().name());
    } else {
        // compute what method to use either GET or POST (header take precedence)
        HttpMethods m = exchange.getIn().getHeader(Exchange.HTTP_METHOD, HttpMethods.class);
        if (m != null) {
            // always use what end-user provides in a header
            answer = m;
        } else if (queryString != null) {
            // if a query string is provided then use GET
            answer = HttpMethods.GET;
        } else {
            // fallback to POST if we have payload, otherwise GET
            answer = hasPayload ? HttpMethods.POST : HttpMethods.GET;
        }
    }
    return answer;
}
Also used : RuntimeExchangeException(org.apache.camel.RuntimeExchangeException) HttpMethods(org.apache.camel.component.http4.HttpMethods) URI(java.net.URI) RuntimeExchangeException(org.apache.camel.RuntimeExchangeException) URISyntaxException(java.net.URISyntaxException)

Aggregations

URISyntaxException (java.net.URISyntaxException)1633 URI (java.net.URI)1080 IOException (java.io.IOException)451 URL (java.net.URL)287 File (java.io.File)280 ArrayList (java.util.ArrayList)146 MalformedURLException (java.net.MalformedURLException)102 InputStream (java.io.InputStream)93 HashMap (java.util.HashMap)91 Test (org.testng.annotations.Test)88 Response (javax.ws.rs.core.Response)87 Builder (javax.ws.rs.client.Invocation.Builder)84 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)84 Parameters (org.testng.annotations.Parameters)84 BaseTest (org.xdi.oxauth.BaseTest)84 ResponseType (org.xdi.oxauth.model.common.ResponseType)84 AuthorizationRequest (org.xdi.oxauth.client.AuthorizationRequest)78 Test (org.junit.Test)75 REGISTRATION_CLIENT_URI (org.xdi.oxauth.model.register.RegisterResponseParam.REGISTRATION_CLIENT_URI)72 Intent (android.content.Intent)63