Java - Apache CXF: return response code(HTTP status code)

less than 1 minute read

1
2
3
4
5
6
7
import javax.ws.rs.core.Response;
    Entity entity = service.getById(uuid);
    if(entity == null) {
        return Response.status(Response.Status.NOT_FOUND).entity("Entity not found for UUID: " + uuid).build();
    }
    String json = //convert entity to json
    return Response.ok(json, MediaType.APPLICATION_JSON).build();