Jin Kwon
Jin Kwon

Reputation: 22027

How can I test a MessageBodyWriter for a List<Some>?

I have a JAX-RS resource method.

@GET
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public List<Some> list() {

    final List<Some> list = get();

    // list and each elements are ok.

    return list;
}

The problem is that application/xml generates an 500 without any specific server(tomcat) log.

application/json works fine.

I check JAXB-marshaller for every element in list.

How can I debug this? How can I test any MessageBodyWriter for List<Some>?

UPDATE

The root cause of this problem (500 without a error log) is a wrongly JAXB-annotated class.

I created an ExceptionMapper<Exception> as @peeskillet suggested.

@Provider
public class MyExceptionMapper implements ExceptionMapper<Exception> {
    @Override
    public Response toResponse(final Exception exception) {
        exception.printStackTrace(System.err);
        return Response.serverError().build();
    }
}

Then I could see what error JAXB made. I still don't understand why any JAXB-error is not reported.

Upvotes: 0

Views: 139

Answers (1)

Paul Samsotha
Paul Samsotha

Reputation: 209092

"How can I debug this?"

Sometimes when errors/exceptions aren't being logged, I'll create an

ExceptionMapper<Throwable or Exception> 

and just print the stack trace. If the exception is being thrown in the JAX-RS context, it should go through the mapper.

Upvotes: 1

Related Questions