cxf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sergey Beryozkin (JIRA)" <>
Subject [jira] [Commented] (CXF-6437) @Produces has no effect if the annotated method returns void when using ClientProxy
Date Thu, 04 Jun 2015 09:33:38 GMT


Sergey Beryozkin commented on CXF-6437:

Thanks for marking this issue as a Wish because it is indeed not a bug and it works as expected.

@Produces on the main method is not relevant if 'void' is returned and if you need to return
the same object with the error status then the exception mapper needs to set up Content-Type
IMHO it would be cleaner to avoid keeping the same invocation path for error and not error
responses, simply introduce say StorageObjectError, return its representation with 401.
If  it can be either XML or JSON then check the input Content-Type (with the injected HttpHeaders)
and set it on the response.
Next register ResponseExceptionProvider with the proxy (given that you use a proxy API and
a void method) and return BadRequestException from it, catch the exception and do ex.getResponse().readEntity(StorageObjectError.class).
If you do prefer to keep the current style then change 'void' to 'Response'

> @Produces has no effect if the annotated method returns void when using ClientProxy
> -----------------------------------------------------------------------------------
>                 Key: CXF-6437
>                 URL:
>             Project: CXF
>          Issue Type: Wish
>          Components: JAX-RS
>    Affects Versions: 2.7.16
>            Reporter: Serhiy Yakovyn
> @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<String,
String>, 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

View raw message