-
- All Superinterfaces:
- SyncInvoker
- Enclosing interface:
- Invocation
public static interface Invocation.Builder extends SyncInvoker
A client request invocation builder. The builder, obtained via a call to one of therequest(...)
methods on aresource target
, provides methods for preparing a client request invocation. Once the request is prepared the invocation builder can be either used to build anInvocation
with a generic execution interface:Client client = ClientBuilder.newClient(); WebTarget resourceTarget = client.target("http://examples.jaxrs.com/"); // Build a HTTP GET request that accepts "text/plain" response type // and contains a custom HTTP header entry "Foo: bar". Invocation invocation = resourceTarget.request("text/plain") .header("Foo", "bar").buildGet(); // Invoke the request using generic interface String response = invocation.invoke(String.class);
Alternatively, one of the inheritedsynchronous invocation methods
can be used to invoke the prepared request and return the server response in a single step, e.g.:Client client = ClientBuilder.newClient(); WebTarget resourceTarget = client.target("http://examples.jaxrs.com/"); // Build and invoke the get request in a single step String response = resourceTarget.request("text/plain") .header("Foo", "bar").get(String.class);
Once the request is fully prepared for invoking, switching to anasynchronous invocation
mode is possible by calling theasync()
method on the builder, e.g.:Client client = ClientBuilder.newClient(); WebTarget resourceTarget = client.target("http://examples.jaxrs.com/"); // Build and invoke the get request asynchronously in a single step Future
response = resourceTarget.request("text/plain") .header("Foo", "bar").async().get(String.class);
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method and Description Invocation.Builder
accept(MediaType... mediaTypes)
Add the accepted response media types.Invocation.Builder
accept(String... mediaTypes)
Add the accepted response media types.Invocation.Builder
acceptEncoding(String... encodings)
Add acceptable encodings.Invocation.Builder
acceptLanguage(Locale... locales)
Add acceptable languages.Invocation.Builder
acceptLanguage(String... locales)
Add acceptable languages.AsyncInvoker
async()
Access the asynchronous uniform request invocation interface to asynchronously invoke the built request.Invocation
build(String method)
Build a request invocation using an arbitrary request method name.Invocation
build(String method, Entity<?> entity)
Build a request invocation using an arbitrary request method name and request entity.Invocation
buildDelete()
Build a DELETE request invocation.Invocation
buildGet()
Build a GET request invocation.Invocation
buildPost(Entity<?> entity)
Build a POST request invocation.Invocation
buildPut(Entity<?> entity)
Build a PUT request invocation.Invocation.Builder
cacheControl(CacheControl cacheControl)
Set the cache control data of the message.Invocation.Builder
cookie(Cookie cookie)
Add a cookie to be set.Invocation.Builder
cookie(String name, String value)
Add a cookie to be set.Invocation.Builder
header(String name, Object value)
Add an arbitrary header.Invocation.Builder
headers(MultivaluedMap<String,Object> headers)
Replaces all existing headers with the newly supplied headers.Invocation.Builder
property(String name, Object value)
Set a new property in the context of a request represented by this invocation builder.
-
-
-
Method Detail
-
build
Invocation build(String method)
Build a request invocation using an arbitrary request method name.- Parameters:
method
- request method name.- Returns:
- invocation encapsulating the built request.
-
build
Invocation build(String method, Entity<?> entity)
Build a request invocation using an arbitrary request method name and request entity.- Parameters:
method
- request method name.entity
- request entity, including it's fullVariant
information. Any variant-related HTTP headers previously set (namelyContent-Type
,Content-Language
andContent-Encoding
) will be overwritten using the entity variant information.- Returns:
- invocation encapsulating the built request.
-
buildGet
Invocation buildGet()
Build a GET request invocation.- Returns:
- invocation encapsulating the built GET request.
-
buildDelete
Invocation buildDelete()
Build a DELETE request invocation.- Returns:
- invocation encapsulating the built DELETE request.
-
buildPost
Invocation buildPost(Entity<?> entity)
Build a POST request invocation.- Parameters:
entity
- request entity, including it's fullVariant
information. Any variant-related HTTP headers previously set (namelyContent-Type
,Content-Language
andContent-Encoding
) will be overwritten using the entity variant information.- Returns:
- invocation encapsulating the built POST request.
-
buildPut
Invocation buildPut(Entity<?> entity)
Build a PUT request invocation.- Parameters:
entity
- request entity, including it's fullVariant
information. Any variant-related HTTP headers previously set (namelyContent-Type
,Content-Language
andContent-Encoding
) will be overwritten using the entity variant information.- Returns:
- invocation encapsulating the built PUT request.
-
async
AsyncInvoker async()
Access the asynchronous uniform request invocation interface to asynchronously invoke the built request.- Returns:
- asynchronous uniform request invocation interface.
-
accept
Invocation.Builder accept(String... mediaTypes)
Add the accepted response media types.- Parameters:
mediaTypes
- accepted response media types.- Returns:
- the updated builder.
-
accept
Invocation.Builder accept(MediaType... mediaTypes)
Add the accepted response media types.- Parameters:
mediaTypes
- accepted response media types.- Returns:
- the updated builder.
-
acceptLanguage
Invocation.Builder acceptLanguage(Locale... locales)
Add acceptable languages.- Parameters:
locales
- an array of the acceptable languages.- Returns:
- the updated builder.
-
acceptLanguage
Invocation.Builder acceptLanguage(String... locales)
Add acceptable languages.- Parameters:
locales
- an array of the acceptable languages.- Returns:
- the updated builder.
-
acceptEncoding
Invocation.Builder acceptEncoding(String... encodings)
Add acceptable encodings.- Parameters:
encodings
- an array of the acceptable encodings.- Returns:
- the updated builder.
-
cookie
Invocation.Builder cookie(Cookie cookie)
Add a cookie to be set.- Parameters:
cookie
- to be set.- Returns:
- the updated builder.
-
cookie
Invocation.Builder cookie(String name, String value)
Add a cookie to be set.- Parameters:
name
- the name of the cookie.value
- the value of the cookie.- Returns:
- the updated builder.
-
cacheControl
Invocation.Builder cacheControl(CacheControl cacheControl)
Set the cache control data of the message.- Parameters:
cacheControl
- the cache control directives, ifnull
any existing cache control directives will be removed.- Returns:
- the updated builder.
-
header
Invocation.Builder header(String name, Object value)
Add an arbitrary header.- Parameters:
name
- the name of the headervalue
- the value of the header, the header will be serialized using aRuntimeDelegate.HeaderDelegate
if one is available viaRuntimeDelegate.createHeaderDelegate(java.lang.Class)
for the class ofvalue
or using itstoString
method if a header delegate is not available. Ifvalue
isnull
then all current headers of the same name will be removed.- Returns:
- the updated builder.
-
headers
Invocation.Builder headers(MultivaluedMap<String,Object> headers)
Replaces all existing headers with the newly supplied headers.- Parameters:
headers
- new headers to be set, ifnull
all existing headers will be removed.- Returns:
- the updated builder.
-
property
Invocation.Builder property(String name, Object value)
Set a new property in the context of a request represented by this invocation builder.The property is available for a later retrieval via
ClientRequestContext.getProperty(String)
orInterceptorContext.getProperty(String)
. If a property with a given name is already set in the request context, the existing value of the property will be updated. Setting anull
value into a property effectively removes the property from the request property bag.- Parameters:
name
- property name.value
- (new) property value.null
value removes the property with the given name.- Returns:
- the updated builder.
- See Also:
Invocation.property(String, Object)
-
-
Deutsche Übersetzung
Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.
Vielen Dank im Voraus.
Dokument erstellt 11/06/2005, zuletzt geändert 18/08/2025
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/java-api-javaee-rf-javax/ws/rs/client/Invocation.Builder.html
Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.
Referenzen
Diese Verweise und Links verweisen auf Dokumente, die während des Schreibens dieser Seite konsultiert wurden, oder die zusätzliche Informationen liefern können, aber die Autoren dieser Quellen können nicht für den Inhalt dieser Seite verantwortlich gemacht werden.
Der Autor dieser Website ist allein dafür verantwortlich, wie die verschiedenen Konzepte und Freiheiten, die mit den Nachschlagewerken gemacht werden, hier dargestellt werden. Denken Sie daran, dass Sie mehrere Quellinformationen austauschen müssen, um das Risiko von Fehlern zu reduzieren.