Example usage for java.net URL toExternalForm

List of usage examples for java.net URL toExternalForm

Introduction

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

Prototype

public String toExternalForm() 

Source Link

Document

Constructs a string representation of this URL .

Usage

From source file:es.juntadeandalucia.panelGestion.negocio.utiles.Utils.java

public static boolean isLocalFile(URL url) {
    return url.toExternalForm().toLowerCase().startsWith("file:");
}

From source file:com.github.jrh3k5.chef.client.jersey.JerseyCookbookClientITest.java

@BeforeClass
public static void getApacheInfo() throws Exception {
    final ClientConfig clientConfig = new ClientConfig();
    clientConfig.register(JacksonJsonProvider.class);
    final Client client = ClientBuilder.newClient(clientConfig);
    try {//  w w  w.j  ava  2s  .c  om
        apacheCookbook = client.target(JerseyCookbookClient.V1_API_URL).path("cookbooks").path("apache")
                .request(MediaType.APPLICATION_JSON_TYPE).accept(MediaType.APPLICATION_JSON_TYPE)
                .get(JsonCookbookObject.class);
        final String latestVersionUrlString = apacheCookbook.getLatestVersion().toExternalForm();
        apacheVersions = new ArrayList<JsonCookbookVersionObject>(apacheCookbook.versions.length);
        for (URL version : apacheCookbook.versions) {
            final JsonCookbookVersionObject versionObject = client.target(version.toURI())
                    .request(MediaType.APPLICATION_JSON_TYPE).accept(MediaType.APPLICATION_JSON_TYPE)
                    .get(JsonCookbookVersionObject.class);
            versionObject.location = version;
            apacheVersions.add(versionObject);
            if (version.toExternalForm().equals(latestVersionUrlString)) {
                apacheCookbook.setLatestVersionObject(versionObject);
            }
        }
    } finally {
        client.close();
    }
}

From source file:hudson.remoting.Launcher.java

private static Document loadDom(URL slaveJnlpURL, URLConnection con)
        throws ParserConfigurationException, SAXException, IOException {
    DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    return db.parse(con.getInputStream(), slaveJnlpURL.toExternalForm());
}

From source file:net.sf.taverna.t2.security.credentialmanager.impl.HTTPAuthenticatorIT.java

@BeforeClass
public static void jettyServer() throws Exception {

    server = new Server();

    Connector connector = new SelectChannelConnector();
    connector.setPort(PORT);/*from  ww w  . j a  v a 2 s  .  c om*/
    server.setConnectors(new Connector[] { connector });
    ConstraintMapping cm = new ConstraintMapping();
    Constraint constraint = new Constraint();
    constraint.setName(Constraint.__BASIC_AUTH);
    constraint.setRoles(new String[] { ROLE_NAME });
    constraint.setAuthenticate(true);
    cm.setConstraint(constraint);
    cm.setPathSpec("/*");

    sh = new SecurityHandler();
    userRealm = new HashUserRealm(REALM);
    userRealm.put(USERNAME, PASSWORD);
    userRealm.addUserToRole(USERNAME, ROLE_NAME);
    sh.setUserRealm(userRealm);
    sh.setConstraintMappings(new ConstraintMapping[] { cm });

    WebAppContext webappcontext = new WebAppContext();
    webappcontext.setContextPath("/");

    URL htmlRoot = HTTPAuthenticatorIT.class.getResource(HTML);
    assertNotNull("Could not find " + HTML, htmlRoot);
    webappcontext.setWar(htmlRoot.toExternalForm());

    webappcontext.addHandler(sh);

    HandlerCollection handlers = new HandlerCollection();
    handlers.setHandlers(new Handler[] { webappcontext, new DefaultHandler() });

    server.setHandler(handlers);
    server.start();
}

From source file:Main.java

