eclipse-ee4j / eclipse-ee4j/jersey

WebResourceFactory proxy client does not allow to set Content-Language with POST method

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

Description

Using the Jersey proxy client, there is no way to set the Content-Language header, specifying the language (Locale) of the entity sent over with the POST HTTP request.

The way to do this with regular (non-proxy) Jersey client is to explicitly specify the Variant object with the appropriate Locale.

But there is just no way to do it with the proxy client: the Variant is hardcoded to use a Variant with a null Locale (through the Entity.entity(Object,String) helper), see [https://github.com/jersey/jersey/blob/ac34707df4ca97028ce6abfc2eeb4a39eae77b81/ext/proxy-client/src/main/java/org/glassfish/jersey/client/proxy/WebResourceFactory.java#L343](https://github.com/jersey/jersey/blob/ac34707df4ca97028ce6abfc2eeb4a39eae77b81/ext/proxy-client/src/main/java/org/glassfish/jersey/client/proxy/WebResourceFactory.java#L343) .

Instead, the WebResourceFactory class should use the language set as a header when available, similarly to what is done with header Content-Type at [https://github.com/jersey/jersey/blob/ac34707df4ca97028ce6abfc2eeb4a39eae77b81/ext/proxy-client/src/main/java/org/glassfish/jersey/client/proxy/WebResourceFactory.java#L298](https://github.com/jersey/jersey/blob/ac34707df4ca97028ce6abfc2eeb4a39eae77b81/ext/proxy-client/src/main/java/org/glassfish/jersey/client/proxy/WebResourceFactory.java#L298) .

This way, using a @HeaderParam("Content-Language") parameter in the endpoint signature will seamlessly enable to specify the language of the request, such as with example below:

```
@POST
@Path("/api")
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.APPLICATION_JSON)
String operation(
@HeaderParam(HttpHeaders.CONTENT_LANGUAGE) String language,
String body
);
```
#### Affected Versions
[2.23.2]

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.