hk2

HK2 MethodInterceptor with Jersey resource

回眸只為那壹抹淺笑 提交于 2019-12-23 10:34:03
问题 How can I set up an aop MethodInterceptor to work with Jersey resources? Here is what I've tried, following this documentation: Step 1 - InterceptionService public class MyInterceptionService implements InterceptionService { private final Provider<AuthFilter> authFilterProvider; @Inject public HK2MethodInterceptionService(Provider<AuthFilter> authFilterProvider) { this.authFilterProvider = authFilterProvider; } /** * Match any class. */ @Override public Filter getDescriptorFilter() { return

Jersey2, Hk2 dependency injection (automatically) gives AbstractMethodError: org.jvnet.hk2.internal.DynamicConfigurationImpl.addIdempotentFilter

天大地大妈咪最大 提交于 2019-12-23 02:56:12
问题 Stuck on this problem for a while. I'm trying to integrate Tomcat 9, JDK 10, Jersey 2.23, HK2 (for DI) along with Automatic dependency injection. I've followed this tutorial, but getting below error, I've searched a lot but couldn't find anything on that. I've used dependency to generate "META-INF/hk2-locator/default" which is getting generate properly. Dependency <dependency> <groupId>org.glassfish.hk2</groupId> <artifactId>hk2-metadata-generator</artifactId> <version>2.4.0</version> <

Jersey HK2 Dependency Injection doesn't work after update to v2.27

泪湿孤枕 提交于 2019-12-23 02:53:29
问题 I have a project using Jersey v2.25.1. I was using Jersey's inbuilt HK2 injection to perform dependency injection, and everything worked fine. Fast forward to now, I decided to update to Jersey v2.27. When I ran my project, I got the following exception: java.lang.IllegalStateException: InjectionManagerFactory not found After some googling, I found that I needed to add the jersey-hk2 dependency. Doing so made me get the following exception: org.glassfish.hk2.api.UnsatisfiedDependencyException

Jersey 2 + HK2 - automatic binding of classess

谁都会走 提交于 2019-12-22 05:10:51
问题 Continuation of topic Jersey 2 + HK2 - @ApplicationScoped not working. I already know, how to bind classes in order to @Inject them properly. Do you have any ideas, how to automize this process? Putting every single service in bind statements seems like very bad smell in my application. 回答1: After using Google's Guice for a number of years, I am accustomed to the availability of a Just-In-Time binder, allowing the injection of arbitrary types without requiring any upfront configuration. I too

How do I inject constants with hk2 in jersey 2.0?

删除回忆录丶 提交于 2019-12-22 04:18:14
问题 How do I inject a constant into some class using HK2 in jersey? With Guice I could have some class like public class DependsOnFoo { @Inject public DependsOnFoo(@Named("FOO") String foo) { ... } ... } and I would configure it in the injector with something like bind(String.class).named("FOO").toInstance(new String("foo")) What's the equivalent, if any, in HK2? 回答1: I'm in the process of learning hk2 coming from Guice. Honestly I am still in the weeds a little with the complexity of hk2 vs the

Jersey and HK2 - Injecting current user

戏子无情 提交于 2019-12-20 03:19:27
问题 I'm working with jersey 2.17 and HK2 to create a simple rest app. I have a ContainerRequestFilter that rejects any request that doesn't have the "currentuser" cookie. I have something like this: @Path("/users") public class UserResource { private UserService userService; @GET @Path("/orders") @Produces("application/json") public List<Order> findOrdersOfCurrentUser() { // some ugly code to access headers, extract cookies, and finally // extract username (a String) from a particular cookie

@Immediate annotation use in Jersey2

十年热恋 提交于 2019-12-19 08:12:40
问题 I have a similar issue to the one raised here: How do I get my Jersey 2 Endpoints to eagerly initialize on startup? But slightly further down the line. I can get my resource immediately loaded, but when I try to use it by calling the REST url, I get the following stack trace. java.lang.IllegalStateException: Could not find an active context for org.glassfish.hk2.api.Immediate 2. java.lang.IllegalStateException: While attempting to create a service for SystemDescriptor( implementation=com

Jersey + HK2 + Grizzly: Proper way to inject EntityManager?

爱⌒轻易说出口 提交于 2019-12-18 12:34:08
问题 I've managed to set up injection (into resource classes) of my own service classes in Jersey, HK2 and a plain GrizzlyServer. (Basically followed this example.) I'm now curious what the best is to inject JPA EntityManagers into my resource classes? (I'm currently considering one request as one unit of work). One option that I'm currently exploring is to use a Factory<EntityManager> in the following way: class MyEntityManagerFactory implements Factory<EntityManager> { EntityManagerFactory emf;

HK2 IterableProvider named method not finding Implementation

烈酒焚心 提交于 2019-12-18 09:35:14
问题 I have a problem trying to inject a contract with two services bound to it. I'm using Jersey, and extending ResourceConfig to configure my app, where I'm binding two different implementations (classes FooImpl1 and FooImpl2 ) to a same contract (interface Foo ), ranking them differently. Each of these implementations is annotated with @Named and its name. In one of my controllers I want to have access to both implementations, so I inject an IterableProvider<Foo> fooProvider . If I do not

Registering a custom ResourceMethodInvocationHandler in Jersey

自作多情 提交于 2019-12-18 05:12:17
问题 I am attempting to intercept a resource call after it's JSON has been unmarshalled. Reading through some forums and posts I discovered that I may be able to do so by implementing org.glassfish.jersey.server.spi.internal.ResourceMethodInvocationHandlerProvider . Having done so I am now stuck trying to get my CustomResourceMethodInvocationHandler provider registered so that the jersey/hk2 internals call my overridden public InvocationHandler create(Invocable invocable) method. Any help would be