Example usage for java.net URI create

List of usage examples for java.net URI create

Introduction

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

Prototype

public static URI create(String str) 

Source Link

Document

Creates a URI by parsing the given string.

Usage

From source file:com.github.sardine.impl.methods.HttpAcl.java

public HttpAcl(final String uri) {
    this(URI.create(uri));
}

From source file:org.callimachusproject.client.HttpUriEntity.java

public URI getURI() {
    return URI.create(systemId);
}

From source file:com.opengamma.integration.marketdata.WatchListRecorder.java

/**
 * Main entry point./*from   ww w  .  j  a v a 2 s . c om*/
 * 
 * @param args the arguments
 * @throws Exception if an error occurs
 */
public static void main(final String[] args) throws Exception { // CSIGNORE
    final CommandLineParser parser = new PosixParser();
    final Options options = new Options();
    final Option outputFileOpt = new Option("o", "output", true, "output file");
    outputFileOpt.setRequired(true);
    options.addOption(outputFileOpt);
    final Option urlOpt = new Option("u", "url", true, "server url");
    options.addOption(urlOpt);
    String outputFile = "watchList.txt";
    String url = "http://localhost:8080/jax";
    try {
        final CommandLine cmd = parser.parse(options, args);
        outputFile = cmd.getOptionValue("output");
        url = cmd.getOptionValue("url");
    } catch (final ParseException exp) {
        s_logger.error("Option parsing failed: {}", exp.getMessage());
        System.exit(0);
    }

    final WatchListRecorder recorder = create(URI.create(url), "main", "combined");
    recorder.addWatchScheme(ExternalSchemes.BLOOMBERG_TICKER);
    recorder.addWatchScheme(ExternalSchemes.BLOOMBERG_BUID);
    final PrintWriter pw = new PrintWriter(outputFile);
    recorder.setPrintWriter(pw);
    recorder.run();

    pw.close();
    System.exit(0);
}

From source file:com.orange.clara.cloud.servicedbdumper.helper.UrlForge.java

public String createDownloadLink(DatabaseDumpFile databaseDumpFile) {
    URI appInUri = URI.create(appUri);
    String port = this.getPortInString();
    return appInUri.getScheme() + "://" + databaseDumpFile.getUser() + ":" + databaseDumpFile.getPassword()
            + "@" + appInUri.getHost() + port + DOWNLOAD_ROUTE + "/" + databaseDumpFile.getId();
}

From source file:com.tinyhydra.botd.GoogleOperations.java

