carlesarnal commented on code in PR #24844: URL: https://github.com/apache/camel/pull/24844#discussion_r4132418003
########## components/camel-apicurio-registry/src/main/java/org/apache/camel/component/apicurioregistry/ApicurioRegistryConsumer.java: ########## @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.apicurioregistry; + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; + +import io.apicurio.registry.rest.client.RegistryClient; +import io.apicurio.registry.rest.client.models.SearchedVersion; +import io.apicurio.registry.rest.client.models.VersionSearchResults; +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.Processor; +import org.apache.camel.support.ScheduledPollConsumer; + +public class ApicurioRegistryConsumer extends ScheduledPollConsumer { + + private final ApicurioRegistryEndpoint endpoint; + private final ApicurioRegistryConfiguration configuration; + private volatile Long lastSeenGlobalId; + + public ApicurioRegistryConsumer(ApicurioRegistryEndpoint endpoint, Processor processor, + ApicurioRegistryConfiguration configuration) { + super(endpoint, processor); + this.endpoint = endpoint; + this.configuration = configuration; + } + + @Override + protected int poll() throws Exception { + String groupId = endpoint.getGroupId(); + String artifactId = endpoint.getArtifactId(); + + if (groupId == null || artifactId == null) { + throw new IllegalArgumentException( + "Both groupId and artifactId are required for the consumer"); + } + + RegistryClient client = endpoint.getRegistryClient(); + VersionSearchResults results = client.groups().byGroupId(groupId) + .artifacts().byArtifactId(artifactId).versions().get(); Review Comment: Fixed in 9ffb47280a0. The consumer now pages through versions ordered by globalId, newest first, 100 at a time, and stops at the first version it has already seen, so a steady-state poll usually needs a single request. listVersions follows every page and returns the full list in globalId order. Tests use a fake that applies the registry's default page of 20 when no limit is given, and cover 250 versions, the requested offsets, and a later poll that only fetches the first page. _AI-assisted response prepared with OpenCode on behalf of @carlesarnal._ ########## components/camel-apicurio-registry/src/main/java/org/apache/camel/component/apicurioregistry/ApicurioRegistryConsumer.java: ########## @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.apicurioregistry; + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; + +import io.apicurio.registry.rest.client.RegistryClient; +import io.apicurio.registry.rest.client.models.SearchedVersion; +import io.apicurio.registry.rest.client.models.VersionSearchResults; +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.Processor; +import org.apache.camel.support.ScheduledPollConsumer; + +public class ApicurioRegistryConsumer extends ScheduledPollConsumer { + + private final ApicurioRegistryEndpoint endpoint; + private final ApicurioRegistryConfiguration configuration; + private volatile Long lastSeenGlobalId; + + public ApicurioRegistryConsumer(ApicurioRegistryEndpoint endpoint, Processor processor, + ApicurioRegistryConfiguration configuration) { + super(endpoint, processor); + this.endpoint = endpoint; + this.configuration = configuration; + } + + @Override + protected int poll() throws Exception { + String groupId = endpoint.getGroupId(); + String artifactId = endpoint.getArtifactId(); + Review Comment: Fixed in 9ffb47280a0. The consumer now pages through versions ordered by globalId, newest first, 100 at a time, and stops at the first version it has already seen, so a steady-state poll usually needs a single request. listVersions follows every page and returns the full list in globalId order. Tests use a fake that applies the registry's default page of 20 when no limit is given, and cover 250 versions, the requested offsets, and a later poll that only fetches the first page. _AI-assisted response prepared with OpenCode on behalf of @carlesarnal._ ########## components/camel-apicurio-registry/src/main/java/org/apache/camel/component/apicurioregistry/ApicurioRegistryProducer.java: ########## @@ -0,0 +1,241 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.apicurioregistry; + +import java.io.InputStream; + +import io.apicurio.registry.rest.client.RegistryClient; +import io.apicurio.registry.rest.client.models.ArtifactMetaData; +import io.apicurio.registry.rest.client.models.CreateArtifact; +import io.apicurio.registry.rest.client.models.CreateArtifactResponse; +import io.apicurio.registry.rest.client.models.CreateGroup; +import io.apicurio.registry.rest.client.models.CreateVersion; +import io.apicurio.registry.rest.client.models.GroupMetaData; +import io.apicurio.registry.rest.client.models.IfArtifactExists; +import io.apicurio.registry.rest.client.models.RuleViolationProblemDetails; +import io.apicurio.registry.rest.client.models.VersionContent; +import io.apicurio.registry.rest.client.models.VersionMetaData; +import io.apicurio.registry.rest.client.models.VersionSearchResults; +import org.apache.camel.Message; +import org.apache.camel.spi.InvokeOnHeader; +import org.apache.camel.support.HeaderSelectorProducer; + +public class ApicurioRegistryProducer extends HeaderSelectorProducer { + + private final ApicurioRegistryEndpoint endpoint; + private final ApicurioRegistryConfiguration configuration; + + public ApicurioRegistryProducer(ApicurioRegistryEndpoint endpoint, + ApicurioRegistryConfiguration configuration) { + super(endpoint, ApicurioRegistryConstants.HEADER_OPERATION, configuration::getOperation); + this.endpoint = endpoint; + this.configuration = configuration; + } + + private RegistryClient getClient() { + return endpoint.getRegistryClient(); + } + + private String resolveGroupId(Message message) { + String gid = message.getHeader(ApicurioRegistryConstants.HEADER_GROUP_ID, String.class); + return gid != null ? gid : endpoint.getGroupId(); + } + + private String resolveArtifactId(Message message) { + String aid = message.getHeader(ApicurioRegistryConstants.HEADER_ARTIFACT_ID, String.class); + return aid != null ? aid : endpoint.getArtifactId(); + } + + @InvokeOnHeader(ApicurioRegistryConstants.OPERATION_CREATE_ARTIFACT) + public void createArtifact(Message message) { + String groupId = resolveGroupId(message); + String artifactId = resolveArtifactId(message); + String artifactType = message.getHeader( + ApicurioRegistryConstants.HEADER_ARTIFACT_TYPE, configuration.getArtifactType(), String.class); + String name = message.getHeader(ApicurioRegistryConstants.HEADER_ARTIFACT_NAME, String.class); + String description = message.getHeader(ApicurioRegistryConstants.HEADER_ARTIFACT_DESCRIPTION, String.class); + String content = message.getBody(String.class); + String contentType = message.getHeader( + ApicurioRegistryConstants.HEADER_CONTENT_TYPE, "application/json", String.class); + String ifExistsVal = message.getHeader( + ApicurioRegistryConstants.HEADER_IF_EXISTS, configuration.getIfExists(), String.class); + + CreateArtifact createArtifact = new CreateArtifact(); + createArtifact.setArtifactId(artifactId); + createArtifact.setArtifactType(artifactType); + createArtifact.setName(name); + createArtifact.setDescription(description); + + if (content != null) { + CreateVersion firstVersion = new CreateVersion(); + VersionContent vc = new VersionContent(); + vc.setContent(content); + vc.setContentType(contentType); + firstVersion.setContent(vc); + createArtifact.setFirstVersion(firstVersion); + } + + CreateArtifactResponse result = getClient().groups().byGroupId(groupId).artifacts() + .post(createArtifact, config -> { + if (ifExistsVal != null) { + config.queryParameters.ifExists = IfArtifactExists.forValue(ifExistsVal); + } + }); + message.setBody(result); + } + + @InvokeOnHeader(ApicurioRegistryConstants.OPERATION_UPDATE_ARTIFACT) + public void updateArtifact(Message message) { + String groupId = resolveGroupId(message); + String artifactId = resolveArtifactId(message); + String content = message.getBody(String.class); + String version = message.getHeader(ApicurioRegistryConstants.HEADER_VERSION, String.class); + String contentType = message.getHeader( + ApicurioRegistryConstants.HEADER_CONTENT_TYPE, "application/json", String.class); + + CreateVersion createVersion = new CreateVersion(); + createVersion.setVersion(version); + VersionContent vc = new VersionContent(); + vc.setContent(content); + vc.setContentType(contentType); + createVersion.setContent(vc); + + VersionMetaData result = getClient().groups().byGroupId(groupId).artifacts() + .byArtifactId(artifactId).versions().post(createVersion); + message.setBody(result); + } + + @InvokeOnHeader(ApicurioRegistryConstants.OPERATION_DELETE_ARTIFACT) + public void deleteArtifact(Message message) { + String groupId = resolveGroupId(message); + String artifactId = resolveArtifactId(message); + getClient().groups().byGroupId(groupId).artifacts().byArtifactId(artifactId).delete(); + } + + @InvokeOnHeader(ApicurioRegistryConstants.OPERATION_GET_ARTIFACT_CONTENT) + public void getArtifactContent(Message message) throws Exception { + String groupId = resolveGroupId(message); + String artifactId = resolveArtifactId(message); + String version = message.getHeader( + ApicurioRegistryConstants.HEADER_VERSION, "branch=latest", String.class); + + try (InputStream content = getClient().groups().byGroupId(groupId).artifacts() + .byArtifactId(artifactId).versions().byVersionExpression(version).content().get()) { + message.setBody(content.readAllBytes()); + } + } + + @InvokeOnHeader(ApicurioRegistryConstants.OPERATION_GET_ARTIFACT_METADATA) + public void getArtifactMetadata(Message message) { + String groupId = resolveGroupId(message); + String artifactId = resolveArtifactId(message); + + ArtifactMetaData metadata = getClient().groups().byGroupId(groupId).artifacts() + .byArtifactId(artifactId).get(); + message.setBody(metadata); + } + + @InvokeOnHeader(ApicurioRegistryConstants.OPERATION_SEARCH_ARTIFACTS) + public void searchArtifacts(Message message) { + var results = getClient().search().artifacts().get(config -> { + String name = message.getHeader(ApicurioRegistryConstants.HEADER_ARTIFACT_NAME, String.class); + String groupId = resolveGroupId(message); + String description = message.getHeader( + ApicurioRegistryConstants.HEADER_ARTIFACT_DESCRIPTION, String.class); + if (name != null) { + config.queryParameters.name = name; + } + if (groupId != null) { + config.queryParameters.groupId = groupId; + } + if (description != null) { + config.queryParameters.description = description; + } + }); + message.setBody(results); + } + + @InvokeOnHeader(ApicurioRegistryConstants.OPERATION_LIST_VERSIONS) + public void listVersions(Message message) { + String groupId = resolveGroupId(message); + String artifactId = resolveArtifactId(message); + + VersionSearchResults results = getClient().groups().byGroupId(groupId).artifacts() + .byArtifactId(artifactId).versions().get(); + message.setBody(results); + } + + @InvokeOnHeader(ApicurioRegistryConstants.OPERATION_CREATE_GROUP) + public void createGroup(Message message) { + String groupId = resolveGroupId(message); + String description = message.getHeader( + ApicurioRegistryConstants.HEADER_ARTIFACT_DESCRIPTION, String.class); + + CreateGroup createGroup = new CreateGroup(); + createGroup.setGroupId(groupId); + createGroup.setDescription(description); + + GroupMetaData result = getClient().groups().post(createGroup); + message.setBody(result); + } + + @InvokeOnHeader(ApicurioRegistryConstants.OPERATION_TEST_COMPATIBILITY) + public void testCompatibility(Message message) throws Exception { + boolean compatible = doDryRun(message); + message.setBody(compatible); Review Comment: Done in 9ffb47280a0: testCompatibility now sets CamelApicurioRegistryValidationResult as well as the body, the header description says it is set by both operations, and the compatibility tests assert it. _AI-assisted response prepared with OpenCode on behalf of @carlesarnal._ ########## components/camel-apicurio-registry/src/main/java/org/apache/camel/component/apicurioregistry/ApicurioRegistryProducer.java: ########## @@ -0,0 +1,241 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.apicurioregistry; + +import java.io.InputStream; + +import io.apicurio.registry.rest.client.RegistryClient; +import io.apicurio.registry.rest.client.models.ArtifactMetaData; +import io.apicurio.registry.rest.client.models.CreateArtifact; +import io.apicurio.registry.rest.client.models.CreateArtifactResponse; +import io.apicurio.registry.rest.client.models.CreateGroup; +import io.apicurio.registry.rest.client.models.CreateVersion; +import io.apicurio.registry.rest.client.models.GroupMetaData; +import io.apicurio.registry.rest.client.models.IfArtifactExists; +import io.apicurio.registry.rest.client.models.RuleViolationProblemDetails; +import io.apicurio.registry.rest.client.models.VersionContent; +import io.apicurio.registry.rest.client.models.VersionMetaData; +import io.apicurio.registry.rest.client.models.VersionSearchResults; +import org.apache.camel.Message; +import org.apache.camel.spi.InvokeOnHeader; +import org.apache.camel.support.HeaderSelectorProducer; + +public class ApicurioRegistryProducer extends HeaderSelectorProducer { + + private final ApicurioRegistryEndpoint endpoint; + private final ApicurioRegistryConfiguration configuration; + + public ApicurioRegistryProducer(ApicurioRegistryEndpoint endpoint, + ApicurioRegistryConfiguration configuration) { + super(endpoint, ApicurioRegistryConstants.HEADER_OPERATION, configuration::getOperation); + this.endpoint = endpoint; + this.configuration = configuration; + } + + private RegistryClient getClient() { + return endpoint.getRegistryClient(); + } + + private String resolveGroupId(Message message) { + String gid = message.getHeader(ApicurioRegistryConstants.HEADER_GROUP_ID, String.class); + return gid != null ? gid : endpoint.getGroupId(); + } + + private String resolveArtifactId(Message message) { + String aid = message.getHeader(ApicurioRegistryConstants.HEADER_ARTIFACT_ID, String.class); + return aid != null ? aid : endpoint.getArtifactId(); + } + + @InvokeOnHeader(ApicurioRegistryConstants.OPERATION_CREATE_ARTIFACT) + public void createArtifact(Message message) { + String groupId = resolveGroupId(message); + String artifactId = resolveArtifactId(message); + String artifactType = message.getHeader( + ApicurioRegistryConstants.HEADER_ARTIFACT_TYPE, configuration.getArtifactType(), String.class); + String name = message.getHeader(ApicurioRegistryConstants.HEADER_ARTIFACT_NAME, String.class); + String description = message.getHeader(ApicurioRegistryConstants.HEADER_ARTIFACT_DESCRIPTION, String.class); + String content = message.getBody(String.class); + String contentType = message.getHeader( + ApicurioRegistryConstants.HEADER_CONTENT_TYPE, "application/json", String.class); + String ifExistsVal = message.getHeader( + ApicurioRegistryConstants.HEADER_IF_EXISTS, configuration.getIfExists(), String.class); + + CreateArtifact createArtifact = new CreateArtifact(); + createArtifact.setArtifactId(artifactId); + createArtifact.setArtifactType(artifactType); + createArtifact.setName(name); + createArtifact.setDescription(description); + + if (content != null) { + CreateVersion firstVersion = new CreateVersion(); + VersionContent vc = new VersionContent(); + vc.setContent(content); + vc.setContentType(contentType); + firstVersion.setContent(vc); + createArtifact.setFirstVersion(firstVersion); + } + + CreateArtifactResponse result = getClient().groups().byGroupId(groupId).artifacts() + .post(createArtifact, config -> { + if (ifExistsVal != null) { + config.queryParameters.ifExists = IfArtifactExists.forValue(ifExistsVal); + } + }); + message.setBody(result); + } + + @InvokeOnHeader(ApicurioRegistryConstants.OPERATION_UPDATE_ARTIFACT) + public void updateArtifact(Message message) { + String groupId = resolveGroupId(message); + String artifactId = resolveArtifactId(message); + String content = message.getBody(String.class); + String version = message.getHeader(ApicurioRegistryConstants.HEADER_VERSION, String.class); + String contentType = message.getHeader( + ApicurioRegistryConstants.HEADER_CONTENT_TYPE, "application/json", String.class); + + CreateVersion createVersion = new CreateVersion(); + createVersion.setVersion(version); + VersionContent vc = new VersionContent(); + vc.setContent(content); + vc.setContentType(contentType); + createVersion.setContent(vc); + + VersionMetaData result = getClient().groups().byGroupId(groupId).artifacts() + .byArtifactId(artifactId).versions().post(createVersion); + message.setBody(result); + } + + @InvokeOnHeader(ApicurioRegistryConstants.OPERATION_DELETE_ARTIFACT) + public void deleteArtifact(Message message) { + String groupId = resolveGroupId(message); + String artifactId = resolveArtifactId(message); + getClient().groups().byGroupId(groupId).artifacts().byArtifactId(artifactId).delete(); + } + + @InvokeOnHeader(ApicurioRegistryConstants.OPERATION_GET_ARTIFACT_CONTENT) + public void getArtifactContent(Message message) throws Exception { + String groupId = resolveGroupId(message); + String artifactId = resolveArtifactId(message); + String version = message.getHeader( + ApicurioRegistryConstants.HEADER_VERSION, "branch=latest", String.class); + + try (InputStream content = getClient().groups().byGroupId(groupId).artifacts() + .byArtifactId(artifactId).versions().byVersionExpression(version).content().get()) { + message.setBody(content.readAllBytes()); + } + } + + @InvokeOnHeader(ApicurioRegistryConstants.OPERATION_GET_ARTIFACT_METADATA) + public void getArtifactMetadata(Message message) { + String groupId = resolveGroupId(message); + String artifactId = resolveArtifactId(message); + + ArtifactMetaData metadata = getClient().groups().byGroupId(groupId).artifacts() + .byArtifactId(artifactId).get(); + message.setBody(metadata); + } + + @InvokeOnHeader(ApicurioRegistryConstants.OPERATION_SEARCH_ARTIFACTS) + public void searchArtifacts(Message message) { + var results = getClient().search().artifacts().get(config -> { + String name = message.getHeader(ApicurioRegistryConstants.HEADER_ARTIFACT_NAME, String.class); + String groupId = resolveGroupId(message); + String description = message.getHeader( + ApicurioRegistryConstants.HEADER_ARTIFACT_DESCRIPTION, String.class); + if (name != null) { + config.queryParameters.name = name; + } + if (groupId != null) { + config.queryParameters.groupId = groupId; + } + if (description != null) { + config.queryParameters.description = description; + } + }); + message.setBody(results); + } + + @InvokeOnHeader(ApicurioRegistryConstants.OPERATION_LIST_VERSIONS) Review Comment: Done in 9ffb47280a0: testCompatibility now sets CamelApicurioRegistryValidationResult as well as the body, the header description says it is set by both operations, and the compatibility tests assert it. _AI-assisted response prepared with OpenCode on behalf of @carlesarnal._ ########## components/camel-apicurio-registry/src/main/java/org/apache/camel/component/apicurioregistry/ApicurioRegistryEndpoint.java: ########## @@ -0,0 +1,154 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.apicurioregistry; + +import java.util.concurrent.TimeUnit; + +import io.apicurio.registry.client.RegistryClientFactory; +import io.apicurio.registry.client.common.RegistryClientOptions; +import io.apicurio.registry.rest.client.RegistryClient; +import io.vertx.core.Vertx; +import org.apache.camel.Category; +import org.apache.camel.Consumer; +import org.apache.camel.Processor; +import org.apache.camel.Producer; +import org.apache.camel.spi.EndpointServiceLocation; +import org.apache.camel.spi.UriEndpoint; +import org.apache.camel.spi.UriParam; +import org.apache.camel.spi.UriPath; +import org.apache.camel.support.ScheduledPollEndpoint; + +/** + * Manage artifacts, versions, and groups in Apicurio Registry v3. + */ +@UriEndpoint(firstVersion = "4.23.0", scheme = "apicurio-registry", title = "Apicurio Registry", + syntax = "apicurio-registry:groupId/artifactId", + category = { Category.CLOUD, Category.API }, headersClass = ApicurioRegistryConstants.class) +public class ApicurioRegistryEndpoint extends ScheduledPollEndpoint implements EndpointServiceLocation { + + @UriPath(description = "The artifact group ID") + private String groupId; + + @UriPath(description = "The artifact ID") + private String artifactId; + + @UriParam + private ApicurioRegistryConfiguration configuration; + + @UriParam(label = "advanced", description = "To use a pre-configured RegistryClient instance") + private RegistryClient registryClient; + + private Vertx vertx; + + ApicurioRegistryEndpoint(String uri, ApicurioRegistryComponent component, + ApicurioRegistryConfiguration configuration, + String groupId, String artifactId) { + super(uri, component); + this.configuration = configuration; + this.groupId = groupId; + this.artifactId = artifactId; + } + + @Override + public Producer createProducer() throws Exception { + return new ApicurioRegistryProducer(this, configuration); + } + + @Override + public Consumer createConsumer(Processor processor) throws Exception { + ApicurioRegistryConsumer consumer = new ApicurioRegistryConsumer(this, processor, configuration); + configureConsumer(consumer); + return consumer; + } + + @Override + protected void doStart() throws Exception { + super.doStart(); + if (registryClient == null) { + vertx = Vertx.vertx(); + try { + registryClient = createRegistryClient(); + } catch (Exception e) { + closeVertx(); + throw e; + } + } + } + + @Override + protected void doStop() throws Exception { + super.doStop(); + if (vertx != null) { + registryClient = null; + closeVertx(); + } + } + + private void closeVertx() throws Exception { + try { + vertx.close().toCompletionStage().toCompletableFuture().get(30, TimeUnit.SECONDS); + } finally { + vertx = null; + } + } + + private RegistryClient createRegistryClient() { + RegistryClientOptions options = RegistryClientOptions.create(configuration.getRegistryUrl(), vertx); + String authType = configuration.getAuthType(); + if ("basic".equalsIgnoreCase(authType)) { + options.basicAuth(configuration.getUsername(), configuration.getPassword()); + } else if ("oidc".equalsIgnoreCase(authType)) { + options.oauth2(configuration.getTokenEndpoint(), configuration.getClientId(), + configuration.getClientSecret(), configuration.getScope()); + } + return RegistryClientFactory.create(options); + } + + public RegistryClient getRegistryClient() { + return registryClient; + } + + public void setRegistryClient(RegistryClient registryClient) { + this.registryClient = registryClient; + } + + public String getGroupId() { + return groupId; + } + + public String getArtifactId() { + return artifactId; + } + + public ApicurioRegistryConfiguration getConfiguration() { + return configuration; + } + + public void setConfiguration(ApicurioRegistryConfiguration configuration) { + this.configuration = configuration; + } + + @Override + public String getServiceUrl() { + return configuration.getRegistryUrl(); + } + + @Override + public String getServiceProtocol() { + return "http"; Review Comment: Leaving this as "http" for now: @davsclaus said in his review that the current value is fine, so I would rather not change it without agreement from the maintainers. _AI-assisted response prepared with OpenCode on behalf of @carlesarnal._ ########## components/camel-apicurio-registry/src/main/java/org/apache/camel/component/apicurioregistry/ApicurioRegistryEndpoint.java: ########## @@ -0,0 +1,154 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.apicurioregistry; + +import java.util.concurrent.TimeUnit; + +import io.apicurio.registry.client.RegistryClientFactory; +import io.apicurio.registry.client.common.RegistryClientOptions; +import io.apicurio.registry.rest.client.RegistryClient; +import io.vertx.core.Vertx; +import org.apache.camel.Category; +import org.apache.camel.Consumer; +import org.apache.camel.Processor; +import org.apache.camel.Producer; +import org.apache.camel.spi.EndpointServiceLocation; +import org.apache.camel.spi.UriEndpoint; +import org.apache.camel.spi.UriParam; +import org.apache.camel.spi.UriPath; +import org.apache.camel.support.ScheduledPollEndpoint; + +/** + * Manage artifacts, versions, and groups in Apicurio Registry v3. + */ +@UriEndpoint(firstVersion = "4.23.0", scheme = "apicurio-registry", title = "Apicurio Registry", + syntax = "apicurio-registry:groupId/artifactId", + category = { Category.CLOUD, Category.API }, headersClass = ApicurioRegistryConstants.class) +public class ApicurioRegistryEndpoint extends ScheduledPollEndpoint implements EndpointServiceLocation { + + @UriPath(description = "The artifact group ID") + private String groupId; + + @UriPath(description = "The artifact ID") + private String artifactId; + + @UriParam + private ApicurioRegistryConfiguration configuration; + + @UriParam(label = "advanced", description = "To use a pre-configured RegistryClient instance") + private RegistryClient registryClient; + + private Vertx vertx; + + ApicurioRegistryEndpoint(String uri, ApicurioRegistryComponent component, + ApicurioRegistryConfiguration configuration, + String groupId, String artifactId) { + super(uri, component); + this.configuration = configuration; + this.groupId = groupId; + this.artifactId = artifactId; + } + + @Override + public Producer createProducer() throws Exception { + return new ApicurioRegistryProducer(this, configuration); + } + + @Override + public Consumer createConsumer(Processor processor) throws Exception { + ApicurioRegistryConsumer consumer = new ApicurioRegistryConsumer(this, processor, configuration); + configureConsumer(consumer); + return consumer; + } + + @Override + protected void doStart() throws Exception { + super.doStart(); + if (registryClient == null) { + vertx = Vertx.vertx(); + try { + registryClient = createRegistryClient(); + } catch (Exception e) { + closeVertx(); + throw e; + } + } + } + + @Override + protected void doStop() throws Exception { + super.doStop(); + if (vertx != null) { + registryClient = null; + closeVertx(); + } + } + + private void closeVertx() throws Exception { + try { + vertx.close().toCompletionStage().toCompletableFuture().get(30, TimeUnit.SECONDS); + } finally { + vertx = null; + } + } + + private RegistryClient createRegistryClient() { + RegistryClientOptions options = RegistryClientOptions.create(configuration.getRegistryUrl(), vertx); + String authType = configuration.getAuthType(); + if ("basic".equalsIgnoreCase(authType)) { + options.basicAuth(configuration.getUsername(), configuration.getPassword()); + } else if ("oidc".equalsIgnoreCase(authType)) { + options.oauth2(configuration.getTokenEndpoint(), configuration.getClientId(), + configuration.getClientSecret(), configuration.getScope()); + } + return RegistryClientFactory.create(options); + } + + public RegistryClient getRegistryClient() { + return registryClient; + } + + public void setRegistryClient(RegistryClient registryClient) { + this.registryClient = registryClient; + } + + public String getGroupId() { + return groupId; + } + + public String getArtifactId() { + return artifactId; + } + + public ApicurioRegistryConfiguration getConfiguration() { + return configuration; + } + + public void setConfiguration(ApicurioRegistryConfiguration configuration) { + this.configuration = configuration; + } + + @Override Review Comment: Leaving this as "http" for now: @davsclaus said in his review that the current value is fine, so I would rather not change it without agreement from the maintainers. _AI-assisted response prepared with OpenCode on behalf of @carlesarnal._ -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
