Example usage for java.net URL toString

List of usage examples for java.net URL toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Constructs a string representation of this URL .

Usage

From source file:com.celamanzi.liferay.portlets.rails286.Rails286PortletFunctions.java

public static java.net.URL getRequestURL(java.net.URL railsBaseURL, String servlet, String route) {
    try {/*from  w  w w . j av a2s  . c  o m*/
        RouteAnalyzer routeAnalyzer = new RouteAnalyzer(railsBaseURL, servlet);
        URL requestURL = routeAnalyzer.getFullURL(route);
        log.debug("Request URL: " + requestURL.toString());
        return requestURL;

    } catch (java.net.MalformedURLException e) {
        log.error("getRequestURL: " + e.getMessage());
    }
    return null;
}

From source file:com.norconex.commons.lang.url.URLStreamer.java

/**
 * Streams URL content to a String.// w  ww  .  java2  s  . c  o  m
 * @param url the URL to stream
 * @param creds credentials for a protected URL
 * @param proxy proxy to use to stream the URL
 * @return a URL content as a String
 */
public static String streamToString(URL url, Credentials creds, HttpHost proxy) {
    return streamToString(url.toString(), creds, proxy);
}

From source file:com.appleframework.jmx.connector.framework.ConnectorRegistry.java

@SuppressWarnings("deprecation")
private static ConnectorRegistry create(ApplicationConfig config) throws Exception {

    Map<String, String> paramValues = config.getParamValues();
    String appId = config.getApplicationId();
    String connectorId = (String) paramValues.get("connectorId");

    File file1 = new File(CoreUtils.getConnectorDir() + File.separatorChar + connectorId);

    URL[] urls = new URL[] { file1.toURL() };
    ClassLoader cl = ClassLoaderRepository.getClassLoader(urls, true);

    //URLClassLoader cl = new URLClassLoader(urls,
    //        ConnectorMBeanRegistry.class.getClassLoader());

    Registry.MODELER_MANIFEST = MBEANS_DESCRIPTOR;
    URL res = cl.getResource(MBEANS_DESCRIPTOR);

    logger.info("Application ID   : " + appId);
    logger.info("Connector Archive: " + file1.getAbsoluteFile());
    logger.info("MBean Descriptor : " + res.toString());

    //Thread.currentThread().setContextClassLoader(cl);
    //Registry.setUseContextClassLoader(true);

    ConnectorRegistry registry = new ConnectorRegistry();
    registry.loadMetadata(cl);/*from   w ww. jav a2 s . c om*/

    String[] mbeans = registry.findManagedBeans();

    MBeanServer server = MBeanServerFactory.newMBeanServer(DOMAIN_CONNECTOR);

    for (int i = 0; i < mbeans.length; i++) {
        ManagedBean managed = registry.findManagedBean(mbeans[i]);
        String clsName = managed.getType();
        String domain = managed.getDomain();
        if (domain == null) {
            domain = DOMAIN_CONNECTOR;
        }

        Class<?> cls = Class.forName(clsName, true, cl);
        Object objMBean = null;

        // Use the factory method when it is defined.
        Method[] methods = cls.getMethods();
        for (Method method : methods) {
            if (method.getName().equals(FACTORY_METHOD) && Modifier.isStatic(method.getModifiers())) {
                objMBean = method.invoke(null);
                logger.info("Create MBean using factory method.");
                break;
            }
        }

        if (objMBean == null) {
            objMBean = cls.newInstance();
        }

        // Call the initialize method if the MBean extends ConnectorSupport class
        if (objMBean instanceof ConnectorSupport) {
            Method method = cls.getMethod("initialize", new Class[] { Map.class });
            Map<String, String> props = config.getParamValues();
            method.invoke(objMBean, new Object[] { props });
        }
        ModelMBean mm = managed.createMBean(objMBean);

        String beanObjName = domain + ":name=" + mbeans[i];
        server.registerMBean(mm, new ObjectName(beanObjName));
    }

    registry.setMBeanServer(server);
    entries.put(appId, registry);
    return registry;
}

From source file:AnimatedMetadataGraph.java

public static JSONObject getAllResources(URL sfsUrl) {
    if (sfsUrl != null) {
        try {/* www  .  j a va 2  s.  co m*/
            URL sfsGetRsrcsUrl = new URL(sfsUrl.toString() + "/admin/listrsrcs/");
            URLConnection smapConn = sfsGetRsrcsUrl.openConnection();
            smapConn.setConnectTimeout(5000);
            smapConn.connect();

            //GET reply
            BufferedReader reader = new BufferedReader(new InputStreamReader(smapConn.getInputStream()));
            StringBuffer lineBuffer = new StringBuffer();
            String line = null;
            while ((line = reader.readLine()) != null)
                lineBuffer.append(line);
            line = lineBuffer.toString();
            reader.close();

            return (JSONObject) JSONSerializer.toJSON(line);
        } catch (Exception e) {
            logger.log(Level.WARNING, "", e);
            return null;
        }
    }
    return null;
}

From source file:com.nesscomputing.config.util.LocalHttpService.java

