Jersey returns 500 when trying to return an XML response

前端 未结 4 1198
闹比i
闹比i 2021-01-20 03:56

I\'m trying to create my own RESTful WS application using Jersey 2.12 based from this article. I want to return an XML representation of a class depending on the id been pas

4条回答
  •  别那么骄傲
    2021-01-20 04:30

    Stuff below is not the answer, but will probably help Johne to find out, whats up.

    Out of the comments I've extract, that the main problem is, that you don't have any noticeable debug output in your console. So you are not able to find the issue by yourself, rather than give us some logs which would help to find out, what the exact problem could be.

    Therefore pls implement an ExceptionMapper first, which will force console output of the stacktrace:

    Example:

    import javax.ws.rs.core.MediaType;
    import javax.ws.rs.core.Response;
    import javax.ws.rs.core.Response.Status;
    import javax.ws.rs.ext.ExceptionMapper;
    import javax.ws.rs.ext.Provider;
    
    @Provider
    public class HelpMeExceptionMapper implements ExceptionMapper {
    
        @Override
        public Response toResponse(Exception e) {
            e.printStackTrace();
            return Response
                        .status(Status.INTERNAL_SERVER_ERROR)
                        .type(MediaType.APPLICATION_JSON)
                        .entity(e.getCause())
                        .build();
        }
    
    }
    

    The ExceptionMapper has to be in a subpackage of your resource-config/providers path test.services:

    
        jersey.config.server.provider.packages
        test.services
    
    

    As i didn't implement your/vogellas code i would like to recommend you, to debug this step by step to find out whats up.

    I reckon, that you miss to import something. But who knows ...

    Have a nice day ...

提交回复
热议问题