eclipse-ee4j / eclipse-ee4j/jersey

Client LoggingFilter should print headers setted by other client filters

Open
#3,193 4 comments 0 reactions 0 assignees View on GitHub
Component: core Priority: Minor Type: Improvement
Dominant language
Java
Stars
730
Forks
382
PR merge metrics
No merged PRs in 30d

Description

The LoggingFilter is not really relevant when registered by a Client because it will not logged every headers that have been added by others ClientRequestFilter.

For example :

```
ClientConfig config = new ClientConfig()
.register(LoggingFilter.class)
.register(new EncodingFeature("gzip", GZipEncoder.class));

Client client = ClientBuilder.newBuilder()
.withConfig(config)
.build();

Response response = client.target("https://www.google.com")
.request()
.get();

response.close();
```

Output :

```
13:00:31.743 [main] INFO o.g.jersey.filter.LoggingFilter - 1 * Sending client request on thread main
1 > GET https://www.google.com
```

Instead of:

```
13:00:31.743 [main] INFO o.g.jersey.filter.LoggingFilter - 1 * Sending client request on thread main
1 > GET https://www.google.com 1 > Accept-Encoding: gzip, x-gzip
```

IMO the LoggingFilter priority is too low and doesn't reflect what is really sent by the client.

```
@Priority(Integer.MIN_VALUE)
```

I think a good solution could be to separate the logging filter into 2 separate filters that could be registered with a Feature :

```
@Priority(HEADER_DECORATOR + 100)
public class RequestLoggingFilter implements ContainerRequestFilter, ClientRequestFilter, WriterInterceptor {
// filter code }

@Priority(Integer.MIN_VALUE)
public class ResponseLoggingFilter implements ContainerResponseFilter, ClientResponseFilter {
// filter code }
```

The cons of this solution is that the filter will not log anymore requests which are aborted earlier in the filter chain. But given that this filter is used for dev purpose It should provide accurate and not false information on queries.

I can work on it if you are ok.
#### Affected Versions
[2.19]

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.