Example usage for java.net URL getPath

List of usage examples for java.net URL getPath

Introduction

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

Prototype

public String getPath() 

Source Link

Document

Gets the path part of this URL .

Usage

From source file:com.linkedin.flashback.smartproxy.FlashbackRunnerTest.java

License:asdf

@Test
public void testNotMatchMethod() throws IOException, InterruptedException {
    URL flashbackScene = getClass().getResource(FLASHBACK_SCENE_DIR);
    String rootPath = flashbackScene.getPath();
    SceneConfiguration sceneConfiguration = new SceneConfiguration(rootPath, SCENE_MODE, HTTP_SCENE);
    try (FlashbackRunner flashbackRunner = new FlashbackRunner.Builder().mode(SCENE_MODE).sceneAccessLayer(
            new SceneAccessLayer(SceneFactory.create(sceneConfiguration), MatchRuleUtils.matchEntireRequest()))
            .build()) {//from   ww w .  ja v a2 s  . co  m
        flashbackRunner.start();
        HttpHost host = new HttpHost(PROXY_HOST, PROXY_PORT);
        String url = "http://www.example.org/";
        HttpClient client = HttpClientBuilder.create().setProxy(host).build();
        HttpPost post = new HttpPost(url);
        HttpResponse httpResponse = client.execute(post);
        Assert.assertEquals(httpResponse.getStatusLine().getStatusCode(), 400);
        Assert.assertTrue(EntityUtils.toString(httpResponse.getEntity()).contains("No Matching Request"));
    }
}

From source file:org.carewebframework.ui.LabelFinder.java

private void findLabelResources(ApplicationContext appContext, String root, String prefix,
        Map<String, LabelLocator> labelLocators) {
    try {/*from   ww  w  .j  a  v  a 2s  . c o  m*/
        Resource[] resources = appContext.getResources(root + prefix + "-label*.properties");

        for (Resource resource : resources) {
            URL url = resource.getURL();
            String path = url.getPath();
            path = path.substring(path.lastIndexOf('!') + 1, path.lastIndexOf('/'));
            LabelLocator labelLocator = labelLocators.get(path);

            if (labelLocator == null) {
                labelLocator = new LabelLocator();
                labelLocators.put(path, labelLocator);
                Labels.register(labelLocator);

                if (log.isInfoEnabled()) {
                    log.info("Label resource(s) found at '" + path + "'.");
                }
            }

            labelLocator.addUrl(url);

            if (validate) {
                validate(resource);
            }
        }
    } catch (IOException e) {
        log.error("Error searching for labels: " + e.getMessage());
    }

}

From source file:com.linkedin.flashback.smartproxy.FlashbackRunnerTest.java

License:asdf

@Test
public void testNotMatchHeaders() throws IOException, InterruptedException {
    URL flashbackScene = getClass().getResource(FLASHBACK_SCENE_DIR);
    String rootPath = flashbackScene.getPath();
    SceneConfiguration sceneConfiguration = new SceneConfiguration(rootPath, SCENE_MODE, HTTP_SCENE);
    try (FlashbackRunner flashbackRunner = new FlashbackRunner.Builder().mode(SCENE_MODE).sceneAccessLayer(
            new SceneAccessLayer(SceneFactory.create(sceneConfiguration), MatchRuleUtils.matchEntireRequest()))
            .build()) {//from ww  w.  j  a  v  a2  s .co m
        flashbackRunner.start();
        HttpHost host = new HttpHost(PROXY_HOST, PROXY_PORT);
        String url = "http://www.example.org/";
        HttpClient client = HttpClientBuilder.create().setProxy(host).build();
        HttpGet request = new HttpGet(url);
        request.addHeader("a", "b");
        HttpResponse httpResponse = client.execute(request);
        Assert.assertEquals(httpResponse.getStatusLine().getStatusCode(), 400);
        Assert.assertTrue(EntityUtils.toString(httpResponse.getEntity()).contains("No Matching Request"));
    }
}

From source file:edu.stanford.epad.epadws.listener.StartupListener.java

public void contextInitialized(ServletContextEvent event) {
    // Skip, if we are using same APP
    if (!Main.separateWebServicesApp)
        return;/*from w w w .  j  ava  2  s .  co m*/
    log.info("#####################################################");
    log.info("############# Starting ePAD Web Service #############");
    log.info("#####################################################");

    // call Spring's context ContextLoaderListener to initialize
    // all the context files specified in web.xml
    super.contextInitialized(event);

    ServletContext servletContext = event.getServletContext();
    appContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
    webAppPath = servletContext.getRealPath("/");
    try {
        URL url = servletContext.getResource("/");
        webAppURL = "http:/" + url.getPath(); // Does not look correct
        System.out.println("Context initialized , webAppUrl=" + webAppURL + " webappPath=" + webAppPath);
    } catch (Exception x) {
    }
    Main.checkPropertiesFile();
    Main.checkResourcesFolders();
    Main.checkPluginsFile();
    RemotePACService.checkPropertiesFile();
    Main.initializePlugins();
    Main.startSupportThreads();
    Main.loadPluginClasses();
    new ServerStatusHandler(); // Sets startup time
}

