Return-Path: X-Original-To: apmail-cxf-issues-archive@www.apache.org Delivered-To: apmail-cxf-issues-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id EC274107B2 for ; Fri, 5 Jun 2015 10:33:05 +0000 (UTC) Received: (qmail 27527 invoked by uid 500); 5 Jun 2015 10:33:00 -0000 Delivered-To: apmail-cxf-issues-archive@cxf.apache.org Received: (qmail 27486 invoked by uid 500); 5 Jun 2015 10:33:00 -0000 Mailing-List: contact issues-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list issues@cxf.apache.org Received: (qmail 27422 invoked by uid 99); 5 Jun 2015 10:33:00 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 05 Jun 2015 10:33:00 +0000 Date: Fri, 5 Jun 2015 10:33:00 +0000 (UTC) From: "Serhiy Yakovyn (JIRA)" To: issues@cxf.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Comment Edited] (CXF-6437) @Produces has no effect if the annotated method returns void when using ClientProxy MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/CXF-6437?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14574277#comment-14574277 ] Serhiy Yakovyn edited comment on CXF-6437 at 6/5/15 10:32 AM: -------------------------------------------------------------- My workaround of this limitation was to set inheritHeaders in the factory method creating the proxy client and then set Accept header to application/json: {code} final JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); ... bean.setInheritHeaders(true); ... RestApiClient client = bean.create(RestApiClient.class); ... WebClient.client(client).header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON); ... return client; {code} Thanks for the proposed solutions that caused me to think of some other alternatives. was (Author: syakovyn): My workaround of this limitation was to set inheritHeaders in the factory method creating the proxy client and then set Accept header to application/json: {code} final JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); ... bean.setInheritHeaders(true); ... RestApiClient client = bean.create(RestApiClient.class); ... WebClient.client(client).header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON); {code} Thanks for the proposed solutions that caused me to think of some other alternatives. > @Produces has no effect if the annotated method returns void when using ClientProxy > ----------------------------------------------------------------------------------- > > Key: CXF-6437 > URL: https://issues.apache.org/jira/browse/CXF-6437 > Project: CXF > Issue Type: Wish > Components: JAX-RS > Affects Versions: 2.7.16 > Reporter: Serhiy Yakovyn > Assignee: Sergey Beryozkin > Fix For: Invalid > > > @Produces has no effect on CXF if the annotated method returns void. The "accept" is set to default "\*/\*". > Though it looks right for successful calls of the method, it starts causing issues when there are different type of responses in case of an error. > For example: > {code} > @PUT > @Path("{id}/info") > @Consumes(MediaType.APPLICATION_JSON) > @Produces(MediaType.APPLICATION_JSON) > void setInfo(@PathParam("id") String documentId, StorageObject newInfo); > {code} > No response is expected on success. > However when the passed StorageObject contains some invalid data the server responds with "HTTP/1.1 400 Bad Request" and the body contains detailed information about which fields contain invalid values. > That information can be send either as JSON or as XML data, but I cannot make CXF to specify which format I want the error to be sent in. > The issue is in > org.apache.cxf.jaxrs.client.ClientProxyImpl.setRequestHeaders(MultivaluedMap, OperationResourceInfo, boolean, Class, Class) > method, namely in lines 359-360 (cxf-rt-frontend-jaxrs-2.7.16.jar): > {code} > } else if (responseClass == Void.class || responseClass == Void.TYPE) { > accepts = Collections.singletonList(MediaType.WILDCARD_TYPE); > {code} > which I would like to remove. > As a workaround I'm using my own Void class not to satisfy the above part of the if statement -- This message was sent by Atlassian JIRA (v6.3.4#6332)