-
Interface Summary Interface Description AsyncInvoker Uniform interface for asynchronous invocation of HTTP methods.Client Client is the main entry point to the fluent API used to build and execute client requests in order to consume responses returned.ClientRequestContext Client request filter context.ClientRequestFilter An extension interface implemented by client request filters.ClientResponseContext Client response filter context.ClientResponseFilter An extension interface implemented by client response filters.Invocation A client request invocation.Invocation.Builder A client request invocation builder.InvocationCallback<RESPONSE> Callback that can be implemented to receive the asynchronous processing events from the invocation processing.SyncInvoker Uniform interface for synchronous invocation of HTTP methods.WebTarget A resource target identified by the resource URI. -
Class Summary Class Description ClientBuilder Main entry point to the client API used to bootstrapClient
instances.Entity<T> Encapsulates message entity including the associated variant information. -
Exception Summary Exception Description ResponseProcessingException JAX-RS client-side runtime processing exception thrown to indicate that response processing has failed (e.g.
Package javax.ws.rs.client Description
The JAX-RS client API
The JAX-RS client API is a Java based API used to access Web resources. It is not restricted to resources implemented using JAX-RS. It provides a higher-level abstraction compared to aplain HTTP communication API
as well as integration with the JAX-RS extension
providers, in order to enable concise and efficient implementation of
reusable client-side solutions that leverage existing and well
established client-side implementations of HTTP-based communication.
The JAX-RS Client API encapsulates the Uniform Interface Constraint –
a key constraint of the REST architectural style – and associated data
elements as client-side Java artifacts and supports a pluggable architecture
by defining multiple extension points.
Client API Bootstrapping and Configuration
The main entry point to the API is aClientBuilder
that is used to bootstrap Client
instances -
configurable
, heavy-weight objects
that manage the underlying communication infrastructure and serve as the root
objects for accessing any Web resource. The following example illustrates the
bootstrapping and configuration of a Client
instance:
Client client = ClientBuilder.newClient(); client.property("MyProperty", "MyValue") .register(MyProvider.class) .enable(MyFeature.class);
Accessing Web Resources
A Web resource can be accessed using a fluent API in which method invocations are chained to configure and ultimately submit an HTTP request. The following example gets atext/plain
representation of the resource identified by
"http://example.org/hello"
:
Client client = ClientBuilder.newClient(); Response res = client.target("http://example.org/hello").request("text/plain").get();Conceptually, the steps required to submit a request are the following:
- obtain an
Client
instance - create a
WebTarget
pointing at a Web resource build
a request- submit a request to directly retrieve a response or get a prepared
Invocation
for later submission
WebTarget
instance is bound to a
concrete URI, e.g. "http://example.org/messages/123"
,
or a URI template, e.g. "http://example.org/messages/{id}"
.
That way a single target can either point at a particular resource or represent
a larger group of resources (that e.g. share a common configuration) from which
concrete resources can be later derived:
// Parent target for all messages WebTarget messages = client.target("http://example.org/messages/{id}"); WebTarget msg123 = messages.resolveTemplate("id", 123); // New target for http://example.org/messages/123 WebTarget msg456 = messages.resolveTemplate("id", 456); // New target for http://example.org/messages/456
Generic Invocations
AnInvocation
is a request that has been prepared
and is ready for execution.
Invocations provide a generic interface that enables a separation of concerns
between the creator and the submitter. In particular, the submitter does not
need to know how the invocation was prepared, but only whether it should be
executed synchronously or asynchronously.
Invocation inv1 = client.target("http://example.org/atm/balance") .queryParam("card", "111122223333").queryParam("pin", "9876") .request("text/plain").buildGet(); Invocation inv2 = client.target("http://example.org/atm/withdrawal") .queryParam("card", "111122223333").queryParam("pin", "9876") .request().buildPost(text("50.0"))); Collectioninvs = Arrays.asList(inv1, inv2); // Executed by the submitter Collection ress = Collections.transform(invs, new F () { public Response apply(Invocation inv) {return inv.invoke(); } });
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/package-summary.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.