dependabot[bot] on gradle
xvik on master
Bump com.gradle.enterprise from… Merge pull request #241 from xv… (compare)
dependabot[bot] on gradle
xvik on master
Bump io.spring.dependency-manag… Merge pull request #242 from xv… (compare)
dependabot[bot] on gradle
Bump io.spring.dependency-manag… (compare)
dependabot[bot] on gradle
Bump com.gradle.enterprise from… (compare)
dependabot[bot] on gradle
Bump spock-core from 2.2-M1-gro… (compare)
dependabot[bot] on gradle
xvik on master
Bump com.gradle.enterprise from… Merge pull request #237 from xv… (compare)
hooks is a generic mechanism:
GuiceyConfigurationHook hook = builder -> builder.extensions(...);
here lambda used instead of direct inteface implementation
hook.register()
Dynamic features
CredentialRequiredFeature (c.k.restful.filter)
LoginRequiredFeature (c.k.restful.filter)
Exception mappers
IndexNotFoundException IndexNotFoundExceptionMapper (c.k.r.exceptionmapper)
ERROR [2020-06-16 18:22:29,915] io.dropwizard.jersey.errors.LoggingExceptionMapper: Error handling a request: c6536299f686a565
! org.apache.lucene.index.IndexNotFoundException: index 7617868c-fb63-41b5-81e6-50290cdc903exx does not exist
! at com.kalasearch.restful.filter.CredentialRequiredFilter.filter(CredentialRequiredFilter.java:61)
! at org.glassfish.jersey.server.ContainerFilteringStage.apply(ContainerFilteringStage.java:108)
bootstrap.addBundle(GuiceBundle.builder()
.extensions(IndexNotFoundExceptionMapper.class)
.extensions(
AccountResource.class,
AppResource.class,
IndexResource.class,
DocResource.class,
CredentialRequiredFeature.class,
LoginRequiredFeature.class
)
LoggingExceptionMapper
(shown in error log) is the default dropwizard mapper, so mappers mechanism was used. It is better to debug exception handling to see why it choose default handler instead of your custom mapper. org.glassfish.jersey.internal.ExceptionMapperFactory#find(java.lang.Class<T>, T)
- mapper selection logic
public Index getIndex(@PathParam("indexId") String indexId) {
Optional<Index> indexOpt = indexDao.findById(indexId);
if (indexOpt.isPresent()) {
return indexOpt.get();
} else {
throw new IndexNotFoundException(indexId);
}
}
@Provider
public class IndexNotFoundExceptionMapper
implements ExceptionMapper<IndexNotFoundException> {
@Override
public Response toResponse(IndexNotFoundException indexNotFoundException) {
int errorCode = ErrorConstants.INDEX_NOT_FOUND_CODE;
String errorMessage =
String.format(
ErrorConstants.INDEX_NOT_FOUND,
indexNotFoundException.getIndexId()
);
return Response
.status(Response.Status.NOT_FOUND)
.entity(
new KalaErrorEntity(
errorMessage,
errorCode
)
)
.build();
}
}
public void initialize(Bootstrap<HttpServerConfiguration> bootstrap) {
// register hbn bundle before guice to make sure factory initialized before guice context start
final HbnBundle hibernate = new HbnBundle();
bootstrap.addBundle(hibernate);
// do not use auto scan here otherwise filter will be scanned without CredentialRequiredFeature
bootstrap.addBundle(GuiceBundle.builder()
.extensions(
AccountResource.class,
AppResource.class,
IndexResource.class,
DocResource.class,
CredentialRequiredFeature.class,
LoginRequiredFeature.class,
IndexNotFoundExceptionMapper.class,
CredentialUnauthorizedExceptionMapper.class
)
.modules(new HbnModule(hibernate))
.modules(new GuiceModule())
.build());
}
Application<HttpServerConfiguration>
and without using extensions(IndexNotFoundExceptionMapper)
but use environment.jersey().register(new CredentialUnauthorizedExceptionMapper());
instead right?
public ResourceExtension resourceExtension = ResourceExtension.builder()
.addResource(
new IndexResource(indexDao, indexServiceManager)
)
.addResource(new IndexNotFoundExceptionMapper())
.build();
Hi all , I have a question regarding the JDBI3 extension.
I'm trying to add to our solution a support for @UnitOfWork annotation with the JDBI extension.
Currently we use Guice to inject Resources and DAO's.
We have one ServiceModule and one DataAccessModule
in ServiceModule we do the following for all our Jeresy resources
binder.bind(FooResource.class);
And in our DataAccessModule
@Provides
fun fooDao(dbi: Jdbi): FooDao = dbi.onDemand(FooDao::class.java)
and of all these are defined in the Init function in the server
guiceBundle = GuiceBundle.builder()
.modules(ServiceModule, DataAccessModule...)
.build();
This code above works , however once ill change it to
`guiceBundle = GuiceBundle.builder()
.bundles(JdbiBundle.<Configucation>forDatabase((conf, env) -> conf.getDataSourceFactory()))
.modules(ServiceModule)
.build();`
(notice I removed the DataAccessModule as I marked my DAO's with @JDBIRepository annotations so the repositoryInstaller should install them.
Now as you can see I added the JdbiBundle as per the documentation, but I'm getting a lot of Guice exceptions such as
1) No implementation for ..fooDAO was bound.
while locating .FooDao
for the 3rd parameter of fooHandler.<init>(FooHandler.kt:21)
Basically it looks like the resources are getting fired up before the DAO's in Guice , which causing him to throw exceptions as he don't have yet their mappings.
I added some debug information to Guicey and saw the following order of modules
ServiceModule (c.n.claims.di)
...
JdbiModule (r.v.g.jdbi3.module)
GuiceBootstrapModule (r.v.d.guice.module)
Can anyone give me some pointers on what am I doing wrong?
Thanks