标签: dropwizard

通过 JDBI dropwizard 使用自定义 where 条件

我正在尝试使用 dropwizard 探索 JDBI,我的客户代码如下。

public interface UserDao {
@SqlQuery("SELECT FROM `t_user` :cond")
@Mapper(UserMapper.class)
List<User> fetch(@Bind("cond") String cond);
}
Run Code Online (Sandbox Code Playgroud)

并尝试使用以下代码进行调用

Application.getJdbi().onDemand(UserDao.class).fetch("where logon_id="+p.getEmail()+"'");
Run Code Online (Sandbox Code Playgroud)

并得到以下问题

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM `t_user` 'where logon_id=sanjaypatel2525@gmail.com\''' at line 1
Run Code Online (Sandbox Code Playgroud)

我遇到了引号问题,因为它是作为字符串传递的。通过这种方式,我试图为所有查询实现通用的 where 子句代码。我的问题是 1. 如何解决这个问题。2. 这是这样的代码的正确方法吗?或者我们可以使用准备好的语句。如果是的话怎么办。

非常感谢提前:)

java sql jdbi dropwizard

2
推荐指数
1
解决办法
3127
查看次数

两个具有相似 @Path 注释的资源类上的 Jersey 404

我有一个 RESTful Web 服务,使用 Drop Wizard 0.8.5 和 Jersey 2.21。我有一个资源类,其注释为:

@Path("/mysite/somepath")

这个类包含各种方法,例如@GETs、@PUTS等,都工作得很好。

现在,我有另一个用@Path("/mysite"). 在此资源类中,我需要添加一些用路径注释的方法,如下所示:

@Path("/somepath/dothis")
@Path("/somepath/dothat")
Run Code Online (Sandbox Code Playgroud)

资源类都注册得很好。然而,当我调用第二个类时,我得到了 404,因为泽西岛似乎正在我的第一个类中寻找这些方法。除了更改我的 @Path 注释以避免这种命名冲突之外,还有其他方法可以解决此问题吗?

java rest jersey dropwizard jersey-2.0

2
推荐指数
1
解决办法
1001
查看次数

如何在 Dropwizard 中将 HTTP 请求记录到文件中?

我的 Dropwizard(版本 1.3.8)应用程序将 HTTP 请求记录到文件中时遇到问题。我按照 Dropwizard 的文档配置 YAML 文件,我的config.yml外观如下:

\n
logging:\n  level: INFO\n  loggers:\n    com.nikolas.master_thesis: DEBUG\n\n  appenders:\n    - type: file\n      currentLogFilename: /home/nikola/Documents/DWApp-LOGs/DW-Bookshop_LOG.log\n      threshold: ALL\n      queueSize: 512\n      archive: true\n      archivedLogFilenamePattern: /home/nikola/Documents/DWApp-LOGs/DW-Bookshop_LOG-%d.log\n      archivedFileCount: 5\n      timeZone: UTC\n      logFormat: "%-5p [%d{ISO8601,UTC}] %c: %m%n%rEx"\n      # logFormat: "%h %l %u %t \\"%r\\" %>s %b \\"%{Referer}i\\" \\"%{User-agent}i\\"" combined\n#      logFormat: \xe2\x80\x9c%h %l %u %t \xe2\x80\x9c%r\xe2\x80\x9c %s %b \xe2\x80\x9c%{Referer}i\xe2\x80\x9c \xe2\x80\x9c%{User-Agent}i\xe2\x80\x9c\xe2\x80\x9c combined\n#      logFormat: \'%h %l %u %t \'%r\' %\\\\>s %b \'%{Referer}i\' \'%{User-Agent}i\'\'\n#      logFormat: "%d{HH:mm:ss.SSS} [%thread] …
Run Code Online (Sandbox Code Playgroud)

java logging yaml dropwizard

2
推荐指数
1
解决办法
2713
查看次数

运行部署在heroku上的gradle dropwizard应用程序时无法访问jar

我正在尝试在heroku上部署一个无法启动的dropwizard应用程序.它使用"gradle run server config.yml"在本地工作正常

我正在使用gradle进行构建,当我推送到heroku时,构建成功. 我的gradle阶段任务取决于清洁和jar(胖罐创建)

我的Procfile有:

web:java $ JAVA_OPTS -jar dropwizard-app/build/libs/dropwizard-app.jar server dropwizard-app/config.yml

以上失败,"无法访问jarfile dropwizard-app/build/libs/dropwizard-app.jar"

我尝试过失败了

web:java $ JAVA_OPTS -jar build/libs/dropwizard-app.jar server config.yml

我也尝试使用gradle命令执行

web:gradle run server config.yml

这给出了错误 bash:找不到gradle命令

我的gradle任务如下:

    task stage(dependsOn: ['clean', 'jar'])

    run {
        args 'server', 'config.yml'
    }

    jar {
        manifest {
            attributes  'Title': 'dropwizard-app', 'Version': version,'Main-Class':  mainClassName
        }
        archiveName 'dropwizard-app'
        dependsOn configurations.runtime
        from {
            configurations.compile.collect {it.isDirectory()? it: zipTree(it)}
        }
    }
Run Code Online (Sandbox Code Playgroud)

我错过了什么吗?如何启动我的dropwizard应用程序?

heroku dropwizard

1
推荐指数
1
解决办法
1308
查看次数

如何只返回类的某些属性作为JSON

我正在使用drop wizard,它使用Jackson作为JSON返回类.

如何只返回类中的某些属性作为JSON而不是返回所有属性.

例如用户POJO

public class User {
  private int id;
  private String username;
  private String password
  //getter setters
}
Run Code Online (Sandbox Code Playgroud)

signin路径:

@GET
@Path("/signin")
public User signin(@Auth User user) {
    return user;
}
Run Code Online (Sandbox Code Playgroud)

返回{"password":null,"id":0,"username":"foobar"}我怎么才能返回{"username":"foobar"}

java json jackson dropwizard

1
推荐指数
1
解决办法
249
查看次数

使用Dropwizard 0.7.1设置hibernate的问题."无法在0.7.1上创建一个hibernate会话"

我无法在0.7.1中创建hibernate会话.我知道我没有正确创建hibernate会话.但是无法弄清楚我哪里出错了.任何帮助将不胜感激.

ERROR:
! org.hibernate.HibernateException: No session currently bound to execution context
! at org.hibernate.context.internal.ManagedSessionContext.currentSession(ManagedSessionContext.java:75) ~[userengine-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
! at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1014) ~[userengine-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
Run Code Online (Sandbox Code Playgroud)

应用程序文件:

public class UserEngineApplication extends Application<UserEngineConfiguration>{

public static void main(String[] args) throws Exception {
    new UserEngineApplication().run(args);
}

private final HibernateBundle<UserEngineConfiguration> hibernateBundle =
        new HibernateBundle<UserEngineConfiguration>(Persons.class) {
            @Override
            public DataSourceFactory getDataSourceFactory (UserEngineConfiguration configuration) 
            {
                return configuration.getDataSourceFactory();
            }
};

@Override
public void initialize(Bootstrap<UserEngineConfiguration> bootstrap) {
    bootstrap.addBundle(hibernateBundle);
}

@Override
public void run(UserEngineConfiguration configuration, Environment environment) throws Exception {

    final PersonDAO personsdao = new PersonDAO(hibernateBundle.getSessionFactory());
        environment.jersey().register(new …
Run Code Online (Sandbox Code Playgroud)

java hibernate dropwizard

1
推荐指数
1
解决办法
1016
查看次数

我们如何使用dropwizard web serivce实现删除操作

我阅读了很多博客和教程,但我没有在dropwizard Web服务中找到删除操作.

这是我的代码:

public class PersonDAO extends AbstractDAO<Person> {
    public PersonDAO(SessionFactory factory) {
        super(factory);
    }
    public Optional<Person> findById(Long id) {
        return Optional.fromNullable(get(id));
    }

    public Person create(Person person) {
        return persist(person);
    }

    public List<Person> findAll() {
        return list(namedQuery("com.example.helloworld.core.Person.findAll"));
    }
    //here i want to create delete method
}
Run Code Online (Sandbox Code Playgroud)

这是我的服务文件:

@Path("/people")
@Produces(MediaType.APPLICATION_JSON)
public class PeopleResource {

    private final PersonDAO peopleDAO;

    public PeopleResource(PersonDAO peopleDAO) {
        this.peopleDAO = peopleDAO;
    }

    @POST
    @UnitOfWork
    public Person createPerson(Person person) {
        return peopleDAO.create(person);
    }

    @GET
    @UnitOfWork
    public List<Person> listPeople() …
Run Code Online (Sandbox Code Playgroud)

java jersey dropwizard

1
推荐指数
1
解决办法
2391
查看次数

使用Dropwizard和JDBI查询具有多个模式的数据库?

我正在使用DropWizard(使用JDBI)构建Java Rest API,我的要求是我需要使用相同的应用程序查询多个MySQL模式.它基本上是一个包含多个模式的AWS MySQL实例 - 每个客户端一个模式.

我需要的是一种机制,它知道根据请求查询哪个"模式" - IE:请求属于哪个客户端.

我知道如何创建DataSource,DAO等(使用本教程:https://dropwizard.github.io/dropwizard/manual/jdbi.html),但不知道如何查询多个模式.

有任何想法吗?

java mysql multiple-schema jdbi dropwizard

1
推荐指数
1
解决办法
2698
查看次数

如何使用带有dropwizard的自定义验证器?

我有一个由其他人编写的REST api,其中处理对特定url的请求的方法接受从路径参数填充的一堆参数.

@POST
@Path("/{classid}/{studentid}/details")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@SuppressWarnings("unchecked")


public Response processFile(@FormDataParam("sourceFile") InputStream aStream, @PathParam("classid") String classId, @PathParam("studentid")  String studentId, @Context HttpServletRequest httpRequest) {

// Code to do stuff and return a response
}
Run Code Online (Sandbox Code Playgroud)

写这篇文章的人使用了DropWizard,我之前没有使用它的经验.我的任务是通过将studentId字段与db中的值进行比较来验证studentId字段.这将是非常简单的,但我被告知使用自定义验证器.我对编写注释很新,但经过多次挖掘写了这样的注释,

@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Constraint(validatedBy = StudentIdValidator.StudentIdValidation.class)

public @interface StudentIdValidator {

    String message() default "{Invalid Id}";

      Class<?>[] groups() default {};

      Class<? extends Payload>[] payload() default {};


      class StudentIdValidation implements ConstraintValidator<StudentIdValidator, String> {

        @Override
        public void initialize(StudentIdValidator constraintAnnotation) {
            System.out.println("Annotation initialize !!!!!!!!!");
        }


        @Override
        public boolean isValid(String value, ConstraintValidatorContext context) …
Run Code Online (Sandbox Code Playgroud)

java validation annotations jersey dropwizard

1
推荐指数
1
解决办法
3639
查看次数

要为不受支持的PATCH返回的HTTP代码

我在dropwizard REST资源上实现了一个PATCH方法.目前只有要修补的资源属性的子集.目前只能实现更换操作.

如果我看到未PATCH支持的属性/路径请求,我应该返回哪个HTTP代码?如果请求不受支持addremove操作,我应该返回什么?

rest http dropwizard http-patch

1
推荐指数
1
解决办法
248
查看次数