Top Description Methods
jakarta.ws.rs.client

public Interface WebTarget

extends Configurable<WebTarget>
Imports
java.net.URI, java.util.Map, jakarta.ws.rs.core.Configurable, .MediaType, .UriBuilder

A resource target identified by the resource URI.
Author
Marek Potociar
Since
2.0

Method Summary

Modifier and TypeMethod and Description
public URI

Returns:

the resource URI.
getUri
()

Get the URI identifying the resource.

public UriBuilder

Returns:

the initialized URI builder.
getUriBuilder
()

Get the URI builder initialized with the URI of the current resource target.

public WebTarget

Returns:

a new target instance.
matrixParam
(String
the matrix parameter name, may contain URI template parameters.
name
,
Object...
the matrix parameter value(s), each object will be converted to a String using its toString() method. Stringified values may contain URI template parameters.
values
)

Create a new WebTarget instance by appending a matrix parameter to the existing set of matrix parameters of the current final segment of the URI of the current target instance.

public WebTarget

Returns:

a new target instance.
path
(String
the path, may contain URI template parameters.
path
)

Create a new WebTarget instance by appending path to the URI of the current target instance.

public WebTarget

Returns:

a new target instance.
queryParam
(String
the query parameter name, may contain URI template parameters
name
,
Object...
the query parameter value(s), each object will be converted to a String using its toString() method. Stringified values may contain URI template parameters.
values
)

Create a new WebTarget instance by configuring a query parameter on the URI of the current target instance.

public Invocation.Builder

Returns:

builder for a request targeted at the URI referenced by this target instance.
request
()

Start building a request to the targeted web resource.

public Invocation.Builder

Returns:

builder for a request targeted at the URI referenced by this target instance.
request
(String...
accepted response media types.
acceptedResponseTypes
)

Start building a request to the targeted web resource and define the accepted response media types.

public Invocation.Builder

Returns:

builder for a request targeted at the URI referenced by this target instance.
request
(MediaType...
accepted response media types.
acceptedResponseTypes
)

Start building a request to the targeted web resource and define the accepted response media types.

public WebTarget

Returns:

a new target instance.
resolveTemplate
(String
name of the URI template.
name
,
Object
value to be used to resolve the template.
value
)

Create a new WebTarget instance by resolving a URI template with a given name in the URI of the current target instance using a supplied value.

public WebTarget

Returns:

a new target instance.
resolveTemplate
(String
name of the URI template.
name
,
Object
value to be used to resolve the template.
value
,
boolean
if true, the slash ('/') characters in template values will be encoded if the template is placed in the URI path component, otherwise the slash characters will not be encoded in path templates.
encodeSlashInPath
)

Create a new WebTarget instance by resolving a URI template with a given name in the URI of the current target instance using a supplied value.

public WebTarget

Returns:

a new target instance.
resolveTemplateFromEncoded
(String
name of the URI template.
name
,
Object
encoded value to be used to resolve the template.
value
)

Create a new WebTarget instance by resolving a URI template with a given name in the URI of the current target instance using a supplied encoded value.

public WebTarget

Returns:

a new target instance or the same target instance in case the input name-value map is empty.
resolveTemplates
(Map<String, Object>
a map of URI template names and their values.
templateValues
)

Create a new WebTarget instance by resolving one or more URI templates in the URI of the current target instance using supplied name-value pairs.

public WebTarget

Returns:

a new target instance or the same target instance in case the input name-value map is empty.
resolveTemplates
(Map<String, Object>
a map of URI template names and their values.
templateValues
,
boolean
if true, the slash ('/') characters in template values will be encoded if the template is placed in the URI path component, otherwise the slash characters will not be encoded in path templates.
encodeSlashInPath
)

Create a new WebTarget instance by resolving one or more URI templates in the URI of the current target instance using supplied name-value pairs.

public WebTarget

Returns:

a new target instance or the same target instance in case the input name-value map is empty.
resolveTemplatesFromEncoded
(Map<String, Object>
a map of URI template names and their encoded values.
templateValues
)

Create a new WebTarget instance by resolving one or more URI templates in the URI of the current target instance using supplied name-encoded value pairs.

