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:org.openscore.lang.compiler.modeller.transformers.PublishTransformerTest.java

@Test(timeout = DEFAULT_TIMEOUT)
public void testInvalidOutputType() throws Exception {
    URL resource = getClass().getResource("/flow_with_invalid_publish_from_task.yaml");
    ParsedSlang file = yamlParser.parse(SlangSource.fromFile(new File(resource.toURI())));
    List<Map<String, Map>> flow = (List<Map<String, Map>>) file.getFlow().get(SlangTextualKeys.WORKFLOW_KEY);
    List<Object> publishMap = new ArrayList<>();
    for (Map<String, Map> task : flow) {
        if (task.keySet().iterator().next().equals("CheckWeather")) {
            publishMap = (List) task.values().iterator().next().get(SlangTextualKeys.PUBLISH_KEY);
            break;
        }/* w w  w.  j a  v  a 2s. c  o m*/
    }
    exception.expect(RuntimeException.class);
    exception.expectMessage("weather");
    exception.expectMessage("3");
    publishTransformer.transform(publishMap);
}

From source file:com.omertron.tvmazeapi.TvMazeApi.java

/**
 * Get the API information//from w  w w  .j  a  v a2  s .  c o  m
 *
 * @param url
 * @return
 * @throws TvMazeException
 */
private String requestWebPage(URL url) throws TvMazeException {
    LOG.trace("Requesting: {}", url.toString());
    try {
        final HttpGet httpGet = new HttpGet(url.toURI());
        httpGet.addHeader("accept", "application/json");

        final DigestedResponse response = DigestedResponseReader.requestContent(httpClient, httpGet, charset);

        if (response.getStatusCode() >= HTTP_STATUS_500) {
            throw new TvMazeException(ApiExceptionType.HTTP_503_ERROR, response.getContent(),
                    response.getStatusCode(), url);
        } else if (response.getStatusCode() >= HTTP_STATUS_300) {
            throw new TvMazeException(ApiExceptionType.HTTP_404_ERROR, response.getContent(),
                    response.getStatusCode(), url);
        }

        return response.getContent();
    } catch (URISyntaxException ex) {
        throw new TvMazeException(ApiExceptionType.INVALID_URL, "Invalid URL", url, ex);
    } catch (IOException ex) {
        throw new TvMazeException(ApiExceptionType.CONNECTION_ERROR, "Error retrieving URL", url, ex);
    }
}

From source file:com.omertron.slackbot.utils.HttpTools.java

/**
 * Execute a DELETE on the URL//from   w ww.  j  a v  a  2  s  .c  o m
 *
 * @param url URL to use in the request
 * @return String content
 * @throws ApiException
 */
public String deleteRequest(final URL url) throws ApiException {
    try {
        HttpDelete httpDel = new HttpDelete(url.toURI());
        return validateResponse(DigestedResponseReader.deleteContent(httpClient, httpDel, CHARSET), url);
    } catch (URISyntaxException | IOException ex) {
        throw new ApiException(ApiExceptionType.CONNECTION_ERROR, null, url, ex);
    }
}

From source file:org.n52.ses.util.http.SESHttpClient.java

public SESHttpResponse sendPost(URL destination, String content, ContentType contentType) throws Exception {
    checkSetup();//  w ww.j  a  v a 2  s  .com

    if (this.authenticator != null) {
        URI uri = destination.toURI();
        HttpHost host = new HttpHost(uri.getHost(), uri.getPort());
        this.httpClient.provideAuthentication(host, this.authenticator.getUsername(),
                this.authenticator.getPassword());
    }

    HttpResponse postResponse = this.httpClient.executePost(destination.toString(), content, contentType);

    SESHttpResponse response = null;
    if (postResponse != null && postResponse.getEntity() != null) {
        response = new SESHttpResponse(postResponse.getEntity().getContent(),
                postResponse.getEntity().getContentType().getValue());
    } else if (postResponse != null
            && postResponse.getStatusLine().getStatusCode() == HttpStatus.SC_NO_CONTENT) {
        return SESHttpResponse.NO_CONTENT_RESPONSE;
    }

    return response;
}

From source file:org.opendaylight.sfc.sbrest.json.SfExporterTest.java

private String gatherServiceFunctionJsonStringFromFile(String testFileName) {
    String jsonString = null;//ww w. j ava2s .  c  om

    try {
        URL fileURL = getClass().getResource(testFileName);
        jsonString = TestUtil.readFile(fileURL.toURI(), StandardCharsets.UTF_8);
    } catch (IOException | URISyntaxException e) {
        e.printStackTrace();
    }

    for (SfTestValues sfTestValue : SfTestValues.values()) {
        jsonString = jsonString != null
                ? jsonString.replaceAll("\\b" + sfTestValue.name() + "\\b", sfTestValue.getValue())
                : null;
    }

    return jsonString;
}