public static String getDefaultNamespaceUri(URL xmlResource, String rootElementName)
        throws IOException, ParserConfigurationException, SAXException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(false);//from  ww  w  .  j av a2  s  . co  m
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document document = builder.parse(xmlResource.openStream());
    NodeList nodes = document.getElementsByTagName(rootElementName);
    if (nodes == null || nodes.getLength() == 0) {
        throw new IllegalArgumentException("Root element \"" + rootElementName + "\" not found in xml \""
                + xmlResource.toExternalForm() + "\".");
    }
    for (int i = 0; i < nodes.getLength(); i++) {
        Node node = nodes.item(i);
        Node xmlns = node.getAttributes().getNamedItem("xmlns");
        if (xmlns != null) {
            String value = xmlns.getNodeValue();
            return value.substring(value.indexOf("=") + 1);
        }
    }
    return null;
}

From source file:lucee.commons.net.http.httpclient4.HTTPEngine4Impl.java

/**
 * does a http get request/*from  ww w .ja v  a 2  s. c om*/
 * @param url
 * @param username
 * @param password
 * @param timeout
 * @param charset
 * @param useragent
 * @param proxyserver
 * @param proxyport
 * @param proxyuser
 * @param proxypassword
 * @param headers
 * @return
 * @throws IOException
 */
public static HTTPResponse get(URL url, String username, String password, long timeout, int maxRedirect,
        String charset, String useragent, ProxyData proxy, lucee.commons.net.http.Header[] headers)
        throws IOException {
    HttpGet get = new HttpGet(url.toExternalForm());
    return _invoke(url, get, username, password, timeout, maxRedirect, charset, useragent, proxy, headers,
            null);
}

From source file:lucee.commons.net.http.httpclient4.HTTPEngine4Impl.java

/**
* does a http post request//from  ww  w  .  j  a v a  2 s  . c o m
 * @param url
 * @param username
 * @param password
 * @param timeout
 * @param charset
 * @param useragent
 * @param proxyserver
 * @param proxyport
 * @param proxyuser
 * @param proxypassword
 * @param headers
 * @return
 * @throws IOException
 */
public static HTTPResponse post(URL url, String username, String password, long timeout, int maxRedirect,
        String charset, String useragent, ProxyData proxy, lucee.commons.net.http.Header[] headers)
        throws IOException {
    HttpPost post = new HttpPost(url.toExternalForm());
    return _invoke(url, post, username, password, timeout, maxRedirect, charset, useragent, proxy, headers,
            null);
}

From source file:lucee.commons.net.http.httpclient4.HTTPEngine4Impl.java

/**
* does a http head request//w  ww.j a v  a2  s . c  o  m
 * @param url
 * @param username
 * @param password
 * @param timeout
 * @param charset
 * @param useragent
 * @param proxyserver
 * @param proxyport
 * @param proxyuser
 * @param proxypassword
 * @param headers
 * @return
 * @throws IOException
 */
public static HTTPResponse head(URL url, String username, String password, long timeout, int maxRedirect,
        String charset, String useragent, ProxyData proxy, lucee.commons.net.http.Header[] headers)
        throws IOException {
    HttpHead head = new HttpHead(url.toExternalForm());
    return _invoke(url, head, username, password, timeout, maxRedirect, charset, useragent, proxy, headers,
            null);
}

From source file:com.telefonica.iot.cygnus.utils.CommonUtils.java

/**
 * Only works in DEBUG level./* w  ww  .ja v a  2 s.  c o  m*/
 * Prints the loaded .jar files at the start of Cygnus run.
 */
