Search in sources :

Example 6 with JsonbConfig

use of javax.json.bind.JsonbConfig 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)

Example 7 with JsonbConfig

use of javax.json.bind.JsonbConfig in project component-runtime by Talend.

the class Generator method generatedContributors.

private static void generatedContributors(final File generatedDir, final String user, final String pwd) throws Exception {
    final Collection<Contributor> contributors;
    if (user == null || user.trim().isEmpty() || "skip".equals(user)) {
        log.error("No Github credentials, will skip contributors generation");
        return;
    } else {
        try {
            contributors = new Github(user, pwd).load();
        } catch (final RuntimeException re) {
            log.error(re.getMessage(), re);
            return;
        }
    }
    final File file = new File(generatedDir, "generated_contributors.adoc");
    try (final Jsonb jsonb = JsonbBuilder.create(new JsonbConfig().withPropertyOrderStrategy(PropertyOrderStrategy.LEXICOGRAPHICAL).withFormatting(true));
        final OutputStream writer = new WriteIfDifferentStream(file)) {
        writer.write("++++\n".getBytes(StandardCharsets.UTF_8));
        jsonb.toJson(contributors, writer);
        writer.write("\n++++".getBytes(StandardCharsets.UTF_8));
    }
}
Also used : Jsonb(javax.json.bind.Jsonb) JsonbConfig(javax.json.bind.JsonbConfig) FilterOutputStream(java.io.FilterOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 8 with JsonbConfig

use of javax.json.bind.JsonbConfig in project component-runtime by Talend.

the class ComponentMetadataMojo method doWork.

@Override
protected void doWork(final ComponentManager manager, final Container container, final ContainerComponentRegistry registry) throws MojoExecutionException, MojoFailureException {
    final File output = new File(classes, location);
    if (!output.getParentFile().exists() && !output.getParentFile().mkdirs()) {
        throw new MojoExecutionException("Can't create " + output);
    }
    final Collection<Component> components = registry.getComponents().values().stream().flatMap(c -> Stream.concat(c.getPartitionMappers().values().stream().map(p -> new Component(p.getParent().getCategories(), p.getParent().getName(), p.getName(), p.findBundle(container.getLoader(), Locale.ENGLISH).displayName().orElse(p.getName()), p.getIcon(), emptyList(), singletonList("MAIN"))), c.getProcessors().values().stream().map(p -> {
        final Method listener = p.getListener();
        return new Component(p.getParent().getCategories(), p.getParent().getName(), p.getName(), p.findBundle(container.getLoader(), Locale.ENGLISH).displayName().orElse(p.getName()), p.getIcon(), getDesignModel(p).getInputFlows(), getDesignModel(p).getOutputFlows());
    }))).collect(toList());
    try (final Jsonb mapper = inPluginContext(JsonbBuilder::newBuilder).withConfig(new JsonbConfig().setProperty("johnzon.cdi.activated", false).setProperty("johnzon.attributeOrder", String.CASE_INSENSITIVE_ORDER)).build()) {
        container.execute(() -> {
            try {
                mapper.toJson(new ComponentContainer(components), new FileOutputStream(output));
            } catch (final FileNotFoundException e) {
                throw new IllegalStateException(e);
            }
            getLog().info("Created " + output);
            return null;
        });
    } catch (final Exception e) {
        throw new MojoExecutionException(e.getMessage());
    }
}
Also used : JsonbBuilder(javax.json.bind.JsonbBuilder) ContainerComponentRegistry(org.talend.sdk.component.runtime.manager.ContainerComponentRegistry) Container(org.talend.sdk.component.container.Container) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) FileOutputStream(java.io.FileOutputStream) Parameter(org.apache.maven.plugins.annotations.Parameter) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) JsonbConfig(javax.json.bind.JsonbConfig) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) Collections.singletonList(java.util.Collections.singletonList) MojoFailureException(org.apache.maven.plugin.MojoFailureException) Mojo(org.apache.maven.plugins.annotations.Mojo) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) Locale(java.util.Locale) PROCESS_CLASSES(org.apache.maven.plugins.annotations.LifecyclePhase.PROCESS_CLASSES) Data(lombok.Data) Jsonb(javax.json.bind.Jsonb) ComponentManager(org.talend.sdk.component.runtime.manager.ComponentManager) COMPILE_PLUS_RUNTIME(org.apache.maven.plugins.annotations.ResolutionScope.COMPILE_PLUS_RUNTIME) AllArgsConstructor(lombok.AllArgsConstructor) Method(java.lang.reflect.Method) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) JsonbBuilder(javax.json.bind.JsonbBuilder) FileNotFoundException(java.io.FileNotFoundException) Method(java.lang.reflect.Method) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) FileNotFoundException(java.io.FileNotFoundException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) Jsonb(javax.json.bind.Jsonb) JsonbConfig(javax.json.bind.JsonbConfig) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 9 with JsonbConfig

use of javax.json.bind.JsonbConfig in project component-runtime by Talend.

the class LoopState method toJsonObject.

private JsonObject toJsonObject(final Object value) {
    if (jsonb == null) {
        synchronized (this) {
            if (jsonb == null) {
                final ComponentManager manager = ComponentManager.instance();
                jsonb = manager.getJsonbProvider().create().withProvider(manager.getJsonpProvider()).withConfig(new JsonbConfig().setProperty("johnzon.cdi.activated", false)).build();
            }
        }
    }
    return jsonb.fromJson(jsonb.toJson(value), JsonObject.class);
}
Also used : JsonbConfig(javax.json.bind.JsonbConfig) ComponentManager(org.talend.sdk.component.runtime.manager.ComponentManager)

Aggregations

JsonbConfig (javax.json.bind.JsonbConfig)9 Jsonb (javax.json.bind.Jsonb)7 Test (org.junit.Test)4 PersonAdapter (com.baeldung.adapter.PersonAdapter)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 ComponentManager (org.talend.sdk.component.runtime.manager.ComponentManager)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 FilterOutputStream (java.io.FilterOutputStream)1 OutputStream (java.io.OutputStream)1 Method (java.lang.reflect.Method)1 Collection (java.util.Collection)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.singletonList (java.util.Collections.singletonList)1 Locale (java.util.Locale)1 Collectors.toList (java.util.stream.Collectors.toList)1 Stream (java.util.stream.Stream)1 JsonbBuilder (javax.json.bind.JsonbBuilder)1 JsonProvider (javax.json.spi.JsonProvider)1