Have you tried setting the content type directly on your Response?
On Wed, Mar 27, 2019 at 5:44 AM Lange Gunter (ID SWS) <
[email protected]> wrote:

> Hi
>
> Can anybody help me?
>
> We are using apache-cxf-3.3.1.
>
> I want to intercept JSON Mapping Errors. It goes well but the response’s
> Content-Type is always XML.
>
> My provider method is:
>
> public class JsonMappingExceptionMapper implements
> ExceptionMapper<JsonMappingException> {
>
>     private final HashMap<String, ResponsePayload> payloads =
>
> Messages.INSTANCE.getResponsePayloads(this.getClass().getSimpleName());
>
>     @Override
>     public Response toResponse(JsonMappingException ex) {
>
>         ResponsePayload payload =
> payloads.get("mapping_error").format(ex.getMessage());
>         return
> Response.status(Response.Status.BAD_REQUEST).entity(payload).build();
>     }
> }
>
>
> The Restful Web Service is called with Header Parameter: -H
> "Content-Type:application/json;charset=UTF-8" -H "Accept:application/json"
>
> As I see in ExceptionUtils.java (line 99)  :
> JAXRSUtils.setMessageContentType(currentMessage, response) the
> currentMessage contains "Content-Type" -> "application/json;charset=UTF-8"
>
> But then in setMessageContentType()
>
>         if (response != null) {
>             Object ct =
> response.getMetadata().getFirst(HttpHeaders.CONTENT_TYPE);
>
> this information about the currentMessage.Content-Type is not taken into
> account.
>
> How I'm able to reply with a JSON Response?
>
> Thanks in advanced.
>
> Best regards
> Gunter
>
>

Reply via email to