I have an http client that sends request to a RESTful web service and receives a response. It was working successfully when deployed in Tomcat 8. But when I tried to deploy the same client and server in Tomcat versions 8.5 and above, the server receives response code as 200 but response message is null instead of OK.
Below is my client code snippet
httpclient = HttpClientBuilder.create().build();
postrequest.setEntity(new UrlEncodedFormEntity(urlParameters));
HttpResponse response = httpclient.execute(postrequest);
HttpEntity entity = response.getEntity();
System.out.println("Response from server ");
System.out.println(response.getStatusLine().getStatusCode());
System.out.println(response.getStatusLine().getReasonPhrase());
and my server code snippet for response is
@POST
@Path("/download/{filename}")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response getFile(@PathParam("filename") String file)
{
try
{
File downloadfile = new File("/home/upload/"+file);
ResponseBuilder response = Response.ok((Object) downloadfile);
response.header("Content-Disposition", downloadfile.getName());
return response.build();
}
catch(Exception e)
{
logger.error("Error is : "+e);
e.printStackTrace();
}
}
The output I get is just
Response from server
200
It should actually be
Response from server
200
OK
As per the reported issue in tomcat, they have stopped sending "Reason Phrase" from tomcat 8.5 version onward.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60183
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With