이 콘텐츠는 선택한 언어로 제공되지 않습니다.

48.5. Configuring the Client Endpoint


Overview

It is possible to augment the functionality of the base javax.ws.rs.client.Client object by registering and configuring features and providers.

Example

The following example shows a client configured to have a logging feature, a custom entity provider, and to set the prettyLogging property to true:
// 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");
Copy to Clipboard Toggle word wrap

Configurable API for registering objects

The Client class supports the Configurable API for registering objects, which provides several variants of the register method. 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())
Copy to Clipboard Toggle word wrap
For more details about the register variants, see the reference documentation for Configurable.

What can you configure on the client?

You can configure the following aspects of a client endpoint:
  • Features
  • Providers
  • Properties
  • Filters
  • Interceptors

Features

A javax.ws.rs.core.Feature is 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.

Providers

A provider is a particular kind of client plug-in that provides a mapping capability. The JAX-RS 2.0 specification defines the following kinds of provider:
Entity providers
An entity provider provides the capability of mapping between a specific media type a Java type. For more details, see Section 48.4, “Parsing Requests and Responses”.
Exception mapping providers
An exception mapping provider maps a checked runtime exception to an instance of Response.
Context providers
A context provider is used on the server side, to supply context to resource classes and other service providers.

Filters

A JAX-RS 2.0 filter is a plug-in that gives you access to the URI, headers, and miscellaneous context data at various points (extension points) of the message processing pipeline. For details, see Chapter 60, JAX-RS 2.0 Filters and Interceptors.

Interceptors

A JAX-RS 2.0 interceptor is a plug-in that gives you access to the message body of a request or response as it is being read or written. For details, see Chapter 60, JAX-RS 2.0 Filters and Interceptors.

Properties

By setting one or more properties on the client, you can customize the configuration of a registered feature or a registered provider.

Other configurable types

It is possible, not only to configure a javax.ws.rs.client.Client (and javax.ws.rs.client.ClientBuilder) object, but also a WebTarget object. When you change the configuration of a WebTarget object, the underlying client configuration is deep copied to give the new WebTarget configuration. Hence, it is possible to change the configuration of the WebTarget object without changing the configuration of the original Client object.
맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat