Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
9 changed files
with
359 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
integration-tests/bean/src/main/java/org/apache/camel/quarkus/component/bean/Counter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* 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; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
@ApplicationScoped | ||
public class Counter { | ||
private final AtomicInteger value = new AtomicInteger(0); | ||
|
||
public int increment() { | ||
return value.incrementAndGet(); | ||
} | ||
|
||
public int getValue() { | ||
return value.get(); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
...ean/src/main/java/org/apache/camel/quarkus/component/bean/EagerAppScopedRouteBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* 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; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.inject.Inject; | ||
|
||
import org.apache.camel.CamelContext; | ||
import org.apache.camel.builder.RouteBuilder; | ||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
|
||
/** | ||
* A {@link RouteBuilder} injected into {@link CamelResource} and thus instantiated eagerly. | ||
*/ | ||
@ApplicationScoped | ||
public class EagerAppScopedRouteBuilder extends RouteBuilder { | ||
|
||
static final AtomicInteger INSTANCE_COUNTER = new AtomicInteger(0); | ||
static final AtomicInteger CONFIGURE_COUNTER = new AtomicInteger(0); | ||
|
||
@Inject | ||
Counter counter; | ||
|
||
@ConfigProperty(name = "my.foo.property", defaultValue = "not found") | ||
String myFooValue; | ||
|
||
@PostConstruct | ||
public void postConstruct() { | ||
INSTANCE_COUNTER.incrementAndGet(); | ||
} | ||
|
||
@Override | ||
public void addRoutesToCamelContext(CamelContext context) throws Exception { | ||
CONFIGURE_COUNTER.incrementAndGet(); | ||
super.addRoutesToCamelContext(context); | ||
} | ||
|
||
@Override | ||
public void configure() { | ||
|
||
/* | ||
* counter and config-property should actually work without the bean extension. Doing it here because we have | ||
* quarkus.camel.enable-main=true in the core itest | ||
*/ | ||
from("direct:counter") | ||
.id("counter") | ||
.setBody(() -> counter.increment()) | ||
.to("log:counter"); | ||
from("direct:config-property") | ||
.id("config-property") | ||
.setBody(() -> "myFooValue = " + myFooValue) | ||
.to("log:config-property"); | ||
} | ||
|
||
public Counter getCounter() { | ||
return counter; | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
...bean/src/main/java/org/apache/camel/quarkus/component/bean/LazyAppScopedRouteBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* 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; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
import org.apache.camel.builder.RouteBuilder; | ||
|
||
/** | ||
* An @ApplicationScoped {@link RouteBuilder} that would normally get removed from the CDI container because it is not | ||
* injected anywhere and because it has no observer method, etc. | ||
*/ | ||
@ApplicationScoped | ||
public class LazyAppScopedRouteBuilder extends RouteBuilder { | ||
|
||
@Override | ||
public void configure() { | ||
from("direct:lazy") | ||
.setBody(() -> "lazy"); | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
.../bean/src/main/java/org/apache/camel/quarkus/component/bean/RouteBuilderWithProducer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* 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; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.inject.Produces; | ||
|
||
import org.apache.camel.builder.RouteBuilder; | ||
|
||
/** | ||
* A {@link RouteBuilder} with a @Produces method that makes it a CDI bean. It would normally get removed from the CDI | ||
* container. | ||
*/ | ||
public class RouteBuilderWithProducer extends RouteBuilder { | ||
|
||
@Override | ||
public void configure() { | ||
from("direct:with-producer") | ||
.setBody(() -> "with-producer"); | ||
} | ||
|
||
@Produces | ||
@ApplicationScoped | ||
Hello hello() { | ||
return new Hello(); | ||
} | ||
|
||
public static class Hello { | ||
public String getHello() { | ||
return "hello"; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.