The JAX-RS API 2.0 defines the Headers interface to access a list of all provided request headers. Typically this form of mass-provision is utilized by some kind of filtering and / or iteration algorithm, since obviously nobody really needs literally all headers (including even potentially unknown custom headers).
With the rise of Java 8 in the incarnation of both, the current Java SE 8 and the future Java EE 8 platforms, Streams API is the typical means to code bulk processing. Java SE 8 for example was overhauled to provide streams to process lots of mass-content like in the Collections API. The resulting code is often more concise and better readable, also supports potentially parallel execution by usage of parallel streams.
As Java SE 8 might be very popular at time of JAX-RS 2.1 publication, and as Java EE 8 is assumed to demand JAX-RS 2.1 and Java SE 8 as core technologies, it would be wise and beneficial to define additional APIs which allow to directly produce streams for header batch-processing.
The following serves as a proposal to discuss:
Wherever bulk access on headers is used in JAX-RS 2.0 (like the Headers interface), there should be an additional, similar method defined producing a stream of headers. To illustrate this, the following API...
While it is clear that the following code is possible without streams...
for (final Map.Entry<String, String> h: Headers.getRequestHeaders().entrySet())
if (h.getKey().startsWith("X-OTRS") {
final List<String> v = h.getValue();
if (v.contains("XYZ")
System.out.println(v);
}
...it is obvious that the following stream processing looks more concise to readers familiar with the Stream API...
The JAX-RS API 2.0 defines the Headers interface to access a list of all provided request headers. Typically this form of mass-provision is utilized by some kind of filtering and / or iteration algorithm, since obviously nobody really needs literally all headers (including even potentially unknown custom headers).
With the rise of Java 8 in the incarnation of both, the current Java SE 8 and the future Java EE 8 platforms, Streams API is the typical means to code bulk processing. Java SE 8 for example was overhauled to provide streams to process lots of mass-content like in the Collections API. The resulting code is often more concise and better readable, also supports potentially parallel execution by usage of parallel streams.
As Java SE 8 might be very popular at time of JAX-RS 2.1 publication, and as Java EE 8 is assumed to demand JAX-RS 2.1 and Java SE 8 as core technologies, it would be wise and beneficial to define additional APIs which allow to directly produce streams for header batch-processing.
The following serves as a proposal to discuss:
Wherever bulk access on headers is used in JAX-RS 2.0 (like the Headers interface), there should be an additional, similar method defined producing a stream of headers. To illustrate this, the following API...
...could get extended by the following API...
...to simplify processing using the Streams API.
While it is clear that the following code is possible without streams...
...it is obvious that the following stream processing looks more concise to readers familiar with the Stream API...
Environment
Java SE 8, Java EE 8
Affected Versions
[2.1]