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:com.cloudbees.mtslaves.client.RemoteReference.java

protected URL getEntityUrl(String restOfUrl) throws MalformedURLException {
    URL u = url;
    if (url.toString().endsWith("/"))
        u = new URL(u, restOfUrl);
    else/*from  www .j  a va2 s  . c o  m*/
        u = new URL(u.toExternalForm() + '/' + restOfUrl);
    return u;
}

From source file:com.norconex.jefmon.server.JEFMonServer.java

private void initHttpsConnector() {
    HttpConfiguration https = new HttpConfiguration();
    https.addCustomizer(new SecureRequestCustomizer());
    URL keystore = JEFMonServer.class.getClassLoader().getResource("keystore");
    SslContextFactory sslContextFactory = new SslContextFactory(keystore.toExternalForm());
    // TODO use jasypt to handle password
    sslContextFactory.setKeyStorePassword("vyU2Pk_Q-2");
    sslContextFactory.setKeyManagerPassword("vyU2Pk_Q-2");
    ServerConnector sslConnector = new ServerConnector(server,
            new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(https));
    sslConnector.setPort(port);//from w w  w.ja va  2s . c om
    server.addConnector(sslConnector);
}

From source file:org.jasig.portlet.notice.service.ssp.SSPApi.java

/**
 * Get the authentication token to use./*from   www  .j ava  2 s  . co  m*/
 *
 * @param forceUpdate if true, get a new auth token even if a cached instance exists.
 * @return The authentication token
 * @throws MalformedURLException if the authentication URL is invalid
 * @throws RestClientException if an error occurs when talking to SSP
 */
private synchronized SSPToken getAuthenticationToken(boolean forceUpdate)
        throws MalformedURLException, RestClientException {
    if (authenticationToken != null && !authenticationToken.hasExpired() && !forceUpdate) {
        return authenticationToken;
    }

    String authString = getClientId() + ":" + getClientSecret();
    String authentication = new Base64().encodeToString(authString.getBytes());

    HttpHeaders headers = new HttpHeaders();
    headers.add(AUTHORIZATION, BASIC + " " + authentication);

    // form encode the grant_type...
    MultiValueMap<String, String> form = new LinkedMultiValueMap<>();
    form.add(GRANT_TYPE, CLIENT_CREDENTIALS);

    HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(form, headers);

    URL authURL = getAuthenticationURL();
    authenticationToken = restTemplate.postForObject(authURL.toExternalForm(), request, SSPToken.class);
    return authenticationToken;
}

From source file:com.gargoylesoftware.htmlunit.html.HTMLParserListener.java

private String format(final String message, final URL url, final String html, final int line,
        final int column) {
    final StringBuilder buffer = new StringBuilder(message);
    buffer.append(" (");
    buffer.append(url.toExternalForm());
    buffer.append(" ");
    buffer.append(line);/*from   w w  w.  j a va  2 s  .c o  m*/
    buffer.append(":");
    buffer.append(column);
    if (null != html) {
        buffer.append(" htmlSnippet: '");
        buffer.append(html);
        buffer.append("'");
    }
    buffer.append(")");
    return buffer.toString();
}

From source file:com.thinkberg.moxo.dav.PropFindHandler.java

private Document getMultiStatusRespons(FileObject object, List<String> requestedProperties, URL baseUrl,
        int depth, boolean ignoreValues) throws FileSystemException {
    Document propDoc = DocumentHelper.createDocument();
    propDoc.setXMLEncoding("UTF-8");

    Element multiStatus = propDoc.addElement(TAG_MULTISTATUS, "DAV:");
    FileObject[] children = object.findFiles(new DepthFileSelector(depth));
    for (FileObject child : children) {
        Element responseEl = multiStatus.addElement(TAG_RESPONSE);
        try {//from   w  ww .  j a  va  2s  . c  o  m
            URL url = new URL(baseUrl, URLEncoder.encode(child.getName().getPath(), "UTF-8"));
            log("!! " + url);
            responseEl.addElement(TAG_HREF).addText(url.toExternalForm());
        } catch (Exception e) {
            e.printStackTrace();
        }
        DavResource resource = DavResourceFactory.getInstance().getDavResource(child);
        resource.setIgnoreValues(ignoreValues);
        resource.serializeToXml(responseEl, requestedProperties);
    }
    return propDoc;
}

From source file:org.eclipse.skalli.nexus.internal.NexusClientImpl.java

