Giter Club home page Giter Club logo

dropwizard-guicey-ext's Introduction

Dropwizard-guicey extensions

License CI Appveyor build status codecov

About

IMPORTANT Modules were moved into the core repository in order to unify versions and release cycles (for guicey 6, dropwizard 3 and beyond)

Dropwizard-guicey 5.x extensions and integrations. Provided modules may be used directly and for educational purposes (as examples for custom integrations).

NOTE: Extension modules version is derived from guicey version: guiceyVersion-Number (the same convention as for dropwizard modules). For example version 5.0.0-1 means first extensions release (1) for guicey 5.0.0.

Also, guicey base package ru.vyarus.dropwizard.guice is different from extensions base package ru.vyarus.guicey.

Older versions:

Setup

Maven Central

You can either use modules directly (in this case see module page for setup) or use provided BOM to unify versions management.

BOM

Provides:

  • Guicey bom
  • Guice bom
  • Dropwizard bom

Maven:

<!-- Implicitly imports Dropwizard and Guice BOMs -->
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>ru.vyarus.guicey</groupId>
            <artifactId>guicey-bom</artifactId>
            <version>5.7.1-1</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <!-- uncomment to override dropwizard and its dependencies versions  
        <dependency>
            <groupId>io.dropwizard/groupId>
            <artifactId>dropwizard-dependencies</artifactId>
            <version>2.1.5</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency> --> 
    </dependencies>
</dependencyManagement>

<!-- declare guice and ext modules without versions -->
<dependencies>
    <dependency>
      <groupId>ru.vyarus</groupId>
      <artifactId>dropwizard-guicey</artifactId>
    </dependency>
    <!-- For example, using dropwizard module (without version) -->
    <dependency>
      <groupId>io.dropwizard</groupId>
      <artifactId>dropwizard-auth</artifactId>
    </dependency>
    <!-- Example of extension module usage -->
    <dependency>
      <groupId>ru.vyarus.guicey</groupId>
      <artifactId>guicey-eventbus</artifactId>
    </dependency>
</dependencies>

Gradle:

dependencies {
    implementation platform('ru.vyarus.guicey:guicey-bom:5.7.1-1')
    // uncomment to override dropwizard and its dependencies versions    
    //implementation platform('io.dropwizard:dropwizard-dependencies:2.1.5')
    
    // declare guice and ext modules without versions 
    implementation 'ru.vyarus:dropwizard-guicey'
    implementation 'io.dropwizard:dropwizard-auth'
    implementation 'ru.vyarus.guicey:guicey-eventbus' 
}
    
Dependencies override

You may override BOM version for any dependency by simply specifying exact version in dependency declaration section.

If you want to use newer version (then provided by guicey BOM) of dropwizard or guice then import also their BOMs directly:

  • io.dropwizard:dropwizard-dependencies:$VERSION for dropwizard
  • com.google.inject:guice-bom:$VERSION for guice

Snapshots

Snapshots may be used through JitPack

WARNING: snapshot may not contain today's commits due to ~1day publication lag!

WARNING2: master-SHAPSHOT versions are not working due to incorrect pom generation (yet unkown reason), use exact commits instead

Add JitPack repository:

repositories { maven { url 'https://jitpack.io' } }

For spring dependencies plugin:

dependencyManagement {
    resolutionStrategy {
        cacheChangingModulesFor 0, 'seconds'
    }
    imports {
        mavenBom "ru.vyarus.guicey:guicey-bom:COMMIT-HASH"
    }
}   

dependencies {
    implementation 'ru.vyarus.guicey:guicey-validation'
}

If you don't use BOM:

configurations.all {
    resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}

dependencies {
    implementation 'ru.vyarus.guicey:guicey-validation:COMMIT-HASH'
}

Note that in both cases resolutionStrategy setting required for correct updating snapshot with recent commits (without it you will not always have up-to-date snapshot)

OR you can depend on exact commit:

  • Go to JitPack project page
  • Select Commits section and click Get it on commit you want to use and use commit hash as version: ru.vyarus.guicey:guicey-bom:8585300d12

Maven:

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>  

<dependencyManagement> 
    <dependencies>
        <dependency>
            <groupId>ru.vyarus.guicey</groupId>
            <artifactId>guicey-bom</artifactId>
            <version>COMMIT-HASH</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>  
 
<dependencies>
    <dependency>
        <groupId>ru.vyarus.guicey</groupId>
        <artifactId>guicey-validation</artifactId>
    </dependency>