private static Connector getSSLClientCertHttpConnector(String truststore, String truststorePassword,
        String keystore, String keystorePassword, String keystoreType) {
    final URL keystoreUrl = Resources.getResource(LocalHttpService.class, keystore);

    final SslContextFactory contextFactory = new SslContextFactory();
    contextFactory.setKeyStorePath(keystoreUrl.toString());
    contextFactory.setKeyStorePassword(keystorePassword);
    contextFactory.setKeyManagerPassword(keystorePassword);
    contextFactory.setKeyStoreType(keystoreType);

    final URL truststoreUrl = Resources.getResource(LocalHttpService.class, truststore);
    contextFactory.setTrustStore(truststoreUrl.toString());
    contextFactory.setTrustStorePassword(truststorePassword);
    contextFactory.setTrustStoreType("JKS");

    contextFactory.setNeedClientAuth(true);

    final SslSelectChannelConnector scc = new SslSelectChannelConnector(contextFactory);
    scc.setPort(0);/*  w ww.  j  ava2s . c  o  m*/
    scc.setHost("localhost");

    return scc;
}

From source file:com.opensymphony.xwork2.util.FileManager.java

/**
 * Loads opens the named file and returns the InputStream
 *
 * @param fileUrl    - the URL of the file to open
 * @param openStream - if true, open an InputStream to the file and return it
 * @return an InputStream of the file contents or null
 * @throws IllegalArgumentException if there is no file with the given file name
 *///w  w w .  j a  v  a  2s .c o  m
public static InputStream loadFile(URL fileUrl, boolean openStream) {
    if (fileUrl == null) {
        return null;
    }

    String fileName = fileUrl.toString();
    InputStream is = null;

    if (openStream) {
        try {
            is = fileUrl.openStream();

            if (is == null) {
                throw new IllegalArgumentException("No file '" + fileName + "' found as a resource");
            }
        } catch (IOException e) {
            throw new IllegalArgumentException("No file '" + fileName + "' found as a resource");
        }
    }

    if (isReloadingConfigs()) {
        Revision revision;

        if (LOG.isDebugEnabled()) {
            LOG.debug("Creating revision for URL: " + fileName);
        }
        if (URLUtil.isJBoss5Url(fileUrl)) {
            revision = JBossFileRevision.build(fileUrl);
        } else if (URLUtil.isJarURL(fileUrl)) {
            revision = JarEntryRevision.build(fileUrl);
        } else {
            revision = FileRevision.build(fileUrl);
        }
        if (revision == null) {
            files.put(fileName, Revision.build(fileUrl));
        } else {
            files.put(fileName, revision);
        }
    }
    return is;
}

From source file:jenkins.security.ClassFilterImpl.java

/**
 * Tries to determine what JAR file a given class was loaded from.
 * The location is an opaque string suitable only for comparison to others.
 * Similar to {@link Which#jarFile(Class)} but potentially faster, and more tolerant of unknown URL formats.
 * @param c some class/*from   w w w . j  ava2  s .  com*/
 * @return something typically like {@code file://plugins/structs/WEB-INF/lib/structs-1.10.jar};
 *         or null for classes in the Java Platform, some generated classes, etc.
 */
private static @CheckForNull String codeSource(@Nonnull Class<?> c) {
    CodeSource cs = c.getProtectionDomain().getCodeSource();
    if (cs == null) {
        return null;
    }
    URL loc = cs.getLocation();
    if (loc == null) {
        return null;
    }
    String r = loc.toString();
    if (r.endsWith(".class")) {
        // JENKINS-49147: Tomcat bug. Now do the more expensive check
        String suffix = c.getName().replace('.', '/') + ".class";
        if (r.endsWith(suffix)) {
            r = r.substring(0, r.length() - suffix.length());
        }
    }
    if (r.startsWith("jar:file:/") && r.endsWith(".jar!/")) {
        // JENKINS-49543: also an old behavior of Tomcat. Legal enough, but unexpected by isLocationWhitelisted.
        r = r.substring(4, r.length() - 2);
    }
    return r;
}

From source file:com.nokia.carbide.installpackages.InstallPackages.java

private static PackagesType loadPackages(URL url) throws Exception {
    if (url == null)
        return null;

    URI xmlURI = URI.createURI(url.toString());

    InstallPackagesResourceFactoryImpl factory = new InstallPackagesResourceFactoryImpl();
    Resource r = factory.createResource(xmlURI);

    r.load(null);/*from  w w  w .j  a  v  a2  s  .  c o  m*/
    EList<EObject> contents = r.getContents();

    DocumentRoot root = (DocumentRoot) contents.get(0);
    PackagesType packages = root.getPackages();

    return packages;
}

From source file:com.sun.identity.openid.provider.Codec.java

/**
 * TODO: Description./*ww w .  jav a 2  s  .  c  om*/
 * 
 * @param value
 *            TODO.
 * @return TODO.
 */
public static String encodeURL(URL value) {
    if (value == null) {
        return null;
    }

    return value.toString();
}

From source file:com.opentable.requestid.LocalHttpService.java

private static Connector getSSLHttpConnector(Server server) {
    final URL keystoreUrl = Resources.getResource(LocalHttpService.class, "/ssl-server-keystore.jks");

    final SslContextFactory contextFactory = new SslContextFactory();

    contextFactory.setKeyStorePath(keystoreUrl.toString());
    contextFactory.setKeyStorePassword("changeit");

    final HttpConfiguration config = new HttpConfiguration();
    config.addCustomizer(new SecureRequestCustomizer());

    final ServerConnector scc = new ServerConnector(server,
            new SslConnectionFactory(contextFactory, "http/1.1"), new HttpConnectionFactory(config));
    scc.setPort(0);//from   www  . j a  v  a  2 s. com
    scc.setHost("localhost");

    return scc;
}