Element getElementFromUrlResponse(URL nexusUrl) throws IOException, NexusClientException {
    HttpClient client = getClient(nexusUrl);
    HttpGet method = new HttpGet(nexusUrl.toExternalForm());
    HttpResponse response = null;/*www. j av  a  2s .  co m*/
    try {
        LOG.info("GET " + nexusUrl); //$NON-NLS-1$
        response = client.execute(method);
        int status = response.getStatusLine().getStatusCode();
        LOG.info(status + " " + response.getStatusLine().getReasonPhrase()); //$NON-NLS-1$
        if (status == HttpStatus.SC_OK) {
            InputStream in = response.getEntity().getContent();
            Document document;
            try {
                document = XMLUtils.documentFromStream(in);
            } catch (SAXException e) {
                throw new NexusClientException(
                        MessageFormat.format("Problems found for {0}: {1}", nexusUrl, e.getMessage()), e);
            } catch (ParserConfigurationException e) {
                throw new NexusClientException(
                        MessageFormat.format("Problems found for {0}: {1}", nexusUrl, e.getMessage()), e);
            }
            return document.getDocumentElement();
        } else {
            switch (status) {
            case SC_UNAUTHORIZED:
                throw new IOException(MessageFormat.format("{0} found but authentication required", nexusUrl));
            case SC_MOVED_PERMANENTLY:
                throw new IOException(
                        MessageFormat.format("{0} not found. Resource has been moved permanently to {1}",
                                nexusUrl, response.getFirstHeader("Location")));
            default:
                throw new IOException(
                        MessageFormat.format("{0} not found. Host reports a temporary problem: {1} {2}",
                                nexusUrl, status, response.getStatusLine().getReasonPhrase()));
            }
        }
    } finally {
        HttpUtils.consumeQuietly(response);
    }
}

From source file:org.picketbox.test.jaxrs.RESTEasyStandaloneTestCase.java

@Override
protected void establishUserApps() {
    ClassLoader tcl = Thread.currentThread().getContextClassLoader();
    if (tcl == null) {
        tcl = getClass().getClassLoader();
    }/*from   w ww .  j  av a2s  .  c  om*/

    final String WEBAPPDIR = "resteasy/standalone";

    final String CONTEXTPATH = "/*";

    // for localhost:port/admin/index.html and whatever else is in the webapp directory
    final URL warUrl = tcl.getResource(WEBAPPDIR);
    final String warUrlString = warUrl.toExternalForm();

    // WebAppContext context = new WebAppContext(warUrlString, CONTEXTPATH);
    WebAppContext context = createWebApp(CONTEXTPATH, warUrlString);

    context.setContextPath("/");
    ServletHolder servletHolder = new ServletHolder(new HttpServletDispatcher());
    servletHolder.setInitParameter("javax.ws.rs.Application", TestApplicationConfig.class.getName());
    context.addServlet(servletHolder, "/*");

    // context.setParentLoaderPriority(true);
    server.setHandler(context);
}

From source file:com.googlecode.flyway.core.util.scanner.ClassPathScanner.java

/**
 * Finds the resources names present at this location and below on the classpath starting with this prefix and
 * ending with this suffix./*from  w  w w  . j a v a  2  s . co  m*/
 *
 * @param location The location on the classpath to scan.
 * @param prefix   The filename prefix to match.
 * @param suffix   The filename suffix to match.
 * @return The resource names.
 * @throws IOException when scanning this location failed.
 */
private Set<String> findResourceNames(String location, String prefix, String suffix) throws IOException {
    Set<String> resourceNames = new TreeSet<String>();

    String normalizedLocation = normalizeLocation(location);

    Enumeration<URL> locationsUrls = getClassLoader().getResources(normalizedLocation);
    if (!locationsUrls.hasMoreElements()) {
        LOG.debug("Unable to determine URL for classpath location: " + normalizedLocation + " (ClassLoader: "
                + getClassLoader() + ")");
    }
    while (locationsUrls.hasMoreElements()) {
        URL locationUrl = locationsUrls.nextElement();
        LOG.debug("Scanning URL: " + locationUrl.toExternalForm());

        String scanRoot = URLDecoder.decode(locationUrl.getFile(), "UTF-8");
        if (scanRoot.endsWith("/")) {
            scanRoot = scanRoot.substring(0, scanRoot.length() - 1);
        }

        String protocol = locationUrl.getProtocol();
        LocationScanner locationScanner = createLocationScanner(protocol);
        if (locationScanner == null) {
            LOG.warn("Unable to scan location: " + scanRoot + " (unsupported protocol: " + protocol + ")");
        } else {
            resourceNames.addAll(locationScanner.findResourceNames(normalizedLocation, scanRoot));
        }
    }

    return filterResourceNames(resourceNames, prefix, suffix);
}

From source file:at.newsagg.parser.FeedParser.java

public ChannelIF parse(ChannelIF cBuilder, URL aURL) throws IOException, ParseException {
    return parse(cBuilder, new InputSource(aURL.toExternalForm()), aURL);
}

From source file:com.icesoft.faces.webapp.parser.JspPageToDocument.java

/**
 * @param context/*  ww w  .j a  v  a 2s  . c o  m*/
 * @param namespaceURL
 * @return InputStream
 * @throws IOException
 */
public static InputStream getTldInputStream(ExternalContext context, String namespaceURL) throws IOException {

    // InputStream in = null;
    JarFile jarFile = null;
    String[] location = null;

    namespaceURL = String.valueOf(namespaceURL);

    // "jsp" is only a placeholder for standard JSP tags that are
    // not supported, so just return null

    if ("jsp".equals(namespaceURL)) {
        return null;
    }

    if ("http://java.sun.com/JSP/Page".equals(namespaceURL)) {
        return null;
    }

    // TldLocationsCache may fail esp. with SecurityException on SUN app server
    TldLocationsCache tldCache = new TldLocationsCache(context);
    try {
        location = tldCache.getLocation(namespaceURL);
    } catch (Exception e) {
        if (log.isDebugEnabled()) {
            log.debug(e.getMessage(), e);
        }
    }

    if (null == location) {
        if (namespaceURL.startsWith("/") && namespaceURL.endsWith(".tld")) {
            location = new String[] { namespaceURL };
        }
    }

    if (null == location) {
        location = scanJars(context, namespaceURL);
    }

    if (null == location) {
        //look for Sun implementation
        URL tagURL = JspPageToDocument.class.getClassLoader().getResource(SUN_TAG_CLASS);
        if (null != tagURL) {

            // Bug 876
            // Not all app servers (ie WebLogic 8.1) return
            // an actual JarURLConnection.
            URLConnection conn = tagURL.openConnection();

            //ICE-3683: Special processing for JBoss 5 micro-container with VFS
            if (tagURL.getProtocol().equals("vfszip")) {
                String tagPath = tagURL.toExternalForm();
                String jarPath = tagPath.substring(0, tagPath.indexOf(SUN_TAG_CLASS));

                String tldPath = jarPath;
                if (namespaceURL.endsWith("html")) {
                    tldPath += HTML_TLD_SUFFIX;
                } else if (namespaceURL.endsWith("core")) {
                    tldPath += CORE_TLD_SUFFIX;
                }

                URL tldURL = new URL(tldPath);
                return tldURL.openConnection().getInputStream();
            }

            if (conn instanceof JarURLConnection) {
                location = scanJar((JarURLConnection) conn, namespaceURL);
            } else {
                //OSGi-based servers (such as GlassFishv3 and WebSphere7)
                //do not provide JarURLConnection to their resources so
                //we handle the JSF TLDs as a special case.
                if (namespaceURL.endsWith("html")) {
                    location = getBundleLocation(tagURL, HTML_TLD_SUFFIX);
                } else if (namespaceURL.endsWith("core")) {
                    location = getBundleLocation(tagURL, CORE_TLD_SUFFIX);
                }
            }
        }
    }

    if (null == location) {
        try {
            // scan WebSphere dirs for JSF jars
            String separator = System.getProperty("path.separator");
            String wsDirs = System.getProperty("ws.ext.dirs");

            String[] dirs = null;
            if (null != wsDirs) {
                dirs = wsDirs.split(separator);
            } else {
                dirs = new String[] {};
            }
            Iterator theDirs = Arrays.asList(dirs).iterator();
            while (theDirs.hasNext()) {
                String dir = (String) theDirs.next();
                try {
                    location = scanJars(dir, namespaceURL);
                } catch (Exception e) {
                    //catch all possible exceptions including runtime exception
                    //so that the rest of jars still can be scanned.
                }
                if (null != location) {
                    break;
                }
            }
        } catch (Exception e) {
            if (log.isDebugEnabled()) {
                log.debug(e.getMessage(), e);
            }
        }
    }

    if (null == location) {
        //look for MyFaces implementation
        URL tagURL = JspPageToDocument.class.getClassLoader().getResource(MYFACES_TAG_CLASS);

        if (null != tagURL) {
            URLConnection conn = tagURL.openConnection();

            if (conn instanceof JarURLConnection) {
                location = scanJar((JarURLConnection) conn, namespaceURL);
            } else {
                //OSGi-based servers (such as GlassFishv3 and WebSphere7)
                //do not provide JarURLConnection to their resources so
                //we handle the JSF TLDs as a special case.
                if (namespaceURL.endsWith("html")) {
                    location = getBundleLocation(tagURL, HTML_TLD_SUFFIX);
                } else if (namespaceURL.endsWith("core")) {
                    location = getBundleLocation(tagURL, CORE_TLD_SUFFIX);
                }
            }
        }
    }

    if (null == location) {
        String msg = "Can't find TLD for location [" + namespaceURL
                + "]. JAR containing the TLD may not be in the classpath";
        log.error(msg);
        return null;
    } else {
        if (log.isTraceEnabled()) {
            for (int i = 0; i < location.length; i++) {
                log.trace("Found TLD location for " + namespaceURL + " = " + location[i]);
            }
        }
    }

    if (!location[0].endsWith("jar")) {
        InputStream tldStream = context.getResourceAsStream(location[0]);
        if (null == tldStream) {
            tldStream = (new URL(location[0])).openConnection().getInputStream();
        }
        return tldStream;
    } else {
        // Tag library is packaged in JAR file
        URL jarFileUrl = new URL("jar:" + location[0] + "!/");
        JarURLConnection conn = (JarURLConnection) jarFileUrl.openConnection();
        conn.setUseCaches(false);
        conn.connect();
        jarFile = conn.getJarFile();
        ZipEntry jarEntry = jarFile.getEntry(location[1]);
        return jarFile.getInputStream(jarEntry);
    }

}