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.digitalpebble.stormcrawler.protocol.file.FileResponse.java

public FileResponse(String u, Metadata md, FileProtocol fp) throws MalformedURLException, IOException {

    fileProtocol = fp;// www .  j a v  a2 s.co m
    metadata = md;

    URL url = new URL(u);

    if (!url.getPath().equals(url.getFile())) {
        LOG.warn("url.getPath() != url.getFile(): {}.", url);
    }

    String path = "".equals(url.getPath()) ? "/" : url.getPath();

    File file = new File(URLDecoder.decode(path, fileProtocol.getEncoding()));

    if (!file.exists()) {
        statusCode = HttpStatus.SC_NOT_FOUND;
        return;
    }

    if (!file.canRead()) {
        statusCode = HttpStatus.SC_UNAUTHORIZED;
        return;
    }

    if (!file.equals(file.getCanonicalFile())) {
        metadata.setValue(HttpHeaders.LOCATION, file.getCanonicalFile().toURI().toURL().toString());
        statusCode = HttpStatus.SC_MULTIPLE_CHOICES;
        return;
    }

    if (file.isDirectory()) {
        getDirAsHttpResponse(file);
    } else if (file.isFile()) {
        getFileAsHttpResponse(file);
    } else {
        statusCode = HttpStatus.SC_INTERNAL_SERVER_ERROR;
        return;
    }

    if (content == null) {
        content = new byte[0];
    }
}

From source file:com.eviware.soapui.impl.wsdl.support.wsdl.CachedWsdlLoader.java

private void setFilenameForUrl(String fileUrl, String type, Map<String, String> urlToFileMap)
        throws MalformedURLException {
    URL url = new URL(fileUrl);
    String path = url.getPath();

    int ix = path.lastIndexOf('/');
    String fileName = ix == -1 ? path : path.substring(ix + 1);

    ix = fileName.lastIndexOf('.');
    if (ix != -1)
        fileName = fileName.substring(0, ix);

    if (type.equals(Constants.WSDL11_NS))
        fileName += ".wsdl";
    else if (type.equals(Constants.XSD_NS))
        fileName += ".xsd";
    else//from  w w  w . j a va  2s .co  m
        fileName += ".xml";

    while (urlToFileMap.containsValue(fileName)) {
        ix = fileName.lastIndexOf('.');
        fileName = fileName.substring(0, ix) + "_" + fileName.substring(ix);
    }

    urlToFileMap.put(fileUrl, fileName);
}

From source file:com.silverpeas.mailinglist.service.job.TestZimbraConnection.java

@Test
public void testOpenImapConnection() {
    URL url = this.getClass().getClassLoader().getResource("truststore.jks");
    String path = url.getPath();
    System.setProperty("javax.net.ssl.trustStore", path);
    System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
    Store mailAccount = null;//www. j av a2s.  c  o  m
    Folder inbox = null;
    Session mailSession = Session.getInstance(System.getProperties());
    try {
        mailSession.setDebug(true);
        mailAccount = mailSession.getStore(props.getProperty("mail.server.protocol"));
        mailAccount.connect(props.getProperty("mail.server.host"),
                Integer.parseInt(props.getProperty("mail.server.port")), props.getProperty("mail.server.login"),
                props.getProperty("mail.server.password"));
        inbox = mailAccount.getFolder("INBOX");
        if (inbox == null) {
            throw new MessagingException("No POP3 INBOX");
        }
        // -- Open the folder for read write --
        inbox.open(Folder.READ_WRITE);

        // -- Get the message wrappers and process them --
        Message[] msgs = inbox.getMessages();
        FetchProfile profile = new FetchProfile();
        profile.add(FetchProfile.Item.FLAGS);
        inbox.fetch(msgs, profile);
    } catch (MessagingException mex) {
        SilverTrace.error("mailingList", "MessageChecker.checkNewMessages", "mail.processing.error", mex);
    } catch (Exception mex) {
        SilverTrace.error("mailingList", "MessageChecker.checkNewMessages", "mail.processing.error", mex);
    } finally {
        // -- Close down nicely --
        try {
            if (inbox != null) {
                inbox.close(false);
            }
            if (mailAccount != null) {
                mailAccount.close();
            }
        } catch (Exception ex2) {
            SilverTrace.error("mailingList", "MessageChecker.checkNewMessages", "mail.processing.error", ex2);
        }
    }

}

From source file:org.apache.usergrid.chop.stack.StackTest.java

