|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.jayway.restassured.internal.http.URIBuilder
public class URIBuilder
This class implements a mutable URI. All set, add
and remove methods affect this class' internal URI
representation. All mutator methods support chaining, e.g.
new URIBuilder("http://www.google.com/")
.setScheme( "https" )
.setPort( 443 )
.setPath( "some/path" )
.toString();
A slightly more 'Groovy' version would be:
new URIBuilder('http://www.google.com/').with {
scheme = 'https'
port = 443
path = 'some/path'
query = [p1:1, p2:'two']
}.toString()
| Field Summary | |
|---|---|
protected URI |
base
|
| Constructor Summary | |
|---|---|
URIBuilder(URI uri,
boolean urlEncodingEnabled,
EncoderConfig config)
|
|
| Method Summary | |
|---|---|
protected URIBuilder |
addQueryParam(org.apache.http.NameValuePair nvp)
|
URIBuilder |
addQueryParam(String param,
Object value)
This will append a query parameter to the existing query string. |
protected URIBuilder |
addQueryParams(List<org.apache.http.NameValuePair> nvp)
|
URIBuilder |
addQueryParams(Map<?,?> params)
Add these parameters to the URIBuilder's existing query string. |
Object |
asType(Class<?> type)
Implementation of Groovy's as operator, to allow type
conversion. |
protected URIBuilder |
clone()
Create a copy of this URIBuilder instance. |
static URI |
convertToURI(Object uri)
Utility method to convert a number of type to a URI instance. |
static String |
encode(String content,
String encoding)
|
boolean |
equals(Object obj)
Determine if this URIBuilder is equal to another URIBuilder instance. |
Map<String,Object> |
getQuery()
Get the query string as a map for convenience. |
protected List<org.apache.http.NameValuePair> |
getQueryNVP()
|
boolean |
hasQueryParam(String name)
Indicates if the given parameter is already part of this URI's query string. |
URIBuilder |
removeQueryParam(String param)
Remove the given query parameter from this URI's query string. |
URIBuilder |
setFragment(String fragment)
The document fragment, without a preceeding '#' |
URIBuilder |
setHost(String host)
|
URIBuilder |
setPath(String path)
Set the path component of this URI. |
URIBuilder |
setPort(int port)
|
URIBuilder |
setQuery(Map<?,?> params)
Set the query portion of the URI. |
protected URIBuilder |
setQueryNVP(List<org.apache.http.NameValuePair> nvp)
|
URIBuilder |
setScheme(String scheme)
Set the URI scheme, AKA the 'protocol.' e.g. |
String |
toString()
Print this builder's URI representation. |
URI |
toURI()
Convenience method to convert this object to a URI instance. |
URL |
toURL()
Convenience method to convert this object to a URL instance. |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected URI base
| Constructor Detail |
|---|
public URIBuilder(URI uri,
boolean urlEncodingEnabled,
EncoderConfig config)
throws IllegalArgumentException
uri -
IllegalArgumentException - if uri is null| Method Detail |
|---|
public static URI convertToURI(Object uri)
throws URISyntaxException
uri - a URI, URL or any object that produces a
valid URI string from its toString() result.
URISyntaxException
public URIBuilder setScheme(String scheme)
throws URISyntaxException
setScheme('https')
URISyntaxException - if the given scheme contains illegal characters.
public URIBuilder setPort(int port)
throws URISyntaxException
URISyntaxException
public URIBuilder setHost(String host)
throws URISyntaxException
URISyntaxException
public URIBuilder setPath(String path)
throws URISyntaxException
def uri = new URIBuilder( 'http://localhost/p1/p2?a=1' ) uri.path = '/p3/p2' assert uri.toString() == 'http://localhost/p3/p2?a=1' uri.path = 'p2a' assert uri.toString() == 'http://localhost/p3/p2a?a=1' uri.path = '../p4' assert uri.toString() == 'http://localhost/p4?a=1&b=2&c=3#frag'
path - the path portion of this URI, relative to the current URI.
URISyntaxException - if the given path contains characters that
cannot be converted to a valid URI
protected URIBuilder setQueryNVP(List<org.apache.http.NameValuePair> nvp)
throws URISyntaxException
URISyntaxException
public URIBuilder setQuery(Map<?,?> params)
throws URISyntaxException
uri.query = [ p1:'val1', p2:['val2', 'val3'] ] // will produce a query string of ?p1=val1&p2=val2&p2=val3
params - a Map of parameters that will be transformed into the query string
URISyntaxExceptionpublic Map<String,Object> getQuery()
p1=one&p1=two) both values will be
inserted into a list for that paramter key ([p1 : ['one','two']]
). Note that this is not a "live" map. Therefore, you cannot
call
uri.query.a = 'BCD'You will not modify the query string but instead the generated map of parameters. Instead, you need to use
removeQueryParam(String)
first, then addQueryParam(String, Object), or call
setQuery(Map) which will set the entire query string.
protected List<org.apache.http.NameValuePair> getQueryNVP()
public boolean hasQueryParam(String name)
name - the query parameter name
public URIBuilder removeQueryParam(String param)
throws URISyntaxException
param - the query name to remove
URISyntaxException
protected URIBuilder addQueryParam(org.apache.http.NameValuePair nvp)
throws URISyntaxException
URISyntaxException
public URIBuilder addQueryParam(String param,
Object value)
throws URISyntaxException
removeQueryParam(String) first, or use getQuery(),
modify the value in the map, then call setQuery(Map).
param - query parameter namevalue - query parameter value (will be converted to a string if
not null. If value is null, it will be set as the empty
string.
URISyntaxException - if the query parameter values cannot be
converted to a valid URI.setQuery(Map)
protected URIBuilder addQueryParams(List<org.apache.http.NameValuePair> nvp)
throws URISyntaxException
URISyntaxException
public URIBuilder addQueryParams(Map<?,?> params)
throws URISyntaxException
uriBuilder.addQueryParams( [one:1,two:2] ) uriBuilder.addQueryParams( three : 3 )If any of the parameters already exist in the URI query, these values will not replace them. Multiple values for the same query parameter may be added by putting them in a list. See
setQuery(Map).
params - parameters to add to the existing URI query (if any).
URISyntaxException
public URIBuilder setFragment(String fragment)
throws URISyntaxException
fragment -
URISyntaxException - if the given value contains illegal characters.public String toString()
toString in class Object
public URL toURL()
throws MalformedURLException
MalformedURLException - if the underlying URI does not represent a
valid URL.public URI toURI()
public Object asType(Class<?> type)
throws MalformedURLException
as operator, to allow type
conversion.
type - URL, URL, or String.
MalformedURLException - if type is URL and this
URIBuilder instance does not represent a valid URL.protected URIBuilder clone()
clone in class Objectpublic boolean equals(Object obj)
equals in class Objectobj is a URIBuilder instance whose underlying
URI implementation is equal to this one's.URI.equals(Object)
public static String encode(String content,
String encoding)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||