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:dk.kk.ibikecphlib.search.HTTPAutocompleteHandler.java

@SuppressLint("NewApi")

public static JsonNode performGET(String urlString) {
    JsonNode ret = null;/*  ww  w .  j  a  v  a2 s  .c  om*/

    HttpParams myParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(myParams, 20000);
    HttpConnectionParams.setSoTimeout(myParams, 20000);
    HttpClient httpclient = new DefaultHttpClient(myParams);
    HttpGet httpget = null;

    URL url = null;

    try {

        url = new URL(urlString);
        httpget = new HttpGet(url.toString());
        LOG.d("Request " + url.toString());
        httpget.setHeader("Content-type", "application/json");
        HttpResponse response = httpclient.execute(httpget);
        String serverResponse = EntityUtils.toString(response.getEntity());
        LOG.d("Response " + serverResponse);
        ret = Util.stringToJsonNode(serverResponse);

    } catch (Exception e) {
        if (e != null && e.getLocalizedMessage() != null)
            LOG.e(e.getLocalizedMessage());
    }
    return ret;
}

From source file:de.unisb.cs.st.javalanche.rhino.RhinoTestRunnable.java

public static String getCommand(String[] args) {
    StringBuilder sb = new StringBuilder();
    sb.append("java -cp ");
    String main = "org/mozilla/javascript/tools/shell/Main.class";
    URL resource = ClassLoader.getSystemResource(main);
    if (resource != null) {
        String location = resource.toString().substring(0, resource.toString().length() - main.length());
        logger.info(location);//from  w ww.  j a v a2s. c  o  m
        File f;
        try {
            f = new File(new URI(location));
            sb.append(f.toString());
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
    }
    // sb
    // .append(":/scratch/schuler/subjects/ibugs_rhino-0.1/jars/xmlbeans-2.2.0/lib/jsr173_1.0_api.jar:/scratch/schuler/subjects/ibugs_rhino-0.1/jars/xmlbeans-2.2.0/lib/xbean.jar");
    sb.append(":" + System.getProperty("java.class.path"));
    sb.append(" org.mozilla.javascript.tools.shell.Main ");
    for (String arg : args) {
        sb.append(arg + " ");
    }
    String message = sb.toString();
    return message;
}

From source file:com.arjuna.qa.junit.HttpUtils.java

public static HttpMethodBase createMethod(URL url, int type) {
    HttpMethodBase request = null;/*from www  .jav  a  2s.  c o m*/
    switch (type) {
    case GET:
        request = new GetMethod(url.toString());
        break;
    case POST:
        request = new PostMethod(url.toString());
        break;
    case HEAD:
        request = new HeadMethod(url.toString());
        break;
    case OPTIONS:
        request = new OptionsMethod(url.toString());
        break;
    case PUT:
        request = new PutMethod(url.toString());
        break;
    case DELETE:
        request = new DeleteMethod(url.toString());
        break;
    case TRACE:
        request = new TraceMethod(url.toString());
        break;
    }
    return request;
}

From source file:Main.java

/** Creates a schema-aware XML parser */
private static DocumentBuilder createSchemaAwareParser(URL schemaURL) {
    DocumentBuilderFactory dbf = createNamespaceAwareDocumentBuilderFactory();
    dbf.setValidating(true);/* www  .  j ava  2 s .  co m*/
    dbf.setAttribute(ATTRIBUTE_SCHEMA_LANGUAGE, SCHEMA_URL);
    dbf.setAttribute(ATTRIBUTE_SCHEMA_SOURCE, schemaURL.toString());

    try {
        return dbf.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        throw new IllegalStateException("No document builder found, probably Java is misconfigured!", e);
    }
}

From source file:com.qualogy.qafe.web.ContextLoader.java

public static String getContextPath(ServletContext servletContext)
        throws MalformedURLException, URISyntaxException {
    // The default way: works on JBoss/Tomcat/Jetty
    String contextPath = servletContext.getRealPath("/WEB-INF/");

    // This is how a weblogic explicitly wants the fetching of resources.
    if (contextPath == null) {
        URL url = servletContext.getResource("/WEB-INF/");
        logger.log(Level.INFO, "Fallback scenario " + url.toString());
        if (url != null) {
            logger.log(Level.INFO, "URL to config file " + url.toString());
            contextPath = url.toURI().toString();
        } else {/*from w  w  w  .j  av  a  2s. c  o m*/
            throw new RuntimeException(
                    "Strange Error: /WEB-INF/ cannot be found. Check the appserver or installation directory.");
        }
    }
    return contextPath;
}

From source file:com.sunchenbin.store.feilong.core.net.URLUtil.java

/**
 * To string array./*w w w  . ja  v  a 2  s.  c o m*/
 *
 * @param urls
 *            the urls
 * @return the string[]
 * @since 1.2.1
 */
public static String[] toStringArray(URL[] urls) {
    if (Validator.isNullOrEmpty(urls)) {
        throw new NullPointerException("urls can't be null/empty!");
    }

    String[] stringArray = new String[urls.length];

    int i = 0;
    for (URL url : urls) {
        stringArray[i] = url.toString();
        i++;
    }
    return stringArray;
}

From source file:com.omertron.traileraddictapi.tools.TrailerAddictParser.java

public static List<Trailer> getTrailers(URL url) {
    Document doc;/*from www .j a  va  2 s . c  o  m*/
    List<Trailer> trailers = new ArrayList<Trailer>();

    try {
        LOG.trace("Attempting to get trailer XML from {}", url.toString());
        doc = DOMHelper.getEventDocFromUrl(url.toString());
    } catch (TrailerAddictException ex) {
        LOG.trace("Exception processing document: {}", url.toString(), ex);
        return trailers;
    }

    NodeList nlTrailers = doc.getElementsByTagName("trailer");
    Node nTrailer;
    Element eTrailer;
    Trailer trailer;

    for (int loop = 0; loop < nlTrailers.getLength(); loop++) {
        nTrailer = nlTrailers.item(loop);
        if (nTrailer.getNodeType() == Node.ELEMENT_NODE) {
            eTrailer = (Element) nTrailer;
            trailer = new Trailer();
            trailer.setCombinedTitle(DOMHelper.getValueFromElement(eTrailer, "title"));
            trailer.setLink(DOMHelper.getValueFromElement(eTrailer, "link"));

            String trailerId = DOMHelper.getValueFromElement(eTrailer, "trailer_id");
            if (StringUtils.isNumeric(trailerId)) {
                trailer.setTrailerId(Integer.parseInt(trailerId));
            }

            trailer.setPublishDate(DOMHelper.getValueFromElement(eTrailer, "pubDate"));
            trailer.addEmbed(DOMHelper.getValueFromElement(eTrailer, "embed"));

            // Simple API stuff here
            trailer.setTrailerTitle(DOMHelper.getValueFromElement(eTrailer, "video_title"));
            trailer.setDescription(DOMHelper.getValueFromElement(eTrailer, "description"));
            trailer.setFilmTitle(DOMHelper.getValueFromElement(eTrailer, "film"));
            trailer.addEmbed(TrailerSize.STANDARD, DOMHelper.getValueFromElement(eTrailer, "embed_standard"));
            trailer.addEmbed(TrailerSize.SMALL, DOMHelper.getValueFromElement(eTrailer, "embed_small"));
            trailer.addEmbed(TrailerSize.MEDIUM, DOMHelper.getValueFromElement(eTrailer, "embed_medium"));
            trailer.addEmbed(TrailerSize.LARGE, DOMHelper.getValueFromElement(eTrailer, "embed_large"));
            trailer.setDirectors(DOMHelper.getValueFromElement(eTrailer, "director"));
            trailer.setWriters(DOMHelper.getValueFromElement(eTrailer, "writer"));
            trailer.setCast(DOMHelper.getValueFromElement(eTrailer, "cast"));
            trailer.setStudio(DOMHelper.getValueFromElement(eTrailer, "studio"));
            trailer.setReleaseDate(DOMHelper.getValueFromElement(eTrailer, "release_date"));

            // Add the trailer to the list
            trailers.add(trailer);
        }
    }

    LOG.trace("Found {} trailers for {}", trailers.size(), url.toString());
    return trailers;

}

From source file:edu.uci.ics.hyracks.control.common.deployment.DeploymentUtils.java

/**
 * Download remote Http URLs and return the stored local file URLs
 * // ww w . j a  v a  2 s . c  o  m
 * @param urls
 *            the remote Http URLs
 * @param deploymentDir
 *            the deployment jar storage directory
 * @param isNC
 *            true is NC/false is CC
 * @return a list of local file URLs
 * @throws HyracksException
 */
private static List<URL> downloadURLs(List<URL> urls, String deploymentDir, boolean isNC)
        throws HyracksException {
    //retry 10 times at maximum for downloading binaries
    int retryCount = 10;
    int tried = 0;
    Exception trace = null;
    while (tried < retryCount) {
        try {
            tried++;
            List<URL> downloadedFileURLs = new ArrayList<URL>();
            File dir = new File(deploymentDir);
            if (!dir.exists()) {
                FileUtils.forceMkdir(dir);
            }
            for (URL url : urls) {
                String urlString = url.toString();
                int slashIndex = urlString.lastIndexOf('/');
                String fileName = urlString.substring(slashIndex + 1).split("&")[1];
                String filePath = deploymentDir + File.separator + fileName;
                File targetFile = new File(filePath);
                if (isNC) {
                    HttpClient hc = HttpClientBuilder.create().build();
                    HttpGet get = new HttpGet(url.toString());
                    HttpResponse response = hc.execute(get);
                    InputStream is = response.getEntity().getContent();
                    OutputStream os = new FileOutputStream(targetFile);
                    try {
                        IOUtils.copyLarge(is, os);
                    } finally {
                        os.close();
                        is.close();
                    }
                }
                downloadedFileURLs.add(targetFile.toURI().toURL());
            }
            return downloadedFileURLs;
        } catch (Exception e) {
            e.printStackTrace();
            trace = e;
        }
    }
    throw new HyracksException(trace);
}

From source file:net.refractions.udig.document.source.ShpDocUtils.java

/**
 * Gets the absolute path with the url as the parent path and the relative path as the child
 * path.//w w w.j ava 2 s . c o m
 * 
 * @param url
 * @param relativePath
 * @return absolute path
 */
public static String getAbsolutePath(URL url, String relativePath) {
    if (relativePath != null && relativePath.trim().length() > 0) {
        try {
            final File parentFile = new File(new URI(url.toString()));
            final File childFile = new File(parentFile.getParent(), relativePath);
            return childFile.getAbsolutePath();
        } catch (URISyntaxException e) {
            // Should not happen as shapefile should be a valid file
            e.printStackTrace();
        }
    }
    return null;
}

From source file:com.asakusafw.testdriver.DirectIoUtil.java

private static <T> DataModelSourceFactory load0(DataModelDefinition<T> definition,
        BinaryStreamFormat<? super T> format, URL source) throws IOException, InterruptedException {
    String path = source.toString();
    try (InputStream stream = source.openStream();
            ModelInput<? super T> input = format.createInput(definition.getModelClass(), path, stream)) {
        return collect(definition, input);
    }//from   ww w . j  a  v  a 2  s  .  c  o m
}