MultiException when custom jersey param throws exception

1,207 views
Skip to first unread message

Srikanth Chikkulapelly

unread,
Apr 29, 2015, 2:06:45 AM4/29/15
to dropwiz...@googlegroups.com
Here is my custom java 8 LocalDateTime param for @QueryParam annotation to convert. It converts YYYY-MM-DD format date to LocalDateTime (YYYY-MM-DD 00:00:00).



 

public class LocalDateTimeParam extends AbstractParam<LocalDateTime> {

     
public LocalDateTimeParam(String input) {
       
super(input);
   
}


   
@Override
   
protected LocalDateTime parse(String input) throws Exception {
       
return LocalDateTime.of(LocalDate.parse(input), LocalTime.MIDNIGHT);
   
}

   
@Override
   
protected Response error(String input, Exception e) {
       
// returns valid Response object here.
   
}
}


The following MyBean is injected into resource method using @BeanParam annotation. Resource class is in RequestScoped lifecycle.

public class MyBean {

    @NotNull(message = "startDate must be specified")    
  @QueryParam("startDate")    
  private LocalDateTimeParam startDate;

}

When I send GET request with startDate query param it works great if the date format is valid (YYYY-MM-DD). However when I pass invalid date format, I expected it to return Response from LocalDateTimeParam. I received MultiException from HK2. I fixed this by having a custom exception mapper that returns WebApplicationException response. But this doesn't look right. Has anyone faced this before?


Here is parts of stacktrace.

org.glassfish.jersey.internal.Errors: The following warnings have been detected: WARNING: Unknown HK2 failure detected:

MultiException stack 1 of 3

javax.ws.rs.WebApplicationException: HTTP 400 Bad Request

at io.dropwizard.jersey.params.AbstractParam.<init>(AbstractParam.java:28)

at com.fun.personal.finance.params.LocalDateTimeParam.<init>(LocalDateTimeParam.java:20)

....

....

MultiException stack 2 of 3

java.lang.IllegalArgumentException: While attempting to resolve the dependencies of com.fun.personal.finance.params.PaginationFilters errors were found

at org.jvnet.hk2.internal.ClazzCreator.resolveAllDependencies(ClazzCreator.java:249)

at org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:360)

at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:471)

at org.glassfish.jersey.process.internal.RequestScope.findOrCreate(RequestScope.java:162)

...

...

MultiException stack 3 of 3

java.lang.IllegalStateException: Unable to perform operation: resolve on com.fun.personal.finance.params.PaginationFilters

at org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:389)

at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:471)

at org.glassfish.jersey.process.internal.RequestScope.findOrCreate(RequestScope.java:162)


Srikanth Chikkulapelly

unread,
May 4, 2015, 3:02:20 PM5/4/15
to dropwiz...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages