Tag: dropwizard

覆盖DropWizard ConstraintViolation消息

所以我想通过DropWizard资源更改用于validation模型的validation消息。 我正在使用java beanvalidation注释。 例如,这是我要validation的字段之一: @NotEmpty(message = “Password must not be empty.”) 我可以使用validation器按预期测试它的工作原理。 但是,当我使用DropWizard对资源进行validation时,它会为该消息添加一些额外的内容。 我看到的是这个 – password Password must not be empty. (was null) password Password must not be empty. (was null)我发现这里的代码 – https://github.com/dropwizard/dropwizard/blob/master/dropwizard-validation/src/main/java/io/dropwizard/validation/ConstraintViolations。 java的 特别是这种方法 – public static String format(ConstraintViolation v) { if (v.getConstraintDescriptor().getAnnotation() instanceof ValidationMethod) { final ImmutableList nodes = ImmutableList.copyOf(v.getPropertyPath()); final ImmutableList usefulNodes […]

如何在Dropwizard中进行资源的基本身份validation

我相信我有基本的身份validation工作,但我不知道如何保护资源,以便只有在用户登录时才能访问它们。 public class SimpleAuthenticator implements Authenticator { UserDAO userDao; public SimpleAuthenticator(UserDAO userDao) {this.userDao = userDao;} @Override public Optional authenticate(BasicCredentials credentials) throws AuthenticationException { User user = this.userDao.getUserByName(credentials.getUsername()); if (user!=null && user.getName().equalsIgnoreCase(credentials.getUsername()) && BCrypt.checkpw(credentials.getPassword(), user.getPwhash())) { return Optional.of(new User(credentials.getUsername())); } return Optional.absent(); } } 我的Signin资源是这样的: @Path(“/myapp”) @Produces(MediaType.APPLICATION_JSON) public class UserResource { @GET @Path(“/signin”) public User signin(@Auth […]

Spring – 以编程方式生成一组bean

我有一个Dropwizard应用程序,需要为配置列表中的每个配置生成十几个bean。 健康检查,石英调度等等。 像这样的东西: @Component class MyModule { @Inject private MyConfiguration configuration; @Bean @Lazy public QuartzModule quartzModule() { return new QuartzModule(quartzConfiguration()); } @Bean @Lazy public QuartzConfiguration quartzConfiguration() { return this.configuration.getQuartzConfiguration(); } @Bean @Lazy public HealthCheck healthCheck() throws SchedulerException { return this.quartzModule().quartzHealthCheck(); } } 我有多个MyConfiguration实例都需要像这样的bean。 现在我必须复制并粘贴这些定义,并为每个新配置重命名它们。 我可以以某种方式迭代我的配置类并为每个类生成一组bean定义吗? 我可以使用子类化解决方案或类型安全的任何东西,而不会让我复制并粘贴相同的代码,并在我必须添加新服务时重命名方法。 编辑:我应该补充一点,我有其他依赖这些bean的组件(例如,他们注入Collection 。)

DropWizard Auth by Example

我试图了解DropWizard中的身份validation和授权是如何工作的。 我已经阅读了他们的auth指南以及GitHub上的dropwizard-security项目,但我觉得我仍然缺少一些重要的概念。 public class SimpleCredential { private String password; public SimpleCredential(String password) { super(); this.password = password; } } public class SimplePrincipal { pivate String username; public SimplePrincipal(String username) { super(); this.username = username; } } public class SimpleAuthenticator implements Authenticator { @Override public Optional authenticate(SimpleCredential credential) throws AuthenticationException { if(!”12345″.equals(credential.getPassword())) { throw new AuthenticationException(“Sign […]

传递自定义类型查询参数

我如何接受自定义类型查询参数? public String detail(@QueryParam(“request”) final MYRequest request) { 上面的行在启动服务器时出错 jersey.server.model.ModelValidationException: Validation of the application resource model has failed during application initialization.

Dropwizard不会将自定义记录器记录到文件中

我有一个dropwizard应用程序,我将logger appender配置为文件,如下所示: logging: level: INFO loggers: “mylogger”: INFO “com.path.to.class”: INFO appenders: – type: file currentLogFilename: .logs/mylogs.log archivedLogFilenamePattern: .logs/archive.%d.log.gz archivedFileCount: 14 并且,在我的应用中创建了记录器: import org.slf4j.Logger; import org.slf4j.LoggerFactory; private final Logger OpLogger = LoggerFactory.getLogger(“mylogger”); (and) private final Logger ClassLogger = LoggerFactory.getLogger(pathToClass.class); 在main()中进行一些测试记录: OpLogger.info(“test 1”); ClassLogger.info(“test 2); 应用程序启动并运行没有问题; 但我没有得到任何日志(除了Jetty访问日志,当然,正确打印到mylogs.log),无论是在stdout还是在mylogs.log文件中。 相反,如果我删除configuration.yml中的记录器配置,我会将所有日志打印到stdout。 也许这是dropwizard的问题,或者我必须在configuration.yml中添加一些东西? 我正在使用Dropwizard 0.8.0