Inherited from jakarta.ws.rs.core.Configurable:
getConfigurationpropertyregisterregisterregisterregisterregisterregisterregisterregister

Method Detail

getUriback to summary
public URI getUri()

Get the URI identifying the resource.

Returns:URI

the resource URI.

getUriBuilderback to summary
public UriBuilder getUriBuilder()

Get the URI builder initialized with the URI of the current resource target. The returned URI builder is detached from the target, i.e. any updates in the URI builder MUST NOT have any effects on the URI of the originating target.

Returns:UriBuilder

the initialized URI builder.

matrixParamback to summary
public WebTarget matrixParam(String name, Object... values)

Create a new WebTarget instance by appending a matrix parameter to the existing set of matrix parameters of the current final segment of the URI of the current target instance. If multiple values are supplied the parameter will be added once per value. In case a single null value is entered, all parameters with that name in the current final path segment are removed (if present) from the collection of last segment matrix parameters inherited from the current target.

Note that the matrix parameters are tied to a particular path segment; appending a value to an existing matrix parameter name will not affect the position of the matrix parameter in the URI path.

A snapshot of the present configuration of the current (parent) target instance is taken and is inherited by the newly constructed (child) target instance.

Parameters
name:String

the matrix parameter name, may contain URI template parameters.

values:Object[]

the matrix parameter value(s), each object will be converted to a String using its toString() method. Stringified values may contain URI template parameters.

Returns:WebTarget

a new target instance.

Exceptions
NullPointerException:
if the parameter name is null or if there are multiple values present and any of those values is null.
See Also
Matrix URIs
pathback to summary
public WebTarget path(String path)

Create a new WebTarget instance by appending path to the URI of the current target instance.

When constructing the final path, a '/' separator will be inserted between the existing path and the supplied path if necessary. Existing '/' characters are preserved thus a single value can represent multiple URI path segments.

A snapshot of the present configuration of the current (parent) target instance is taken and is inherited by the newly constructed (child) target instance.

Parameters
path:String

the path, may contain URI template parameters.

Returns:WebTarget

a new target instance.

Exceptions
NullPointerException:
if path is null.
queryParamback to summary
public WebTarget queryParam(String name, Object... values)

Create a new WebTarget instance by configuring a query parameter on the URI of the current target instance. If multiple values are supplied the parameter will be added once per value. In case a single null value is entered, all parameters with that name are removed (if present) from the collection of query parameters inherited from the current target.

A snapshot of the present configuration of the current (parent) target instance is taken and is inherited by the newly constructed (child) target instance.

Parameters
name:String

the query parameter name, may contain URI template parameters

values:Object[]

the query parameter value(s), each object will be converted to a String using its toString() method. Stringified values may contain URI template parameters.

Returns:WebTarget

a new target instance.

Exceptions
NullPointerException:
if the parameter name is null or if there are multiple values present and any of those values is null.
requestback to summary
public Invocation.Builder request()

Start building a request to the targeted web resource.

Returns:Invocation.Builder

builder for a request targeted at the URI referenced by this target instance.

requestback to summary
public Invocation.Builder request(String... acceptedResponseTypes)

Start building a request to the targeted web resource and define the accepted response media types.

Invoking this method is identical to:

webTarget.request().accept(types);
Parameters
acceptedResponseTypes:String[]

accepted response media types.

Returns:Invocation.Builder

builder for a request targeted at the URI referenced by this target instance.

requestback to summary
public Invocation.Builder request(MediaType... acceptedResponseTypes)

Start building a request to the targeted web resource and define the accepted response media types.

Invoking this method is identical to:

webTarget.request().accept(types);
Parameters
acceptedResponseTypes:MediaType[]

accepted response media types.

Returns:Invocation.Builder

builder for a request targeted at the URI referenced by this target instance.

resolveTemplateback to summary
public WebTarget resolveTemplate(String name, Object value)

Create a new WebTarget instance by resolving a URI template with a given name in the URI of the current target instance using a supplied value. In case a null template name or value is entered a NullPointerException is thrown.

A snapshot of the present configuration of the current (parent) target instance is taken and is inherited by the newly constructed (child) target instance.

Parameters
name:String

name of the URI template.

value:Object

value to be used to resolve the template.

