I followed this post and created the first custom injection provider, LocaleProvider , which scans an HTTP request for the Accept-Language header. It works fine if I use it in a Jersey resource:
@Path("test") @GET public Response getStatus(@Context Locale locale) { log.finer("Locale: "+ locale); Response response = Response .noContent() .build(); return response; }
But when I want to use it in ExceptionMapper , I do not know how to enter the locale. I tried to annotate it as a member variable:
public class MyExceptionMapper implements ExceptionMapper<MyException> { @Context private Locale locale; @Override public Response toResponse(MyException ex) { ... } }
but this fails during deployment:
The following errors and warnings have been detected with resource and/or provider classes: SEVERE: Missing dependency for field: private java.util.Locale com.package.MyExceptionMapper.locale
Other things, such as UriInfo or HttpServletRequest , can be entered this way. How to access my own LocaleProvider?
FYI is on Glassfish 3.1.1 using Jersey 1.8.
Hank
source share