hk2

HK2 Factory invoked prior to Jersey filter when @Context is used for setter/field/constructor injection

99封情书 提交于 2019-11-30 03:01:49
问题 I've been able to inject into my jersey resource from a filter as per How to inject an object into jersey request context?. This allows me to successfully inject into a method parameter: @GET public Response getTest(@Context MyObject myObject) { // this works However, for setter/field/constructor injection, the HK2 Factory is invoked before the jersey filter, which means the provide() method returns null: @Override public MyObject provide() { // returns null because the filter has not yet run

汉语言处理工具pyhanlp的简繁转换

删除回忆录丶 提交于 2019-11-29 18:38:57
繁简转换 HanLP几乎实现了所有我们需要的繁简转换方式,并且已经封装到了HanLP中,使得我们可以轻松的使用,而分词器中已经默认支持多种繁简格式或者混合。这里我们不再做过多描述。 说明 : ·HanLP能够识别简繁分歧词,比如打印机=印表機。许多简繁转换工具不能区分“以后”“皇后”中的两个“后”字,HanLP可以。 算法详解 : ·《汉字转拼音与简繁转换的Java实现》——请查阅此文 from pyhanlp import * # 繁简转化 print(HanLP.convertToTraditionalChinese("“以后等你当上皇后,就能买草莓庆祝了”。发现一根白头发")) print(HanLP.convertToSimplifiedChinese("憑藉筆記簿型電腦寫程式HanLP")) # 简体转台湾繁体 print(HanLP.s2tw("hankcs在台湾写代码")) # 台湾繁体转简体 print(HanLP.tw2s("hankcs在臺灣寫程式碼")) # 简体转香港繁体 print(HanLP.s2hk("hankcs在香港写代码")) # 香港繁体转简体 print(HanLP.hk2s("hankcs在香港寫代碼")) # 香港繁体转台湾繁体 print(HanLP.hk2tw("hankcs在臺灣寫代碼")) # 台湾繁体转香港繁体 print

HK2 IterableProvider named method not finding Implementation

别来无恙 提交于 2019-11-29 16:58:09
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 specify anything, the implementation with the highest rank is injected always, which is what I want. The

Registering a custom ResourceMethodInvocationHandler in Jersey

ぃ、小莉子 提交于 2019-11-29 07:52:25
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 much appreciated! Let's have a look at this approach: (Tested with Jersey 2.10 and JSON serialization)

Jersey HK2 Dependency Injection

一世执手 提交于 2019-11-28 14:19:34
I'm writing a simple microservices that exposes REST API. So I started working with Jersey and of course I need to Inject my object into jersey resources. Basically I have 2 classes that defines a set of resources and some of them need to use another service. So basically I have: public interface MyService { String getServiceName(); void doService(); } 2 implementations of this interface (MyServiceBean and MyAlternativeServiceBean) and, as far as I understood reading jersey docs, I defined an hk2 Binder: public class MyBinder implements Binder{ @Override public void bind(DynamicConfiguration

How does ServiceLocator find @Service and @Contact automatically in HK2?

若如初见. 提交于 2019-11-28 13:37:26
According to HK2 @Service javadoc Annotation placed on classes that are to be automatically added to an hk2 ServiceLocator. I don't know how to make ServiceLocator find annotated classes automatically. TestService @Contract public interface TestService { } TestServiceImpl @Service public class TestServiceImpl implements TestService { } Main public static void main(String[] args) { ServiceLocator locator = ServiceLocatorUtilities.createAndPopulateServiceLocator(); TestService service = locator.getService(TestServiceImpl.class); System.out.println(service); // null } The result is always null .

Using Jersey's Dependency Injection in a Standalone application

你离开我真会死。 提交于 2019-11-28 08:55:09
问题 I have a interface here interface Idemo{ public int getDemo(int i); } And it's one implementation class DemoImpl implements Idemo{ @Override public int getDemo(int i){ return i+10; } } And there is a class which has a dependency on Idemo class Sample{ @Inject Idemo demo; public int getSample(int i){ return demo.getDemo(i); } } Now say I want to test Sample class public class SampleTest extends JerseyTest { @Inject Sample s; @Override protected Application configure() { AbstractBinder binder =

Jersey HK2 Dependency Injection

冷暖自知 提交于 2019-11-27 08:18:49
问题 I'm writing a simple microservices that exposes REST API. So I started working with Jersey and of course I need to Inject my object into jersey resources. Basically I have 2 classes that defines a set of resources and some of them need to use another service. So basically I have: public interface MyService { String getServiceName(); void doService(); } 2 implementations of this interface (MyServiceBean and MyAlternativeServiceBean) and, as far as I understood reading jersey docs, I defined an

How do I properly configure an EntityManager in a jersey / hk2 application?

随声附和 提交于 2019-11-27 02:10:30
I have a jersey-2 / hk2 application which uses JPA persistence. The EntityManager is bound at startup like this public MyApplication() { // ... register(new AbstractBinder() { @Override public void configure() { bindFactory(EmFactory.class) .to(EntityManager.class) .in(RequestScoped.class); } }); } with the factory class being public class EmFactory implements Factory<EntityManager> { private static final String PERSISTENCE_UNIT = "unit"; private EntityManagerFactory emf; private CloseableService closeableService; @Inject public EmFactory(@Named(PERSISTENCE_UNIT) String persistenceUnit,

HK2 is not injecting the HttpServletRequest with jersey

不打扰是莪最后的温柔 提交于 2019-11-26 11:39:12
问题 I am trying to follow the example located here to create a factory in order to inject my HttpSession. Unfortunately no matter what I try it is not working. Not sure what could be the issue. I have tried injecting just the HttpServletRequest and a provider. Here is my example using a provider. The error is a null pointer exception when trying to access the provider in the provide method. If I try to inject the HttpServletRequest I get no object available for injection. I am running this inside