Search in sources :

Example 36 with URI

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;
}
Also used : IgniteComputeEndpoint(org.apache.camel.component.ignite.compute.IgniteComputeEndpoint) MalformedURLException(java.net.MalformedURLException) IgniteMessagingEndpoint(org.apache.camel.component.ignite.messaging.IgniteMessagingEndpoint) IgniteQueueEndpoint(org.apache.camel.component.ignite.queue.IgniteQueueEndpoint) IgniteCacheEndpoint(org.apache.camel.component.ignite.cache.IgniteCacheEndpoint) IgniteSetEndpoint(org.apache.camel.component.ignite.set.IgniteSetEndpoint) IgniteIdGenEndpoint(org.apache.camel.component.ignite.idgen.IgniteIdGenEndpoint) URI(java.net.URI) IgniteEventsEndpoint(org.apache.camel.component.ignite.events.IgniteEventsEndpoint)

Example 37 with URI

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);
    }
}
Also used : ArrayList(java.util.ArrayList) RuntimeCamelException(org.apache.camel.RuntimeCamelException) URI(java.net.URI) RuntimeCamelException(org.apache.camel.RuntimeCamelException) URISyntaxException(java.net.URISyntaxException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 38 with URI

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

Example 39 with URI

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;
}
Also used : Subtask(com.atlassian.jira.rest.client.domain.Subtask) Issue(com.atlassian.jira.rest.client.domain.Issue) BasicIssue(com.atlassian.jira.rest.client.domain.BasicIssue) BasicVotes(com.atlassian.jira.rest.client.domain.BasicVotes) Attachment(com.atlassian.jira.rest.client.domain.Attachment) BasicProject(com.atlassian.jira.rest.client.domain.BasicProject) URI(java.net.URI) DateTime(org.joda.time.DateTime) BasicIssueType(com.atlassian.jira.rest.client.domain.BasicIssueType) Field(com.atlassian.jira.rest.client.domain.Field) BasicUser(com.atlassian.jira.rest.client.domain.BasicUser) Worklog(com.atlassian.jira.rest.client.domain.Worklog) Version(com.atlassian.jira.rest.client.domain.Version) BasicComponent(com.atlassian.jira.rest.client.domain.BasicComponent) BasicPriority(com.atlassian.jira.rest.client.domain.BasicPriority) Comment(com.atlassian.jira.rest.client.domain.Comment) IssueLink(com.atlassian.jira.rest.client.domain.IssueLink) BasicWatchers(com.atlassian.jira.rest.client.domain.BasicWatchers) BasicResolution(com.atlassian.jira.rest.client.domain.BasicResolution) ChangelogGroup(com.atlassian.jira.rest.client.domain.ChangelogGroup) JSONObject(org.codehaus.jettison.json.JSONObject) TimeTracking(com.atlassian.jira.rest.client.domain.TimeTracking) BasicIssue(com.atlassian.jira.rest.client.domain.BasicIssue) BasicStatus(com.atlassian.jira.rest.client.domain.BasicStatus)

Example 40 with URI

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

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