Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
63 views1 page

Configuration Scopes

The document discusses the configuration scopes of various JAX-RS Client API components, including ClientBuilder, Client, and WebTarget, which all implement the Configurable interface. It explains how properties and registered components can be inherited or overridden, allowing for flexible configuration management. The chapter concludes by emphasizing the benefits of this scoping approach in reducing code complexity and improving initialization efficiency.

Uploaded by

Diego Amaya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views1 page

Configuration Scopes

The document discusses the configuration scopes of various JAX-RS Client API components, including ClientBuilder, Client, and WebTarget, which all implement the Configurable interface. It explains how properties and registered components can be inherited or overridden, allowing for flexible configuration management. The chapter concludes by emphasizing the benefits of this scoping approach in reducing code complexity and improving initialization efficiency.

Uploaded by

Diego Amaya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

7.

Configuration Scopes:
If we look at the declarations of ClientBuilder, Client, WebTarget, Invocation, and
Invocation.Builder, you’ll notice that they all implement the Configurable interface.
Each one of these interfaces has its own scope of properties and registered
components that it inherits from wherever it was created from. We can also override
or add registered components or properties for each one of these components.
For example:
Client client = ClientBuilder.newBuilder()
.property("authentication.mode", "Basic")
.property("username", "bburke")
.property("password", "geheim")
.build();

WebTarget target1 = client.target("http://facebook.com");


WebTarget target2 = client.target("http://google.com")
.property("username", "wburke")
.register(JacksonJsonProvider.class);

If we look at the properties of target1 we can find the same properties as those
defined on the client instances, as WebTargets inherit their configuration from the
Client or WebTarget they were created from. The target2 variable overrides the
username property and registers a provider specifically for target2. So, target2’s
configuration properties and registered components will be a little bit different than
target1’s. This way of configuration scoping makes it much easier for you to share
initialization code so we can avoid creating a lot of extra objects we don’t need and
reduce the amount of code you have to write.
Wrapping Up:
In this chapter, we learned about the JAX-RS Client API. Client interfaces manage
global configuration and the underlying socket connections we’ll use to communicate
with a service. WebTarget represents a URI that you can build and invoke HTTP
requests from.

You might also like