Skip to content

Commit

Permalink
Merge pull request #383 from WhiteCat22/update_jaxrs_refs
Browse files Browse the repository at this point in the history
Update JAX-RS references to Jakarta RESTful Web Services
  • Loading branch information
Emily-Jiang authored Jun 18, 2024
2 parents e13aa88 + 3ed06d7 commit 9b5d730
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
* Invoking {@link #newBuilder()} is intended to always create a new instance, not use a cached version.
* </p>
* <p>
* The <code>RestClientBuilder</code> is a {@link Configurable} class as defined by JAX-RS. This allows a user to
* register providers, implementation specific configuration.
* The <code>RestClientBuilder</code> is a {@link Configurable} class as defined by Jakarta RESTful Web Services. This
* allows a user to register providers, implementation specific configuration.
* </p>
* <p>
* Implementations are expected to implement this class and provide the instance via the mechanism in
Expand Down Expand Up @@ -123,8 +123,8 @@ default RestClientBuilder baseUri(String uri) {
/**
* Set the connect timeout.
* <p>
* Like JAX-RS's <code>jakarta.ws.rs.client.ClientBuilder</code>'s <code>connectTimeout</code> method, specifying a
* timeout of 0 represents infinity, and negative values are not allowed.
* Like Jakarta RESTful Web Services's <code>jakarta.ws.rs.client.ClientBuilder</code>'s <code>connectTimeout</code>
* method, specifying a timeout of 0 represents infinity, and negative values are not allowed.
* </p>
* <p>
* If the client instance is injected via CDI and the
Expand All @@ -146,12 +146,12 @@ default RestClientBuilder baseUri(String uri) {
/**
* Set the read timeout.
* <p>
* Like JAX-RS's <code>jakarta.ws.rs.client.ClientBuilder</code>'s <code>readTimeout</code> method, specifying a
* timeout of 0 represents infinity, and negative values are not allowed.
* Like Jakarta RESTful Web Services's <code>jakarta.ws.rs.client.ClientBuilder</code>'s <code>readTimeout</code>
* method, specifying a timeout of 0 represents infinity, and negative values are not allowed.
* </p>
* <p>
* Also like the JAX-RS Client API, if the read timeout is reached, the client interface method will throw a
* <code>jakarta.ws.rs.ProcessingException</code>.
* Also like the Jakarta RESTful Web Services Client API, if the read timeout is reached, the client interface
* method will throw a <code>jakarta.ws.rs.ProcessingException</code>.
* </p>
* <p>
* If the client instance is injected via CDI and the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* <p>
* If no implementation class of the ClientHeadersFactory interface is specified in the annotation, then the
* {@link DefaultClientHeadersFactoryImpl} will be used. This implementation will simply propagate headers (specified
* via MP Config property) from an inbound JAX-RS request (if applicable) to the outbound request.
* via MP Config property) from an inbound Jakarta RESTful Web Services request (if applicable) to the outbound request.
* <p>
* If a ClientHeadersFactory class specified is not found on the classpath, this should be considered a deployment
* exception.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,19 @@
/**
* This interface is intended for generating or propagating HTTP headers. It is invoked by the MP Rest Client
* implementation before invoking any entity providers on the outbound processing chain. It contains a single method,
* <code>update</code> which takes parameters of headers passed in from the incoming JAX-RS request (if applicable, if
* not, this will be an empty map) and a read-only map of headers specified by <code>ClientHeaderParam</code> or
* <code>HeaderParam</code> annotations on the client interface.
* <code>update</code> which takes parameters of headers passed in from the incoming Jakarta RESTful Web Services
* request (if applicable, if not, this will be an empty map) and a read-only map of headers specified by
* <code>ClientHeaderParam</code> or <code>HeaderParam</code> annotations on the client interface.
* <p>
* This method should return a MultivaluedMap of headers to be merged with the outgoing headers. If it's desired for
* {@code clientOutgoingHeaders} to be present in addition to any propagated headers,
* {@link #update(MultivaluedMap, MultivaluedMap) update} needs to combine the two sets to return. This will determine
* the final set of HTTP headers that will be sent to the outbound entity provider processing chain - thus any filters,
* MessageBodyWriters, interceptors, etc. could further refine the set of headers actually sent on the client request.
* <p>
* If the ClientHeadersFactory instance is invoked while in the context of a JAX-RS request, the implementation may
* optionally support injection of fields and methods annotated with <code>{@literal @}Context</code>.
* If the ClientHeadersFactory instance is invoked while in the context of a Jakarta RESTful Web Services request, the
* implementation may optionally support injection of fields and methods annotated with
* <code>{@literal @}Context</code>.
* <p>
* If the ClientHeadersFactory instance is managed by CDI (i.e. it is annotated with
* <code>{@literal @}ApplicationScoped</code>, etc.), the implementation must use the appropriate CDI-managed instance,
Expand All @@ -47,8 +48,8 @@ public interface ClientHeadersFactory {
* could further update the headers.
*
* @param incomingHeaders
* - the map of headers from the inbound JAX-RS request. This will be an empty map if the associated
* client interface is not part of a JAX-RS request.
* - the map of headers from the inbound Jakarta RESTful Web Services request. This will be an empty map
* if the associated client interface is not part of a Jakarta RESTful Web Services request.
* @param clientOutgoingHeaders
* - the read-only map of header parameters specified on the client interface.
* @return a map of HTTP headers to merge with the clientOutgoingHeaders to be sent to the remote service.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
import jakarta.ws.rs.core.MultivaluedMap;

/**
* This class propagates JAX-RS headers whose names are specified using the MicroProfile Config property,
* <code>org.eclipse.microprofile.rest.client.propagateHeaders</code>.
* This class propagates Jakarta RESTful Web Services headers whose names are specified using the MicroProfile Config
* property, <code>org.eclipse.microprofile.rest.client.propagateHeaders</code>.
*
* <p>
* The value of this property should be a comma-separated list of HTTP header names. If the headers specified in the
* property exist in the inbound JAX-RS request, this class will propagate those headers to the outbound Rest Client
* request.
* property exist in the inbound Jakarta RESTful Web Services request, this class will propagate those headers to the
* outbound Rest Client request.
*
* <p>
* Any headers present on {@code clientOutgoingHeaders} will not be returned when calling the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import jakarta.ws.rs.core.Response;

/**
* Converts an JAX-RS Response object into an Exception.
* Converts an Jakarta RESTful Web Services Response object into an Exception.
*
*/
public interface ResponseExceptionMapper<T extends Throwable> {
Expand All @@ -37,7 +37,7 @@ public interface ResponseExceptionMapper<T extends Throwable> {
* If this method reads the response body as a stream it must ensure that it resets the stream.
*
* @param response
* the JAX-RS response processed from the underlying client
* the Jakarta RESTful Web Services response processed from the underlying client
* @return A throwable, if this mapper could convert the response.
*/
T toThrowable(Response response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*******************************************************************************/

/**
* APIs for building a type-safe RESTful client leveraging existing JAX-RS APIs, for example:
* APIs for building a type-safe RESTful client leveraging existing Jakarta RESTful Web Services APIs, for example:
*
* <pre>
* public interface MyClientService {
Expand Down
4 changes: 2 additions & 2 deletions spec/src/main/asciidoc/clientexamples.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,12 @@ public interface MyInvalidClient {
}
----

It is also possible to add or propagate headers en masse using a `ClientHeadersFactory`. This interface has a single method and takes two read-only `MultivaluedMap` parameters: The first map represents headers for the incoming request - if the client is executing in a JAX-RS environment then this map will contain headers from the inbound JAX-RS request. The second map represents the headers to be sent,
It is also possible to add or propagate headers en masse using a `ClientHeadersFactory`. This interface has a single method and takes two read-only `MultivaluedMap` parameters: The first map represents headers for the incoming request - if the client is executing in a Jakarta RESTful Web Services environment then this map will contain headers from the inbound Jakarta RESTful Web Services request. The second map represents the headers to be sent,
and it contains headers that have been specified via `@ClientHeaderParam`, `@HeaderParam`, `@BeanParam`, etc. The method should return a `MultivaluedMap` containing the "final" map of headers to be sent to the outbound processing flow. Providers such as filters, interceptors, message body writers, etc. could still modify the final map of headers prior to
sending the HTTP request.

By default, no `ClientHeadersFactory` implementation is used. To enable a `ClientHeadersFactory`, the client interface must be annotated with the `@RegisterClientHeaders` annotation. If this annotation specifies a value, the client implementation must invoke an instance of the specified `ClientHeadersFactory` implementation class. If no value is specified, then the client
implementation must invoke the `DefaultClientHeadersFactoryImpl`. This default factory will propagate specified headers from the inbound JAX-RS request to the outbound request - these headers are specified with a comma-separated list using the following MicroProfile Config property:
implementation must invoke the `DefaultClientHeadersFactoryImpl`. This default factory will propagate specified headers from the inbound Jakarta RESTful Web Services request to the outbound request - these headers are specified with a comma-separated list using the following MicroProfile Config property:

`org.eclipse.microprofile.rest.client.propagateHeaders`

Expand Down
12 changes: 6 additions & 6 deletions spec/src/main/asciidoc/integration.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ the default connect and read timeouts and use the timeout value specified in the
blocking/non-interruptible operations should be less than or equal to the time specified in the annotation, allowing the MP Fault Tolerance implementation to
interrupt the request and the throw the appropriate `TimeoutException`.

=== JAX-RS
=== Jakarta RESTful Web Services

When a client interface is executed from within a JAX-RS context (resource or provider class), it is possible to propagate HTTP headers using the `DefaultClientHeadersFactoryImpl` by adding the
`@RegisterClientHeaders` annotation to the interface with no value. To specify which headers to propagate from the inbound JAX-RS request to the outbound MP Rest Client request, users must use a
When a client interface is executed from within a Jakarta RESTful Web Services context (resource or provider class), it is possible to propagate HTTP headers using the `DefaultClientHeadersFactoryImpl` by adding the
`@RegisterClientHeaders` annotation to the interface with no value. To specify which headers to propagate from the inbound Jakarta RESTful Web Services request to the outbound MP Rest Client request, users must use a
comma-separated list of headers in the following MicroProfile Config property:

`org.eclipse.microprofile.rest.client.propagateHeaders`.

If the client interface is used within a JAX-RS context, then the implementation may support injection of `@Context`
fields and methods into custom `ClientHeadersFactory` instances. The injected objects are related to the JAX-RS context
(i.e. an injected `UriInfo` will be specific to the JAX-RS resource's URI, not the URI of the MP Rest Client interface).
If the client interface is used within a Jakarta RESTful Web Services context, then the implementation may support injection of `@Context`
fields and methods into custom `ClientHeadersFactory` instances. The injected objects are related to the Jakarta RESTful Web Services context
(i.e. an injected `UriInfo` will be specific to the Jakarta RESTful Web Services resource's URI, not the URI of the MP Rest Client interface).
This injection is optional for the implementation, so the only portable injection mechanism of `ClientHeadersFactory`
instances is `@Inject` when the client is managed by CDI.

Expand Down
14 changes: 7 additions & 7 deletions spec/src/main/asciidoc/providers.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
[[providers]]
== MicroProfile Rest Client Provider Registration

The RestClientBuilder interface extends the `Configurable` interface from JAX-RS, allowing a user to register custom providers while its being built. The behavior of the providers supported is defined by the JAX-RS Client API specification. Below is a list of provider types expected to be supported by an implementation:
The RestClientBuilder interface extends the `Configurable` interface from Jakarta RESTful Web Services, allowing a user to register custom providers while its being built. The behavior of the providers supported is defined by the Jakarta RESTful Web Services Client API specification. Below is a list of provider types expected to be supported by an implementation:

=== ClientResponseFilter

Expand All @@ -31,15 +31,15 @@ Both the `ClientRequestFilter` and `ClientResponseFilter` interfaces contains me

=== MessageBodyReader

The `MessageBodyReader` interface defined by JAX-RS allows the entity to be read from the API response after invocation.
The `MessageBodyReader` interface defined by Jakarta RESTful Web Services allows the entity to be read from the API response after invocation.

=== MessageBodyWriter

The `MessageBodyWriter` interface defined by JAX-RS allows a request body to be written in the request for `@POST`, `@PUT` operations, as well as other HTTP methods that support bodies.
The `MessageBodyWriter` interface defined by Jakarta RESTful Web Services allows a request body to be written in the request for `@POST`, `@PUT` operations, as well as other HTTP methods that support bodies.

=== ParamConverter

The `ParamConverter` interface defined by JAX-RS allows a parameter in a resource method to be converted to a format to be used in a request or a response.
The `ParamConverter` interface defined by Jakarta RESTful Web Services allows a parameter in a resource method to be converted to a format to be used in a request or a response.

=== ReaderInterceptor

Expand All @@ -55,7 +55,7 @@ The `ResponseExceptionMapper` is specific to MicroProfile Rest Client. This map

==== How to Implement ResponseExceptionMapper

The specification provides default methods for `getPriority()` and `handles(int status, MultivaluedMap<String,Object> headers)` methods. Priority is meant to be derived via a `@Priority` annotation added to the `ResponseExceptionMapper` implementation. The runtime will sort ascending, taking the one with the lowest numeric value first to check if it can handle the `Response` object based on it's status code and headers. The usage of ascending sorting is done to be consistent with JAX-RS behavior.
The specification provides default methods for `getPriority()` and `handles(int status, MultivaluedMap<String,Object> headers)` methods. Priority is meant to be derived via a `@Priority` annotation added to the `ResponseExceptionMapper` implementation. The runtime will sort ascending, taking the one with the lowest numeric value first to check if it can handle the `Response` object based on it's status code and headers. The usage of ascending sorting is done to be consistent with Jakarta RESTful Web Services behavior.

Likewise, the `handles` method by default will handle any response status code >= 400. You may override this behavior if you so choose to handle other response codes (both a smaller ranger and a larger range are expected) or base the decision on the response headers.

Expand Down Expand Up @@ -166,7 +166,7 @@ Implementations may provide any number of providers registered automatically, bu

=== JSON-P and JSON-B Providers

Implementations of the MicroProfile Rest Client should behave similar to JAX-RS implementations with regard to built-in JSON-P and JSON-B providers. Implementations must provide a built-in JSON-P entity provider. If the implementation supports JSON-B, then it must also provide a built-in JSON-B entity provider. Note that the JSON-B provider should take precedence over the JSON-P provider unless the client interface method's entity parameter or return type is a JSON-P object type (`jakarta.json.JsonObject`, `jakarta.json.JsonArray`, etc.).
Implementations of the MicroProfile Rest Client should behave similar to Jakarta RESTful Web Services implementations with regard to built-in JSON-P and JSON-B providers. Implementations must provide a built-in JSON-P entity provider. If the implementation supports JSON-B, then it must also provide a built-in JSON-B entity provider. Note that the JSON-B provider should take precedence over the JSON-P provider unless the client interface method's entity parameter or return type is a JSON-P object type (`jakarta.json.JsonObject`, `jakarta.json.JsonArray`, etc.).

When an interface is registered that contains:

Expand All @@ -175,7 +175,7 @@ When an interface is registered that contains:
- a method that declares input or output of type `jakarta.json.JsonValue` or any subclass therein (JSON-P only) or
- no `@Produces` or `@Consumes`

Then a JSON-B or JSON-P `MessageBodyReader` and `MessageBodyWriter` will be registered automatically by the implementation. This is in alignment with the JAX-RS 2.1 specification. The provider registered will have a priority of `Integer.MAX_VALUE`, allowing a user to register a custom provider to be used instead.
Then a JSON-B or JSON-P `MessageBodyReader` and `MessageBodyWriter` will be registered automatically by the implementation. This is in alignment with the Jakarta RESTful Web Services specification. The provider registered will have a priority of `Integer.MAX_VALUE`, allowing a user to register a custom provider to be used instead.

Users may configure how JSON-B serializes a request entity or deserializes a response entity by registering a class or instance of `ContextResolver<Jsonb>`. For example, the following code would enable the JSON-B provider implementation to deserialize private fields (without needing getters/setters):

Expand Down
Loading

0 comments on commit 9b5d730

Please sign in to comment.