Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.AnnotationValue;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.ClassInfo.NestingType;
import org.jboss.jandex.DotName;
import org.jboss.jandex.FieldInfo;
import org.jboss.jandex.MethodInfo;
Expand Down Expand Up @@ -209,10 +208,8 @@ void processBindToRegistryAnnotations(
.filter(BindToRegistryBeanInfo::isValid)
// Filter out @BindToRegistry usage on RouteBuilder impls as Camel can already handle this internally
.filter(bindToRegistryBeanInfo -> camelRoutes.stream()
.noneMatch(routeBuilder -> !bindToRegistryBeanInfo.getDeclaringType().nestingType()
.equals(NestingType.TOP_LEVEL)
&& routeBuilder.getDotName()
.equals(bindToRegistryBeanInfo.getDeclaringType().enclosingClass())))
.noneMatch(routeBuilder -> routeBuilder.getDotName()
.equals(bindToRegistryBeanInfo.getDeclaringType().name())))
// Filter any existing named beans compared to the @BindToRegistry bean name
.filter(bindToRegistryBeanInfo -> containerBeans.getBeans()
.stream()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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.quarkus.component.bean.bind;

import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithDefault;

@ConfigMapping(prefix = "bind.to.registry.test")
public interface BindToRegistryConfig {
@WithDefault("This is the default message")
String message();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.quarkus.component.bean.bind;

import java.util.concurrent.atomic.AtomicInteger;

import org.apache.camel.Exchange;
import org.apache.camel.Processor;

public class BindToRegistryProcessor implements Processor {
static final AtomicInteger COUNTER = new AtomicInteger();

private final String message;

public BindToRegistryProcessor(String message) {
COUNTER.incrementAndGet();
this.message = message;
}

@Override
public void process(Exchange exchange) {
exchange.getMessage().setBody(message.formatted(COUNTER.get()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,19 @@
package org.apache.camel.quarkus.component.bean.bind;

import io.quarkus.runtime.annotations.RegisterForReflection;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import org.apache.camel.BindToRegistry;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;

@ApplicationScoped
public class BindToRegistryRoutes extends RouteBuilder {
@Inject
BindToRegistryConfig config;

@Override
public void configure() throws Exception {
from("direct:invokeBindToRegistryBean")
Expand All @@ -39,6 +45,9 @@ public void process(Exchange exchange) throws Exception {
exchange.getMessage().setBody(bean.hello("BindToRegistrySimpleBean"));
}
});

from("direct:checkBeanInstantiationCount")
.process("bindToRegistryProcessor");
}

@RegisterForReflection(fields = false)
Expand All @@ -48,4 +57,9 @@ public String hello(String name) {
return "Hello " + name;
}
}

@BindToRegistry
public BindToRegistryProcessor bindToRegistryProcessor() {
return new BindToRegistryProcessor(config.message());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ my.injected.property.a = Test @PropertyInject
my.injected.property.d = Test @PropertyInject Setter Method
my.injected.property.e = Test @PropertyInject Method Argument

bind.to.registry.test.message=BindToRegistryProcessor instantiation count: %d

# DataSource Test
quarkus.datasource.db-kind = h2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,12 @@ void bindToRegistryWhereNamedCdiBeanAlreadyExists() {
.then()
.body(equalTo("Hello CDI Bean"));
}

@Test
void bindToRegistryBeanInstantiationCount() {
RestAssured.given()
.get("/bean/route/checkBeanInstantiationCount")
.then()
.body(equalTo("BindToRegistryProcessor instantiation count: 1"));
}
}