|
||||||||||
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 java.net.URI |
base
|
Constructor Summary | |
---|---|
URIBuilder(java.net.URI uri,
EncoderConfig config)
|
Method Summary | |
---|---|
protected URIBuilder |
addQueryParam(org.apache.http.NameValuePair nvp)
|
URIBuilder |
addQueryParam(java.lang.String param,
java.lang.Object value)
This will append a query parameter to the existing query string. |
protected URIBuilder |
addQueryParams(java.util.List<org.apache.http.NameValuePair> nvp)
|
URIBuilder |
addQueryParams(java.util.Map<?,?> params)
Add these parameters to the URIBuilder's existing query string. |
java.lang.Object |
asType(java.lang.Class<?> type)
Implementation of Groovy's as operator, to allow type
conversion. |
protected URIBuilder |
clone()
Create a copy of this URIBuilder instance. |
static java.net.URI |
convertToURI(java.lang.Object uri)
Utility method to convert a number of type to a URI instance. |
static java.lang.String |
encode(java.lang.String content,
java.lang.String encoding)
|
boolean |
equals(java.lang.Object obj)
Determine if this URIBuilder is equal to another URIBuilder instance. |
java.util.Map<java.lang.String,java.lang.Object> |
getQuery()
Get the query string as a map for convenience. |
protected java.util.List<org.apache.http.NameValuePair> |
getQueryNVP()
|
boolean |
hasQueryParam(java.lang.String name)
Indicates if the given parameter is already part of this URI's query string. |
URIBuilder |
removeQueryParam(java.lang.String param)
Remove the given query parameter from this URI's query string. |
URIBuilder |
setFragment(java.lang.String fragment)
The document fragment, without a preceeding '#' |
URIBuilder |
setHost(java.lang.String host)
|
URIBuilder |
setPath(java.lang.String path)
Set the path component of this URI. |
URIBuilder |
setPort(int port)
|
URIBuilder |
setQuery(java.util.Map<?,?> params)
Set the query portion of the URI. |
protected URIBuilder |
setQueryNVP(java.util.List<org.apache.http.NameValuePair> nvp)
|
URIBuilder |
setScheme(java.lang.String scheme)
Set the URI scheme, AKA the 'protocol.' e.g. |
java.lang.String |
toString()
Print this builder's URI representation. |
java.net.URI |
toURI()
Convenience method to convert this object to a URI instance. |
java.net.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 java.net.URI base
Constructor Detail |
---|
public URIBuilder(java.net.URI uri, EncoderConfig config) throws java.lang.IllegalArgumentException
uri
-
java.lang.IllegalArgumentException
- if uri is nullMethod Detail |
---|
public static java.net.URI convertToURI(java.lang.Object uri) throws java.net.URISyntaxException
uri
- a URI
, URL
or any object that produces a
valid URI string from its toString()
result.
java.net.URISyntaxException
public URIBuilder setScheme(java.lang.String scheme) throws java.net.URISyntaxException
setScheme('https')
java.net.URISyntaxException
- if the given scheme contains illegal characters.public URIBuilder setPort(int port) throws java.net.URISyntaxException
java.net.URISyntaxException
public URIBuilder setHost(java.lang.String host) throws java.net.URISyntaxException
java.net.URISyntaxException
public URIBuilder setPath(java.lang.String path) throws java.net.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.
java.net.URISyntaxException
- if the given path contains characters that
cannot be converted to a valid URIprotected URIBuilder setQueryNVP(java.util.List<org.apache.http.NameValuePair> nvp) throws java.net.URISyntaxException
java.net.URISyntaxException
public URIBuilder setQuery(java.util.Map<?,?> params) throws java.net.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
java.net.URISyntaxException
public java.util.Map<java.lang.String,java.lang.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 java.util.List<org.apache.http.NameValuePair> getQueryNVP()
public boolean hasQueryParam(java.lang.String name)
name
- the query parameter name
public URIBuilder removeQueryParam(java.lang.String param) throws java.net.URISyntaxException
param
- the query name to remove
java.net.URISyntaxException
protected URIBuilder addQueryParam(org.apache.http.NameValuePair nvp) throws java.net.URISyntaxException
java.net.URISyntaxException
public URIBuilder addQueryParam(java.lang.String param, java.lang.Object value) throws java.net.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.
java.net.URISyntaxException
- if the query parameter values cannot be
converted to a valid URI.setQuery(Map)
protected URIBuilder addQueryParams(java.util.List<org.apache.http.NameValuePair> nvp) throws java.net.URISyntaxException
java.net.URISyntaxException
public URIBuilder addQueryParams(java.util.Map<?,?> params) throws java.net.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).
java.net.URISyntaxException
public URIBuilder setFragment(java.lang.String fragment) throws java.net.URISyntaxException
fragment
-
java.net.URISyntaxException
- if the given value contains illegal characters.public java.lang.String toString()
toString
in class java.lang.Object
public java.net.URL toURL() throws java.net.MalformedURLException
java.net.MalformedURLException
- if the underlying URI does not represent a
valid URL.public java.net.URI toURI()
public java.lang.Object asType(java.lang.Class<?> type) throws java.net.MalformedURLException
as
operator, to allow type
conversion.
type
- URL
, URL
, or String
.
java.net.MalformedURLException
- if type
is URL and this
URIBuilder instance does not represent a valid URL.protected URIBuilder clone()
clone
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
obj
is a URIBuilder instance whose underlying
URI implementation is equal to this one's.URI.equals(Object)
public static java.lang.String encode(java.lang.String content, java.lang.String encoding)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |