Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Aug 11 06:12

    dependabot[bot] on gradle

    (compare)

  • Aug 11 06:12

    xvik on master

    Bump com.gradle.enterprise from… Merge pull request #241 from xv… (compare)

  • Aug 11 06:12
    xvik closed #241
  • Aug 11 06:12

    dependabot[bot] on gradle

    (compare)

  • Aug 11 06:12

    xvik on master

    Bump io.spring.dependency-manag… Merge pull request #242 from xv… (compare)

  • Aug 11 06:12
    xvik closed #242
  • Aug 10 23:14
    dependabot[bot] labeled #242
  • Aug 10 23:14
    dependabot[bot] opened #242
  • Aug 10 23:14

    dependabot[bot] on gradle

    Bump io.spring.dependency-manag… (compare)

  • Aug 10 23:14
    dependabot[bot] labeled #241
  • Aug 10 23:14
    dependabot[bot] opened #241
  • Aug 10 23:14

    dependabot[bot] on gradle

    Bump com.gradle.enterprise from… (compare)

  • Jul 15 23:11
    dependabot[bot] labeled #238
  • Jul 15 23:11
    dependabot[bot] opened #238
  • Jul 15 23:11

    dependabot[bot] on gradle

    Bump spock-core from 2.2-M1-gro… (compare)

  • Jul 12 05:03

    dependabot[bot] on gradle

    (compare)

  • Jul 12 05:03

    xvik on master

    Bump com.gradle.enterprise from… Merge pull request #237 from xv… (compare)

  • Jul 12 05:03
    xvik closed #237
  • Jul 11 23:13
    dependabot[bot] labeled #237
  • Jul 11 23:13
    dependabot[bot] opened #237
Eddie Xie
@oeddyo

Hi @xvik ! I'm using a guava cache in my filter: ``` @Inject
private SessionFactory sessionFactory;

@Inject
public CredentialRequiredFilter(AppDao appDao, Cache<String, App> appCache) {
this.appDao = appDao;
this.appCache = appCache;
}
```

sorry gitter code format is always a mystery to me
image.png
now I'm trying to replace the cache with a mock cache in test. I saw in GuiceyHook it's possible but I'm using junit-5. Is there anything I can do now or shall I wait for your changes?
Vyacheslav Rusakov
@xvik
hi!

hooks is a generic mechanism:

GuiceyConfigurationHook hook  = builder -> builder.extensions(...);

here lambda used instead of direct inteface implementation

to register hook: hook.register()
there only problem is to register it before application startap
your junit extension use BeforeAll hook, so it is impossible to register anything beofre extension execution
so you will have to add hooks support inside your extension (to register them before startup)
Eddie Xie
@oeddyo
i see. I'll try out and see if I can get it work
Vyacheslav Rusakov
@xvik
and about formatting: just start ''' on new line. To activate syntax highlighting put language name after it like '''java
Eddie Xie
@oeddyo
ah ok
thanks
hooks doc
Eddie Xie
@oeddyo
neat!
Eddie Xie
@oeddyo
image.png
I seem to get it working in the extension via:
i pass the overrideModule in the extension's constructor, and in the overrideModule I override the cache I wanted to mock. from the guice print it seems to be overridden
image.png
does this sound reasonable?
Vyacheslav Rusakov
@xvik
yes ofc, report confirms that
Eddie Xie
@oeddyo
it works!
Fazeem Mohammed
@fazeem84
@xvik i had a suggestion to dropwizard core project to add the application build version during startup,which is rejected unfortunately..i want to know your opinion about this feature dropwizard/dropwizard#3331
Vyacheslav Rusakov
@xvik
I agree that it is too specific addition (and could be easily done in the application if required).
Fazeem Mohammed
@fazeem84
Ok.. thanks for your opinion :)
Eddie Xie
@oeddyo
Hi @xvik I'm seeing my customized Exceptionmapper registered but it's not called when exception happens. The exception is thrown in one of the filter I created
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)
maybe I'm not registering it correctly?
    bootstrap.addBundle(GuiceBundle.builder()
        .extensions(IndexNotFoundExceptionMapper.class)
        .extensions(
            AccountResource.class,
            AppResource.class,
            IndexResource.class,
            DocResource.class,
            CredentialRequiredFeature.class,
            LoginRequiredFeature.class
        )
Eddie Xie
@oeddyo
ah I found it probably has something to do with the exception is thrown in the ContainerRequestFilter
if it's thrown elsewhere, the ExceptionMapper can actually catch it
Vyacheslav Rusakov
@xvik
hi @oeddyo ! Actually 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
Eddie Xie
@oeddyo
@xvik looks like in the function you mentioned, it's trying to search for which is the most "suitable" exceptionMapper by looking at distance
Eddie Xie
@oeddyo
it's interesting... i didn't do anything new but now it seems be able to recognize the exp mapper :|
Eddie Xie
@oeddyo
hmm... it happened again. I'm throwing an exception in resource now, but for some reason the mapperFactory you mentioned keep finding the default mapper so my IndexNotFoundExceptionMapper is not used
image.png
Eddie Xie
@oeddyo
The code in resource is very simple. I'm testing if an indexId exists, if not throw this exception:
  public Index getIndex(@PathParam("indexId") String indexId) {
    Optional<Index> indexOpt = indexDao.findById(indexId);
    if (indexOpt.isPresent()) {
      return indexOpt.get();
    } else {
      throw new IndexNotFoundException(indexId);
    }
  }
exception mapper:

@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();
  }
}
Eddie Xie
@oeddyo

  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());
  }
Tried so many things... doesn't seem to be working :(
Vyacheslav Rusakov
@xvik
@oeddyo don't know why it's not working.. it should. Only debug could reveal the reason. You can try to use ExtendedExceptionMapper: it has an addition method to implement which is always called during mapper search. Not much, just the way to be sure jersey is aware of your mapper (just don't use it).. but in this case also further debug will be required.
Eddie Xie
@oeddyo
I think jersey is aware of the mapper. When the mapperFactory.find is trying to find a proper mapper (by computing some sort of distance) I can see the defined mapper IndexNotFoundExceptionMapper there
is it possible this is caused by Guicey? to verify that I can register the mapper in run function of Application<HttpServerConfiguration> and without using extensions(IndexNotFoundExceptionMapper) but use environment.jersey().register(new CredentialUnauthorizedExceptionMapper()); instead right?
Eddie Xie
@oeddyo
got it! I didn't add the mapper in test case when I'm testing Resource.
  public ResourceExtension resourceExtension = ResourceExtension.builder()
      .addResource(
          new IndexResource(indexDao, indexServiceManager)
      )
      .addResource(new IndexNotFoundExceptionMapper())
      .build();
this works^