HTTP 500 Internal Server Error in simple REST based program. Confused in GET and POST while receiving/sending response from server

后端 未结 2 1856
南旧
南旧 2020-11-28 12:06

I am implementing a basic client server architecture using REST services for the first time. This time I making it more complicated with including some more classes and serv

相关标签:
2条回答
  • 2020-11-28 12:45

    One way to debug things like this is to create a simple ExceptionMapper to catch exceptions that are not mapped. When there is no mapper, often the exception will bubble up to the container level, which just gives us generic 500 server error (which most of the time is of little help).

    @Provider
    public class DebugExceptionMapper implements ExceptionMapper<Exception> {
    
        @Override
        public Response toResponse(Exception exception) {
            exception.printStackTrace();
            return Response.serverError().entity(exception.getMessage()).build();
        } 
    }
    

    Then just register the mapper. When running a simple test with your ImageProgress class, when the exception is thrown, the stacktrace gets printed, and you can see the exception message

    ...ImageProgress does not have a no-arg default constructor

    So just add a default (no-arg constructor) to the ImageProgress class. This is a requirement with JAXB models.

    0 讨论(0)
  • 2020-11-28 12:54

    Add this line of code before class HPCResponse:

    @XmlAccessorType(XmlAccessType.FIELD)
    
    0 讨论(0)
提交回复
热议问题