Example usage for java.net URL toString

List of usage examples for java.net URL toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Constructs a string representation of this URL .

Usage

From source file:io.github.retz.executor.DummyExecutorDriver.java

private Protos.ExecutorInfo buildExecutorInfo(TemporaryFolder folder, Protos.FrameworkInfo frameworkInfo) {
    // Copied from Applications.Application

    URL jarUrl = DummyExecutorDriver.class.getProtectionDomain().getCodeSource().getLocation();
    String jarFile = FilenameUtils.getName(jarUrl.toString());

    String[] appFilesArray = { "file://foo/bar/baz.tar.gz", "http://example.com:4242/day/of/gluttony.tgz" };
    List<String> appFiles = Arrays.asList(appFilesArray);

    String appName = "dummy-executor-driver-dummy-app";

    // Actually this is not used as this is just a test
    String cmd = "java -cp " + jarFile + " " + MesosExecutorLauncher.getFullClassName();
    Protos.CommandInfo.Builder commandInfoBuilder = Protos.CommandInfo.newBuilder()
            .setEnvironment(Protos.Environment.newBuilder().addVariables(
                    Protos.Environment.Variable.newBuilder().setName("ASAKUSA_HOME").setValue(".").build()))
            .setValue(cmd).setShell(true)
            .addUris(Protos.CommandInfo.URI.newBuilder().setValue(jarUrl.toString()).setCache(false)); // In production, set this true

    for (String file : appFiles) {
        commandInfoBuilder.addUris(Protos.CommandInfo.URI.newBuilder().setValue(file).setCache(true));
    }// w  w w.  j  a v  a2s .com

    Protos.ExecutorInfo executorInfo = Protos.ExecutorInfo.newBuilder().setCommand(commandInfoBuilder.build())
            .setExecutorId(Protos.ExecutorID.newBuilder().setValue(appName).build())
            .setFrameworkId(frameworkInfo.getId()).build();
    return executorInfo;
}

From source file:io.apiman.common.plugin.PluginClassLoaderTest.java

/**
 * Test method for {@link io.apiman.common.plugin.PluginClassLoader#getPolicyDefinitionResources()}.
 * @throws Exception exception catch-all
 *///from  w  w  w .j a v  a2  s .  c  o m
@Test
public void testGetPolicyDefinitionResources() throws Exception {
    File file = new File("src/test/resources/plugin-with-policyDefs.war");
    if (!file.exists()) {
        throw new Exception(
                "Failed to find test WAR: plugin-with-policyDefs.war at: " + file.getAbsolutePath());
    }
    PluginClassLoader classloader = new TestPluginClassLoader(file);
    List<URL> resources = classloader.getPolicyDefinitionResources();
    Assert.assertNotNull(resources);
    Assert.assertEquals(2, resources.size());
    URL url = resources.get(0);
    Assert.assertNotNull(url);
    Assert.assertTrue(url.toString().contains("META-INF/apiman/policyDefs"));
}

From source file:hudson.model.UpdateSiteTest.java

@Test
public void relativeURLs() throws Exception {
    PersistedList<UpdateSite> sites = j.jenkins.getUpdateCenter().getSites();
    sites.clear();/* w w  w .  j  a  v  a  2 s  .  c om*/
    URL url = new URL(baseUrl, "/plugins/tasks-update-center.json");
    UpdateSite site = new UpdateSite(UpdateCenter.ID_DEFAULT, url.toString());
    sites.add(site);
    assertEquals(FormValidation.ok(), site.updateDirectly(false).get());
    Data data = site.getData();
    assertNotNull(data);
    assertEquals(new URL(url, "jenkins.war").toString(), data.core.url);
    assertEquals(new HashSet<String>(Arrays.asList("tasks", "dummy")), data.plugins.keySet());
    assertEquals(new URL(url, "tasks.jpi").toString(), data.plugins.get("tasks").url);
    assertEquals("http://nowhere.net/dummy.hpi", data.plugins.get("dummy").url);

    UpdateSite.Plugin tasksPlugin = data.plugins.get("tasks");
    assertEquals("Wrong name of plugin found", "Task Scanner Plug-in", tasksPlugin.getDisplayName());
}

From source file:fredboat.audio.source.HttpSourceManager.java