From source file:au.org.ala.delta.confor.ToIntTest.java

private File urlToFile(String urlString) throws Exception {
    URL url = ToIntTest.class.getResource(urlString);
    File file = new File(url.toURI());
    return file;//from  w  w w.  j a v a2  s.  c  om
}

From source file:com.h3xstream.findbugs.test.service.FindBugsLauncher.java

/**
 * The minimum requirement to have a "valid" archive plugin is to include
 * findbugs.xml, messages.xml and MANIFEST.MF files. The rest of the
 * resources are load using the parent ClassLoader (Not requires to be in
 * the jar).//ww w. ja  va2s  . c  om
 * <p>
 * Instead of building a file on disk, the result of the stream is kept in
 * memory and return as a byte array.
 *
 * @return
 * @throws IOException
 * @throws URISyntaxException 
 */
private byte[] buildFakePluginJar() throws IOException, URISyntaxException {
    ClassLoader cl = getClass().getClassLoader();

    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    JarOutputStream jar = new JarOutputStream(buffer);

    final URL metadata = cl.getResource("metadata");
    if (metadata != null) {
        final File dir = new File(metadata.toURI());

        //Add files to the jar stream
        addFilesToStream(cl, jar, dir, "");
    }
    jar.finish();
    jar.close();

    return buffer.toByteArray();
}

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

@SuppressWarnings("deprecation")
public void testEmptyRequest() 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("/empty.xml");
    File file = new File(url.toURI());

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

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

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

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

/**
 * Perform GET query and return Response
 * @param endpoint to be called//from   w w w . j av a 2s  .co m
 * @return Response object
 * @throws Exception
 */
public APICaller.Response get(URL endpoint) throws Exception {
    // prepare connection
    HttpClient client = HttpClientBuilder.create().build();

    // create request
    HttpGet request = new HttpGet(endpoint.toURI());
    request.addHeader("Accept", "application/json");
    request.addHeader("Content-Type", "application/json");

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

From source file:com.asakusafw.runtime.stage.optimizer.LibraryCopySuppressionConfigurator.java

@Override
public void configure(Job job) throws IOException, InterruptedException {
    Configuration conf = job.getConfiguration();
    if (conf.getBoolean(KEY_ENABLED, DEFAULT_ENABLED) == false) {
        return;//from w w w . java2  s.c o  m
    }
    // activates only if application launcher is used
    if (conf.getBoolean(ApplicationLauncher.KEY_LAUNCHER_USED, false) == false) {
        return;
    }
    if (StageUtil.isLocalMode(job) == false) {
        return;
    }
    String libraries = conf.get(KEY_CONF_LIBRARIES);
    if (libraries == null || libraries.isEmpty()) {
        return;
    }
    Set<String> loaded = new HashSet<>();
    ClassLoader loader = conf.getClassLoader();
    if (loader instanceof URLClassLoader) {
        for (URL url : ((URLClassLoader) loader).getURLs()) {
            try {
                loaded.add(url.toURI().toString());
            } catch (URISyntaxException e) {
                LOG.warn(MessageFormat.format("Failed to analyze classpath: {0}", url));
            }
        }
    }
    if (loaded.isEmpty()) {
        return;
    }
    StringBuilder result = new StringBuilder();
    for (String library : libraries.split(",")) { //$NON-NLS-1$
        if (loaded.contains(library)) {
            if (LOG.isDebugEnabled()) {
                LOG.debug(MessageFormat.format("Keep library: {0}", library)); //$NON-NLS-1$
            }
        } else {
            if (LOG.isDebugEnabled()) {
                LOG.debug(MessageFormat.format("Suppress library: {0}", library)); //$NON-NLS-1$
            }
            if (result.length() != 0) {
                result.append(',');
            }
            result.append(library);
        }
    }
    if (result.length() > 0) {
        conf.set(KEY_CONF_LIBRARIES, result.toString());
    } else {
        if (CONFIGURATION_UNSET != null) {
            try {
                CONFIGURATION_UNSET.invoke(conf, KEY_CONF_LIBRARIES);
                return;
            } catch (Exception e) {
                LOG.warn(MessageFormat.format("Failed to invoke {0}", CONFIGURATION_UNSET), e);
            }
        }
        String newLibraries = selectLibraries(libraries);
        conf.set(KEY_CONF_LIBRARIES, newLibraries);
    }
}