Search in sources :

Example 1 with HttpClientFactoryImpl

use of org.talend.sdk.component.runtime.manager.service.HttpClientFactoryImpl in project component-runtime by Talend.

the class ReflectionServiceTest method copiable.

@Test
void copiable() throws NoSuchMethodException {
    final HashMap<Class<?>, Object> precomputed = new HashMap<>();
    precomputed.put(UserHttpClient.class, new HttpClientFactoryImpl("test", new ReflectionService(new ParameterModelService()), JsonbBuilder.create(), emptyMap()).create(UserHttpClient.class, "http://foo"));
    final Method httpMtd = TableOwner.class.getMethod("http", UserHttpClient.class);
    final HttpClient client1 = HttpClient.class.cast(reflectionService.parameterFactory(httpMtd, precomputed).apply(emptyMap())[0]);
    final HttpClient client2 = HttpClient.class.cast(reflectionService.parameterFactory(httpMtd, precomputed).apply(emptyMap())[0]);
    assertNotSame(client1, client2);
    final InvocationHandler handler1 = Proxy.getInvocationHandler(client1);
    final InvocationHandler handler2 = Proxy.getInvocationHandler(client2);
    assertNotSame(handler1, handler2);
    assertEquals(handler1.toString(), handler2.toString());
}
Also used : HashMap(java.util.HashMap) HttpClient(org.talend.sdk.component.api.service.http.HttpClient) HttpClientFactoryImpl(org.talend.sdk.component.runtime.manager.service.HttpClientFactoryImpl) ReflectionService(org.talend.sdk.component.runtime.manager.reflect.ReflectionService) ParameterModelService(org.talend.sdk.component.runtime.manager.reflect.ParameterModelService) Method(java.lang.reflect.Method) InvocationHandler(java.lang.reflect.InvocationHandler) Test(org.junit.jupiter.api.Test)

Example 2 with HttpClientFactoryImpl

use of org.talend.sdk.component.runtime.manager.service.HttpClientFactoryImpl in project component-runtime by Talend.

the class ComponentManager method containerServices.

protected void containerServices(final Container container, final Map<Class<?>, Object> services) {
    // note: we can move it to manager instances at some point
    final JsonProvider jsonpProvider = new PreComputedJsonpProvider(container.getId(), this.jsonpProvider, jsonpParserFactory, jsonpWriterFactory, jsonpBuilderFactory, jsonpGeneratorFactory, jsonpReaderFactory);
    services.put(JsonProvider.class, jsonpProvider);
    services.put(JsonBuilderFactory.class, javaProxyEnricherFactory.asSerializable(container.getLoader(), container.getId(), JsonBuilderFactory.class.getName(), jsonpBuilderFactory));
    services.put(JsonParserFactory.class, javaProxyEnricherFactory.asSerializable(container.getLoader(), container.getId(), JsonParserFactory.class.getName(), jsonpParserFactory));
    services.put(JsonReaderFactory.class, javaProxyEnricherFactory.asSerializable(container.getLoader(), container.getId(), JsonReaderFactory.class.getName(), jsonpReaderFactory));
    services.put(JsonWriterFactory.class, javaProxyEnricherFactory.asSerializable(container.getLoader(), container.getId(), JsonWriterFactory.class.getName(), jsonpWriterFactory));
    services.put(JsonGeneratorFactory.class, javaProxyEnricherFactory.asSerializable(container.getLoader(), container.getId(), JsonGeneratorFactory.class.getName(), jsonpGeneratorFactory));
    final Jsonb jsonb = jsonbProvider.create().withProvider(// reuses the same memory buffering
    jsonpProvider).withConfig(new JsonbConfig().setProperty("johnzon.cdi.activated", false)).build();
    final Jsonb serializableJsonb = Jsonb.class.cast(javaProxyEnricherFactory.asSerializable(container.getLoader(), container.getId(), Jsonb.class.getName(), jsonb));
    services.put(Jsonb.class, serializableJsonb);
    // not JSON services
    services.put(HttpClientFactory.class, new HttpClientFactoryImpl(container.getId(), reflections, serializableJsonb, services));
    services.put(LocalCache.class, new LocalCacheService(container.getId()));
    services.put(LocalConfiguration.class, new LocalConfigurationService(createRawLocalConfigurations(), container.getId()));
    services.put(ProxyGenerator.class, proxyGenerator);
    services.put(Resolver.class, new ResolverImpl(container.getId(), container.getLocalDependencyRelativeResolver()));
}
Also used : LocalConfigurationService(org.talend.sdk.component.runtime.manager.service.LocalConfigurationService) PreComputedJsonpProvider(org.talend.sdk.component.runtime.manager.json.PreComputedJsonpProvider) Jsonb(javax.json.bind.Jsonb) JsonbConfig(javax.json.bind.JsonbConfig) HttpClientFactoryImpl(org.talend.sdk.component.runtime.manager.service.HttpClientFactoryImpl) LocalCacheService(org.talend.sdk.component.runtime.manager.service.LocalCacheService) ResolverImpl(org.talend.sdk.component.runtime.manager.service.ResolverImpl) JsonProvider(javax.json.spi.JsonProvider)

Aggregations

HttpClientFactoryImpl (org.talend.sdk.component.runtime.manager.service.HttpClientFactoryImpl)2 InvocationHandler (java.lang.reflect.InvocationHandler)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 Jsonb (javax.json.bind.Jsonb)1 JsonbConfig (javax.json.bind.JsonbConfig)1 JsonProvider (javax.json.spi.JsonProvider)1 Test (org.junit.jupiter.api.Test)1 HttpClient (org.talend.sdk.component.api.service.http.HttpClient)1 PreComputedJsonpProvider (org.talend.sdk.component.runtime.manager.json.PreComputedJsonpProvider)1 ParameterModelService (org.talend.sdk.component.runtime.manager.reflect.ParameterModelService)1 ReflectionService (org.talend.sdk.component.runtime.manager.reflect.ReflectionService)1 LocalCacheService (org.talend.sdk.component.runtime.manager.service.LocalCacheService)1 LocalConfigurationService (org.talend.sdk.component.runtime.manager.service.LocalConfigurationService)1 ResolverImpl (org.talend.sdk.component.runtime.manager.service.ResolverImpl)1