private AudioReference resolve(AudioReference original, String resolve) {
    if (resolve.startsWith("http")) {
        return new AudioReference(resolve, original.title);
    }/* www  .  j av a2 s .c  o m*/
    try {
        URL resolved = new URL(new URL(original.identifier), resolve);
        return new AudioReference(resolved.toString(), original.title);
    } catch (MalformedURLException e) {
        throw new FriendlyException("Error resolving relative url of playlist link", SUSPICIOUS, e);
    }
}

From source file:de.tudarmstadt.ukp.dkpro.core.api.resources.ResourceUtils.java

/**
 * Make the given URL available as a file. A temporary file is created and deleted upon a
 * regular shutdown of the JVM. If the parameter {@code aCache} is {@code true}, the temporary
 * file is remembered in a cache and if a file is requested for the same URL at a later time,
 * the same file is returned again. If the previously created file has been deleted meanwhile,
 * it is recreated from the URL. This method should not be used for creating executable
 * binaries. For this purpose, getUrlAsExecutable should be used.
 *
 * @param aUrl/*w ww. j av a2s  .  c  om*/
 *            the URL.
 * @param aCache
 *            use the cache or not.
 * @param aForceTemp
 *            always create a temporary file, even if the URL is already a file.
 * @return a file created from the given URL.
 * @throws IOException
 *             if the URL cannot be accessed to (re)create the file.
 */
public static synchronized File getUrlAsFile(URL aUrl, boolean aCache, boolean aForceTemp) throws IOException {
    // If the URL already points to a file, there is not really much to do.
    if (!aForceTemp && "file".equalsIgnoreCase(aUrl.getProtocol())) {
        try {
            return new File(aUrl.toURI());
        } catch (URISyntaxException e) {
            throw new IOException(e);
        }
    }

    synchronized (urlFileCache) {
        // Lets see if we already have a file for this URL in our cache. Maybe
        // the file has been deleted meanwhile, so we also check if the file
        // actually still exists on disk.
        File file = urlFileCache.get(aUrl.toString());
        if (!aCache || (file == null) || !file.exists()) {
            // Create a temporary file and try to preserve the file extension
            String suffix = FilenameUtils.getExtension(aUrl.getPath());
            if (suffix.length() == 0) {
                suffix = "temp";
            }
            String name = FilenameUtils.getBaseName(aUrl.getPath());

            // Get a temporary file which will be deleted when the JVM shuts
            // down.
            file = File.createTempFile(name, "." + suffix);
            file.deleteOnExit();

            // Now copy the file from the URL to the file.

            InputStream is = null;
            OutputStream os = null;
            try {
                is = aUrl.openStream();
                os = new FileOutputStream(file);
                copy(is, os);
            } finally {
                closeQuietly(is);
                closeQuietly(os);
            }

            // Remember the file
            if (aCache) {
                urlFileCache.put(aUrl.toString(), file);
            }
        }

        return file;
    }
}

From source file:org.opencastproject.loadtest.impl.JobChecker.java

/**
 * Use the TrustedHttpClient from matterhorn to check the status of jobs. 
 * //from  www. ja  v  a 2s .c om
 * @param id
 *          The media package id to check. 
 * @param mediaPackageLocation
 *          The location of the mediapackage we want to ingest.
 */
private void checkJobWithJava(IngestJob job) {
    String id = job.getID();
    logger.info("Checking recording: {}", id);
    try {
        URL url = new URL(loadTest.getCoreAddress() + "/workflow/instance/" + id);
        logger.debug("Check Job URL is " + url.toString());
        HttpGet getMethod = new HttpGet(url.toString());

        // Send the request
        HttpResponse response = null;
        int retValue = -1;
        try {
            response = client.execute(getMethod);
        } catch (TrustedHttpClientException e) {
            logger.error("Unable to check ingest {}, message reads: {}.", id, e.getMessage());
        } catch (NullPointerException e) {
            logger.error("Unable to check ingest {}, null pointer exception!", id);
        } finally {
            if (response != null) {
                retValue = response.getStatusLine().getStatusCode();
                client.close(response);
            } else {
                retValue = -1;
            }
        }

        if (retValue == HttpURLConnection.HTTP_OK) {
            logger.info(id + " successfully ingested, is now processing and will be marked as done.");
            ingestJobs.remove(job);
            ThreadCounter.subtract();
        } else {
            logger.info(id + " has not ingested yet.");
        }

    } catch (MalformedURLException e) {
        logger.error("Malformed URL for ingest target \"" + loadTest.getCoreAddress()
                + "/ingest/addZippedMediaPackage\"");
    }
}

