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);
}
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;
}
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;
}
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);
}
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);
}
Aggregations