</dependencies>

Or simply change dependency version if BOM not used (repository definition is still required).

Modules

Admin context rest support (mirror main rest).

Support for @PostConstruct, @PreDestroy, @PostStartup annotations on guice beans.

Allows using validation annotations on any guice bean method (the same way as dropwizard rest validation)

Module provides integration with Guava EventBus: automates subscriptions, report events with subscriptions and registers EventBus for inject.

Based on dropwizard integration. Introduce thread bound transactions, defined with annotations. Sql proxies could be used as usual guice beans without extra efforts to use them in the same transaction.

Jdbi3 integration, based on dropwizard module. Introduce thread bound transactions, defined with annotations. Sql proxies could be used as usual guice beans without extra efforts to use them in the same transaction.

Correct redirect to index page for html5 client routing urls (e.g. html5 routing enabled by default in Angular 2).

JSP like simplicity for dropwizard-views.

JUnit 4 rules.

Spock 1 extensions.


java lib generator

dropwizard-guicey-ext's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar xvik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

dropwizard-guicey-ext's Issues

Cannot access a member of the interface ... with modifiers "public"

I have guicey working for the most part but seeing a curious issue:

@JdbiRepository
public interface CrudRepository {
insert(String name);
update(String name);

/*convoluted example*/
   default T save(String name) {
       if(name != "test") {
         insert(name);
       } else return update(name);
    }
}

@JdbiRepository
public interface BaseRepository  extends CrudRepository {
@SqlUpdate("insert into table(name) values(:name)")
int insert(String name);
@SqlUpdate("update table set name = :name")
int update(String name);
}

@JdbiRepository
public interface MyRepository extends CrudRepository {
@SqlUpdate("insert into second_table(name) values(:name)")
int insert(String name);
@SqlUpdate("update second_table set name = :name")
int update(String name);
}
class ServiceBase
{
 protected BaseRepository baseRepo;
@Inject 
public ServiceBase(BaseRepository baseRepo) {
  this.baseRepo = baseRepo;
 }

@InTransaction
public void baseMethod() {
  baseRepo.save("test");
  baseRepo.save("test2");
}
}

