Java Code Examples for org.apache.http.client.utils.URIBuilder#getQueryParams()

The following examples show how to use org.apache.http.client.utils.URIBuilder#getQueryParams() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SharethroughUriBuilderUtil.java    From prebid-server-java with Apache License 2.0 6 votes vote down vote up
/**
 * Creates uri with parameters for sharethrough request
 */
static StrUriParameters buildSharethroughUrlParameters(String uri) {
    try {
        final URIBuilder uriBuilder = new URIBuilder(uri);
        final List<NameValuePair> queryParams = uriBuilder.getQueryParams();

        return StrUriParameters.builder()
                .height(getHeight(queryParams))
                .width(getWidth(queryParams))
                .iframe(Boolean.parseBoolean(getValueByKey(queryParams, "stayInIframe")))
                .consentRequired(Boolean.parseBoolean(getValueByKey(queryParams, "consent_required")))
                .pkey(getValueByKey(queryParams, "placement_key"))
                .bidID(getValueByKey(queryParams, "bidId"))
                .consentString(getValueByKey(queryParams, "consent_string"))
                .build();

    } catch (URISyntaxException e) {
        throw new IllegalArgumentException("Cant resolve uri: " + uri, e);
    }
}
 
Example 2
Source File: HFCAClient.java    From fabric-sdk-java with Apache License 2.0 6 votes vote down vote up
String addCAToURL(String url) throws URISyntaxException, MalformedURLException {
    URIBuilder uri = new URIBuilder(url);
    if (caName != null) {
        boolean found = false;

        for (NameValuePair nameValuePair : uri.getQueryParams()) {
            if ("ca".equals(nameValuePair.getName())) {
                found = true;
                break;
            }
        }
        if (!found) {
            uri.addParameter("ca", caName);
        }
    }
    return uri.build().toURL().toString();
}
 
Example 3
Source File: HttpSender.java    From iaf with Apache License 2.0 6 votes vote down vote up
private URI encodeQueryParameters(URI url) throws UnsupportedEncodingException, URISyntaxException {
	URIBuilder uri = new URIBuilder(url);
	ArrayList<NameValuePair> pairs = new ArrayList<>(uri.getQueryParams().size());
	for(NameValuePair pair : uri.getQueryParams()) {
		String paramValue = pair.getValue(); //May be NULL
		if(StringUtils.isNotEmpty(paramValue)) {
			paramValue = URLEncoder.encode(paramValue, getCharSet()); //Only encode if the value is not null
		}
		pairs.add(new BasicNameValuePair(pair.getName(), paramValue));
	}
	if(pairs.size() > 0) {
		uri.clearParameters();
		uri.addParameters(pairs);
	}
	return uri.build();
}
 
Example 4
Source File: ApiController.java    From restfiddle with Apache License 2.0 5 votes vote down vote up
@RequestMapping(value = "/api/oauth/form", method = RequestMethod.POST)
   public ModelAndView oauthFormRedirect(@ModelAttribute OAuth2RequestDTO oAuth2RequestDTO) throws URISyntaxException {
List<String> scopes = oAuth2RequestDTO.getScopes();
String authorizationUrl = oAuth2RequestDTO.getAuthorizationUrl();
if (authorizationUrl == null || authorizationUrl.isEmpty()) {
    return null;
}
URIBuilder uriBuilder = new URIBuilder(authorizationUrl);
List<NameValuePair> queryParams = uriBuilder.getQueryParams();
List<String> responseTypes = new ArrayList<String>();
if (queryParams != null && !queryParams.isEmpty()) {
    for (NameValuePair nameValuePair : queryParams) {
	if ("response_type".equals(nameValuePair.getName())) {
	    responseTypes.add(nameValuePair.getValue());
	    break;
	}
    }
}

BrowserClientRequestUrl browserClientRequestUrl = new BrowserClientRequestUrl(authorizationUrl, oAuth2RequestDTO.getClientId());
if (!responseTypes.isEmpty()) {
    browserClientRequestUrl = browserClientRequestUrl.setResponseTypes(responseTypes);
}
String url = browserClientRequestUrl.setState(RESTFIDDLE).setScopes(scopes).setRedirectUri(HTTP_LOCALHOST_8080_OAUTH_RESPONSE).build();

return new ModelAndView("redirect:" + url);
   }
 
Example 5
Source File: HttpRequestBuilder.java    From gocd with Apache License 2.0 5 votes vote down vote up
private static Map<String, List<String>> splitQuery(URIBuilder builder) {
    Map<String, List<String>> params = new LinkedHashMap<>();

    for (NameValuePair nameValuePair : builder.getQueryParams()) {
        if (!params.containsKey(nameValuePair.getName())) {
            params.put(nameValuePair.getName(), new ArrayList<>());
        }
        params.get(nameValuePair.getName()).add(nameValuePair.getValue());
    }

    return params;
}
 
Example 6
Source File: AwsRequestSigner.java    From presto with Apache License 2.0 4 votes vote down vote up
@Override
public void process(final HttpRequest request, final HttpContext context)
        throws IOException
{
    String method = request.getRequestLine().getMethod();

    URI uri = URI.create(request.getRequestLine().getUri());
    URIBuilder uriBuilder = new URIBuilder(uri);

    Map<String, List<String>> parameters = new TreeMap<>(CASE_INSENSITIVE_ORDER);
    for (NameValuePair parameter : uriBuilder.getQueryParams()) {
        parameters.computeIfAbsent(parameter.getName(), key -> new ArrayList<>())
                .add(parameter.getValue());
    }

    Map<String, String> headers = Arrays.stream(request.getAllHeaders())
            .collect(toImmutableMap(Header::getName, Header::getValue));

    InputStream content = null;
    if (request instanceof HttpEntityEnclosingRequest) {
        HttpEntityEnclosingRequest enclosingRequest = (HttpEntityEnclosingRequest) request;
        if (enclosingRequest.getEntity() != null) {
            content = enclosingRequest.getEntity().getContent();
        }
    }

    DefaultRequest<?> awsRequest = new DefaultRequest<>(SERVICE_NAME);

    HttpHost host = (HttpHost) context.getAttribute(HTTP_TARGET_HOST);
    if (host != null) {
        awsRequest.setEndpoint(URI.create(host.toURI()));
    }
    awsRequest.setHttpMethod(HttpMethodName.fromValue(method));
    awsRequest.setResourcePath(uri.getRawPath());
    awsRequest.setContent(content);
    awsRequest.setParameters(parameters);
    awsRequest.setHeaders(headers);

    signer.sign(awsRequest, credentialsProvider.getCredentials());

    Header[] newHeaders = awsRequest.getHeaders().entrySet().stream()
            .map(entry -> new BasicHeader(entry.getKey(), entry.getValue()))
            .toArray(Header[]::new);

    request.setHeaders(newHeaders);

    InputStream newContent = awsRequest.getContent();
    checkState(newContent == null || request instanceof HttpEntityEnclosingRequest);
    if (newContent != null) {
        BasicHttpEntity entity = new BasicHttpEntity();
        entity.setContent(newContent);
        ((HttpEntityEnclosingRequest) request).setEntity(entity);
    }
}