From source file:WebstartLauncher.java

private String getLocalName(String jnlpUrl) {
    try {/*  ww  w  .j a  v  a 2 s  . c o  m*/
        URL url = new File(System.getProperty("java.io.tmpdir") + "/" + FilenameUtils.getName(jnlpUrl)).toURL();
        return url.getPath();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:cn.edu.pku.sei.plde.conqueroverfitting.localization.gzoltar.GZoltarSuspiciousProgramStatements.java

protected GZoltarSuspiciousProgramStatements(final URL[] classpath, Collection<String> packageNames,
        Metric metric, String testSrcPath, String srcPath, List<String> libPath) {
    try {/*from  www. j  a  va 2  s  .  co  m*/
        //gzoltar = new GZoltarJava7();
        gzoltar = new WGzoltar(System.getProperty("user.dir"), metric, testSrcPath, srcPath, libPath);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    ArrayList<String> classpaths = new ArrayList<String>();
    for (URL url : classpath) {
        if ("file".equals(url.getProtocol())) {
            classpaths.add(url.getPath());
        } else {
            classpaths.add(url.toExternalForm());
        }
    }

    gzoltar.setClassPaths(classpaths);
    gzoltar.addPackageNotToInstrument("org.junit");
    gzoltar.addPackageNotToInstrument("junit.framework");
    gzoltar.addTestPackageNotToExecute("junit.framework");
    gzoltar.addTestPackageNotToExecute("org.junit");
    for (String packageName : packageNames) {
        gzoltar.addPackageToInstrument(packageName);
    }
    for (URL url : classpath) {
        if (url.getPath().endsWith(".jar")) {
            gzoltar.addClassNotToInstrument(url.getPath());
            gzoltar.addPackageNotToInstrument(url.getPath());
        }
    }
}

From source file:com.asual.lesscss.Resource.java

public Resource(ServletContext servletContext, String uri, String charset, boolean cache)
        throws ResourceNotFoundException {

    this.servletContext = servletContext;
    this.charset = charset;
    this.cache = cache;

    URL url = getUrl(uri);
    File file = getFile(uri);//  www .j  av a  2s  .c om

    if (url != null || (file != null && file.exists())) {
        path = url != null ? url.getPath() : file.getAbsolutePath();
        resource = url != null ? url : file;
    } else {
        logger.error("Error processing " + uri + ".");
        throw new ResourceNotFoundException("Error processing " + uri + ".");
    }
}

From source file:com.brightcove.com.zartan.verifier.video.StreamingFLVURLVerifier.java

@ZartanCheck(value = "Primary Rendition is the correct type")
public ResultEnum assertPrimaryRenditionTypeCorrect(UploadData upData) throws Throwable {
    URL u = getPrimaryRenditionUrl(upData);
    if (upData.getmOptions().getTargetCodec().equals("MP4")) {
        assertTrue("type should be mp4 of " + u.getPath(), u.getPath().toLowerCase().endsWith("mp4"));
    } else {/*ww w. j ava2 s  .  co  m*/
        assertTrue("type should be flv of " + u.getPath(), u.getPath().toLowerCase().endsWith("flv"));
    }
    return ResultEnum.PASS;
}

From source file:ch.kostceco.tools.kostsimy.service.impl.ConfigurationServiceImpl.java

private XMLConfiguration getConfig() {
    if (this.config == null) {

        try {//  w  ww.  ja  v a2 s .c o m

            String path = "configuration/kostsimy.conf.xml";

            URL locationOfJar = KOSTSimy.class.getProtectionDomain().getCodeSource().getLocation();
            String locationOfJarPath = locationOfJar.getPath();

            if (locationOfJarPath.endsWith(".jar")) {
                File file = new File(locationOfJarPath);
                String fileParent = file.getParent();
                path = fileParent + "/" + path;
            }

            config = new XMLConfiguration(path);

        } catch (ConfigurationException e) {
            LOGGER.logError(getTextResourceService().getText(MESSAGE_XML_MODUL_CI)
                    + getTextResourceService().getText(MESSAGE_XML_CONFIGURATION_ERROR_1));
            LOGGER.logError(getTextResourceService().getText(MESSAGE_XML_MODUL_CI)
                    + getTextResourceService().getText(MESSAGE_XML_CONFIGURATION_ERROR_2));
            LOGGER.logError(getTextResourceService().getText(MESSAGE_XML_MODUL_CI)
                    + getTextResourceService().getText(MESSAGE_XML_CONFIGURATION_ERROR_3));
            System.exit(1);
        }
    }
    return config;
}

From source file:com.ehsy.solr.util.SimplePostTool.java

/**
 * Appends to the path of the URL/*from w w w  . j av a  2  s . c om*/
 * @param url the URL
 * @param append the path to append
 * @return the final URL version 
 */
protected static URL appendUrlPath(URL url, String append) throws MalformedURLException {
    return new URL(url.getProtocol() + "://" + url.getAuthority() + url.getPath() + append
            + (url.getQuery() != null ? "?" + url.getQuery() : ""));
}