Example usage for java.net URL toURI

List of usage examples for java.net URL toURI

Introduction

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

Prototype

public URI toURI() throws URISyntaxException 

Source Link

Document

Returns a java.net.URI equivalent to this URL.

Usage

From source file:com.citruspay.mobile.payment.PaymentGateway.java

public JSONObject postPayment() {
    JSONObject result = null;// w  w w  .  ja va  2 s.  com
    HttpResponse response = null;

    try {
        URL url = new URL(serverUrl);
        HttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(url.toURI());

        /*These headers are compulsory*/

        httpPost.setHeader("access_key", accessKey);
        httpPost.setHeader("Content-Type", "application/json");

        httpPost.setEntity(new StringEntity(txnObject.toString()));
        response = httpClient.execute(httpPost);
        StringBuffer res = new StringBuffer();

        BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        String inputLine;
        while ((inputLine = in.readLine()) != null) {
            res.append(inputLine);
        }

        in.close();

        result = new JSONObject(res.toString());
    } catch (Exception e) {
        throw new RuntimeException(String.valueOf(response.getStatusLine().getStatusCode()));
    }

    return result;
}

From source file:com.netflix.genie.web.services.impl.HttpFileTransferImpl.java

/**
 * {@inheritDoc}// ww  w .  java2 s  .com
 */
@Override
public long getLastModifiedTime(final String path) throws GenieException {
    final long start = System.nanoTime();
    try {
        final URL url = new URL(path);
        final long time = this.restTemplate.headForHeaders(url.toURI()).getLastModified();
        // Returns now if there was no last modified header as best we can do is assume file is brand new
        return time != -1 ? time : Instant.now().toEpochMilli();
    } catch (final MalformedURLException | URISyntaxException e) {
        log.error(e.getLocalizedMessage(), e);
        throw new GenieServerException(e);
    } finally {
        this.getLastModifiedTimer.record(System.nanoTime() - start, TimeUnit.NANOSECONDS);
    }
}

From source file:org.apache.camel.component.restlet.RestletHttpsWithSSLContextParametersTest.java

private void postRequestMessage(String message) throws Exception {
    // ensure jsse clients can validate the self signed dummy localhost cert, 
    // use the server keystore as the trust store for these tests
    URL trustStoreUrl = this.getClass().getClassLoader().getResource("jsse/localhost.ks");
    System.setProperty("javax.net.ssl.trustStore", trustStoreUrl.toURI().getPath());

    HttpPost post = new HttpPost("https://localhost:" + portNum + "/users/");
    post.addHeader(Exchange.CONTENT_TYPE, "application/xml");
    post.setEntity(new StringEntity(message));

    HttpResponse response = doExecute(post);
    assertHttpResponse(response, 200, "application/xml");
    String s = context.getTypeConverter().convertTo(String.class, response.getEntity().getContent());
    assertEquals("<status>OK</status>", s);
}

From source file:azkaban.database.AzkabanDatabaseUpdaterTest.java

@Ignore
@Test/*from  w w  w.  j a  v  a  2s  .c  o  m*/
public void testMySQLAutoCreate() throws Exception {
    clearMySQLTestDb();

    URL resourceUrl = Resources.getResource("conf/dbtestmysql");
    assertNotNull(resourceUrl);
    File resource = new File(resourceUrl.toURI());
    String confDir = resource.getParent();

    System.out.println("1.***Now testing check");
    AzkabanDatabaseUpdater.main(new String[] { "-c", confDir });

    System.out.println("2.***Now testing update");
    AzkabanDatabaseUpdater.main(new String[] { "-u", "-c", confDir });

    System.out.println("3.***Now testing check again");
    AzkabanDatabaseUpdater.main(new String[] { "-c", confDir });

    System.out.println("4.***Now testing update again");
    AzkabanDatabaseUpdater.main(new String[] { "-c", confDir, "-u" });

    System.out.println("5.***Now testing check again");
    AzkabanDatabaseUpdater.main(new String[] { "-c", confDir });
}

