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

The following examples show how to use org.apache.http.client.utils.URIBuilder#addParameters() . 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: ConnectorCommon.java    From nextcloud-java-api with GNU General Public License v3.0 6 votes vote down vote up
private URI buildUrl(String subPath, List<NameValuePair> queryParams)
{
	if(serverConfig.getSubpathPrefix()!=null) {
		subPath = serverConfig.getSubpathPrefix()+"/"+subPath;
	}
	
    URIBuilder uB= new URIBuilder()
    .setScheme(serverConfig.isUseHTTPS() ? "https" : "http")
    .setHost(serverConfig.getServerName())
    .setPort(serverConfig.getPort())
    .setUserInfo(serverConfig.getUserName(), serverConfig.getPassword())
    .setPath(subPath);
    if (queryParams != null)
    {
        uB.addParameters(queryParams);
    }
    try {
        return uB.build();
    } catch (URISyntaxException e) {
        throw new NextcloudApiException(e);
    }
}
 
Example 2
Source File: SmartUriAdapter.java    From rya with Apache License 2.0 6 votes vote down vote up
private static IRI createTypePropertiesUri(final ImmutableMap<RyaIRI, ImmutableMap<RyaIRI, Property>> typeProperties) throws SmartUriException {
    final List<NameValuePair> nameValuePairs = new ArrayList<>();
    for (final Entry<RyaIRI, ImmutableMap<RyaIRI, Property>> typeProperty : typeProperties.entrySet()) {
        final RyaIRI type = typeProperty.getKey();
        final Map<RyaIRI, Property> propertyMap = typeProperty.getValue();
        final IRI typeUri = createIndividualTypeWithPropertiesUri(type, propertyMap);
        final String keyString = type.getDataType().getLocalName();
        final String valueString = typeUri.getLocalName();
        nameValuePairs.add(new BasicNameValuePair(keyString, valueString));
    }

    final URIBuilder uriBuilder = new URIBuilder();
    uriBuilder.addParameters(nameValuePairs);

    String uriString;
    try {
        final java.net.URI uri = uriBuilder.build();
        final String queryString = uri.getRawSchemeSpecificPart();
        uriString = "urn:test" + queryString;
    } catch (final URISyntaxException e) {
        throw new SmartUriException("Unable to create type properties for the Smart URI", e);
    }

    return VF.createIRI(uriString);
}
 
Example 3
Source File: SmartUriAdapter.java    From rya with Apache License 2.0 6 votes vote down vote up
private static IRI createTypeMapUri(final List<RyaIRI> types) throws SmartUriException {
    final List<NameValuePair> nameValuePairs = new ArrayList<>();
    for (final RyaIRI type : types) {
        final String shortName = getShortNameForType(type);
        nameValuePairs.add(new BasicNameValuePair(type.getData(), shortName));
    }

    final URIBuilder uriBuilder = new URIBuilder();
    uriBuilder.addParameters(nameValuePairs);

    String uriString;
    try {
        final java.net.URI uri = uriBuilder.build();
        final String queryString = uri.getRawSchemeSpecificPart();
        uriString = ENTITY_TYPE_MAP_URN + queryString;
    } catch (final URISyntaxException e) {
        throw new SmartUriException("Unable to create type properties for the Smart URI", e);
    }

    return VF.createIRI(uriString);
}
 
Example 4
Source File: BackDoor.java    From teammates with GNU General Public License v2.0 6 votes vote down vote up
private static URI createBasicUri(String url, Map<String, String[]> params) {
    List<NameValuePair> postParameters = new ArrayList<>();
    if (params != null) {
        params.forEach((key, values) -> Arrays.stream(values).forEach(value -> {
            postParameters.add(new BasicNameValuePair(key, value));
        }));
    }

    try {
        URIBuilder uriBuilder = new URIBuilder(url);
        uriBuilder.addParameters(postParameters);

        return uriBuilder.build();
    } catch (URISyntaxException e) {
        return null;
    }
}
 
Example 5
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 6
Source File: HttpDataService.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected URI getRequestURI(Map<String, Object> parameters)
{
	String url = getURL(parameters);
	if (url == null)
	{
		throw 
			new JRRuntimeException(
				EXCEPTION_MESSAGE_KEY_NO_HTTP_URL_SET,
				(Object[])null);
	}
	
	try
	{
		URIBuilder uriBuilder = new URIBuilder(url);
		List<NameValuePair> urlParameters = collectUrlParameters(parameters);
		if (!urlParameters.isEmpty())
		{
			uriBuilder.addParameters(urlParameters);
		}
		
		URI uri = uriBuilder.build();
		if (log.isDebugEnabled())
		{
			log.debug("request URI " + uri);
		}
		return uri;
	}
	catch (URISyntaxException e)
	{
		throw new JRRuntimeException(e);
	}
}
 
Example 7
Source File: SmartUriAdapter.java    From rya with Apache License 2.0 5 votes vote down vote up
private static IRI createIndividualTypeWithPropertiesUri(final RyaIRI type, final Map<RyaIRI, Property> map) throws SmartUriException {
    final List<NameValuePair> nameValuePairs = new ArrayList<>();
    for (final Entry<RyaIRI, Property> entry : map.entrySet()) {
        final RyaIRI key = entry.getKey();
        final Property property = entry.getValue();

        final RyaType ryaType = property.getValue();
        final String keyString = (VF.createIRI(key.getData())).getLocalName();
        final Value value = RyaToRdfConversions.convertValue(ryaType);
        final String valueString = value.stringValue();
        nameValuePairs.add(new BasicNameValuePair(keyString, valueString));
    }

    final URIBuilder uriBuilder = new URIBuilder();
    uriBuilder.addParameters(nameValuePairs);

    String uriString;
    try {
        final java.net.URI uri = uriBuilder.build();
        final String queryString = uri.getRawSchemeSpecificPart();
        uriString = type.getData()/*VF.createIRI(type.getData()).getLocalName()*/ + queryString;
    } catch (final URISyntaxException e) {
        throw new SmartUriException("Unable to create type URI with all its properties for the Smart URI", e);
    }

    return VF.createIRI(uriString);
}