public static List<JavaShop> GetShops(Handler handler, Location currentLocation, String placesApiKey) {
    // Use google places to get all the shops within '500' (I believe meters is the default measurement they use)
    // make a list of JavaShops and pass it to the ListView adapter
    List<JavaShop> shopList = new ArrayList<JavaShop>();
    try {//from   ww  w  .  j  ava2  s  .  c  o m
        HttpClient client = new DefaultHttpClient();
        HttpGet request = new HttpGet();
        int accuracy = Math.round(currentLocation.getAccuracy());
        if (accuracy < 500)
            accuracy = 500;
        request.setURI(URI.create("https://maps.googleapis.com/maps/api/place/search/json?location="
                + currentLocation.getLatitude() + "," + currentLocation.getLongitude() + "&radius=" + accuracy
                + "&types=" + URLEncoder.encode("cafe|restaurant|food", "UTF-8")
                + "&keyword=coffee&sensor=true&key=" + placesApiKey));
        HttpResponse response = client.execute(request);
        BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        StringBuffer sb = new StringBuffer("");
        String line = "";
        while ((line = in.readLine()) != null) {
            sb.append(line);
        }

        JSONObject predictions = new JSONObject(sb.toString());
        // Google passes back a status string. if we screw up, it won't say "OK". Alert the user.
        String jstatus = predictions.getString("status");
        if (jstatus.equals("ZERO_RESULTS")) {
            Utils.PostToastMessageToHandler(handler, "No shops found in your area.", Toast.LENGTH_SHORT);
            return shopList;
        } else if (!jstatus.equals("OK")) {
            Utils.PostToastMessageToHandler(handler, "Error retrieving local shops.", Toast.LENGTH_SHORT);
            return shopList;
        }

        // This section may fail if there's no results, but we'll just display an empty list.
        //TODO: alert the user and cancel the dialog if this fails
        JSONArray ja = new JSONArray(predictions.getString("results"));

        for (int i = 0; i < ja.length(); i++) {
            JSONObject jo = (JSONObject) ja.get(i);
            shopList.add(new JavaShop(jo.getString("name"), jo.getString("id"), "", jo.getString("reference"),
                    jo.getString("vicinity")));
        }
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return shopList;
}

From source file:net.oneandone.shared.artifactory.UtilsTest.java

/**
 * Test of toUri method, of class Utils.
 *//*from   w w  w .java  2  s . c  o m*/
@Test
public void testToUri() {
    URI expResult = URI.create("http://localhost/");
    URIBuilder uriBuilder = new URIBuilder(expResult);
    String errorMessage = "oops";
    URI result = Utils.toUri(uriBuilder, errorMessage);
    assertEquals(expResult, result);
}

From source file:com.jaeksoft.searchlib.util.LinkUtils.java

public final static URL getLink(URL currentURL, String href, UrlFilterItem[] urlFilterList,
        boolean removeFragment) {

    if (href == null)
        return null;
    href = href.trim();//ww w . j  av a2  s  .  c o  m
    if (href.length() == 0)
        return null;

    String fragment = null;
    try {
        URI u = URIUtils.resolve(currentURL.toURI(), href);
        href = u.toString();
        href = UrlFilterList.doReplace(u.getHost(), href, urlFilterList);
        URI uri = URI.create(href);
        uri = uri.normalize();

        String p = uri.getPath();
        if (p != null)
            if (p.contains("/./") || p.contains("/../"))
                return null;

        if (!removeFragment)
            fragment = uri.getRawFragment();

        return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(),
                uri.getQuery(), fragment).normalize().toURL();
    } catch (MalformedURLException e) {
        Logging.info(e.getMessage());
        return null;
    } catch (URISyntaxException e) {
        Logging.info(e.getMessage());
        return null;
    } catch (IllegalArgumentException e) {
        Logging.info(e.getMessage());
        return null;
    }
}

From source file:io.syndesis.credential.BaseCredentialProviderTest.java

@Test
public void shouldGenerateCallbackUrlWithoutParameters() {
    assertThat(BaseCredentialProvider.callbackUrlFor(URI.create("https://syndesis.io:8443/api/v1/"), NONE))
            .as("The computed callback URL is not as expected")
            .isEqualTo("https://syndesis.io:8443/api/v1/credentials/callback");

}

From source file:reconf.server.domain.result.AllProductsResult.java

public AllProductsResult(List<ProductResult> arg, String baseUrl) {
    this.products = arg;
    this.links = new ArrayList<>();
    this.links.add(new Link(URI.create(baseUrl + "/product"), "self"));
}

From source file:com.almende.arum.RESTEndpoint.java

/**
 * Gets the job./* w ww .  j  a  v a2 s .  c om*/
 */
public void getJob() {

    String url = "http://95.211.177.143:8080/arum/fnsd/production/jobs/";
    HttpGet httpGet = new HttpGet(URI.create(url));
    try {
        httpGet.addHeader("Accept", "application/json");
        HttpResponse resp = client.execute(httpGet);
        String responseBody = EntityUtils.toString(resp.getEntity());
        ArrayNode tree = (ArrayNode) JOM.getInstance().readTree(responseBody);

        if (oldData != null) {

        }
        oldData = tree;

    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (httpGet != null) {
            httpGet.reset();
        }
    }
}