Java Reference
In-Depth Information
...
}
The WebTarget interface represents a specific URI you want to invoke on. Through the Cli-
ent interface, you can create a WebTarget using one of the target() methods:
package
package javax . ws . rs . client . Client ;
public
public interface
interface WebTarget
WebTarget extends
extends Configurable < WebTarget > {
public
public URI getUri ();
public
public UriBuilder getUriBuilder ();
public
public WebTarget path ( String path );
public
public WebTarget resolveTemplate ( String name , Object value );
public
public WebTarget resolveTemplate ( String name , Object value ,
boolean
boolean encodeSlashInPath );
public
public WebTarget resolveTemplateFromEncoded ( String name , Object value );
public
public WebTarget resolveTemplates ( Map < String , Object > templateValues );
public
public WebTarget resolveTemplates ( Map < String , Object > templateValues ,
boolean
boolean encodeSlashInPath );
public
public WebTarget resolveTemplatesFromEncoded (
Map < String , Object > templateValues );
public
public WebTarget matrixParam ( String name , Object ... values );
public
public WebTarget queryParam ( String name , Object ... values );
...
}
WebTarget has additional methods to extend the URI you originally constructed it with. You
can add path segments or query parameters by invoking path() and queryParam() . If the
WebTarget represents a URI template, the resolveTemplate() methods can fill in those
variables:
WebTarget target = client . target ( "http://commerce.com/customers/{id}" )
. resolveTemplate ( "id" , "123" )
. queryParam ( "verbose" , true
true );
In this example, we initialized a WebTarget with a URI template string. The resolveTem-
plate() method fills in the id expression, and we add another query parameter. If you take a
look at the UriBuilder class, you'll see that WebTarget pretty much mirrors it. Instead of
building URIs, though, WebTarget is building instances of WebTargets that you can use to
invoke HTTP requests.
Search WWH ::




Custom Search