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.adaptris.core.fs.FsHelperTest.java

@Test
public void testWindowsFullURI() throws Exception {
    URL url = FsHelper.createUrlFromString("file:///c:/home/fred");
    assertEquals("fred", new File(url.toURI()).getName());
}

From source file:org.atomserver.core.dbstore.RawClientDBSTest.java

@SuppressWarnings("deprecation")
public void testMissingEntryContent() throws Exception {

    String urlToCall = getServerURL() + "widgets/foobar/24560.en.xml";

    HttpClient client = new HttpClient();
    PutMethod put = new PutMethod(urlToCall);
    put.setRequestHeader("Content-type", "text/xml; charset=UTF-8");

    URL url = this.getClass().getResource("/missingEntryContent.xml");
    File file = new File(url.toURI());

    FileInputStream fis = new FileInputStream(file);
    put.setRequestBody(fis);//from  ww w .  ja v a 2s. c o  m

    // Execute the method.
    int statusCode = client.executeMethod(put);

    // 422 -- unprocessable Entity
    log.debug("STATUS CODE= " + statusCode);
    assertTrue(statusCode == 422);
}

From source file:com.jonbanjo.cups.operations.HttpPoster.java

static OperationResult sendRequest(URL url, ByteBuffer ippBuf, InputStream documentStream, final AuthInfo auth)
        throws IOException {

    final OperationResult opResult = new OperationResult();

    if (ippBuf == null) {
        return null;
    }//from w  w  w  .  jav  a2s .  co  m

    if (url == null) {
        return null;
    }

    DefaultHttpClient client = new DefaultHttpClient();

    // will not work with older versions of CUPS!
    client.getParams().setParameter("http.protocol.version", HttpVersion.HTTP_1_1);
    client.getParams().setParameter("http.socket.timeout", SOCKET_TIMEOUT);
    client.getParams().setParameter("http.connection.timeout", CONNECTION_TIMEOUT);
    client.getParams().setParameter("http.protocol.content-charset", "UTF-8");
    client.getParams().setParameter("http.method.response.buffer.warnlimit", new Integer(8092));
    // probabaly not working with older CUPS versions
    client.getParams().setParameter("http.protocol.expect-continue", Boolean.valueOf(true));

    HttpPost httpPost;

    try {
        httpPost = new HttpPost(url.toURI());
    } catch (Exception e) {
        System.out.println(e.toString());
        return null;
    }

    httpPost.getParams().setParameter("http.socket.timeout", SOCKET_TIMEOUT);

    byte[] bytes = new byte[ippBuf.limit()];
    ippBuf.get(bytes);

    ByteArrayInputStream headerStream = new ByteArrayInputStream(bytes);
    // If we need to send a document, concatenate InputStreams
    InputStream inputStream = headerStream;
    if (documentStream != null) {
        inputStream = new SequenceInputStream(headerStream, documentStream);
    }

    // set length to -1 to advice the entity to read until EOF
    InputStreamEntity requestEntity = new InputStreamEntity(inputStream, -1);

    requestEntity.setContentType(IPP_MIME_TYPE);
    httpPost.setEntity(requestEntity);

    if (auth.reason == AuthInfo.AUTH_REQUESTED) {
        AuthHeader.makeAuthHeader(httpPost, auth);
        if (auth.reason == AuthInfo.AUTH_OK) {
            httpPost.addHeader(auth.getAuthHeader());
            //httpPost.addHeader("Authorization", "Basic am9uOmpvbmJveQ==");
        }
    }

    ResponseHandler<byte[]> handler = new ResponseHandler<byte[]>() {
        @Override
        public byte[] handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
            if (response.getStatusLine().getStatusCode() == 401) {
                auth.setHttpHeader(response.getFirstHeader("WWW-Authenticate"));
            } else {
                auth.reason = AuthInfo.AUTH_OK;
            }
            HttpEntity entity = response.getEntity();
            opResult.setHttResult(response.getStatusLine().toString());
            if (entity != null) {
                return EntityUtils.toByteArray(entity);
            } else {
                return null;
            }
        }
    };

    if (url.getProtocol().equals("https")) {

        Scheme scheme = JfSSLScheme.getScheme();
        if (scheme == null)
            return null;
        client.getConnectionManager().getSchemeRegistry().register(scheme);
    }

    byte[] result = client.execute(httpPost, handler);
    //String test = new String(result);
    IppResponse ippResponse = new IppResponse();

    opResult.setIppResult(ippResponse.getResponse(ByteBuffer.wrap(result)));
    opResult.setAuthInfo(auth);
    client.getConnectionManager().shutdown();
    return opResult;
}

From source file:org.atomserver.core.dbstore.RawClientDBSTest.java

@SuppressWarnings("deprecation")
public void testMissingEntryContent2() throws Exception {

    String urlToCall = getServerURL() + "widgets/foobar/24560.en.xml";

    HttpClient client = new HttpClient();
    PutMethod put = new PutMethod(urlToCall);
    put.setRequestHeader("Content-type", "text/xml; charset=UTF-8");

    URL url = this.getClass().getResource("/missingEntryContent2.xml");
    File file = new File(url.toURI());

    FileInputStream fis = new FileInputStream(file);
    put.setRequestBody(fis);// ww w .jav  a2  s. co  m

    // Execute the method.
    int statusCode = client.executeMethod(put);

    // 422 -- unprocessable Entity
    log.debug("STATUS CODE= " + statusCode);
    assertTrue(statusCode == 422);
}

From source file:org.talend.components.api.service.internal.ComponentServiceImplDepsTestIT.java

/**
 * Test method for//from ww  w .j  a v  a 2s.com
 * {@link org.talend.components.api.service.internal.ComponentServiceImpl#loadPom(java.io.InputStream, org.talend.components.api.service.internal.MavenBooter)}
 * .
 */
@Test
public void testLoadPom() throws ModelBuildingException, URISyntaxException, IOException {
    ComponentServiceImpl componentServiceImpl = new ComponentServiceImpl(null);
    URL pomUrl = this.getClass().getResource("pom.xml"); //$NON-NLS-1$
    final File temporaryFolder = new File(new File(pomUrl.toURI()).getParentFile(), "tempFolder");
    try {
        Model pom = componentServiceImpl.loadPom(this.getClass().getResourceAsStream("pom.xml"),
                new MavenBooter() {

                    @Override
                    File getDefaultLocalRepoDir() {
                        return temporaryFolder;
                    }

                }, Collections.EMPTY_LIST);
        List<Dependency> dependencies = pom.getDependencies();
        checkDependencies(dependencies, "runtime", DIRECT_DEPS.split(",")); //$NON-NLS-1$//$NON-NLS-2$
    } finally {
        FileUtils.deleteDirectory(temporaryFolder);
    }
}

From source file:com.app.server.XMLDeploymentScanner.java

public boolean accept(URL url) {

    File file;// ww w.  j ava  2  s .  c o m
    try {
        file = new File(url.toURI());
        return file.getName().toLowerCase().endsWith("-datasource.xml");
    } catch (Exception e) {
        log.error("Syntax of the uri is incorrect", e);
        //e.printStackTrace();
    }
    return false;
}

From source file:gobblin.aws.AWSJobConfigurationManagerTest.java

@Test(dependsOnMethods = "testBootUpNewJobConfigs")
public void testUpdatedNewJobConfigs() throws Exception {
    // Change zip file in the Uri that JobConfigManager is watching
    final URL url = GobblinAWSClusterLauncherTest.class.getClassLoader().getResource(JOB_SECOND_ZIP);
    final String jobConfZipUri = getJobConfigZipUri(new File(url.toURI()));

    // Wait for all job configs to be received (after scheduled execution of 1 minute)
    this.countDownLatchUpdate.await();

    // Wikipedia2.zip has only 2 conf files:
    // 1. The original job conf that is not changed
    // 2. A new job conf that has been added
    // So, we should only receive one new / updated job conf (ie. total number of configs = 2)
    Assert.assertEquals(this.receivedJobConfigs.size(), 2);
    Assert.assertEquals(this.receivedJobConfigs.get(1).getProperty(JOB_NAME_KEY), JOB_SECOND_NAME);
}

From source file:org.talend.components.api.service.internal.ComponentServiceImplDepsTestIT.java

@Test
@Ignore("This requires authentication credential in the settings.xml")
public void testLoadPomWithAuthentification() throws ModelBuildingException, URISyntaxException, IOException {
    ComponentServiceImpl componentServiceImpl = new ComponentServiceImpl(null);
    URL pomUrl = this.getClass().getResource("pom.xml"); //$NON-NLS-1$
    final File temporaryFolder = new File(new File(pomUrl.toURI()).getParentFile(), "tempFolder");
    System.setProperty(MavenBooter.TALEND_MAVEN_REMOTE_REPOSITORY_ID_SYS_PROP, "releases");
    System.setProperty(MavenBooter.TALEND_MAVEN_REMOTE_REPOSITORY_URL_SYS_PROP,
            "http://newbuild.talend.com:8081/nexus/content/repositories/releases/");

    try {/*from   w  w w  .j  a v  a 2  s  .  c om*/
        Model pom = componentServiceImpl.loadPom(
                this.getClass().getResourceAsStream("pom_with_authentified_deps.xml"), new MavenBooter() {

                    @Override
                    File getDefaultLocalRepoDir() {
                        return temporaryFolder;
                    }

                }, Collections.EMPTY_LIST);
        List<Dependency> dependencies = pom.getDependencies();
        checkDependencies(dependencies, "runtime", DIRECT_DEPS.split(","));
    } finally {
        FileUtils.deleteDirectory(temporaryFolder);
    }
}

From source file:ch.cyclops.publish.APICaller.java

/**
 * Perform POST query and return Response
 * @param endpoint to be called// w w w. j ava2s.c om
 * @param object to be passed
 * @return Response object
 * @throws Exception
 */
public APICaller.Response post(URL endpoint, Object object) throws Exception {
    // prepare connection
    HttpClient client = HttpClientBuilder.create().build();

    // create request
    HttpPost request = new HttpPost(endpoint.toURI());
    StringEntity entity = new StringEntity(new Gson().toJson(object));
    request.addHeader("Accept", "application/json");
    request.addHeader("Content-Type", "application/json");
    request.setEntity(entity);

    // execute response
    HttpResponse response = client.execute(request);
    return new Response(IOUtils.toString(response.getEntity().getContent()));
}

From source file:com.blackducksoftware.integration.hubdiff.HubDiff.java

public void saveFiles(SwaggerDoc swaggerDoc) throws HubIntegrationException, IOException, URISyntaxException {
    URL basePath = this.getClass().getProtectionDomain().getCodeSource().getLocation();

    File swaggerFile = new File(basePath.toURI().resolve("api-docs-" + swaggerDoc.getVersion() + ".json"));
    if (!swaggerFile.exists()) {
        FileUtils.write(swaggerFile, swaggerDoc.getSwaggerDoc(), StandardCharsets.UTF_8);
        log.info("No doc for version [{}]. Creating one now.", swaggerDoc.getVersion());
    }/*from   ww  w.  ja  va2  s . co m*/
}