Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java:Tomcat 9 status code 200 but response message null

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

like image 410
Athul Sukumaran Avatar asked Nov 10 '16 07:11

Athul Sukumaran


1 Answers

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

like image 200
Nishit Shah Avatar answered Sep 20 '22 00:09

Nishit Shah