public class MyService extends ServiceBase  
{
  protected MyRepository myRepo;
  @Inject
  public MyService(MyRepository myRepo, BaseRepository baseRepo) {
    super(baseRepo);
    this.myRepo = myRepo;
  }

@InTransaction
public void doSomethingComplex() {
  baseMethod("test");
  myRepo.save("test 3");
}

I believe this setup is wrong somehow but unclear how. When I call doSomethingComplex in my service layer, the exception I see is:

org.jdbi.v3.core.extension.NoSuchExtensionException: Extension not found: interface CrudRepository
! at ru.vyarus.guicey.jdbi3.installer.repository.sql.SqlObjectProvider.lambda$create$0(SqlObjectProvider.java:63)
! at java.base/java.util.Optional.orElseThrow(Optional.java:408)
! at ru.vyarus.guicey.jdbi3.installer.repository.sql.SqlObjectProvider.create(SqlObjectProvider.java:63)
! at ru.vyarus.guicey.jdbi3.installer.repository.sql.SqlObjectProvider.get(SqlObjectProvider.java:46)
! at ru.vyarus.guicey.jdbi3.installer.repository.RepositoryInstaller.lambda$install$0(RepositoryInstaller.java:64)
! at ru.vyarus.guicey.jdbi3.tx.aop.TransactionalInterceptor.lambda$invoke$0(TransactionalInterceptor.java:53)
! at ru.vyarus.guicey.jdbi3.tx.TransactionTemplate.inCurrentTransaction(TransactionTemplate.java:96)
! at ru.vyarus.guicey.jdbi3.tx.TransactionTemplate.inTransaction(TransactionTemplate.java:69)
! at ru.vyarus.guicey.jdbi3.tx.aop.TransactionalInterceptor.invoke(TransactionalInterceptor.java:51)

So... what have I done incorrectly?

Unable to recover from db reboot due to transaction isolation level check

I currently am connected to an RDS cluster in AWS, where db servers can come and go due to auto-scaling. Whenever this happens, I get bad connections that remain in the pool which no longer correspond to physical connections. This issue will persist until I perform a restart of the application.

This appears to be due to the check to get the transaction isolation level, as it doesn't appear to close with the underlying connection.

This is the error that I receive:

! java.sql.SQLException: PooledConnection has already been closed. ! at org.apache.tomcat.jdbc.pool.DisposableConnectionFacade.invoke(DisposableConnectionFacade.java:87) ! at com.sun.proxy.$Proxy95.getTransactionIsolation(Unknown Source) ! at org.jdbi.v3.core.Handle.getTransactionIsolationLevel(Handle.java:523) ! ... 72 common frames omitted ! Causing: org.jdbi.v3.core.transaction.UnableToManipulateTransactionIsolationLevelException: unable to access current setting ! at org.jdbi.v3.core.Handle.getTransactionIsolationLevel(Handle.java:525) ! at ru.vyarus.guicey.jdbi3.tx.TransactionTemplate.inCurrentTransaction(TransactionTemplate.java:87) ! at ru.vyarus.guicey.jdbi3.tx.TransactionTemplate.inTransaction(TransactionTemplate.java:69) ! at ru.vyarus.guicey.jdbi3.tx.aop.TransactionalInterceptor.invoke(TransactionalInterceptor.java:51) ! at com.inrix.fusion.nowcasting.pixel.service.PixelService.getPixelsFromEdges(PixelService.java:51) ! at com.inrix.fusion.nowcasting.pixel.resources.PixelResource.getPixelsFromEdges(PixelResource.java:130)

Here is my db configuration, which I've been changing a lot to experiment with timeouts and checks to work around the issue, but nothing as worked so far.

database: driverClass: org.postgresql.Driver url: xxxx user: xxxx password: xxxx maxSize: 1000 checkConnectionOnBorrow: true checkConnectionOnReturn: true removeAbandoned: true maxConnectionAge: 60s

If this is not a bug, do you have any suggestions on how to work around this issue?

Is there any new release planned for guicey-jdbi for jdbi3

Hi,

I am trying to use guicey-jdbi with jdbi3 but I am getting errors like below. I think this is because guicey-jdbi is bringing in org.jdbi:jdbi:jar:2.78. If I change all my objects to use v2 version of jdbi lib and create abstract classes (as in jdbi v2) instead of Interfaces (required in jdbi v3), everything works fine.
Please let me know if you are planning to release this library's next version which is compatible with jdbi3.

ERROR [2018-04-18 09:06:48,119] io.dropwizard.jersey.errors.LoggingExceptionMapper: Error handling a request: 63e2fac45299937e
! java.lang.NoSuchMethodError: java.lang.Object.findAll()Ljava/util/List;
! at org.skife.jdbi.v2.sqlobject.CloseInternalDoNotUseThisClass$$EnhancerByCGLIB$$5f8e55.CGLIB$findAll$8(<generated>)
! at org.skife.jdbi.v2.sqlobject.CloseInternalDoNotUseThisClass$$EnhancerByCGLIB$$5f8e55$$FastClassByCGLIB$$8d590e90.invoke(<generated>)
! at org.skife.jdbi.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
! at org.skife.jdbi.v2.sqlobject.PassThroughHandler.invoke(PassThroughHandler.java:34)
! at org.skife.jdbi.v2.sqlobject.SqlObject.invoke(SqlObject.java:224)
! at org.skife.jdbi.v2.sqlobject.SqlObject$3.intercept(SqlObject.java:133)
! at org.skife.jdbi.v2.sqlobject.CloseInternalDoNotUseThisClass$$EnhancerByCGLIB$$5f8e55.findAll(<generated>)
! at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
! at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
! at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
! at java.lang.reflect.Method.invoke(Method.java:498)
! at ru.vyarus.guicey.jdbi.installer.repository.RepositoryInstaller.lambda$install$0(RepositoryInstaller.java:56)
! at ru.vyarus.guicey.jdbi.tx.aop.TransactionalInterceptor.lambda$invoke$0(TransactionalInterceptor.java:26)
! at ru.vyarus.guicey.jdbi.tx.TransactionTemplate.lambda$inTransaction$0(TransactionTemplate.java:61)
! at org.skife.jdbi.v2.tweak.transactions.LocalTransactionHandler.inTransaction(LocalTransactionHandler.java:183)
! at org.skife.jdbi.v2.BasicHandle.inTransaction(BasicHandle.java:338)
! at ru.vyarus.guicey.jdbi.tx.TransactionTemplate.inTransaction(TransactionTemplate.java:61)
! at ru.vyarus.guicey.jdbi.tx.aop.TransactionalInterceptor.invoke(TransactionalInterceptor.java:24)
! at net.codingdemon.jdbitest.example.v3.resource.UserResource.findAll(UserResource.java:52)
! at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
! at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
! at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
! at java.lang.reflect.Method.invoke(Method.java:498)

Is it possible to work with JdbiBundle and JdbiRepository with multiple databases

I have a dropwizard-guicey application with two databases and I wish I could use two JDBI and repositories like so

@Override
public void initialize(final Bootstrap<Configuration> bootstrap) {
  bootstrap.addBundle(
      GuiceBundle.builder()
          .enableAutoConfig(getClass().getPackage().getName())
          .bundles(
              JdbiBundle.<Configuration>forDatabase(
                      (conf, env) -> conf.getApplicationDataSourceFactory())
                  .withPlugins(new H2DatabasePlugin()))
          .bundles(
              JdbiBundle.<Configuration>forDatabase(
                      (conf, env) -> conf.getSessionDataSourceFactory())
                  .withPlugins(new H2DatabasePlugin()))
          .build());
...

Would I need to change these lines?

Request: Can we opt out of getting the transaction isolation level when using `inCurrentTransaction` ?

Hey there

Firstly, let me thank you for building this library. We've found it immensely helpful.

We use the @InTransaction annotation in our codebase which ultimately cause us to run the database queries through inCurrentTransaction to utilize the same transaction. This works great from a functional standpoint.

However, we notice that the method is checking the current transaction level of the handle by calling getTransactionIsolationLevel on the underlying connection. In our case, this uses the PgConnection from the org.postgres.postgresql lib for our database, which executes the query SHOW TRANSACTION ISOLATION LEVEL to get this level.

image

In cases where a request is being handled that calls multiple methods decorated with @InTransaction, this causes many calls to getTransactionIsolationLevel and creates some overhead.

I'm curious if you've considered a way to cache the current isolation level for the currently used handle's connection for a period of time and only check the isolation level on the underlying connection when that time has expired.

It would be a great addition from my perspective to provide an optional property to the @InTransaction annotation to let us specify this cache time. I'm happy to submit the pull request for this if you think it's a good idea.

Thanks

Version update release for dropwizard 2.0.2

Hi there's a regression in dropwizard 2.0.0 that's fixed in 2.0.2.

Can you make a release that uses the latest versions please?

dropwizard-guicey 5.0.0-0 depends on dropwizard-jdbi3:2.0.0, which in turn uses jdbi3-core:3.11.1.

Both of these versions get marked as conflicts in my build as the newer versions are included by 2.0.2 versions of other dropwizard modules.

As shown in my gralde build scan:
image

Support for dropwizard 1.1.0

Hello,

Dropwizard 1.1.0 use jdbi 2.78 and current version of guicey-jdbi use 2.73.
If you try to use both in a project, you get in trouble because UnitHandleDing doesn't implement the new method "setContext".

It seems that forcing the version of jdbi to 2.73 is a valid workaround (at least the server start and simple request works) but I'm not sure it's a valid solution.

I've try to checkout the repository to make a pull request but because of the dependency management system, it's a bit complicated to change the version of dropwizard in the gradle :-/

Based on org.skife.jdbi.v2.sqlobject.ConstantHandleDing is seems that a valid implementation could be:

@Override
    public SqlObjectContext setContext(SqlObjectContext context) {
        final Handle handle = handleProvider.get();
        SqlObjectContext oldContext = handle.getSqlObjectContext();
        handle.setSqlObjectContext(context);
        return oldContext;
    }

Disclaimer I'm not a jdbi or guicey expert :)

I've compile guicey-jdbi 0.2.2-SNAPSHOT locally and this implementation seems ok (server start and dao seems ok)

SPA for index that is not at root

I have a REST API where I wish to keep root as is, and serve an SPA at /app/index.html. the classpath location is /assets. I tried:

bootstrap.addBundle(SpaBundle.app("app", "/assets", "/app").build());

But it just behaved like plain AssetsBundle. Angular routing did not work. What am I missing?

Eager instantiate `@JdbiRepository`

Hi there

I'm debugging an issue where the first request to a repository is "slow" on our app, and it seems to be caused by the JdbiRepository being instantiated for the first time. Is there a way to force these objects to be created at startup?

My current solution requires that I make a request to each repository through its public API during a Managed object's startup phase, but that seems messy. Just wondering what you'd recommend here.

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.