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:at.gv.egiz.pdfas.web.helper.RemotePDFFetcher.java

public static byte[] fetchPdfFile(String pdfURL) throws PdfAsWebException {
    URL url;
    String[] fetchInfos;/*from  www  .  j  a  v a  2  s .c  o  m*/
    try {
        fetchInfos = extractSensitiveInformationFromURL(pdfURL);
        url = new URL(fetchInfos[0]);
    } catch (MalformedURLException e) {
        logger.warn("Not a valid URL!", e);
        throw new PdfAsWebException("Not a valid URL!", e);
    } catch (IOException e) {
        logger.warn("Not a valid URL!", e);
        throw new PdfAsWebException("Not a valid URL!", e);
    }
    if (WebConfiguration.isProvidePdfURLinWhitelist(url.toExternalForm())) {
        if (url.getProtocol().equals("http") || url.getProtocol().equals("https")) {
            URLConnection uc = null;
            InputStream is = null;
            try {
                uc = url.openConnection();

                if (fetchInfos.length == 3) {
                    String userpass = fetchInfos[1] + ":" + fetchInfos[2];
                    String basicAuth = "Basic "
                            + javax.xml.bind.DatatypeConverter.printBase64Binary(userpass.getBytes("UTF-8"));
                    uc.setRequestProperty("Authorization", basicAuth);
                }

                is = uc.getInputStream();
                return StreamUtils.inputStreamToByteArray(is);
            } catch (Exception e) {
                logger.warn("Failed to fetch pdf document!", e);
                throw new PdfAsWebException("Failed to fetch pdf document!", e);
            } finally {
                IOUtils.closeQuietly(is);
            }
        } else {
            throw new PdfAsWebException(
                    "Failed to fetch pdf document protocol " + url.getProtocol() + " is not supported");
        }
    } else {
        throw new PdfAsWebException("Failed to fetch pdf document " + url.toExternalForm() + " is not allowed");
    }
}

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

/**
 * does a http get request// w  w  w.  j  a va 2s.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, boolean redirect,
        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, redirect, charset, useragent, proxy, headers, null);
}

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

/**
 * does a http post request/*from w  w w  .j  a  v a  2s  . 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, boolean redirect,
        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, redirect, charset, useragent, proxy, headers, null);
}

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

/**
 * does a http head request//from   ww  w  .ja  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 head(URL url, String username, String password, long timeout, boolean redirect,
        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, redirect, charset, useragent, proxy, headers, null);
}

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

/**
 * does a http delete request/*from ww w  .  java 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 delete(URL url, String username, String password, long timeout, boolean redirect,
        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, redirect, charset, useragent, proxy, headers,
            null);
}

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

/**
* does a http put request//from w  ww .j av a2  s  .co m
 * @param url
 * @param username
 * @param password
 * @param timeout
 * @param charset
 * @param useragent
 * @param proxyserver
 * @param proxyport
 * @param proxyuser
 * @param proxypassword
 * @param headers
 * @param body
 * @return
 * @throws IOException
 * @throws PageException 
 */
public static HTTPResponse put(URL url, String username, String password, long timeout, int maxRedirect,
        String mimetype, String charset, String useragent, ProxyData proxy,
        lucee.commons.net.http.Header[] headers, Object body) throws IOException {
    HttpPut put = new HttpPut(url.toExternalForm());
    setBody(put, body, mimetype, charset);
    return _invoke(url, put, username, password, timeout, maxRedirect, charset, useragent, proxy, headers,
            null);

}

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

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,
        Map<String, String> formfields) throws IOException {
    HttpPost post = new HttpPost(url.toExternalForm());

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

From source file:com.tonbeller.jpivot.core.ModelFactory.java

/**
 * creates a model from an xml configuration file
 * @param url url of model configuration file
 * @return Model/* w w  w  .j a va 2s.c  om*/
 * @throws SAXException
 * @throws IOException
 */
public static Model instance(URL url) throws SAXException, IOException {
    Digester digester = new Digester();
    digester.setValidating(false);

    ModelHolder root = new ModelHolder();
    digester.push(root);

    digester.addObjectCreate("model", "missing \"class\" attribute", "class");
    digester.addSetProperties("model");
    digester.addSetNext("model", "setModel");

    digester.addObjectCreate("model/extension", "missing \"class\" attribute", "class");
    digester.addSetProperties("model/extension");
    digester.addSetNext("model/extension", "addExtension");

    InputSource is = new InputSource(url.toExternalForm());
    digester.parse(is);
    return root.getModel();
}

From source file:gov.nasa.ensemble.common.io.FileUtilities.java

public static URL getDataArea(Location location, String filename) throws IOException {
    URL base = location.getURL();
    if (base == null)
        throw new IOException("Null location");
    String prefix = base.toExternalForm();
    if (prefix.length() > 0 && prefix.charAt(prefix.length() - 1) != '/')
        prefix += '/';
    prefix = prefix.replace(" ", "%20");
    filename = filename.replace('\\', '/');
    if (filename.length() > 0 && filename.charAt(0) == '/')
        filename.substring(1);//  ww  w.  j a  v a  2s . com
    return new URL(prefix + dataAreaPrefix + filename);
}

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

/**
 * does a http put request/*from ww  w .ja  va  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
 * @param body
 * @return
 * @throws IOException
 * @throws PageException
 */
public static HTTPResponse put(URL url, String username, String password, long timeout, boolean redirect,
        String mimetype, String charset, String useragent, ProxyData proxy,
        lucee.commons.net.http.Header[] headers, Object body) throws IOException {
    HttpPut put = new HttpPut(url.toExternalForm());
    setBody(put, body, mimetype, charset);
    return _invoke(url, put, username, password, timeout, redirect, charset, useragent, proxy, headers, null);

}