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:lucee.commons.net.http.httpclient.HTTPEngine4Impl.java

public static HTTPResponse post(URL url, String username, String password, long timeout, boolean redirect,
        String charset, String useragent, ProxyData proxy, lucee.commons.net.http.Header[] headers,
        Map<String, String> formfields) throws IOException {
    HttpPost post = new HttpPost(url.toExternalForm());

    return _invoke(url, post, username, password, timeout, redirect, charset, useragent, proxy, headers,
            formfields);//from w  w  w. ja  va  2s .c o m
}

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

public static boolean isCompressedRemoteFile(URL url, String user, String password) {
    boolean compressed = false;

    String urlString = url.toExternalForm();

    GetMethod get;//ww w .  ja va2  s .  c  om
    try {
        get = RemoteFileReader.httpGet(urlString, user, password);
        String contentType = get.getResponseHeader("Content-Type").getValue();
        compressed = isCompressedFile(contentType);
    } catch (HttpException e) {
        // TODO Auto-generated catch block
    } catch (IOException e) {
        // TODO Auto-generated catch block
    }

    return compressed;
}

From source file:org.cerberus.engine.execution.impl.SeleniumServerService.java

private static void getIPOfNode(TestCaseExecution tCExecution) {
    try {/*from   w w w  .j a  v  a2  s.co m*/
        Session session = tCExecution.getSession();
        HttpCommandExecutor ce = (HttpCommandExecutor) ((RemoteWebDriver) session.getDriver())
                .getCommandExecutor();
        SessionId sessionId = ((RemoteWebDriver) session.getDriver()).getSessionId();
        String hostName = ce.getAddressOfRemoteServer().getHost();
        int port = ce.getAddressOfRemoteServer().getPort();
        HttpHost host = new HttpHost(hostName, port);
        HttpClient client = HttpClientBuilder.create().build();
        URL sessionURL = new URL("http://" + session.getHost() + ":" + session.getPort()
                + "/grid/api/testsession?session=" + sessionId);
        BasicHttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest("POST",
                sessionURL.toExternalForm());
        HttpResponse response = client.execute(host, r);
        if (!response.getStatusLine().toString().contains("403")) {
            InputStream contents = response.getEntity().getContent();
            StringWriter writer = new StringWriter();
            IOUtils.copy(contents, writer, "UTF8");
            JSONObject object = new JSONObject(writer.toString());
            URL myURL = new URL(object.getString("proxyId"));
            if ((myURL.getHost() != null) && (myURL.getPort() != -1)) {
                tCExecution.setIp(myURL.getHost());
                tCExecution.setPort(String.valueOf(myURL.getPort()));
            }
        }

    } catch (IOException ex) {
        LOG.error(ex.toString());
    } catch (JSONException ex) {
        LOG.error(ex.toString());
    }
}

From source file:be.geecko.QuickLyric.lyrics.LyricsWiki.java

public static Lyrics fromMetaData(String artist, String song) {
    if ((artist == null) || (song == null))
        return new Lyrics(Lyrics.ERROR);
    String encodedArtist;//from  www . j a va 2  s.  c o m
    String encodedSong;
    URL url;
    try {
        encodedArtist = URLEncoder.encode(artist, "UTF-8");
        encodedSong = URLEncoder.encode(song, "UTF-8");
        JSONObject json = new JSONObject(
                getUrlAsString(new URL(String.format(baseUrl, encodedArtist, encodedSong))).replace("song = ",
                        ""));
        url = new URL(json.getString("url"));
        artist = json.getString("artist");
        song = json.getString("song");
    } catch (JSONException | IOException e) {
        e.printStackTrace();
        return new Lyrics(Lyrics.ERROR);
    }
    return fromURL(url.toExternalForm(), artist, song);
}

From source file:hudson.plugins.trackplus.Updater.java