From source file:com.msp.jsvc.JRubyDaemon.java

private void loadSupportScripts() {
    String errorsPath = "/ruby/lib/jsvc/errors.rb";
    URL scriptResource = getClass().getResource(errorsPath);
    try {/*from  w  ww . j av a2s  .  co  m*/
        runtime.loadFile(scriptResource.toString(), scriptResource.openStream(), false);
    } catch (IOException e) {
        throw new RuntimeException("Couldn't load script from " + errorsPath);
    }
}

From source file:org.seedstack.w20.internal.W20BridgeIT.java

@Test
@RunAsClient//from  ww  w .ja va2s .  c o m
public void paths_are_correctly_built(@ArquillianResource URL baseUrl) {
    String response = given().auth().basic("ThePoltergeist", "bouh").expect().statusCode(200).when()
            .get(baseUrl.toString() + "seed-w20/application/configuration").getBody().asString();
    String prefix = baseUrl.toString().substring(
            (baseUrl.getProtocol() + "://" + baseUrl.getHost() + ":" + baseUrl.getPort()).length(),
            baseUrl.toString().length() - 1);
    assertThat(response).contains("\"components-path\":\"" + prefix + "/bower_components\"");
    assertThat(response).contains("\"components-path-slash\":\"" + prefix + "/bower_components/\"");
    assertThat(response).contains("\"seed-base-path\":\"" + prefix + "\"");
    assertThat(response).contains("\"seed-base-path-slash\":\"" + prefix + "/\"");
    assertThat(response).contains("\"seed-rest-path\":\"" + prefix + "\"");
    assertThat(response).contains("\"seed-rest-path-slash\":\"" + prefix + "/\"");

}

From source file:com.espertech.esperio.db.config.TestConfig.java

public void testConfigureFromStream() throws Exception {
    URL url = this.getClass().getClassLoader().getResource("esperio-db-sample-config.xml");
    ConfigurationDBAdapterParser.doConfigure(config, url.openStream(), url.toString());
    assertFileConfig(config);//from   ww  w . j av  a2 s  . c  o  m
}

From source file:Viewer3D.java

public void init() {
    if (filename == null) {
        // the path to the file for an applet
        try {// w  w  w  . j  av a2 s.c o m
            java.net.URL path = getCodeBase();
            filename = new java.net.URL(path.toString() + "./ballcone.lws");
        } catch (java.net.MalformedURLException ex) {
            System.err.println(ex.getMessage());
            ex.printStackTrace();
            System.exit(1);
        }
    }

    // Construct the Lw3d loader and load the file
    Loader lw3dLoader = new Lw3dLoader(Loader.LOAD_ALL);
    Scene loaderScene = null;
    try {
        loaderScene = lw3dLoader.load(filename);
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }

    // Construct the applet canvas
    setLayout(new BorderLayout());
    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();

    Canvas3D c = new Canvas3D(config);
    add("Center", c);

    // Create a basic universe setup and the root of our scene
    u = new SimpleUniverse(c);
    BranchGroup sceneRoot = new BranchGroup();

    // Change the back clip distance; the default is small for
    // some lw3d worlds
    View theView = u.getViewer().getView();
    theView.setBackClipDistance(50000f);

    // Now add the scene graph defined in the lw3d file
    if (loaderScene.getSceneGroup() != null) {
        // Instead of using the default view location (which may be
        // completely bogus for the particular file you're loading),
        // let's use the initial view from the file. We can get
        // this by getting the view groups from the scene (there's
        // only one for Lightwave 3D), then using the inverse of the
        // transform on that view as the transform for the entire scene.

        // First, get the view groups (shouldn't be null unless there
        // was something wrong in the load
        TransformGroup viewGroups[] = loaderScene.getViewGroups();

        // Get the Transform3D from the view and invert it
        Transform3D t = new Transform3D();
        viewGroups[0].getTransform(t);
        Matrix4d m = new Matrix4d();
        t.get(m);
        m.invert();
        t.set(m);

        // Now we've got the transform we want. Create an
        // appropriate TransformGroup and parent the scene to it.
        // Then insert the new group into the main BranchGroup.
        TransformGroup sceneTransform = new TransformGroup(t);
        sceneTransform.addChild(loaderScene.getSceneGroup());
        sceneRoot.addChild(sceneTransform);
    }

    // Make the scene graph live by inserting the root into the universe
    u.addBranchGraph(sceneRoot);
}