46.5. Configuring the Client Endpoint
javax.ws.rs.client.Clientobject by registering and configuring features and providers.
// Java import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.client.Client; import org.apache.cxf.feature.LoggingFeature; ... Client client = ClientBuilder.newClient(); client.register(LoggingFeature.class) .register(MyCustomEntityProvider.class) .property("LoggingFeature.prettyLogging","true");
Configurable API for registering objects
Clientclass supports the
ConfigurableAPI for registering objects, which provides several variants of the
registermethod. In most cases, you would register either a class or an object instance, as shown in the following examples:
client.register(LoggingFeature.class) client.register(new LoggingFeature())
registervariants, see the reference documentation for
What can you configure on the client?
javax.ws.rs.core.Featureis effectively a plug-in that adds an extra feature or functionality to a JAX-RS client. Often, a feature installs one or more interceptors in order to provide the required functionality.
- Entity providers
- An entity provider provides the capability of mapping between a specific media type a Java type. For more details, see Section 46.4, “Parsing Requests and Responses”.
- Exception mapping providers
- An exception mapping provider maps a checked runtime exception to an instance of
- Context providers
- A context provider is used on the server side, to supply context to resource classes and other service providers.
Other configurable types
javax.ws.rs.client.ClientBuilder) object, but also a
WebTargetobject. When you change the configuration of a
WebTargetobject, the underlying client configuration is deep copied to give the new
WebTargetconfiguration. Hence, it is possible to change the configuration of the
WebTargetobject without changing the configuration of the original