private static List<String> getScmComments(AbstractBuild<?, ?> build, TrackplusIssue trackplusIssue) {
    RepositoryBrowser repoBrowser = null;
    if (build.getProject().getScm() != null) {
        repoBrowser = build.getProject().getScm().getEffectiveBrowser();
    }/*from  w  w  w.  jav  a 2  s.  c o m*/
    List<String> scmChanges = new ArrayList<String>();
    for (Entry change : build.getChangeSet()) {
        if (trackplusIssue != null
                && !StringUtils.contains(change.getMsg(), Integer.toString(trackplusIssue.getId()))) {
            continue;
        }
        try {
            String uid = change.getAuthor().getId();
            URL url = repoBrowser == null ? null : repoBrowser.getChangeSetLink(change);
            StringBuilder scmChange = new StringBuilder();
            if (StringUtils.isNotBlank(uid)) {
                scmChange.append("<br><b>").append(Messages.Updater_CommittedBy()).append("</b>:<br>")
                        .append(uid).append(" <br> ");
            }
            if (url != null && StringUtils.isNotBlank(url.toExternalForm())) {
                scmChange.append("<a target='vc' href='" + url.toExternalForm() + "'>" + url.toExternalForm()
                        + "</a><br>");
            }
            scmChange.append("<b>").append(Messages.Updater_AffectedFiles()).append("</b>: ").append("<br>");
            for (AffectedFile affectedFile : change.getAffectedFiles()) {
                scmChange.append("* ").append(affectedFile.getPath()).append("<br>");
            }
            if (scmChange.length() > 0) {
                scmChanges.add(scmChange.toString());
            }
        } catch (IOException e) {
            LOGGER.warning("skip failed to calculate scm repo browser link " + e.getMessage());
        }
    }
    return scmChanges;
}

From source file:gate.util.Files.java

/**
 * Convert a file: URL to a <code>java.io.File</code>.  First tries to parse
 * the URL's toExternalForm as a URI and create the File object from that
 * URI.  If this fails, just uses the path part of the URL.  This handles
 * URLs that contain spaces or other unusual characters, both as literals and
 * when encoded as (e.g.) %20./*from  w w w  . j  a v  a 2  s.c om*/
 *
 * @exception IllegalArgumentException if the URL is not convertable into a
 * File.
 */
public static File fileFromURL(URL theURL) throws IllegalArgumentException {
    try {
        URI uri = new URI(theURL.toExternalForm());
        return new File(uri);
    } catch (URISyntaxException use) {
        try {
            URI uri = new URI(theURL.getProtocol(), null, theURL.getPath(), null, null);
            return new File(uri);
        } catch (URISyntaxException use2) {
            throw new IllegalArgumentException("Cannot convert " + theURL + " to a file path");
        }
    }
}

From source file:com.asakusafw.runtime.util.hadoop.ConfigurationProvider.java

private static ClassLoader createLoader(ClassLoader current, URL defaultConfigPath) {
    assert current != null;
    if (defaultConfigPath == null) {
        return current;
    }//  w  w w  .  j a  v  a 2  s .  c  om
    ClassLoader cached = null;
    String configPath = defaultConfigPath.toExternalForm();
    synchronized (CACHE_CLASS_LOADER) {
        ClassLoaderHolder holder = CACHE_CLASS_LOADER.get(current);
        if (holder != null) {
            cached = holder.get();
            if (cached != null && holder.configPath.equals(configPath)) {
                return cached;
            }
        }
    }
    ClassLoader ehnahced = AccessController.doPrivileged(
            (PrivilegedAction<ClassLoader>) () -> new URLClassLoader(new URL[] { defaultConfigPath }, current));
    synchronized (CACHE_CLASS_LOADER) {
        CACHE_CLASS_LOADER.put(current, new ClassLoaderHolder(ehnahced, configPath));
    }
    return ehnahced;
}

From source file:com.thoughtmetric.tl.TLLib.java

public static String parseQuoteText(HtmlCleaner cleaner, URL url, TLHandler handler, Context context)
        throws IOException {
    DefaultHttpClient httpclient = new DefaultHttpClient();
    httpclient.setCookieStore(cookieStore);

    HttpGet httpGet = new HttpGet(url.toExternalForm());
    HttpResponse response = httpclient.execute(httpGet);

    handler.sendEmptyMessage(PROGRESS_DOWNLOADING);
    InputStream is = response.getEntity().getContent();

    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);

    return parseTextArea(br);
}

From source file:fedora.server.security.servletfilters.pubcookie.ConnectPubcookie.java

