Ickhyun Kwon
Ickhyun Kwon

Reputation: 1703

jersey why reponse 404 instead of validation message when I missing parameter

@Path("report/v1")
public class ReportService {

    @Path("report")
    @GET
    @Produces("application/json")
    public ReportResponse report(@NotNull @QueryParam("startDate") String startDate,
                                    @NotNull @QueryParam("endDate") String endDate,
                                    @NotNull(message = "{param.invalid.periodType}") @QueryParam("periodType") String periodType) {
        PublisherResponse res = new PublisherResponse();

I called method like below..

http://localhost:8080/report/v1/report?startDate=20140101&endDate=20140505

I expected validation error because periodType is missing. but returned 404.

How can i fix?

Upvotes: 0

Views: 749

Answers (1)

Paul Samsotha
Paul Samsotha

Reputation: 209052

I'm going to make some assumptions.

  • Assumption 1: You're using Jersey 2.x with it's Bean Validation support
  • Assumption 2: You're actually getting a 400 Bad Request, and not a 404 Not Found

The default behavior for the validation feature is to send a 400 Bad Request (that doesn't get mapped to a response). If we want Jersey to send it's validation error responses, we need to set the following property to true

property(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, true);

See more at Configuring Bean Validation Support

Upvotes: 1

Related Questions