[ 
https://issues.apache.org/jira/browse/CXF-8812?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17807281#comment-17807281
 ] 

Erich Mauerböck commented on CXF-8812:
--------------------------------------

{code:java}
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getMethod(@Context Request request, @Context HttpHeaders 
httpHeaders) {
        // workaround (bug in CXF?): remove content-type header for GET request
        MultivaluedMap<String, String> headersCopy = new 
MetadataMap<>(httpHeaders.getRequestHeaders(), true, false, true);
        headersCopy.remove(HttpHeaders.CONTENT_TYPE);

        RequestEntity<String> requestEntity = new RequestEntity<>(null, 
CollectionUtils.toMultiValueMap(headersCopy), 
HttpMethod.resolve(request.getMethod()), 
UriComponentsBuilder.fromHttpUrl("target url").build().toUri());
        ResponseEntity<String> responseEntity;
        RestTemplate restTemplate = new RestTemplate();

        // works but fails without workaround because target service doesn't 
accept available content-type header (which is null however) on GET request
        responseEntity = restTemplate.exchange(requestEntity, String.class);
} {code}

> Content-Type header created with collection containing "null" value
> -------------------------------------------------------------------
>
>                 Key: CXF-8812
>                 URL: https://issues.apache.org/jira/browse/CXF-8812
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 3.5.5
>         Environment: OpenJDK 1.8.0_352
> CentOS 7
> Tomcat 8.5.57
> Spring 4.3.30.RELEASE
> CXF 3.5.5
>            Reporter: Erich Mauerböck
>            Assignee: Andriy Redko
>            Priority: Major
>         Attachments: image-2023-01-22-13-04-32-164.png
>
>
> I have a simple REST web service method, deployed in tomcat, as follows:
> {code:java}
> @GET
> public void someMethod(@Context HttpHeaders httpHeaders) {
> ...
> } {code}
> When calling it, I get the following injected:
> !image-2023-01-22-13-04-32-164.png!
> I am expecting to get NO "Content-Type" header at all, because it hasn't been 
> sent (verified by tcp dump).
> Btw. httpHeaders.getMediaType() works as expected (returning null) because it 
> can cope with this situation.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to