public static void printLoadedJars() {
    // trace the file containing the httpclient library
    URL myClassURL = PoolingClientConnectionManager.class.getProtectionDomain().getCodeSource().getLocation();
    LOGGER.debug("Loading httpclient from " + myClassURL.toExternalForm());

    // trace the file containing the httpcore library
    myClassURL = DefaultBHttpServerConnection.class.getProtectionDomain().getCodeSource().getLocation();
    LOGGER.debug("Loading httpcore from " + myClassURL.toExternalForm());

    // trace the file containing the junit library
    myClassURL = ErrorCollector.class.getProtectionDomain().getCodeSource().getLocation();
    LOGGER.debug("Loading junit from " + myClassURL.toExternalForm());

    // trace the file containing the flume-ng-node library
    myClassURL = RegexExtractorInterceptorMillisSerializer.class.getProtectionDomain().getCodeSource()
            .getLocation();
    LOGGER.debug("Loading flume-ng-node from " + myClassURL.toExternalForm());

    // trace the file containing the libthrift library
    myClassURL = ListMetaData.class.getProtectionDomain().getCodeSource().getLocation();
    LOGGER.debug("Loading libthrift from " + myClassURL.toExternalForm());

    // trace the file containing the gson library
    myClassURL = JsonPrimitive.class.getProtectionDomain().getCodeSource().getLocation();
    LOGGER.debug("Loading gson from " + myClassURL.toExternalForm());

    // trace the file containing the json-simple library
    myClassURL = Yytoken.class.getProtectionDomain().getCodeSource().getLocation();
    LOGGER.debug("Loading json-simple from " + myClassURL.toExternalForm());

    // trace the file containing the mysql-connector-java library
    myClassURL = Driver.class.getProtectionDomain().getCodeSource().getLocation();
    LOGGER.debug("Loading mysql-connector-java from " + myClassURL.toExternalForm());

    // trace the file containing the postgresql library
    myClassURL = BlobOutputStream.class.getProtectionDomain().getCodeSource().getLocation();
    LOGGER.debug("Loading postgresql from " + myClassURL.toExternalForm());

    // trace the file containing the log4j library
    myClassURL = SequenceNumberPatternConverter.class.getProtectionDomain().getCodeSource().getLocation();
    LOGGER.debug("Loading log4j from " + myClassURL.toExternalForm());

    // trace the file containing the hadoop-core library
    myClassURL = AbstractMetricsContext.class.getProtectionDomain().getCodeSource().getLocation();
    LOGGER.debug("Loading hadoop-core from " + myClassURL.toExternalForm());

    // trace the file containing the hive-exec library
    myClassURL = AbstractMapJoinOperator.class.getProtectionDomain().getCodeSource().getLocation();
    LOGGER.debug("Loading hive-exec from " + myClassURL.toExternalForm());

    // trace the file containing the hive-jdbc library
    myClassURL = HivePreparedStatement.class.getProtectionDomain().getCodeSource().getLocation();
    LOGGER.debug("Loading hive-jdbc from " + myClassURL.toExternalForm());

    // trace the file containing the mongodb-driver library
    myClassURL = AsyncReadWriteBinding.class.getProtectionDomain().getCodeSource().getLocation();
    LOGGER.debug("Loading mongodb-driver from " + myClassURL.toExternalForm());

    // trace the file containing the kafka-clients library
    myClassURL = OffsetOutOfRangeException.class.getProtectionDomain().getCodeSource().getLocation();
    LOGGER.debug("Loading kafka-clientsc from " + myClassURL.toExternalForm());

    // trace the file containing the zkclient library
    myClassURL = ZkNoNodeException.class.getProtectionDomain().getCodeSource().getLocation();
    LOGGER.debug("Loading zkclient from " + myClassURL.toExternalForm());

    // trace the file containing the kafka_2.11 library
    myClassURL = KafkaMigrationTool.class.getProtectionDomain().getCodeSource().getLocation();
    LOGGER.debug("Loading kafka_2.11 from " + myClassURL.toExternalForm());

    // trace the file containing the aws-java-sdk-dynamodb library
    myClassURL = WriteRequest.class.getProtectionDomain().getCodeSource().getLocation();
    LOGGER.debug("Loading aws-java-sdk-dynamodb from " + myClassURL.toExternalForm());

}

From source file:lucee.commons.net.http.httpclient4.HTTPEngine4Impl.java

/**
* does a http delete request/*from   w w  w . jav  a 2 s.c  o  m*/
 * @param url
 * @param username
 * @param password
 * @param timeout
 * @param charset
 * @param useragent
 * @param proxyserver
 * @param proxyport
 * @param proxyuser
 * @param proxypassword
 * @param headers
 * @return
 * @throws IOException
 */
public static HTTPResponse delete(URL url, String username, String password, long timeout, int maxRedirect,
        String charset, String useragent, ProxyData proxy, lucee.commons.net.http.Header[] headers)
        throws IOException {
    HttpDelete delete = new HttpDelete(url.toExternalForm());
    return _invoke(url, delete, username, password, timeout, maxRedirect, charset, useragent, proxy, headers,
            null);
}