Example usage for org.apache.http.client.utils URIBuilder removeQuery

List of usage examples for org.apache.http.client.utils URIBuilder removeQuery

Introduction

In this page you can find the example usage for org.apache.http.client.utils URIBuilder removeQuery.

Prototype

public URIBuilder removeQuery() 

Source Link

Document

Removes URI query.

Usage

From source file:com.github.tomakehurst.wiremock.common.UniqueFilenameGenerator.java

public static String generateIdFromUrl(final String prefix, final String id, final String url) {
    URIBuilder urlbuild = null;
    try {/* w  w  w .  j a  v a2  s. c o m*/
        urlbuild = new URIBuilder(url);
        urlbuild = urlbuild.removeQuery();
        return getRandomId(prefix, id, new URI(urlbuild.toString()));
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.cloud.utils.UriUtils.java

public static String getUpdateUri(String url, boolean encrypt) {
    String updatedPath = null;//from   w  w  w . j a  v a2 s .co m
    try {
        String query = URIUtil.getQuery(url);
        URIBuilder builder = new URIBuilder(url);
        builder.removeQuery();

        StringBuilder updatedQuery = new StringBuilder();
        List<NameValuePair> queryParams = getUserDetails(query);
        ListIterator<NameValuePair> iterator = queryParams.listIterator();
        while (iterator.hasNext()) {
            NameValuePair param = iterator.next();
            String value = null;
            if ("password".equalsIgnoreCase(param.getName()) && param.getValue() != null) {
                value = encrypt ? DBEncryptionUtil.encrypt(param.getValue())
                        : DBEncryptionUtil.decrypt(param.getValue());
            } else {
                value = param.getValue();
            }

            if (updatedQuery.length() == 0) {
                updatedQuery.append(param.getName()).append('=').append(value);
            } else {
                updatedQuery.append('&').append(param.getName()).append('=').append(value);
            }
        }

        String schemeAndHost = "";
        URI newUri = builder.build();
        if (newUri.getScheme() != null) {
            schemeAndHost = newUri.getScheme() + "://" + newUri.getHost();
        }

        updatedPath = schemeAndHost + newUri.getPath() + "?" + updatedQuery;
    } catch (URISyntaxException e) {
        throw new CloudRuntimeException("Couldn't generate an updated uri. " + e.getMessage());
    }

    return updatedPath;
}

From source file:com.askfast.askfastapi.util.HttpUtil.java

/**
 * Returns the url without query parameters
 * //ww w.java  2  s . c o m
 * @param url
 *            Url containing query parameters
 * @return url Url without query parameters
 * @throws IOException
 *             Errors in connecting to the given URL
 */
static public String removeQueryParams(String url) throws IOException {

    try {
        url = url.replace(" ", "%20");
        URIBuilder uriBuilder = new URIBuilder(new URI(url));
        return uriBuilder.removeQuery().toString();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.jasig.portlet.proxy.service.proxy.document.URLRewritingFilter.java

protected String getBaseServerUrl(final String fullUrl) throws URISyntaxException {
    final URIBuilder uriBuilder = new URIBuilder(fullUrl);
    uriBuilder.removeQuery();//from w ww.  j  a  v  a 2 s .  co m
    uriBuilder.setPath("");
    return uriBuilder.build().toString();
}

From source file:org.jasig.portlet.proxy.service.proxy.document.URLRewritingFilter.java

protected String getRelativePathUrl(final String fullUrl) throws URISyntaxException {
    final URIBuilder uriBuilder = new URIBuilder(fullUrl);
    uriBuilder.removeQuery();//from w  w w  . j  a v a2  s  . c  o m
    final String path = uriBuilder.getPath();
    int lastSlash = path.lastIndexOf('/');
    if (lastSlash < 0) {
        uriBuilder.setPath("");
    } else {
        uriBuilder.setPath(path.substring(0, lastSlash + 1));
    }
    return uriBuilder.build().toString();
}

From source file:org.apache.ambari.server.controller.metrics.timeline.AMSReportPropertyProvider.java

private void setProperties(Resource resource, String clusterName, Request request, Set<String> ids)
        throws SystemException {

    Map<String, MetricReportRequest> reportRequestMap = getPropertyIdMaps(request, ids);
    String host = hostProvider.getCollectorHostName(clusterName, TIMELINE_METRICS);
    String port = hostProvider.getCollectorPort(clusterName, TIMELINE_METRICS);
    URIBuilder uriBuilder = AMSPropertyProvider.getAMSUriBuilder(host,
            port != null ? Integer.parseInt(port) : 6188, configuration.isHttpsEnabled());

    for (Map.Entry<String, MetricReportRequest> entry : reportRequestMap.entrySet()) {
        MetricReportRequest reportRequest = entry.getValue();
        TemporalInfo temporalInfo = reportRequest.getTemporalInfo();
        Map<String, String> propertyIdMap = reportRequest.getPropertyIdMap();

        uriBuilder.removeQuery();
        // Call with hostname = null
        uriBuilder.addParameter("metricNames",
                MetricsPropertyProvider.getSetString(propertyIdMap.keySet(), -1));

        uriBuilder.setParameter("appId", "HOST");
        long startTime = temporalInfo.getStartTime();
        if (startTime != -1) {
            uriBuilder.setParameter("startTime", String.valueOf(startTime));
        }//from w w  w .jav  a2  s  . c  o  m

        long endTime = temporalInfo.getEndTime();
        if (endTime != -1) {
            uriBuilder.setParameter("endTime", String.valueOf(endTime));
        }

        TimelineAppMetricCacheKey metricCacheKey = new TimelineAppMetricCacheKey(propertyIdMap.keySet(), "HOST",
                temporalInfo);

        metricCacheKey.setSpec(uriBuilder.toString());

        // Self populating cache updates itself on every get with latest results
        TimelineMetrics timelineMetrics;
        if (metricCache != null && metricCacheKey.getTemporalInfo() != null) {
            timelineMetrics = metricCache.getAppTimelineMetricsFromCache(metricCacheKey);
        } else {
            try {
                timelineMetrics = requestHelper.fetchTimelineMetrics(uriBuilder,
                        temporalInfo.getStartTimeMillis(), temporalInfo.getEndTimeMillis());
            } catch (IOException e) {
                timelineMetrics = null;
            }
        }

        if (timelineMetrics != null) {
            for (TimelineMetric metric : timelineMetrics.getMetrics()) {
                if (metric.getMetricName() != null && metric.getMetricValues() != null) {
                    // Pad zeros or nulls if needed to a clone so we do not cache
                    // padded values
                    TimelineMetric timelineMetricClone = new TimelineMetric(metric);
                    metricsPaddingMethod.applyPaddingStrategy(timelineMetricClone, temporalInfo);

                    String propertyId = propertyIdMap.get(metric.getMetricName());
                    if (propertyId != null) {
                        resource.setProperty(propertyId, getValue(timelineMetricClone, temporalInfo));
                    }
                }
            }
        }
    }
}

From source file:org.openrepose.nodeservice.httpcomponent.HttpComponentRequestProcessor.java

private void setQueryString(URIBuilder builder) throws URISyntaxException {
    String queryString = sourceRequest.getQueryString();
    if (StringUtils.isNotBlank(queryString)) {
        builder.setQuery(queryString);//from w  w  w  .  j  a va 2s .  c om
        if (builder.getQueryParams().isEmpty()) {
            builder.removeQuery();
        }
    }
}