Search code examples
javahttpresponse

ResponseEntity is not shown as it should


I am trying to get the correct statusCode from a response entity, but when I make the request with insomnia, the ResponseEntity is shown as an object but the actual statusCode its always 200, even when y manually set it to be a 400.

This is my code:

@GET
@Path("/tipoArchivos/{id}")
public ResponseEntity<?> getTipoArchivos(@PathParam("id")String idProceso) throws Exception{
    Optional<List<TipoArchivoDTO>> respuesta = Optional.ofNullable(tramiteInt.getAttachmentTypes(idProceso));
    if (!respuesta.isPresent()) {
        HttpHeaders responseHeaders = new HttpHeaders();
        responseHeaders.set("#status#", "400");
        ResponseEntity<String> respuesta1 = new ResponseEntity<String>("El codigo del proceso solo debe contener tres caracteres en mayuscula", responseHeaders, HttpStatus.BAD_REQUEST);
        return respuesta1;
    }
    return new ResponseEntity<List<TipoArchivoDTO>>(respuesta.get(), HttpStatus.OK);
}

And this is what i get: ActualResponse what im doing wrong here? thanks for your time


Solution

  • I don't think ResponseEntity works with Dropwizard (I assume that's what you're using based on the annotations) since that comes from Spring - org.springframework.http.ResponseEntity. For Dropwizard you should use: javax.ws.rs.core.Response