use of java.net.URI in project camel by apache.
the class IgniteComponent method createEndpoint.
@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
ObjectHelper.notNull(getCamelContext(), "Camel Context");
AbstractIgniteEndpoint answer = null;
URI remainingUri = new URI(URISupport.normalizeUri(remaining));
String scheme = remainingUri.getScheme();
switch(scheme) {
case "cache":
answer = new IgniteCacheEndpoint(uri, remainingUri, parameters, this);
break;
case "compute":
answer = new IgniteComputeEndpoint(uri, remainingUri, parameters, this);
break;
case "messaging":
answer = new IgniteMessagingEndpoint(uri, remainingUri, parameters, this);
break;
case "events":
answer = new IgniteEventsEndpoint(uri, remainingUri, parameters, this);
break;
case "set":
answer = new IgniteSetEndpoint(uri, remainingUri, parameters, this);
break;
case "idgen":
answer = new IgniteIdGenEndpoint(uri, remainingUri, parameters, this);
break;
case "queue":
answer = new IgniteQueueEndpoint(uri, remainingUri, parameters, this);
break;
default:
throw new MalformedURLException("An invalid Ignite endpoint URI was provided. Please check that " + "it starts with:" + " ignite:[cache/compute/messaging/...]:...");
}
setProperties(answer, parameters);
return answer;
}
use of java.net.URI in project camel by apache.
the class IrcConfiguration method sanitize.
@Deprecated
public static String sanitize(String uri) {
// may be removed in camel-3.0.0
// make sure it's an URL first
int colon = uri.indexOf(':');
if (colon != -1 && uri.indexOf("://") != colon) {
uri = uri.substring(0, colon) + "://" + uri.substring(colon + 1);
}
try {
URI u = new URI(UnsafeUriCharactersEncoder.encode(uri));
String[] userInfo = u.getUserInfo() != null ? u.getUserInfo().split(":") : null;
String username = userInfo != null ? userInfo[0] : null;
String password = userInfo != null && userInfo.length > 1 ? userInfo[1] : null;
String path = URLDecoder.decode(u.getPath() != null ? u.getPath() : "", "UTF-8");
if (path.startsWith("/")) {
path = path.substring(1);
}
if (path.startsWith("#") && !path.startsWith("##")) {
path = path.substring(1);
}
Map<String, Object> parameters = URISupport.parseParameters(u);
String user = (String) parameters.get("username");
String nick = (String) parameters.get("nickname");
// not specified in authority
if (user != null) {
if (username == null) {
username = user;
} else if (!username.equals(user)) {
LOG.warn("Username specified twice in endpoint URI with different values. " + "The userInfo value ('{}') will be used, paramter ('{}') ignored", username, user);
}
parameters.remove("username");
}
if (nick != null) {
if (username == null) {
username = nick;
}
if (username.equals(nick)) {
// redundant
parameters.remove("nickname");
}
}
if (username == null) {
throw new RuntimeCamelException("IrcEndpoint URI with no user/nick specified is invalid");
}
String pwd = (String) parameters.get("password");
if (pwd != null) {
password = pwd;
parameters.remove("password");
}
// Remove unneeded '#' channel prefixes per convention
// and replace ',' separators and merge channel and key using convention "channel!key"
List<String> cl = new ArrayList<String>();
String channels = (String) parameters.get("channels");
String keys = (String) parameters.get("keys");
// if @keys ends with a ',' it will miss the last empty key after split(",")
keys = keys == null ? keys : keys + " ";
if (channels != null) {
String[] chs = channels.split(",");
String[] ks = keys != null ? keys.split(",") : null;
parameters.remove("channels");
int count = chs.length;
if (ks != null) {
parameters.remove("keys");
if (!path.isEmpty()) {
LOG.warn("Specifying a channel '{}' in the URI path is ambiguous" + " when @channels and @keys are provided and will be ignored", path);
path = "";
}
if (ks.length != chs.length) {
count = count < ks.length ? count : ks.length;
LOG.warn("Different count of @channels and @keys. Only the first {} are used.", count);
}
}
for (int i = 0; i < count; i++) {
String channel = chs[i].trim();
String key = ks != null ? ks[i].trim() : null;
if (channel.startsWith("#") && !channel.startsWith("##")) {
channel = channel.substring(1);
}
if (key != null && !key.isEmpty()) {
channel += "!" + key;
}
cl.add(channel);
}
} else {
if (path.isEmpty()) {
LOG.warn("No channel specified for the irc endpoint");
}
cl.add(path);
}
parameters.put("channel", cl);
StringBuilder sb = new StringBuilder();
sb.append(u.getScheme());
sb.append("://");
sb.append(username);
sb.append(password == null ? "" : ":" + password);
sb.append("@");
sb.append(u.getHost());
sb.append(u.getPort() == -1 ? "" : ":" + u.getPort());
// ignore the path we have it as a @channel now
String query = formatQuery(parameters);
if (!query.isEmpty()) {
sb.append("?");
sb.append(query);
}
// make things a bit more predictable
return sb.toString();
} catch (Exception e) {
throw new RuntimeCamelException(e);
}
}
use of java.net.URI in project camel by apache.
the class IrcConfiguration method configure.
public void configure(String uriStr) throws URISyntaxException, UnsupportedEncodingException {
// fix provided URI and handle that we can use # to indicate the IRC room
if (uriStr.startsWith("ircs")) {
setUsingSSL(true);
if (!uriStr.startsWith("ircs://")) {
uriStr = uriStr.replace("ircs:", "ircs://");
}
} else if (!uriStr.startsWith("irc://")) {
uriStr = uriStr.replace("irc:", "irc://");
}
if (uriStr.contains("?")) {
uriStr = ObjectHelper.before(uriStr, "?");
}
URI uri = new URI(uriStr);
// Because we can get a "sanitized" URI, we need to deal with the situation where the
// user info includes the username and password together or else we get a mangled username
// that includes the user's secret being sent to the server.
String userInfo = uri.getUserInfo();
String username = null;
String password = null;
if (userInfo != null) {
int colonIndex = userInfo.indexOf(":");
if (colonIndex != -1) {
username = userInfo.substring(0, colonIndex);
password = userInfo.substring(colonIndex + 1);
} else {
username = userInfo;
}
}
if (uri.getPort() != -1) {
setPorts(new int[] { uri.getPort() });
setPort(uri.getPort());
}
setNickname(username);
setUsername(username);
setRealname(username);
setPassword(password);
setHostname(uri.getHost());
String path = uri.getPath();
if (path != null && !path.isEmpty()) {
LOG.warn("Channel {} should not be specified in the URI path. Use an @channel query parameter instead.", path);
}
}
use of java.net.URI in project camel by apache.
the class MockIssueClient method getIssue.
@Override
public Issue getIssue(String issueKey, ProgressMonitor progressMonitor) {
String summary = null;
URI self = null;
BasicProject project = null;
BasicIssueType issueType = null;
BasicStatus status = null;
String description = null;
BasicPriority priority = null;
BasicResolution resolution = null;
Collection<Attachment> attachments = null;
BasicUser reporter = null;
BasicUser assignee = null;
DateTime creationDate = null;
DateTime updateDate = null;
DateTime dueDate = null;
Collection<Version> affectedVersions = null;
Collection<Version> fixVersions = null;
Collection<BasicComponent> components = null;
TimeTracking timeTracking = null;
Collection<Field> fields = null;
URI transitionsUri = null;
Collection<IssueLink> issueLinks = null;
BasicVotes votes = null;
Collection<Worklog> worklogs = null;
BasicWatchers watchers = null;
Iterable<String> expandos = null;
Collection<Subtask> subtasks = null;
Collection<ChangelogGroup> changelog = null;
Set<String> labels = null;
JSONObject rawObject = null;
BasicIssue basicIssue = mockSearchRestClient.getBasicIssue(issueKey);
Collection<Comment> comments = mockSearchRestClient.getCommentsForIssue(basicIssue.getId());
Issue issue = new Issue(summary, self, basicIssue.getKey(), basicIssue.getId(), project, issueType, status, description, priority, resolution, attachments, reporter, assignee, creationDate, updateDate, dueDate, affectedVersions, fixVersions, components, timeTracking, fields, comments, transitionsUri, issueLinks, votes, worklogs, watchers, expandos, subtasks, changelog, labels, rawObject);
return issue;
}
use of java.net.URI in project camel by apache.
the class JMXHandbackTest method setUp.
@Before
public void setUp() throws Exception {
hb = new URI("urn:some:handback:object");
super.setUp();
}
Aggregations