From source file:io.fd.maintainer.plugin.parser.MaintainersParserTest.java

@Test
public void testParse() throws URISyntaxException, IOException, MaintainerMismatchException {
    final MaintainersParser parser = new MaintainersParser();

    final URL url = this.getClass().getResource("/maintainers");
    final String content = Files.readLines(new File(url.toURI()), StandardCharsets.UTF_8).stream()
            .collect(Collectors.joining(System.lineSeparator()));
    final List<ComponentInfo> maintainers = parser.parseMaintainers(content);
    assertTrue(!maintainers.isEmpty());/*from  w w  w. j  ava2  s  .c  o m*/

    // tests couple of entries
    assertTrue(compare(maintainers.get(0), buildSystem()));
    assertTrue(compare(maintainers.get(1), buildSystemInternal()));
    assertTrue(compare(maintainers.get(2), doxygen()));
    assertTrue(compare(maintainers.get(3), dpdkDevelopmentPackaging()));
    assertTrue(compare(maintainers.get(4), infrastractureLibrary()));
    assertTrue(compare(maintainers.get(5), vlibLibrary()));
    assertTrue(compare(maintainers.get(6), vlibApiLibraries()));
    assertTrue(compare(maintainers.get(7), vnetBfd()));
    assertEquals(32, maintainers.size());
}

From source file:io.cloudslang.lang.compiler.modeller.transformers.DoTransformerTest.java

private Map loadFirstTaskFromFile(String path) throws URISyntaxException {
    Map doArgumentsMap = new LinkedHashMap();
    URL resource = getClass().getResource(path);
    File file = new File(resource.toURI());
    ParsedSlang parsedSlang = yamlParser.parse(SlangSource.fromFile(file));
    @SuppressWarnings("unchecked")
    List<Map<String, Map>> flow = (List<Map<String, Map>>) parsedSlang.getFlow()
            .get(SlangTextualKeys.WORKFLOW_KEY);
    for (Map<String, Map> task : flow) {
        if (task.keySet().iterator().next().equals("CheckWeather")) {
            doArgumentsMap = (Map) task.values().iterator().next().get(SlangTextualKeys.DO_KEY);
            return doArgumentsMap;
        }//from   w w w.  ja v a 2  s.c  o  m
    }
    return doArgumentsMap;
}

From source file:com.jayway.maven.plugins.android.AbstractAndroidMojoTest.java

@Test
public void givenAndroidManifestWithoutInstrumentationThenInstrumentationRunnerIsNotFound()
        throws MalformedURLException, URISyntaxException, MojoExecutionException {
    final URL url = this.getClass().getResource("AndroidManifestWithoutInstrumentation.xml");
    final URI uri = url.toURI();
    final File file = new File(uri);
    final String foundInstrumentationRunner = androidMojo.extractInstrumentationRunnerFromAndroidManifest(file);
    Assert.assertNull(foundInstrumentationRunner);
}

From source file:org.olat.test.rest.RepositoryRestClient.java

public CourseVO deployDemoCourse() throws URISyntaxException, IOException {
    URL url = ArquillianDeployments.class.getResource("file_resources/Demo-Kurs-7.1.zip");
    File archive = new File(url.toURI());

    String displayname = "Demo-Kurs-" + UUID.randomUUID().toString();
    return deployCourse(archive, "-", displayname);
}

From source file:gov.nih.nci.cacis.nav.DocRouterNotificationSenderSystemTest.java

private String getValidMessage() throws IOException, URISyntaxException {
    final URL url = getClass().getClassLoader().getResource(MSG_FILENAME);
    return FileUtils.readFileToString(new File(url.toURI()));
}

From source file:org.yamj.api.common.http.DefaultPoolingHttpClient.java

@Override
public DigestedResponse requestContent(URL url, Charset charset) throws IOException {
    URI uri;/*from ww w. j  av  a2 s . c  o  m*/
    try {
        uri = url.toURI();
    } catch (URISyntaxException ex) {
        throw new IllegalArgumentException(INVALID_URL + url, ex);
    }

    return requestContent(uri, charset);
}