protected void run() {
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setResourceClasses(BookStoreWithValidation.class);
sf.setResourceProvider(BookStoreWithValidation.class,
new SingletonResourceProvider(new BookStoreWithValidation()));
sf.setProvider(new ValidationExceptionMapper() {
@Override
public Response toResponse(ValidationException exception) {
Response r = super.toResponse(exception);
return JAXRSUtils.toResponseBuilder(
r.getStatus()).type("application/xml").entity(new Book("Validation", 123L)).build();
}
});
sf.setAddress("http://localhost:" + PORT + "/");
BeanValidationInInterceptor in = new JAXRSBeanValidationInInterceptor();
in.setProvider(new BeanValidationProvider(new JAXRSParameterNameProvider()));
sf.setInInterceptors(Arrays.< Interceptor< ? extends Message > >asList(
in));
sf.setOutInterceptors(Arrays.< Interceptor< ? extends Message > >asList(
new JAXRSBeanValidationOutInterceptor()));
sf.create();
}
@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> classes = new HashSet<Class<?>>();
classes.add(AuthenticationResource.class);
classes.add(InvitationResource.class);
classes.add(QuestionnaireDefinitionResource.class);
classes.add(QuestionnaireResource.class);
classes.add(UserResource.class);
classes.add(ResearchResource.class);
classes.add(ApiListingResourceJSON.class);
classes.add(ResourceListingProvider.class);
classes.add(ApiDeclarationProvider.class);
classes.add(JacksonContextResolver.class);
classes.add(JacksonJsonProvider.class);
classes.add(LoginShiroFilter.class);
classes.add(LogoutShiroFilter.class);
classes.add(ShiroExceptionHandler.class);
classes.add(AccountNotFoundExceptionHandler.class);
classes.add(DefaultExceptionHandler.class);
// Validation feature
classes.add(ValidationExceptionMapper.class);
classes.add(JAXRSBeanValidationInInterceptor.class);
classes.add(JAXRSBeanValidationOutInterceptor.class);
return classes;
}