private static final HttpMethodBase setup(HttpClient client, URL url, Map requestParameters,
        Cookie[] requestCookies) {/*w w  w .jav  a2 s  .com*/
    LogFactory.getLog(ConnectPubcookie.class).debug(ConnectPubcookie.class.getName() + ".setup()");
    HttpMethodBase method = null;
    if (requestParameters == null) {
        LogFactory.getLog(ConnectPubcookie.class)
                .debug(ConnectPubcookie.class.getName() + ".setup()" + " requestParameters == null");
        method = new GetMethod(url.toExternalForm());
        //GetMethod is superclass to ExpectContinueMethod, so we don't require method.setUseExpectHeader(false);
        LogFactory.getLog(ConnectPubcookie.class)
                .debug(ConnectPubcookie.class.getName() + ".setup()" + " after getting method");
    } else {
        LogFactory.getLog(ConnectPubcookie.class)
                .debug(ConnectPubcookie.class.getName() + ".setup()" + " requestParameters != null");
        method = new PostMethod(url.toExternalForm()); // "http://localhost:8080/"
        LogFactory.getLog(ConnectPubcookie.class)
                .debug(ConnectPubcookie.class.getName() + ".setup()" + " after getting method");

        //XXX method.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, false); //new way
        //XXX method.getParams().setIntParameter(HttpMethodParams.SO_TIMEOUT, 10000);            
        //XXX method.getParams().setVersion(HttpVersion.HTTP_0_9); //or HttpVersion.HTTP_1_0 HttpVersion.HTTP_1_1

        LogFactory.getLog(ConnectPubcookie.class)
                .debug(ConnectPubcookie.class.getName() + ".setup()" + " after setting USE_EXPECT_CONTINUE");

        //PostMethod is subclass of ExpectContinueMethod, so we require here:            
        //((PostMethod)method).setUseExpectHeader(false);
        //client.setTimeout(30000); // increased from 10000 as temp fix; 2005-03-17 wdn5e
        //HttpClientParams httpClientParams = new HttpClientParams();
        //httpClientParams.setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true); //old way
        //httpClientParams.setIntParameter(HttpMethodParams.SO_TIMEOUT, 30000);

        LogFactory.getLog(ConnectPubcookie.class).debug(ConnectPubcookie.class.getName() + ".setup()" + " A");

        Part[] parts = new Part[requestParameters.size()];
        Iterator iterator = requestParameters.keySet().iterator();
        for (int i = 0; iterator.hasNext(); i++) {
            String fieldName = (String) iterator.next();
            String fieldValue = (String) requestParameters.get(fieldName);
            StringPart stringPart = new StringPart(fieldName, fieldValue);
            parts[i] = stringPart;
            LogFactory.getLog(ConnectPubcookie.class).debug(ConnectPubcookie.class.getName() + ".setup()"
                    + " part[" + i + "]==" + fieldName + "=" + fieldValue);

            ((PostMethod) method).addParameter(fieldName, fieldValue); //old way
        }

        LogFactory.getLog(ConnectPubcookie.class).debug(ConnectPubcookie.class.getName() + ".setup()" + " B");

        //XXX MultipartRequestEntity multipartRequestEntity = new MultipartRequestEntity(parts, method.getParams());
        // ((PostMethod)method).setRequestEntity(multipartRequestEntity); //new way            
    }
    //method.getParams().setCookiePolicy(CookiePolicy.RFC_2109);
    HttpState state = client.getState();
    for (Cookie cookie : requestCookies) {
        state.addCookie(cookie);
    }
    //method.setFollowRedirects(true); this is disallowed at runtime, so redirect won't be honored

    LogFactory.getLog(ConnectPubcookie.class).debug(ConnectPubcookie.class.getName() + ".setup()" + " C");
    LogFactory.getLog(ConnectPubcookie.class)
            .debug(ConnectPubcookie.class.getName() + ".setup()" + " method==" + method);
    LogFactory.getLog(ConnectPubcookie.class)
            .debug(ConnectPubcookie.class.getName() + ".setup()" + " method==" + method.toString());
    return method;
}

From source file:eu.eidas.auth.engine.configuration.dom.DOMConfigurationParser.java

/**
 * Read configuration.//w  w w  . j  av  a2  s  .co  m
 *
 * @return the map< string, instance engine>
 * @throws SAMLEngineException the EIDASSAML engine runtime exception
 */
@Nonnull
public static InstanceMap parseConfiguration(@Nonnull String configurationFileName)
        throws SamlEngineConfigurationException {
    Preconditions.checkNotNull(configurationFileName, "configurationFileName");
    LOG.debug("DOM parsing SAML engine configuration file: \"" + configurationFileName + "\"");
    try {
        // Load configuration file
        URL resource = ResourceLocator.getResource(configurationFileName);
        if (null == resource) {
            String message = "SAML engine configuration file \"" + configurationFileName + "\" cannot be found";
            LOG.error(message);
            throw new SamlEngineConfigurationException(message);
        } else {
            LOG.debug("SAML engine configuration file \"" + configurationFileName + "\" found at \""
                    + resource.toExternalForm() + "\"");
        }
        return parseConfiguration(configurationFileName, resource.openStream());
    } catch (IOException ex) {
        LOG.error(ex.getMessage(), ex);
        throw new SamlEngineConfigurationException(ex);
    }
}