Returns:WebTarget

a new target instance.

Exceptions
NullPointerException:
if the resolved template name or value is null.
resolveTemplateback to summary
public WebTarget resolveTemplate(String name, Object value, boolean encodeSlashInPath)

Create a new WebTarget instance by resolving a URI template with a given name in the URI of the current target instance using a supplied value. In case a null template name or value is entered a NullPointerException is thrown.

A snapshot of the present configuration of the current (parent) target instance is taken and is inherited by the newly constructed (child) target instance.

Parameters
name:String

name of the URI template.

value:Object

value to be used to resolve the template.

encodeSlashInPath:boolean

if true, the slash ('/') characters in template values will be encoded if the template is placed in the URI path component, otherwise the slash characters will not be encoded in path templates.

Returns:WebTarget

a new target instance.

Exceptions
NullPointerException:
if the resolved template name or value is null.
resolveTemplateFromEncodedback to summary
public WebTarget resolveTemplateFromEncoded(String name, Object value)

Create a new WebTarget instance by resolving a URI template with a given name in the URI of the current target instance using a supplied encoded value. A template with a matching name will be replaced by the supplied value. Value is converted to String using its toString() method and is then encoded to match the rules of the URI component to which they pertain. All % characters in the stringified values that are not followed by two hexadecimal numbers will be encoded. In case a null template name or value is entered a NullPointerException is thrown.

A snapshot of the present configuration of the current (parent) target instance is taken and is inherited by the newly constructed (child) target instance.

Parameters
name:String

name of the URI template.

value:Object

encoded value to be used to resolve the template.

Returns:WebTarget

a new target instance.

Exceptions
NullPointerException:
if the resolved template name or value is null.
resolveTemplatesback to summary
public WebTarget resolveTemplates(Map<String, Object> templateValues)

Create a new WebTarget instance by resolving one or more URI templates in the URI of the current target instance using supplied name-value pairs. A call to the method with an empty parameter map is ignored, i.e. same WebTarget instance is returned.

A snapshot of the present configuration of the current (parent) target instance is taken and is inherited by the newly constructed (child) target instance.

Parameters
templateValues:Map<String, Object>

a map of URI template names and their values.

Returns:WebTarget

a new target instance or the same target instance in case the input name-value map is empty.

Exceptions
NullPointerException:
if the name-value map or any of the names or values in the map is null.
resolveTemplatesback to summary
public WebTarget resolveTemplates(Map<String, Object> templateValues, boolean encodeSlashInPath)

Create a new WebTarget instance by resolving one or more URI templates in the URI of the current target instance using supplied name-value pairs. A call to the method with an empty parameter map is ignored, i.e. same WebTarget instance is returned.

A snapshot of the present configuration of the current (parent) target instance is taken and is inherited by the newly constructed (child) target instance.

Parameters
templateValues:Map<String, Object>

a map of URI template names and their values.

encodeSlashInPath:boolean

if true, the slash ('/') characters in template values will be encoded if the template is placed in the URI path component, otherwise the slash characters will not be encoded in path templates.

Returns:WebTarget

a new target instance or the same target instance in case the input name-value map is empty.

Exceptions
NullPointerException:
if the name-value map or any of the names or values in the map is null.
resolveTemplatesFromEncodedback to summary
public WebTarget resolveTemplatesFromEncoded(Map<String, Object> templateValues)

Create a new WebTarget instance by resolving one or more URI templates in the URI of the current target instance using supplied name-encoded value pairs. All templates with their name matching one of the keys in the supplied map will be replaced by the value in the supplied map. Values are converted to String using their toString() method and are then encoded to match the rules of the URI component to which they pertain. All % characters in the stringified values that are not followed by two hexadecimal numbers will be encoded. A call to the method with an empty parameter map is ignored, i.e. same WebTarget instance is returned.

A snapshot of the present configuration of the current (parent) target instance is taken and is inherited by the newly constructed (child) target instance.

Parameters
templateValues:Map<String, Object>

a map of URI template names and their encoded values.

Returns:WebTarget

a new target instance or the same target instance in case the input name-value map is empty.

Exceptions
NullPointerException:
if the name-value map or any of the names or encoded values in the map is null.