Search in sources :

Example 41 with URI

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

the class KestrelComponent method createEndpoint.

protected KestrelEndpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
    // Copy the configuration as each endpoint can override defaults
    KestrelConfiguration config = getConfiguration().copy();
    // Parse the URI, expected to be in one of the following formats:
    // 1. Use the base KestrelConfiguration for host addresses:
    //      kestrel://queue[?parameters]
    //      kestrel:///queue[?parameters]
    // 2. Override the host, but use the default port:
    //      kestrel://host/queue[?parameters]
    // 3. Override the host and port:
    //      kestrel://host:port/queue[?parameters]
    // 4. Supply a list of host addresses:
    //      kestrel://host[:port],host[:port]/queue[?parameters]
    URI u = new URI(uri);
    String queue;
    String[] addresses = null;
    if (u.getPath() == null || "".equals(u.getPath())) {
        // This would be the case when they haven't specified any explicit
        // address(es), and the queue ends up in the "authority" portion of
        // the URI.  For example:
        //      kestrel://queue[?parameters]
        queue = u.getAuthority();
    } else if (u.getAuthority() == null || "".equals(u.getAuthority())) {
        // The "path" was present without an authority, such as:
        //      kestrel:///queue[?parameters]
        queue = u.getPath();
    } else {
        // Both "path" and "authority" were present in the URI, which
        // means both address(es) and the queue were specified, i.e.:
        //      kestrel://host/queue[?parameters]
        //      kestrel://host:port/queue[?parameters]
        //      kestrel://host[:port],host[:port]/queue[?parameters]
        addresses = u.getAuthority().split(",");
        queue = u.getPath();
    }
    // Trim off any slash(es), i.e. "/queue/" -> "queue"
    while (queue.startsWith("/")) {
        queue = queue.substring(1);
    }
    while (queue.endsWith("/")) {
        queue = queue.substring(0, queue.length() - 1);
    }
    if ("".equals(queue)) {
        // the path was just "/" or something...throw an exception.
        throw new IllegalArgumentException("Queue not specified in endpoint URI: " + uri);
    }
    if (addresses != null && addresses.length > 0) {
        // Override the addresses on the copied config
        config.setAddresses(addresses);
    } else {
        // make sure the addresses field was indeed set on the base config.
        if (config.getAddresses() == null) {
            throw new IllegalArgumentException("Addresses not set in base configuration or endpoint: " + uri);
        }
    }
    LOG.info("Creating endpoint for queue \"" + queue + "\" on " + config.getAddressesAsString() + ", parameters=" + parameters);
    // Finally, override config with any supplied URI parameters
    setProperties(config, parameters);
    // Create the endpoint for the given queue with the config we built
    return new KestrelEndpoint(uri, this, config, queue);
}
Also used : URI(java.net.URI)

Example 42 with URI

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

the class LuceneComponent method createEndpoint.

@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
    config.parseURI(new URI(uri), parameters, this);
    LuceneEndpoint luceneEndpoint = new LuceneEndpoint(uri, this, config);
    setProperties(luceneEndpoint.getConfig(), parameters);
    return luceneEndpoint;
}
Also used : URI(java.net.URI)

Example 43 with URI

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

the class MailComponent method createEndpoint.

@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
    URI url = new URI(uri);
    // must use copy as each endpoint can have different options
    MailConfiguration config = getConfiguration().copy();
    // only configure if we have a url with a known protocol
    config.configure(url);
    configureAdditionalJavaMailProperties(config, parameters);
    MailEndpoint endpoint = new MailEndpoint(uri, this, config);
    // special for search term bean reference
    Object searchTerm = getAndRemoveOrResolveReferenceParameter(parameters, "searchTerm", Object.class);
    if (searchTerm != null) {
        SearchTerm st;
        if (searchTerm instanceof SimpleSearchTerm) {
            // okay its a SimpleSearchTerm then lets convert that to SearchTerm
            st = MailConverters.toSearchTerm((SimpleSearchTerm) searchTerm, getCamelContext().getTypeConverter());
        } else {
            st = getCamelContext().getTypeConverter().mandatoryConvertTo(SearchTerm.class, searchTerm);
        }
        endpoint.setSearchTerm(st);
    }
    endpoint.setContentTypeResolver(contentTypeResolver);
    setProperties(endpoint.getConfiguration(), parameters);
    setProperties(endpoint, parameters);
    // special for searchTerm.xxx options
    Map<String, Object> sstParams = IntrospectionSupport.extractProperties(parameters, "searchTerm.");
    if (!sstParams.isEmpty()) {
        // use SimpleSearchTerm as POJO to store the configuration and then convert that to the actual SearchTerm
        SimpleSearchTerm sst = new SimpleSearchTerm();
        setProperties(sst, sstParams);
        SearchTerm st = MailConverters.toSearchTerm(sst, getCamelContext().getTypeConverter());
        endpoint.setSearchTerm(st);
    }
    // sanity check that we know the mail server
    ObjectHelper.notEmpty(config.getHost(), "host");
    ObjectHelper.notEmpty(config.getProtocol(), "protocol");
    return endpoint;
}
Also used : SearchTerm(javax.mail.search.SearchTerm) URI(java.net.URI)

Example 44 with URI

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

the class MinaComponent method createEndpoint.

@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
    // Using the configuration which set by the component as a default one
    // Since the configuration's properties will be set by the URI
    // we need to copy or create a new MinaConfiguration here
    MinaConfiguration config;
    if (configuration != null) {
        config = configuration.copy();
    } else {
        config = new MinaConfiguration();
    }
    URI u = new URI(remaining);
    config.setHost(u.getHost());
    config.setPort(u.getPort());
    config.setProtocol(u.getScheme());
    config.setFilters(resolveAndRemoveReferenceListParameter(parameters, "filters", IoFilter.class));
    setProperties(config, parameters);
    return createEndpoint(uri, config);
}
Also used : IoFilter(org.apache.mina.common.IoFilter) URI(java.net.URI)

Example 45 with URI

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

the class Mina2Component method createEndpoint.

@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
    // Using the configuration which set by the component as a default one
    // Since the configuration's properties will be set by the URI
    // we need to copy or create a new MinaConfiguration here
    // Using the configuration which set by the component as a default one
    // Since the configuration's properties will be set by the URI
    // we need to copy or create a new MinaConfiguration here
    Mina2Configuration config;
    if (configuration != null) {
        config = configuration.copy();
    } else {
        config = new Mina2Configuration();
    }
    URI u = new URI(remaining);
    config.setHost(u.getHost());
    config.setPort(u.getPort());
    config.setProtocol(u.getScheme());
    config.setFilters(resolveAndRemoveReferenceListParameter(parameters, "filters", IoFilter.class));
    setProperties(config, parameters);
    return createEndpoint(uri, config);
}
Also used : IoFilter(org.apache.mina.core.filterchain.IoFilter) URI(java.net.URI)

Aggregations

URI (java.net.URI)5680 Test (org.junit.Test)1852 URISyntaxException (java.net.URISyntaxException)1016 IOException (java.io.IOException)749 File (java.io.File)531 HashMap (java.util.HashMap)458 ArrayList (java.util.ArrayList)452 Test (org.testng.annotations.Test)394 Configuration (org.apache.hadoop.conf.Configuration)321 Path (org.apache.hadoop.fs.Path)267 URL (java.net.URL)266 Map (java.util.Map)262 Response (javax.ws.rs.core.Response)218 List (java.util.List)184 InputStream (java.io.InputStream)154 HashSet (java.util.HashSet)136 FileSystem (org.apache.hadoop.fs.FileSystem)135 RequestContext (com.linkedin.r2.message.RequestContext)129 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)128 RestRequest (com.linkedin.r2.message.rest.RestRequest)112