1

i have a java application in which i want to programmatically add URL parameters to a given base url, instead of string manipulation to form a url. i have heard that URIBuilder is the way to go, though I have not been able to get that class or the maven repository to that class anywhere? is that the way to go or is there any other method to get that done?

EDIT: i have heard of using apache http client utils URIBuilder and not the javax.ws URIBuilder class

1

2 Answers 2

1

Drop this dependency in your pom to get UriBuilder:

 <dependency>
    <groupId>javax.ws.rs</groupId>
    <artifactId>jsr311-api</artifactId>
    <version>1.1.1</version><!-- Select the version you want here -->
 </dependency>

More info: http://mvnrepository.com/artifact/javax.ws.rs/jsr311-api

The Apache version is part of the httpcomponents:

<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.3.1</version>
</dependency>

More info: http://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient/

Sign up to request clarification or add additional context in comments.

7 Comments

not the class i have heard of using. have heard that URIBuilder class of apache http client utils is the way to go
@user2739737 I have added the URIBuilder from apache.
i tried that repo. i was still unable to get the URIBuilder class.
@user2739737 What is a repo for you? org.apache.http.client.utils.URIBuilder is located in this dependency.
i could not find the class URIBuilder within org.apache.http.client.utils
|
0

You can use java.net.URL to create a URL. The set() method allows you to set query parameters.

2 Comments

i could not find the set() method anywhere, though it has an addParameter() method. i'll try that. just one question: how to set the host/base url of the Url?
set() method in java.net.URL is not public. you cannot use in your package.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.