Example usage for java.net URI URI

List of usage examples for java.net URI URI

Introduction

In this page you can find the example usage for java.net URI URI.

Prototype

public URI(String str) throws URISyntaxException 

Source Link

Document

Constructs a URI by parsing the given string.

Usage

From source file:com.thoughtworks.go.util.command.UrlArgument.java

@Override
public String forDisplay() {
    try {/*  w  w w  .  j  a  v a  2s .  com*/
        URI uri = new URI(sanitizeUrl());
        if (uri.getUserInfo() != null) {
            uri = new URI(uri.getScheme(), clean(uri.getScheme(), uri.getUserInfo()), uri.getHost(),
                    uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment());
        }
        return uri.toString();
    } catch (URISyntaxException e) {
        return url;
    }
}

From source file:nl.esciencecenter.octopus.webservice.mac.MacCredentialTest.java

@Before
public void setup() {
    try {//from ww w .ja v  a  2 s.  co  m
        cred = new MacCredential("id", "key", new URI("http://localhost"));
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
}

From source file:com.mellanox.jxio.tests.benchmarks.StatClientSession.java

public StatClientSession(EventQueueHandler eqh, String uriString, int num_clients) {
    this.clients_count = 0;
    this.eqh = eqh;
    this.clients = new ClientSession[num_clients];

    URI uri = null;/*from  w w  w  . jav a 2  s. c  o  m*/
    try {
        uri = new URI(uriString);
    } catch (URISyntaxException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    for (int i = 0; i < num_clients; i++) {
        this.clients[i] = new ClientSession(eqh, uri, new StatSesClientCallbacks(i));
    }
}

From source file:com.rusticisoftware.tincan.Extensions.java

public Extensions(JsonNode jsonNode) throws URISyntaxException {
    Iterator<Map.Entry<String, JsonNode>> items = jsonNode.fields();
    while (items.hasNext()) {
        Map.Entry<String, JsonNode> item = items.next();

        this.put(new URI(item.getKey()), item.getValue());
    }//  www  . j  a v a 2  s.co  m
}

From source file:io.milton.httpclient.LockMethod.java

public LockMethod(String uri, int timeout) throws URISyntaxException {
    setURI(new URI(uri));
    this.timeout = timeout;
}

From source file:com.sap.prd.mobile.ios.mios.SCMUtil.java

public static String getConnectionString(final Properties versionInfo,
        final boolean hideConfidentialInformation) throws IOException {

    final String type = versionInfo.getProperty("type");

    final StringBuilder connectionString = new StringBuilder(128);

    if (type != null && type.equals("git")) {

        final String repo = versionInfo.getProperty("repo");

        if (StringUtils.isBlank(repo)) {
            if (!StringUtils.isBlank(versionInfo.getProperty("repo_1"))) {
                throw new IllegalStateException(
                        "Multipe git repositories provided. This use case is not supported. Provide only one git repository.");
            }// ww  w  .  j a va2  s  .co m
            throw new IllegalStateException("No git repository provided. ");
        }

        if (hideConfidentialInformation) {
            try {
                URI uri = new URI(repo);
                int port = uri.getPort();
                if (port == -1) {
                    final String scheme = uri.getScheme();
                    if (scheme != null && gitDefaultPorts.containsKey(scheme)) {
                        port = gitDefaultPorts.get(scheme);
                    }
                }
                connectionString.append(port);

                if (uri.getHost() != null) {
                    connectionString.append(uri.getPath());
                }
            } catch (URISyntaxException e) {
                throw new IllegalStateException(String.format("Invalid repository uri: %s", repo));
            }
        } else {
            connectionString.append(PROTOCOL_PREFIX_GIT).append(repo);
        }

    } else {

        final String port = versionInfo.getProperty("port");

        if (StringUtils.isBlank(port))
            throw new IllegalStateException("No SCM port provided.");

        final String depotPath = versionInfo.getProperty("depotpath");

        if (hideConfidentialInformation) {
            try {
                URI perforceUri = new URI("perforce://" + port);

                int _port = perforceUri.getPort();
                if (_port == -1) {
                    _port = PERFORCE_DEFAULT_PORT;
                }
                connectionString.append(_port);
                connectionString.append(depotPath);
            } catch (URISyntaxException e) {
                throw new IllegalStateException(String.format("Invalid port: %s", port));
            }
        } else {

            if (StringUtils.isBlank(depotPath))
                throw new IllegalStateException("No depot path provided.");

            connectionString.append(PROTOCOL_PREFIX_PERFORCE).append(port).append(":")
                    .append(getDepotPath(depotPath));
        }
    }

    return connectionString.toString();
}

From source file:org.ovirt.engine.sdk4.internal.SsoUtils.java

/**
 * Construct SSO URL to revoke SSO token
 *
 * @param url oVirt engine URL/*from   ww  w  . j  a  v a  2 s. c o m*/
 * @return URI to be used to revoke token
 */
public static URI buildSsoRevokeUrl(String url) {
    try {
        URI uri = new URI(url);
        URIBuilder uriBuilder = new URIBuilder(String.format("%1$s://%2$s/ovirt-engine/services/sso-logout",
                uri.getScheme(), uri.getAuthority()));
        return uriBuilder.build();
    } catch (URISyntaxException ex) {
        throw new Error("Failed to build SSO revoke URL", ex);
    }
}

From source file:org.gytheio.messaging.amqp.AmqpNodeBootstrapUtils.java

/**
 * Creates an AMQP endpoint (sender and receiver) from the given arguments
 * /*from   w w  w  . java  2  s  .  com*/
 * @param messageConsumer the processor received messages are sent to
 * @param args
 * @return
 */
public static AmqpDirectEndpoint createEndpoint(MessageConsumer messageConsumer, String brokerUrl,
        String brokerUsername, String brokerPassword, String requestEndpoint, String replyEndpoint) {
    validate(brokerUrl, requestEndpoint, replyEndpoint);

    AmqpDirectEndpoint messageProducer = new AmqpDirectEndpoint();
    ObjectMapper objectMapper = ObjectMapperFactory.createInstance();

    URI broker = null;
    try {
        broker = new URI(brokerUrl);
    } catch (URISyntaxException e) {
        // This would have been caught by validation above
    }

    ((AmqpDirectEndpoint) messageProducer).setHost(broker.getHost());
    Integer brokerPort = broker.getPort();
    if (brokerPort != null) {
        ((AmqpDirectEndpoint) messageProducer).setPort(brokerPort);
    }
    if (brokerUsername != null) {
        ((AmqpDirectEndpoint) messageProducer).setUsername(brokerUsername);
    }
    if (brokerPassword != null) {
        ((AmqpDirectEndpoint) messageProducer).setPassword(brokerPassword);
    }
    ((AmqpDirectEndpoint) messageProducer).setReceiveEndpoint(requestEndpoint);
    ((AmqpDirectEndpoint) messageProducer).setSendEndpoint(replyEndpoint);

    ((AmqpDirectEndpoint) messageProducer).setMessageConsumer(messageConsumer);
    ((AmqpDirectEndpoint) messageProducer).setObjectMapper(objectMapper);

    return messageProducer;
}

From source file:org.commonjava.cartographer.rest.util.ResponseUtils.java

public static Response formatCreatedResponse(final String baseUri, final String... params)
        throws URISyntaxException {
    final URI location = new URI(RestUtils.formatUrlTo(baseUri, params));
    return Response.created(location).build();
}

From source file:AuctionServlet.java

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
        PreparedStatement stmt = null;

        try {//from   www  .j a  v a  2  s . co  m

            Class.forName("org.postgresql.Driver");
            URI dbUri = new URI(
                    "postgres://mvraljhmxcpilo:bKYSixo3rO1Z0cxAmyqMMcK7PG@ec2-75-101-162-243.compute-1.amazonaws.com:5432/d89kgd9u0h1bk3?username=mvraljhmxcpilo&password=bKYSixo3rO1Z0cxAmyqMMcK7PG&ssl.true&sslfactory=org.postgresql.ssl.NonValidatingFactory");

            String username = dbUri.getUserInfo().split(":")[0];
            String password = dbUri.getUserInfo().split(":")[1];
            String dbUrl = "jdbc:postgresql://" + dbUri.getHost() + ':' + dbUri.getPort() + dbUri.getPath();

            this.conn = DriverManager.getConnection(dbUrl, username, password);
            String sql;
            sql = "Select * \n" + " from BidData inner join CustomerData on \n"
                    + "BidData.CustomerID=CustomerData.CustomerID inner join \n"
                    + "ProductData on ProductData.ProductID=BidData.ProductID;";
            stmt = conn.prepareStatement(sql);
            ResultSet rs;
            rs = stmt.executeQuery(sql);
            JSONObject dataobj = new JSONObject();
            while (rs.next()) {
                dataobj.put("ProductID", rs.getInt("ProductID"));
                dataobj.put("ProductName", rs.getString("ProductName"));
                dataobj.put("SellerPrice", rs.getInt("SellerPrice"));
                dataobj.put("TimeLimit", rs.getInt("TimeLimit"));
                dataobj.put("ItemCondition", rs.getString("ItemCondition"));
                dataobj.put("DateSubmitted", rs.getDate("DateSubmitted"));
                dataobj.put("ProductPrice", rs.getInt("ProductPrice"));

            }
            out.println(dataobj);
            rs.close();
            stmt.close();
            conn.close();
        } catch (Exception E) {
            out.println(E.getMessage());
        }

    }
}