Example usage for java.net URI toString

List of usage examples for java.net URI toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns the content of this URI as a string.

Usage

From source file:org.syphr.mythtv.ws.impl.ServiceUtils.java

public static String getVersion(URI serviceBaseUri) throws IOException {
    URI uri = URI.create(serviceBaseUri.toString() + "/" + VERSION_URI_PATH);

    HttpClient httpclient = new DefaultHttpClient();
    try {// w w w  .j  a  v  a2 s .  com
        HttpGet httpget = new HttpGet(uri);
        LOGGER.debug("Retrieving service version from {}", httpget.getURI());

        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        String responseBody = httpclient.execute(httpget, responseHandler);
        LOGGER.trace("Version response: {}", responseBody);

        Matcher matcher = VERSION_PATTERN.matcher(responseBody);
        if (matcher.matches()) {
            return matcher.group(1);
        }

        throw new IOException("Failed to retrieve version information");
    } finally {
        httpclient.getConnectionManager().shutdown();
    }
}

From source file:com.zimbra.common.httpclient.HttpProxyConfig.java

private static String safePrint(URI uri) {
    String urlStr = null;/*from   w w w.  ja v  a 2  s  .  co  m*/
    if (uri.getRawQuery() != null) {
        urlStr = uri.toString().replace("?" + uri.getRawQuery(), "");
    } else {
        urlStr = uri.toString();
    }
    return HttpUtil.sanitizeURL(urlStr);
}

From source file:org.n52.web.common.RequestUtils.java

/**
 * Get the request {@link URL} without the query parameter
 *
 * @return Request {@link URL} without query parameter
 * @throws IOException//from w  w  w  .j a v a 2s  . c o m
 * @throws URISyntaxException
 */
public static String resolveQueryLessRequestUrl() throws IOException, URISyntaxException {
    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes())
            .getRequest();

    URL url = new URL(request.getRequestURL().toString());

    String scheme = url.getProtocol();
    String userInfo = url.getUserInfo();
    String host = url.getHost();

    int port = url.getPort();

    String path = request.getRequestURI();
    if (path != null && path.endsWith("/")) {
        path = path.substring(0, path.length() - 1);
    }

    URI uri = new URI(scheme, userInfo, host, port, path, null, null);
    return uri.toString();
}

From source file:org.n52.web.common.RequestUtils.java

/**
 * Get the full request {@link URL} including the query parameter
 *
 * @return Request {@link URL} with query parameter
 * @throws IOException//w ww .j  a v a  2  s .com
 * @throws URISyntaxException
 */
public static String resolveFullRequestUrl() throws IOException, URISyntaxException {
    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes())
            .getRequest();

    URL url = new URL(request.getRequestURL().toString());

    String scheme = url.getProtocol();
    String userInfo = url.getUserInfo();
    String host = url.getHost();

    int port = url.getPort();

    String path = request.getRequestURI();
    if (path != null && path.endsWith("/")) {
        path = path.substring(0, path.length() - 1);
    }
    String query = request.getQueryString();

    URI uri = new URI(scheme, userInfo, host, port, path, query, null);
    return uri.toString();
}

From source file:com.jaeksoft.searchlib.util.LinkUtils.java

public final static URL getLink(URL currentURL, String href, UrlFilterItem[] urlFilterList,
        boolean removeFragment) {

    if (href == null)
        return null;
    href = href.trim();/*w  w w .  ja  va2  s . com*/
    if (href.length() == 0)
        return null;

    String fragment = null;
    try {
        URI u = URIUtils.resolve(currentURL.toURI(), href);
        href = u.toString();
        href = UrlFilterList.doReplace(u.getHost(), href, urlFilterList);
        URI uri = URI.create(href);
        uri = uri.normalize();

        String p = uri.getPath();
        if (p != null)
            if (p.contains("/./") || p.contains("/../"))
                return null;

        if (!removeFragment)
            fragment = uri.getRawFragment();

        return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(),
                uri.getQuery(), fragment).normalize().toURL();
    } catch (MalformedURLException e) {
        Logging.info(e.getMessage());
        return null;
    } catch (URISyntaxException e) {
        Logging.info(e.getMessage());
        return null;
    } catch (IllegalArgumentException e) {
        Logging.info(e.getMessage());
        return null;
    }
}

From source file:piecework.util.ContentUtility.java

public static ContentResource toContent(CloseableHttpClient client, URI uri) {
    if (client == null)
        return null;

    String url = uri.toString();

    return new RemoteResource(client, uri);
}

From source file:com.github.khandroid.http.misc.FileDownloader.java

public static byte[] download(HttpClient httpClient, URI source) throws ClientProtocolException, IOException {
    byte[] ret;//from  w  w w .  ja  v  a2 s  . c  om

    KhandroidLog.v("Downloading " + source.toString());
    HttpGet req = new HttpGet(source);
    HttpResponse response = httpClient.execute(req);
    StatusLine statusLine = response.getStatusLine();
    int statusCode = statusLine.getStatusCode();
    KhandroidLog.v("Status code:" + statusCode);
    if (statusCode == 200) {
        HttpEntity entity = response.getEntity();

        ByteArrayOutputStream output = new ByteArrayOutputStream();

        entity.writeTo(output);
        output.close();

        ret = output.toByteArray();
    } else {
        throw new IOException(
                "Download failed, HTTP response code " + statusCode + " - " + statusLine.getReasonPhrase());
    }
    req.releaseConnection();

    return ret;
}

From source file:com.kolich.aws.services.AbstractAwsService.java

/**
 * Checks if the given URI is non-null, and if it's a complete endpoint
 * URI that already starts with "https://".
 * @param uri//from   ww  w .ja  va 2 s . c  o m
 * @return
 */
private static final boolean isComplete(final URI uri) {
    return uri != null && uri.toString().startsWith(HTTPS);
}

From source file:de.lohndirekt.print.IppHttpConnection.java

private static URI toHttpURI(URI uri) {
    if (uri.getScheme().equals("ipp")) {
        String uriString = uri.toString().replaceFirst("ipp", "http");
        // TODO remove this hack!
        //            uriString = uriString.replaceAll("(\\d{1,3}\\.){3}\\d{1,3}:\\d{1,}", "127.0.0.1:631");
        // endof hack
        try {/*from w ww.  j  av  a2  s .c  om*/
            uri = new URI(uriString);
        } catch (URISyntaxException e) {
            throw new RuntimeException("toHttpURI buggy? : uri was " + uri);
        }
    }
    return uri;
}

From source file:gobblin.source.extractor.extract.kafka.ConfigStoreUtils.java

/**
 * Will return the list of URIs given which are importing tag {@param tagUri}
 *//* ww  w .j  a  va 2 s. c o m*/
public static Collection<URI> getTopicsURIFromConfigStore(ConfigClient configClient, Path tagUri,
        String filterString, Optional<Config> runtimeConfig) {
    try {
        Collection<URI> importedBy = configClient.getImportedBy(new URI(tagUri.toString()), true,
                runtimeConfig);
        return importedBy.stream().filter((URI u) -> u.toString().contains(filterString))
                .collect(Collectors.toList());
    } catch (URISyntaxException | ConfigStoreFactoryDoesNotExistsException | ConfigStoreCreationException e) {
        throw new Error(e);
    }
}