cxf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Philippe Larouche (JIRA)" <>
Subject [jira] [Commented] (CXF-5795) Reading the entity from a Response with 202 - Accepted causes NullPointerException
Date Wed, 13 Aug 2014 13:53:12 GMT


Philippe Larouche commented on CXF-5795:

Hi Sergey,

I confirm I can read the data with the HttpURLConnection.  Here is how I called the WS, please
note that I'm using a post call (I think it's working when using get):

            ObjectMapper mapper = new ObjectMapper();
	    String jsonLot = mapper.writeValueAsString(lot);
	    // Connect to
	    URL url = new URL("http://localhost:9000/api/encaissement/1.0/creerlot");
	    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
	    connection.setRequestProperty("Content-Type", "application/json");
	    connection.setRequestProperty("Content-Length",  String.valueOf(jsonLot.length()));
	    // Write data
	    OutputStream os = connection.getOutputStream();
	    // Read response
	    StringBuilder responseSB = new StringBuilder();
	    BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
	    String line;
	    while ( (line = br.readLine()) != null)
	    // Close streams

At the end, responseSB contains the expected json string.

> Reading the entity from a Response with 202 - Accepted causes NullPointerException
> ----------------------------------------------------------------------------------
>                 Key: CXF-5795
>                 URL:
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.7.11
>         Environment: Apache CXF 2.7.11
>            Reporter: Daniel Peder Dahlsveen
>            Assignee: Sergey Beryozkin
>             Fix For: 2.7.12, 3.0.1
> The entity of a Response with HTTP status code 202 - Accepted is null. This causes a
NullPointerException when calling response.readEntity(). Furthermore, this bug seems to only
occur when using the JAXRSClientFactory, and it was introduced in CXF 2.7.11.
> The stacktrace is of the NullPointerException:
> java.lang.NullPointerException
> 	at org.apache.cxf.jaxrs.impl.ResponseImpl.doReadEntity(
> 	at org.apache.cxf.jaxrs.impl.ResponseImpl.readEntity(
> 	at org.apache.cxf.jaxrs.impl.ResponseImpl.readEntity(
> To recreate the bug do the following:
> Create a REST service that returns a 202 - Accepted with a non-null entity. In our case,
the service was for HTTP POST.
> Create a unit test that tests the service by creating a client with the JAXRSClientFactory
and then reads the entity from the response. 
> Both return Response.accepted(entity).build(); and return Response.status(Response.Status.ACCEPTED).entity(entity).build();
causes the bug.

This message was sent by Atlassian JIRA

View raw message