@Test
public void testCombo() throws Exception {
    stack.setName("UG-2.0").setId(uuid).setDataCenter("es-east-1c").setRuleSetName("UG-Chop-Rules")
            .addInboundRule(new BasicIpRule().withFromPort(80).withToPort(8080).withIpRanges("0.0.0.0/32")
                    .withIpProtocol("tcp"))
            .addInboundRule(new BasicIpRule().withFromPort(443).withToPort(8443).withIpRanges("0.0.0.0/32")
                    .withIpProtocol("tcp"))
            .add(new BasicCluster().setName("ElasticSearch").setSize(6).setInstanceSpec(
                    new BasicInstanceSpec().setKeyName("TestKeyPair").setImageId("ami-c56152ac")
                            .setScriptEnvProperty("ES_PATH", "/var/lib/elastic_search")
                            .setScriptEnvProperty("JAVA_HOME", "/user/lib/jvm/default").setType("m1.large")
                            .addSetupScript(new URL("file://./install_es.sh"))
                            .addSetupScript(new URL("file://./setup_cassandra.sh"))))
            .add(new BasicCluster().setName("Cassandra").setSize(6)
                    .setInstanceSpec(new BasicInstanceSpec().setKeyName("TestKeyPair")
                            .setImageId("ami-c56152ac")
                            .setScriptEnvProperty("CASSANDRA_PATH", "/var/lib/cassandra")
                            .setScriptEnvProperty("JAVA_HOME", "/user/lib/jvm/default").setType("m1.xlarge")
                            .addSetupScript(new URL("file://./install_cassandra.sh"))
                            .addSetupScript(new URL("file://./setup_cassandra.sh"))));

    ObjectMapper mapper = new ObjectMapper();
    String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(stack);
    LOG.info(json);/*from   w  w  w  .  jav  a  2 s . c  o m*/
    LOG.info("---------");

    BasicStack foo = mapper.readValue(new StringReader(json), BasicStack.class);
    assertEquals("UG-2.0", foo.getName());
    assertEquals(uuid.toString(), foo.getId().toString());
    assertNotNull(foo.getClusters().get(0));
    assertEquals("ElasticSearch", foo.getClusters().get(0).getName());

    Cluster cluster = foo.getClusters().get(0);
    InstanceSpec spec = cluster.getInstanceSpec();
    assertEquals("file://./install_es.sh", spec.getSetupScripts().get(0).toString());
    //        URL script = spec.getSetupScripts().get( 0 );
    URL script = new URL("file://./install_es.sh");
    LOG.info("setup script path = {}", script.getPath());

    LOG.info("script modified = {}", script.getPath().substring(1));
    URL reloaded = getClass().getClassLoader().getResource(script.getPath().substring(1));
    LOG.info("reloaded form CL script path = {}", reloaded.toString());
}

From source file:dk.dbc.opensearch.config.ConfigTest.java

@Test
public void testConstructor() throws SecurityException, NoSuchFieldException, IllegalArgumentException,
        IllegalAccessException, ConfigurationException {
    Config c = new Config();
    Field cfgURL;//  w w  w .  j a  va 2 s.c o m
    cfgURL = c.getClass().getDeclaredField("cfgURL");

    cfgURL.setAccessible(true);

    // Test that getResource() finds a file.
    URL url = (URL) cfgURL.get(c);
    assertNotNull(url);

    // Test that getResource() finds the correct file.
    boolean fileName = url.getPath().endsWith("config.xml");
    assertTrue(fileName);
}

From source file:org.ebayopensource.twin.TwinConnection.java

public TwinConnection(URL url) {
    if (url.getPath().endsWith("/"))
        try {/*from w  w  w.  ja  va 2s .c  om*/
            url = new URL(url.getProtocol(), url.getHost(), url.getPort(),
                    url.getPath().substring(0, url.getPath().length() - 1));
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        }
    this.url = url;
}

From source file:com.netflix.prana.http.api.HealthCheckHandler.java

private Observable<HttpClientResponse<ByteBuf>> getResponse(String externalHealthCheckURL) {
    String host = "localhost";
    int port = DEFAULT_APPLICATION_PORT;
    String path = "/healthcheck";
    try {/*from ww  w  . j a v  a2 s .  c  o  m*/
        URL url = new URL(externalHealthCheckURL);
        host = url.getHost();
        port = url.getPort();
        path = url.getPath();
    } catch (MalformedURLException e) {
        //continue
    }
    Integer timeout = DynamicProperty.getInstance("prana.host.healthcheck.timeout")
            .getInteger(DEFAULT_CONNECTION_TIMEOUT);
    HttpClient<ByteBuf, ByteBuf> httpClient = RxNetty.<ByteBuf, ByteBuf>newHttpClientBuilder(host, port)
            .pipelineConfigurator(PipelineConfigurators.<ByteBuf, ByteBuf>httpClientConfigurator())
            .channelOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, timeout).build();
    return httpClient.submit(HttpClientRequest.createGet(path));

}

From source file:com.textuality.keybase.lib.prover.Prover.java

public String getPresenceLabel() throws KeybaseException {
    String answer = mProof.getServiceUrl();
    try {//from   ww w  .j av  a  2 s  .c o  m
        URL u = new URL(answer);
        answer = u.getHost() + u.getPath();
    } catch (MalformedURLException e) {
    }
    return answer;
}

From source file:org.jasig.cas.adaptors.x509.authentication.handler.support.CRLDistributionPointRevocationChecker.java

private void addURL(final List<URL> list, final String uriString) {
    try {/*from w  w w  .j ava2 s. c  om*/
        // Build URI by components to facilitate proper encoding of querystring
        // e.g. http://example.com:8085/ca?action=crl&issuer=CN=CAS Test User CA
        final URL url = new URL(uriString);
        final URI uri = new URI(url.getProtocol(), url.getAuthority(), url.getPath(), url.getQuery(), null);
        list.add(uri.toURL());
    } catch (final Exception e) {
        log.warn(uriString + " is not a valid distribution point URI.");
    }
}

From source file:com.ewcms.plugin.crawler.generate.robotstxt.RobotstxtServer.java

public boolean allows(WebURL webURL) {
    if (!config.isEnabled()) {
        return true;
    }//from   w w w.j a  v  a  2  s  . co m
    try {
        URL url = new URL(webURL.getURL());
        String host = url.getHost().toLowerCase();
        String path = url.getPath();

        HostDirectives directives = host2directivesCache.get(host);

        if (directives != null && directives.needsRefetch()) {
            synchronized (host2directivesCache) {
                host2directivesCache.remove(host);
                directives = null;
            }
        }

        if (directives == null) {
            directives = fetchDirectives(host);
        }
        return directives.allows(path);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    return true;
}