Java RESTful Services Client

This feature enables support for Java Client API for JAX-RS 2.1.

Enabling this feature

To enable the Java RESTful Services Client 2.1 feature, add the following element declaration into your server.xml file, inside the featureManager element:



The JAX-RS Client APIs allow you to specify properties on the client that configure settings like timeouts, proxy hosts, SSL properties, and so on. You can set these properties in the Java code or in the server configuration. The following examples show how you can set webTarget values in the server.xml so that you can change them without having to edit and recompile the Java code.

Changing values when moving from development to production environments

If the application is deployed in a different environment, these settings might need to change. For example, an application might initially be written to run in a development environment, where all remote RESTful services are available without a proxy server and can connect very quickly:

public Widget getRemoteWidget(String id) {
    Client client = ClientBuilder.newClient();
    WebTarget target ="https://somehost:9443/WidgetStore/widgets/");
    Widget widget = target.path(id).request().get(Widget.class);
    return widget;

When this application is deployed in a production environment, however, it might be necessary to add new settings. This can be accomplished by adding the following configuration to the server config (server.xml):

<webTarget uri="https://somehost:9443/WidgetStore*" proxyHost="myProxyHost" proxyPort="55555" proxyType="HTTP"
           connectionTimeout="60000" receiveTimeout="60000" />

This configuration alters the WebTarget in the Java code to use the specified HTTP proxy server (myProxyHost:55555) and use connection and receive timeouts of 60 seconds (60,000 milliseconds) instead of the default timeouts.

Simplifying SSL configuration in development

During development, an SSL certificate might not match the server hostname on which the application is being tested because it matches the server hostname on which the application will ultimately be deployed in production. The configuration can be changed during development to use a different SSL configuration or to disable hostname verification of SSL certificates (this is not recommended in production environments):

<webTarget uri="https://somehost:9443/WidgetStore*" sslConfig="mySSLRef" disableCNCheck="true" />

Setting custom properties

If your application uses providers such as a ClientRequestFilter or ClientResponseFilter, they can read and react to custom properties specified on the JAX-RS Client or WebTarget. It is also possible to change Open Liberty’s client implementation behavior by specifying custom properties. These are normally specified programmatically using"myCustomProperty", "someValue") but you can also specify custom properties for the WebTarget in the configuration:

<webTarget uri="https://somehost:9443/WidgetStore*" myCustomProperty="prod" />

The complete list of pre-defined properties is available here: webTarget.

Standard API packages provided by this feature







Liberty API packages provided by this feature



Features that this feature enables

Supported Java versions

  • JavaSE-1.8

  • JavaSE-11.0

  • JavaSE-14.0

Developing a feature that depends on this feature

If you are developing a feature that depends on this feature, include the following item in the Subsystem-Content header in your feature manifest file.; type="osgi.subsystem.feature"

SPI packages provided by this feature