You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "mertdotcc (via GitHub)" <gi...@apache.org> on 2023/03/12 21:36:45 UTC
[GitHub] [camel-k] mertdotcc opened a new issue, #4124: How to use JVM classpaths in Native mode?
mertdotcc opened a new issue, #4124:
URL: https://github.com/apache/camel-k/issues/4124
I have an integration in which I am using a JAR package for my POJO classes (as per [#1821](https://github.com/apache/camel-k/issues/1821)).
My `kamel run` command looks like this:
```
kamel run \
--config configmap:some-config-file/some-config-parameter \
--config secret:some-secret-file/some-secret-parameter \
--open-api file:./resources/my-app.yaml \
--resource file:./resources/MyPOJO-1.0-SNAPSHOT.jar \
--resource file:./resources/sample-error-response.json \
--dependency mvn:org.mapstruct:mapstruct:1.5.2.Final \
--dependency mvn:com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.14.2 \
--source ./sources/MyBean.java \
--trait jvm.classpath="/etc/camel/resources/MyPOJO-1.0-SNAPSHOT.jar" \
--trait container.enabled=true \
--trait container.request-cpu="250m" \
--trait container.request-memory="256Mi" \
--trait container.limit-cpu="500m" \
--trait container.limit-memory="512Mi" \
--trait container.port=8443 \
--trait health.enabled=true \
--trait health.liveness-probe-enabled=true \
--trait health.liveness-scheme="HTTP" \
--trait health.liveness-initial-delay=0 \
--trait health.liveness-timeout=10 \
--trait health.liveness-period=15 \
--trait health.liveness-success-threshold=1 \
--trait health.liveness-failure-threshold=3 \
--trait health.readiness-probe-enabled=true \
--trait health.readiness-scheme="HTTP" \
--trait health.readiness-initial-delay=0 \
--trait health.readiness-timeout=10 \
--trait health.readiness-period=15 \
--trait health.readiness-success-threshold=1 \
--trait health.readiness-failure-threshold=3 \
--trait knative-service.enabled=true \
--trait knative-service.autoscaling-class="kpa.autoscaling.knative.dev" \
--trait knative-service.autoscaling-metric="rps" \
--trait knative-service.autoscaling-target=100 \
--trait knative-service.min-scale=0 \
--trait knative-service.max-scale=20 \
--trait quarkus.enabled=true \
--trait quarkus.package-type=fast-jar \
--trait quarkus.package-type=native \
MyIntegration.java
```
In my integration, I am calling a method from my bean, and inside that bean, I am importing&using some logic from my POJO.
This code works without the last 3 `quarkus` traits. But when I enable the native mode, it throws an error due to my POJO indicating a reflection-related issue.
```
camel-k-operator {"level":"error","ts":1678656499.1001992,"logger":"camel-k.maven.build","msg":"Failed to execute goal io.quarkus:quarkus-maven-plugin:2.16.0.Final:build (build-integr │
│ ation) on project camel-k-integration: Failed to build quarkus application: io.quarkus.builder.BuildException: Build failure: Build failed due to errors","stacktrace":"github.com/apac │
│ he/camel-k/pkg/util/log.Logger.Error\n\tgithub.com/apache/camel-k/pkg/util/log/log.go:75\ngithub.com/apache/camel-k/pkg/util/maven.normalizeLog\n\tgithub.com/apache/camel-k/pkg/util/m │
│ aven/maven_log.go:83\ngithub.com/apache/camel-k/pkg/util/maven.mavenLogHandler\n\tgithub.com/apache/camel-k/pkg/util/maven/maven_log.go:54\ngithub.com/apache/camel-k/pkg/util.scan\n\t │
│ github.com/apache/camel-k/pkg/util/command.go:77\ngithub.com/apache/camel-k/pkg/util.RunAndLog.func1\n\tgithub.com/apache/camel-k/pkg/util/command.go:56\ngolang.org/x/sync/errgroup.(* │
│ Group).Go.func1\n\tgolang.org/x/sync@v0.1.0/errgroup/errgroup.go:75"} │
│ camel-k-operator {"level":"error","ts":1678656499.1010284,"logger":"camel-k.maven.build","msg":"\t[error]: Build step org.apache.camel.quarkus.dsl.java.joor.deployment.JavaJoorDslProc │
│ essor#compileClassesAOT threw an exception: org.joor.ReflectException: Compilation error:","stacktrace":"github.com/apache/camel-k/pkg/util/log.Logger.Error\n\tgithub.com/apache/camel │
│ -k/pkg/util/log/log.go:75\ngithub.com/apache/camel-k/pkg/util/maven.normalizeLog\n\tgithub.com/apache/camel-k/pkg/util/maven/maven_log.go:83\ngithub.com/apache/camel-k/pkg/util/maven. │
│ mavenLogHandler\n\tgithub.com/apache/camel-k/pkg/util/maven/maven_log.go:54\ngithub.com/apache/camel-k/pkg/util.scan\n\tgithub.com/apache/camel-k/pkg/util/command.go:77\ngithub.com/ap │
│ ache/camel-k/pkg/util.RunAndLog.func1\n\tgithub.com/apache/camel-k/pkg/util/command.go:56\ngolang.org/x/sync/errgroup.(*Group).Go.func1\n\tgolang.org/x/sync@v0.1.0/errgroup/errgroup.g │
│ o:75"} │
│ camel-k-operator {"level":"error","ts":1678656499.1084027,"logger":"camel-k.maven.build","msg":"/com/myCompany/myProject/sources/MyBean.java:3: error: package com │
│ .myCompany.myProject.mappingresources.model.destination does not exist","stacktrace":"github.com/apache/camel-k/pkg/util/log.Logger.Error\n\tgithub.com/apache/camel-k/pkg/u │
│ til/log/log.go:75\ngithub.com/apache/camel-k/pkg/util/maven.normalizeLog\n\tgithub.com/apache/camel-k/pkg/util/maven/maven_log.go:83\ngithub.com/apache/camel-k/pkg/util/maven.mavenLog │
│ Handler\n\tgithub.com/apache/camel-k/pkg/util/maven/maven_log.go:54\ngithub.com/apache/camel-k/pkg/util.scan\n\tgithub.com/apache/camel-k/pkg/util/command.go:77\ngithub.com/apache/cam │
│ el-k/pkg/util.RunAndLog.func1\n\tgithub.com/apache/camel-k/pkg/util/command.go:56\ngolang.org/x/sync/errgroup.(*Group).Go.func1\n\tgolang.org/x/sync@v0.1.0/errgroup/errgroup.go:75"} │
│ camel-k-operator {"level":"error","ts":1678656499.108462,"logger":"camel-k.maven.build","msg":"import com.myCompany.myProject.mappingresources.model.destination.MyDestination │
│ lAccount;","stacktrace":"github.com/apache/camel-k/pkg/util/log.Logger.Error\n\tgithub.com/apache/camel-k/pkg/util/log/log.go:75\ngithub.com/apache/camel-k/pkg/util/maven.normalizeLog │
│ \n\tgithub.com/apache/camel-k/pkg/util/maven/maven_log.go:83\ngithub.com/apache/camel-k/pkg/util/maven.mavenLogHandler\n\tgithub.com/apache/camel-k/pkg/util/maven/maven_log.go:54\ngit │
│ hub.com/apache/camel-k/pkg/util.scan\n\tgithub.com/apache/camel-k/pkg/util/command.go:77\ngithub.com/apache/camel-k/pkg/util.RunAndLog.func1\n\tgithub.com/apache/camel-k/pkg/util/comm │
│ and.go:56\ngolang.org/x/sync/errgroup.(*Group).Go.func1\n\tgolang.org/x/sync@v0.1.0/errgroup/errgroup.go:75"} │
│ camel-k-operator {"level":"error","ts":1678656499.1084936,"logger":"camel-k.maven.build","msg":" ^","stacktr │
│ ace":"github.com/apache/camel-k/pkg/util/log.Logger.Error\n\tgithub.com/apache/camel-k/pkg/util/log/log.go:75\ngithub.com/apache/camel-k/pkg/util/maven.normalizeLog\n\tgithub.com/apac │
│ he/camel-k/pkg/util/maven/maven_log.go:83\ngithub.com/apache/camel-k/pkg/util/maven.mavenLogHandler\n\tgithub.com/apache/camel-k/pkg/util/maven/maven_log.go:54\ngithub.com/apache/came │
│ l-k/pkg/util.scan\n\tgithub.com/apache/camel-k/pkg/util/command.go:77\ngithub.com/apache/camel-k/pkg/util.RunAndLog.func1\n\tgithub.com/apache/camel-k/pkg/util/command.go:56\ngolang.o │
│ rg/x/sync/errgroup.(*Group).Go.func1\n\tgolang.org/x/sync@v0.1.0/errgroup/errgroup.go:75"}
```
Am I missing something here? Or is my gut feeling correct?
What options do we have when we have integrations that use POJOs in them if we want to run them natively?
Any help is appreciated.
Thanks in advance!
--
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: commits-unsubscribe@camel.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-k] essobedo commented on issue #4124: How to use JVM classpaths in Native mode?
Posted by "essobedo (via GitHub)" <gi...@apache.org>.
essobedo commented on issue #4124:
URL: https://github.com/apache/camel-k/issues/4124#issuecomment-1486353845
> > @squakez, unless I miss something, in which use case does it make sense to change the containerPort of the pod?
>
> I guess that this parameter is good when the user want to have full control of the ports used/exposed.
Yes but if you do so without changing the value of `quarkus.http.port`, it won't work, don't you agree?
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-k] essobedo commented on issue #4124: How to use JVM classpaths in Native mode?
Posted by "essobedo (via GitHub)" <gi...@apache.org>.
essobedo commented on issue #4124:
URL: https://github.com/apache/camel-k/issues/4124#issuecomment-1481480037
@mertdotcc Excellent! Thank you very much for the great effort! I will look into it asap
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-k] mertdotcc commented on issue #4124: How to use JVM classpaths in Native mode?
Posted by "mertdotcc (via GitHub)" <gi...@apache.org>.
mertdotcc commented on issue #4124:
URL: https://github.com/apache/camel-k/issues/4124#issuecomment-1488929992
Wow, thank you so much for the detailed response (again)! I will pull your changes and verify as soon as possible.
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-k] mertdotcc commented on issue #4124: How to use JVM classpaths in Native mode?
Posted by "mertdotcc (via GitHub)" <gi...@apache.org>.
mertdotcc commented on issue #4124:
URL: https://github.com/apache/camel-k/issues/4124#issuecomment-1485077773
Sure thing,
```
{
"studentFirstName": "Mert",
"studentLastName": "Öztürk",
"studentFaculty": "SCIENCE",
"createdAt": "2016-09-06T13:37:50+03:00",
"updatedAt": "2016-09-06T13:37:50+03:00",
"grades": {
"gpa": 3.50,
"cgpa": 2.80
}
}
```
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-k] essobedo commented on issue #4124: How to use JVM classpaths in Native mode?
Posted by "essobedo (via GitHub)" <gi...@apache.org>.
essobedo commented on issue #4124:
URL: https://github.com/apache/camel-k/issues/4124#issuecomment-1521574693
In native mode, it starts in 20-30 seconds on your side? Could you please share the log?
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-k] essobedo commented on issue #4124: How to use JVM classpaths in Native mode?
Posted by "essobedo (via GitHub)" <gi...@apache.org>.
essobedo commented on issue #4124:
URL: https://github.com/apache/camel-k/issues/4124#issuecomment-1486410900
> One more remark @essobedo,
>
> "The component mapstruct is not yet supported by Camel-Quarkus, that's why it doesn't work in native mode" -> I am not using the Camel component for MapStruct but the actual MapStruct dependency, which is Quarkus and native ready as per [this](https://mapstruct.org/news/2019-12-06-mapstruct-and-quarkus/). Why would this affect me on the native side? I am a bit confused.
Interesting link, thank you for sharing, let me check if we can leverage it
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-k] essobedo commented on issue #4124: How to use JVM classpaths in Native mode?
Posted by "essobedo (via GitHub)" <gi...@apache.org>.
essobedo commented on issue #4124:
URL: https://github.com/apache/camel-k/issues/4124#issuecomment-1477997375
Could you please provide a simple reproducer? Here it is hard to follow because you changed the name of your classes and the code seems to be more complicated than it should be to illustrate your problem.
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-k] lburgazzoli commented on issue #4124: How to use JVM classpaths in Native mode?
Posted by "lburgazzoli (via GitHub)" <gi...@apache.org>.
lburgazzoli commented on issue #4124:
URL: https://github.com/apache/camel-k/issues/4124#issuecomment-1477448087
@mertdotcc is there any chance to publish the jars to a maven repo ? in such case I think it should be possible to achieve your goal as then the jars will be available at build time
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-k] essobedo commented on issue #4124: How to use JVM classpaths in Native mode?
Posted by "essobedo (via GitHub)" <gi...@apache.org>.
essobedo commented on issue #4124:
URL: https://github.com/apache/camel-k/issues/4124#issuecomment-1485077007
@mertdotcc Could you please also share the payload that you use for your tests?
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-k] squakez commented on issue #4124: How to use JVM classpaths in Native mode?
Posted by "squakez (via GitHub)" <gi...@apache.org>.
squakez commented on issue #4124:
URL: https://github.com/apache/camel-k/issues/4124#issuecomment-1477437069
@mertdotcc unfortunately I don't see any other workaround. If you need to go Quarkus Native, you must include any dependency in the build, and this is something for which Camel K 1.x is not designed.
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-k] mertdotcc commented on issue #4124: How to use JVM classpaths in Native mode?
Posted by "mertdotcc (via GitHub)" <gi...@apache.org>.
mertdotcc commented on issue #4124:
URL: https://github.com/apache/camel-k/issues/4124#issuecomment-1477000023
> The only kind of workaround you can try to adopt at this stage is to try embedding all your dependency source into the same Java class you're using for your Integration (it may be difficult if it's a lot of code, I know).
Unfortunately, this is not a possibility for me as we already have a large codebase with many dependencies. Embedding all said dependencies into the same Java class sounds like a nightmare. 🥲
I've read the discussion in the [#4024](https://github.com/apache/camel-k/issues/4024) that you posted and although I am personally super pumped for the changes/additions that are planned for Camel-K V2, I would like to explore the options that I have atm.
Do you see any potential workarounds that don't involve having all my dependencies in one single Java class?
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-k] squakez commented on issue #4124: How to use JVM classpaths in Native mode?
Posted by "squakez (via GitHub)" <gi...@apache.org>.
squakez commented on issue #4124:
URL: https://github.com/apache/camel-k/issues/4124#issuecomment-1486341813
> @squakez, unless I miss something, in which use case does it make sense to change the containerPort of the pod?
I guess that this parameter is good when the user want to have full control of the ports used/exposed.
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-k] essobedo commented on issue #4124: How to use JVM classpaths in Native mode?
Posted by "essobedo (via GitHub)" <gi...@apache.org>.
essobedo commented on issue #4124:
URL: https://github.com/apache/camel-k/issues/4124#issuecomment-1494331077
@mertdotcc Did you test what I provided on your side?
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-k] essobedo commented on issue #4124: How to use JVM classpaths in Native mode?
Posted by "essobedo (via GitHub)" <gi...@apache.org>.
essobedo commented on issue #4124:
URL: https://github.com/apache/camel-k/issues/4124#issuecomment-1488892624
OK so the link was helpful, I could finally make it work in native mode, and it allowed me to realize that some improvements could be made in the Java DSL support in camel-quarkus.
Description of the changes made in your project `issue4124part2` https://github.com/essobedo/issue4124part2/commit/796b1c52d4848f385228fcd92b6e98098f5260af:
* Add the Jandex plugin to the pom file to allow Quarkus to find the annotations (Annotations in the integration class are ignored by Quarkus for now)
* Add the annotation `RegisterForReflection` to all the classes that are accessed by reflection (by Jackson or camel-bean)
* Configure the Mapper to be able to inject it thanks to CDI (Using `Mappers.getMapper(Class)` is not recommended for the native mode as it uses reflection see https://mapstruct.org/news/2019-12-06-mapstruct-and-quarkus/#summing-up)
* Rewrite `IntegrationBean` to make it compatible with the native mode
The Integration class:
```
// camel-k: language=java
// camel-k: name=issue4124-part1-integration
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.mertdotcc.sources.IntegrationBean;
import org.apache.camel.LoggingLevel;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.jackson.JacksonDataFormat;
import com.mertdotcc.mappingresources.source.Student;
public class Integration extends RouteBuilder {
@Override
public void configure() throws Exception {
onException(Exception.class)
.handled(true)
.setHeader("CamelHttpResponseCode").constant("400")
.setBody().simple("resource:file:/etc/camel/resources/sample-error-response.json")
.log(LoggingLevel.ERROR, "exception", "${exception}").routeId("exception");
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
mapper.registerModule(new JavaTimeModule());
JacksonDataFormat jacksonObjectMapperFormat = new JacksonDataFormat(Student.class);
jacksonObjectMapperFormat.setObjectMapper(mapper);
// POST
from("direct://addStudent").routeId("addStudent")
.log(LoggingLevel.INFO, "before-mapping", "headers: ${headers}; body: ${body}")
.removeHeaders("*")
.convertBodyTo(String.class)
.unmarshal(jacksonObjectMapperFormat)
.to("bean:IntegrationBean?method=handleMapping")
.marshal(jacksonObjectMapperFormat)
.log(LoggingLevel.INFO, "after-mapping", "headers: ${headers}; body: ${body}");
}
}
```
Modifications:
* Configure the `JacksonDataFormat`
* Use the component `camel-bean` to call `handleMapping`
The run script:
```
kamel run \
--open-api file:./resources/part1-openapi.yaml \
--resource file:./resources/sample-error-response.json \
--dependency github:essobedo/issue4124part2 \
--dependency camel:jackson \
--trait container.enabled=true \
--trait container.service-port=8443 \
--trait container.request-cpu="250m" \
--trait container.request-memory="256Mi" \
--trait container.limit-cpu="500m" \
--trait container.limit-memory="512Mi" \
--trait health.enabled=true \
--trait health.liveness-probe-enabled=true \
--trait health.liveness-scheme="HTTP" \
--trait health.liveness-initial-delay=0 \
--trait health.liveness-timeout=10 \
--trait health.liveness-period=15 \
--trait health.liveness-success-threshold=1 \
--trait health.liveness-failure-threshold=3 \
--trait health.readiness-probe-enabled=true \
--trait health.readiness-scheme="HTTP" \
--trait health.readiness-initial-delay=0 \
--trait health.readiness-timeout=10 \
--trait health.readiness-period=15 \
--trait health.readiness-success-threshold=1 \
--trait health.readiness-failure-threshold=3 \
--trait quarkus.enabled=true \
--trait quarkus.package-type=native \
Integration.java
```
Modifications:
* Use the trait option `container.service-port` to configure the port
* Add explicitly the `jackson` component since Camel-K cannot detect it when using a custom configuration
* Remove `mapstruct` from the direct dependency since it is not used by the integration class
## Result
```
2023-03-29 15:32:19,190 INFO [org.apa.cam.k.Runtime] (main) Apache Camel K Runtime 1.17.0
2023-03-29 15:32:19,191 INFO [org.apa.cam.qua.cor.CamelBootstrapRecorder] (main) Bootstrap runtime: org.apache.camel.quarkus.main.CamelMainRuntime
2023-03-29 15:32:19,191 INFO [org.apa.cam.mai.MainSupport] (main) Apache Camel (Main) 3.20.1 is starting
2023-03-29 15:32:19,194 INFO [org.apa.cam.k.lis.SourcesConfigurer] (main) Loading routes from: SourceDefinition{name='part1-openapi', language='xml', type='source', location='file:/etc/camel/sources/part1-openapi.xml', }
2023-03-29 15:32:19,207 INFO [org.apa.cam.imp.eng.AbstractCamelContext] (main) Apache Camel 3.20.1 (camel-1) is starting
2023-03-29 15:32:19,208 INFO [org.apa.cam.imp.eng.AbstractCamelContext] (main) Routes startup (started:2)
2023-03-29 15:32:19,208 INFO [org.apa.cam.imp.eng.AbstractCamelContext] (main) Started addStudent (direct://addStudent)
2023-03-29 15:32:19,208 INFO [org.apa.cam.imp.eng.AbstractCamelContext] (main) Started route1 (rest://post:/student)
2023-03-29 15:32:19,208 INFO [org.apa.cam.imp.eng.AbstractCamelContext] (main) Apache Camel 3.20.1 (camel-1) started in 3ms (build:0ms init:3ms start:0ms)
2023-03-29 15:32:19,264 INFO [io.quarkus] (main) camel-k-integration 1.12.0 native (powered by Quarkus 2.16.0.Final) started in 0.102s. Listening on: http://0.0.0.0:8080
2023-03-29 15:32:19,264 INFO [io.quarkus] (main) Profile prod activated.
2023-03-29 15:32:19,264 INFO [io.quarkus] (main) Installed features: [camel-attachments, camel-bean, camel-core, camel-direct, camel-jackson, camel-java-joor-dsl, camel-k-core, camel-k-runtime, camel-kubernetes, camel-microprofile-health, camel-platform-http, camel-rest, camel-xml-io-dsl, cdi, kubernetes-client, security, smallrye-context-propagation, smallrye-health, vertx]
2023-03-29 15:35:10,158 INFO [before-mapping] (executor-thread-1) headers: {Accept=*/*, Accept-Encoding=gzip, deflate, br, CamelHttpMethod=POST, CamelHttpPath=/student, CamelHttpQuery=null, CamelHttpRawQuery=null, CamelHttpUri=/student, CamelHttpUrl=http://localhost:8080/student, CamelVertxPlatformHttpAuthenticatedUser=io.quarkus.vertx.http.runtime.security.QuarkusHttpUser@14dfb974, Connection=keep-alive, Content-Length=259, Content-Type=application/json, Host=localhost:8080, Postman-Token=be087bbf-a931-42ce-93b1-3c2a881a7818, User-Agent=PostmanRuntime/7.31.3}; body: {
"studentFirstName": "Mert",
"studentLastName": "Öztürk",
"studentFaculty": "SCIENCE",
"createdAt": "2016-09-06T13:37:50+03:00",
"updatedAt": "2016-09-06T13:37:50+03:00",
"grades": {
"gpa": 3.50,
"cgpa": 2.80
}
}
student: Student{studentFirstName='Mert', studentLastName='Öztürk', studentFaculty=SCIENCE, createdAt=2016-09-06T10:37:50Z, updatedAt=2016-09-06T10:37:50Z, grades=StudentGrades{gpa=3.5, cgpa=2.8}}
studentWithGrades: StudentWithGrades{studentFirstName='Mert', studentLastName='Öztürk', studentFaculty='SCIENCE', createdAt=2016-09-06T10:37:50Z, updatedAt=2016-09-06T10:37:50Z, gpa=3.5, cgpa=2.8}
2023-03-29 15:35:10,164 INFO [after-mapping] (executor-thread-1) headers: {Content-Type=application/json}; body: {"studentFirstName":"Mert","studentLastName":"Öztürk","studentFaculty":"SCIENCE","createdAt":"2016-09-06T10:37:50Z","updatedAt":"2016-09-06T10:37:50Z","gpa":3.5,"cgpa":2.8}
```
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-k] mertdotcc commented on issue #4124: How to use JVM classpaths in Native mode?
Posted by "mertdotcc (via GitHub)" <gi...@apache.org>.
mertdotcc commented on issue #4124:
URL: https://github.com/apache/camel-k/issues/4124#issuecomment-1481354636
Hey @essobedo,
I created two repositories, [issue4124part1](https://github.com/mertdotcc/issue4124part1) and [issue4124part2](https://github.com/mertdotcc/issue4124part2)
Part 1 uses part 2 as a maven dependency. Part 2 is basically a basic mapping implementation using MapStruct. Notice that in the `pom.xml` of Part 2, we have the MapStruct plugin which basically creates the implementation class of the interface during `mvn install` process.
I build and push the Part 2 package to the GitHub repo. Then Part 1 uses it basically.
A couple of findings:
This whole flow works perfectly when I deploy the part1 as a non-native image, using the following `kamel run` command:
```
kamel run \
--open-api file:./resources/part1-openapi.yaml \
--resource file:./resources/sample-error-response.json \
--dependency mvn:com.mertdotcc:issue4124part2:1.5 \
--dependency mvn:org.mapstruct:mapstruct:1.5.2.Final \
--dependency mvn:com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.14.2 \
--source ./sources/IntegrationBean.java \
--trait container.enabled=true \
--trait container.request-cpu="250m" \
--trait container.request-memory="256Mi" \
--trait container.limit-cpu="500m" \
--trait container.limit-memory="512Mi" \
--trait container.port=8443 \
--trait health.enabled=true \
--trait health.liveness-probe-enabled=true \
--trait health.liveness-scheme="HTTP" \
--trait health.liveness-initial-delay=0 \
--trait health.liveness-timeout=10 \
--trait health.liveness-period=15 \
--trait health.liveness-success-threshold=1 \
--trait health.liveness-failure-threshold=3 \
--trait health.readiness-probe-enabled=true \
--trait health.readiness-scheme="HTTP" \
--trait health.readiness-initial-delay=0 \
--trait health.readiness-timeout=10 \
--trait health.readiness-period=15 \
--trait health.readiness-success-threshold=1 \
--trait health.readiness-failure-threshold=3 \
Integration.java
```
But when I enable the native mode, it doesn't work. I use the following `kamel run` command to run my integration in native mode:
```
kamel run \
--open-api file:./resources/part1-openapi.yaml \
--resource file:./resources/sample-error-response.json \
--dependency mvn:com.mertdotcc:issue4124part2:1.5 \
--dependency mvn:org.mapstruct:mapstruct:1.5.2.Final \
--dependency mvn:com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.14.2 \
--source ./sources/IntegrationBean.java \
--trait container.enabled=true \
--trait container.request-cpu="250m" \
--trait container.request-memory="256Mi" \
--trait container.limit-cpu="500m" \
--trait container.limit-memory="512Mi" \
--trait container.port=8443 \
--trait health.enabled=true \
--trait health.liveness-probe-enabled=true \
--trait health.liveness-scheme="HTTP" \
--trait health.liveness-initial-delay=0 \
--trait health.liveness-timeout=10 \
--trait health.liveness-period=15 \
--trait health.liveness-success-threshold=1 \
--trait health.liveness-failure-threshold=3 \
--trait health.readiness-probe-enabled=true \
--trait health.readiness-scheme="HTTP" \
--trait health.readiness-initial-delay=0 \
--trait health.readiness-timeout=10 \
--trait health.readiness-period=15 \
--trait health.readiness-success-threshold=1 \
--trait health.readiness-failure-threshold=3 \
--trait quarkus.enabled=true \
--trait quarkus.package-type=native \
Integration.java
```
Please pull the repo for `part1` and check the local history of `Integration.java` line 24. Basically;
Using `.to("bean:IntegrationBean?method=handleMapping")` in non-native mode works fine, in native mode, it compiles and the pod starts but when I send a request, I get the `method not found` exception.
Using `.bean("IntegrationBean", "handleMapping")` in non-native works, but in native it doesn't work. The pod doesn't even start. I get `CrashLoopBackOff`.
Using
```
.process(exchange -> {
IntegrationBean bean =
(IntegrationBean) this.getCamelContext().getRegistry().lookupByName("IntegrationBean");
bean.handleMapping(exchange);
})
```
also doesn't work in native. Same problem: `CrashLoopBackOff`.
I basically need at least one approach that works in native mode as this is critical for our operation.
I am open to any suggestions and would be happy to provide more info/details.
Many thanks in advance.
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-k] essobedo closed issue #4124: How to use JVM classpaths in Native mode?
Posted by "essobedo (via GitHub)" <gi...@apache.org>.
essobedo closed issue #4124: How to use JVM classpaths in Native mode?
URL: https://github.com/apache/camel-k/issues/4124
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-k] mertdotcc commented on issue #4124: How to use JVM classpaths in Native mode?
Posted by "mertdotcc (via GitHub)" <gi...@apache.org>.
mertdotcc commented on issue #4124:
URL: https://github.com/apache/camel-k/issues/4124#issuecomment-1494344159
Not yet, a bit busy atm. I'll test it in the next 1-2 days and definitely keep you posted.
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-k] essobedo commented on issue #4124: How to use JVM classpaths in Native mode?
Posted by "essobedo (via GitHub)" <gi...@apache.org>.
essobedo commented on issue #4124:
URL: https://github.com/apache/camel-k/issues/4124#issuecomment-1490290156
@mertdotcc I think I provided enough information to close this ticket, feel free to reopen it if you meet other problems within the context of this use case
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-k] squakez commented on issue #4124: How to use JVM classpaths in Native mode?
Posted by "squakez (via GitHub)" <gi...@apache.org>.
squakez commented on issue #4124:
URL: https://github.com/apache/camel-k/issues/4124#issuecomment-1477902659
Yes, as I suspected, the reflection kind of problem are from a different nature. I am not very super expert on the Quarkus dynamics, but I have the feeling that you need to write a Quarkus extension for the dependency you're willing to use: https://quarkus.io/guides/writing-extensions - basically it's what we're doing with the core Camel dependencies which are "quarkified" with Camel Quarkus project.
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-k] essobedo commented on issue #4124: How to use JVM classpaths in Native mode?
Posted by "essobedo (via GitHub)" <gi...@apache.org>.
essobedo commented on issue #4124:
URL: https://github.com/apache/camel-k/issues/4124#issuecomment-1485598502
So after a deeper investigation, there are several problems. TBH I'm even surprised that it works in JVM mode on your side.
I had to modify several to have it work in JVM mode.
1. `Integration.java` should not have a package name
2. `IntegrationBean` should be included in your dependency as it is not an integration but a Bean
3. `CrashLoopBackOff` is due to the fact that the port has been changed for `8443` and this port is used to configure the probes but the port exposed by Quarkus is `8080` so probes always fail. I'm wondering why we can even change the port with the trait option `container.port`? If you want to have a different port, you should use `container.service-port` to set the expected port and leave `container.port` as it is by default. @squakez, unless I miss something, in which use case does it make sense to change the `containerPort` of the pod?
4. The component `mapstruct` is not yet supported by Camel-Quarkus, that's why it doesn't work in native mode https://github.com/apache/camel-quarkus/issues/3994
Here is the `Integration.java` after changing it:
```
// camel-k: language=java
// camel-k: name=issue4124-part1-integration
import com.mertdotcc.sources.IntegrationBean;
import org.apache.camel.LoggingLevel;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.BindToRegistry;
public class Integration extends RouteBuilder {
@BindToRegistry
public IntegrationBean IntegrationBean() {
return new IntegrationBean();
}
@Override
public void configure() throws Exception {
onException(Exception.class)
.handled(true)
.setHeader("CamelHttpResponseCode").constant("400")
.setBody().simple("resource:file:/etc/camel/resources/sample-error-response.json")
.log(LoggingLevel.ERROR, "exception", "${exception}").routeId("exception");
// POST
from("direct://addStudent").routeId("addStudent")
.log(LoggingLevel.INFO, "before-mapping", "headers: ${headers}; body: ${body}")
.removeHeaders("*")
.convertBodyTo(String.class)
.process(exchange -> {
IntegrationBean bean =
(IntegrationBean) this.getCamelContext().getRegistry().lookupByName("IntegrationBean");
bean.handleMapping(exchange);
})
.log(LoggingLevel.INFO, "after-mapping", "headers: ${headers}; body: ${body}");
}
}
```
I moved `IntegrationBean` to your dependency https://github.com/essobedo/issue4124part2/commit/6bc07356be.
I also use jitpack to define the location of the dependency using `github:essobedo/issue4124part2`
here is my run.sh
```
kamel run \
--open-api file:./resources/part1-openapi.yaml \
--resource file:./resources/sample-error-response.json \
--dependency github:essobedo/issue4124part2 \
--dependency mvn:org.mapstruct:mapstruct:1.5.2.Final \
--trait container.enabled=true \
--trait container.service-port=8443 \
--trait container.request-cpu="250m" \
--trait container.request-memory="256Mi" \
--trait container.limit-cpu="500m" \
--trait container.limit-memory="512Mi" \
--trait health.enabled=true \
--trait health.liveness-probe-enabled=true \
--trait health.liveness-scheme="HTTP" \
--trait health.liveness-initial-delay=0 \
--trait health.liveness-timeout=10 \
--trait health.liveness-period=15 \
--trait health.liveness-success-threshold=1 \
--trait health.liveness-failure-threshold=3 \
--trait health.readiness-probe-enabled=true \
--trait health.readiness-scheme="HTTP" \
--trait health.readiness-initial-delay=0 \
--trait health.readiness-timeout=10 \
--trait health.readiness-period=15 \
--trait health.readiness-success-threshold=1 \
--trait health.readiness-failure-threshold=3 \
--trait quarkus.enabled=true \
Integration.java
```
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-k] squakez commented on issue #4124: How to use JVM classpaths in Native mode?
Posted by "squakez (via GitHub)" <gi...@apache.org>.
squakez commented on issue #4124:
URL: https://github.com/apache/camel-k/issues/4124#issuecomment-1486400298
> > > @squakez, unless I miss something, in which use case does it make sense to change the containerPort of the pod?
> >
> >
> > I guess that this parameter is good when the user want to have full control of the ports used/exposed.
>
> Yes but if you do so without changing the value of `quarkus.http.port`, it won't work, don't you agree?
Yes, this is a runtime detail. If you change it in the deployment configuration, you'll need to make sure it is changed also in the runtime.
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-k] squakez commented on issue #4124: How to use JVM classpaths in Native mode?
Posted by "squakez (via GitHub)" <gi...@apache.org>.
squakez commented on issue #4124:
URL: https://github.com/apache/camel-k/issues/4124#issuecomment-1465719356
Yeah, your impressions are correct although not directly related to the usage of Java reflection. The problem here is that the jar you're providing is only used at runtime, so it works fine when using JVM mode. When you want to go Quarkus native, you need to pass that jar to the build so that it can be considered by the ahead of time compilation (you may have additional problems because reflection, but that would be a different problem). The only kind of workaround you can try to adopt at this stage is to try embedding all your dependency source into the same Java class you're using for your Integration (it may be difficult if it's a lot of code, I know). I think this kind of problem may be mitigated if change the design to [make a Camel K build a generic phase](https://github.com/apache/camel-k/issues/4024).
Marking this as a feature.
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-k] mertdotcc commented on issue #4124: How to use JVM classpaths in Native mode?
Posted by "mertdotcc (via GitHub)" <gi...@apache.org>.
mertdotcc commented on issue #4124:
URL: https://github.com/apache/camel-k/issues/4124#issuecomment-1485666435
Thank you for the detailed response, really appreciate it! I will pull in your code, analyze and test it, then will get back to you!
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-k] mertdotcc commented on issue #4124: How to use JVM classpaths in Native mode?
Posted by "mertdotcc (via GitHub)" <gi...@apache.org>.
mertdotcc commented on issue #4124:
URL: https://github.com/apache/camel-k/issues/4124#issuecomment-1485835709
One more remark @essobedo,
"The component mapstruct is not yet supported by Camel-Quarkus, that's why it doesn't work in native mode" -> I am not using the Camel component for MapStruct but the actual MapStruct dependency, which is Quarkus and native ready as per [this](https://mapstruct.org/news/2019-12-06-mapstruct-and-quarkus/). Why would this affect me on the native side? I am a bit confused.
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-k] essobedo commented on issue #4124: How to use JVM classpaths in Native mode?
Posted by "essobedo (via GitHub)" <gi...@apache.org>.
essobedo commented on issue #4124:
URL: https://github.com/apache/camel-k/issues/4124#issuecomment-1486344741
> Thank you for the detailed response, really appreciate it!
>
> Couple of questions:
>
> 1. Why exactly do you think this shouldn't work in JVM mode? Because it does. 🙂
Because the port issue is not specific to the native mode
> 2. "`Integration.java` should not have a package name" -> Why? Is it because it's not needed? If so, I give you that. But having it doesn't break anything. On the contrary, it helps with all the regular Java/Maven/IDE functionality. I am rather interested in your personal opinion on this.
You can keep it if you want since it is harmless but in practice, it is useless since you won't reference it from another class. You need to see those specific files more like scripts rather than real classes.
> 3. "`IntegrationBean` should be included in your dependency as it is not an integration but a Bean" -> But I do have it as my dependency. [Here](https://github.com/mertdotcc/issue4124part1/blob/7018cfbbc0d614995e5e33a3da618a314d98daf8/src/main/java/com/mertdotcc/Integration.java#L5) and [here](https://github.com/mertdotcc/issue4124part1/blob/7018cfbbc0d614995e5e33a3da618a314d98daf8/pom.xml#L59).
I mean it should be included in to issue4124part2 like I did https://github.com/essobedo/issue4124part2/blob/main/src/main/java/com/mertdotcc/sources/IntegrationBean.java
> 4. You are right about the `CrashLoopBackOff`, it was a misconfiguration. And you make a good argument, I can't think of a proper need for the `container.port` trait option.
> 5. "The component mapstruct is not yet supported by Camel-Quarkus, that's why it doesn't work in native mode" -> that's a bummer. In the meantime, we will be forced to use it in the JVM mode then...
I will work on it asap to add the support
> 6. "I moved `IntegrationBean` to your dependency" -> Interesting... why exactly? Having it in the same project as the integration doesn't break anything. I understand that having it in the dependency also works, I am just curious about your thinking process.
Again, it is not an integration class, I mean it doesn't create any routes if you prefer, it's only a bean so it has nothing to do with the integration
>
> In the next 1-2 days I will pull in your code, test&analyze it, and share my findings and my follow-up questions (if any). But thank you so much for taking the time and looking into it!
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-k] mertdotcc commented on issue #4124: How to use JVM classpaths in Native mode?
Posted by "mertdotcc (via GitHub)" <gi...@apache.org>.
mertdotcc commented on issue #4124:
URL: https://github.com/apache/camel-k/issues/4124#issuecomment-1485688730
Thank you for the detailed response, really appreciate it!
Couple of questions:
1. Why exactly do you think this shouldn't work in JVM mode?
2. `Integration.java` should not have a package name -> Why? Is it because it's not needed? If so, I give you that. But having it doesn't break anything. On the contrary, it helps with all the regular Java/Maven/IDE functionality. I am rather interested in your personal opinion on this.
3. `IntegrationBean` should be included in your dependency as it is not an integration but a Bean -> But I do have it as my dependency. [Here](https://github.com/mertdotcc/issue4124part1/blob/7018cfbbc0d614995e5e33a3da618a314d98daf8/src/main/java/com/mertdotcc/Integration.java#L5) and [here](https://github.com/mertdotcc/issue4124part1/blob/7018cfbbc0d614995e5e33a3da618a314d98daf8/pom.xml#L59).
4. You are right about the `CrashLoopBackOff`, it was a misconfiguration. And you make a good argument, I can't think of a proper need for the `container.port` trait option.
5. The component mapstruct is not yet supported by Camel-Quarkus, that's why it doesn't work in native mode -> that's a bummer. In the meantime, we will be forced to use it in the JVM mode then...
6. I moved `IntegrationBean` to your dependency -> Interesting... why exactly? Having it in the same project as the integration doesn't break anything. I understand that having it in the dependency also works, I am just curious about your thinking process.
In the next 1-2 days I will pull in your code, test&analyze it, and share my findings and my follow-up questions (if any). But thank you so much for taking the time and looking into it!
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-k] mertdotcc commented on issue #4124: How to use JVM classpaths in Native mode?
Posted by "mertdotcc (via GitHub)" <gi...@apache.org>.
mertdotcc commented on issue #4124:
URL: https://github.com/apache/camel-k/issues/4124#issuecomment-1521556362
Hey @essobedo, I was finally able to test your fork and everything works perfectly! Thank you so much. This was a great learning experience for me. 🙏🏻
`Apache Camel 3.20.1 (camel-1) started in 3ms (build:0ms init:3ms start:0ms)`
`camel-k-integration 1.12.0 native (powered by Quarkus 2.16.0.Final) started in 0.102s`
`3ms` and `102ms`? 👀 These are INSANE speeds. Where and how do you run this? And why in my deployment it is in the 20-30 seconds ballpark? Any idea on that?
Many thanks again.
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-k] mertdotcc commented on issue #4124: How to use JVM classpaths in Native mode?
Posted by "mertdotcc (via GitHub)" <gi...@apache.org>.
mertdotcc commented on issue #4124:
URL: https://github.com/apache/camel-k/issues/4124#issuecomment-1477750845
Hey @squakez and @lburgazzoli, thanks for the replies!
I followed @lburgazzoli's suggestion and am still facing some (new) issues.
Details:
I have the following integration, `MyIntegration`:
```
package com.myCompany.myProject;
// camel-k: language=java
// camel-k: name=my-project-simple-bean-native
// camel-k: dependency=camel:jackson
// camel-k: dependency=camel:jacksonxml
import com.myCompany.myProject.nativeimagetest.model.destination.MyClassA;
import com.myCompany.myProject.nativeimagetest.model.source.MyClassB;
import com.myCompany.myProject.nativeimagetest.model.source.MyClassC;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import io.quarkus.runtime.annotations.RegisterForReflection;
import javax.enterprise.context.ApplicationScoped;
import org.apache.camel.LoggingLevel;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.jackson.JacksonDataFormat;
@ApplicationScoped
@RegisterForReflection(targets = {MyClassA.class, MyClassB.class, MyClassC.class})
public class MyIntegration extends RouteBuilder {
@Override
public void configure() throws Exception {
JacksonDataFormat df = new JacksonDataFormat(MyClassA.class);
df.setEnableFeatures(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS.name());
df.setObjectMapper(new ObjectMapper());
df.getObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
df.addModule(new JavaTimeModule());
onException(Exception.class)
.handled(true)
.setHeader("CamelHttpResponseCode").constant("400")
.setBody().simple("resource:file:/etc/camel/resources/sample-error-response.json")
.log(LoggingLevel.ERROR, "exception", "${exception}").routeId("exception");
// GET
from("direct://getAccountById").routeId("getAccountById")
.log(LoggingLevel.INFO, "log-get", "headers: ${headers}; body: ${body}")
.setProperty("prop1").simple("${headers.prop1}")
.choice()
.when().simple("${exchangeProperty.prop1} != null")
.removeHeaders("*")
.toD("http://somewhere?bridgeEndpoint=false&connectTimeout=-1&connectionRequestTimeout=-1&disableStreamCache=true&httpMethod=GET&socketTimeout=-1&throwExceptionOnFailure=false")
.log(LoggingLevel.INFO, "body-log-1", "BODY BEFORE UNMARSHAL ${body}")
.unmarshal(df)
.log(LoggingLevel.INFO, "body-log-2", "BODY AFTER UNMARSHAL ${body}")
.to("bean:MyBean?method=handleMapping")
.marshal(df).convertBodyTo(String.class)
.endChoice()
.otherwise()
.throwException(new UnsupportedOperationException("The operation is not supported"))
.endChoice()
.end()
.log(LoggingLevel.INFO, "get-end-log", "headers: ${headers}; body: ${body}");
}
}
```
When I call the `GET` endpoint, I receive the following error:
```
{
"status": "Invalid request",
"message": "com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `com.myCompany.myProject.clients.model.MyClassA`: cannot deserialize from Object value (no delegate- or property-based Creator): this appears to be a native image, in which case you may need to configure reflection for the class that is to be deserialized
at [Source: (org.apache.camel.converter.stream.InputStreamCache); line: 2, column: 3
]",
"exchangeId": "A27AB4B2DF324A9-0000000000000001"
}
```
I tried adding the `serialization` and `registerFullHierarchy` config parameters to the `RegisterForReflection` annotation. So my `MyIntegration` looked like:
```
package com.myCompany.myProject;
// camel-k: language=java
// camel-k: name=my-project-simple-bean-native
// camel-k: dependency=camel:jackson
// camel-k: dependency=camel:jacksonxml
import com.myCompany.myProject.nativeimagetest.model.destination.MyClassA;
import com.myCompany.myProject.nativeimagetest.model.source.MyClassB;
import com.myCompany.myProject.nativeimagetest.model.source.MyClassC;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import io.quarkus.runtime.annotations.RegisterForReflection;
import javax.enterprise.context.ApplicationScoped;
import org.apache.camel.LoggingLevel;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.jackson.JacksonDataFormat;
@ApplicationScoped
@RegisterForReflection(targets = {MyClassA.class, MyClassB.class, MyClassC.class}, serialization = true, registerFullHierarchy = true)
public class MyIntegration extends RouteBuilder {
@Override
public void configure() throws Exception {
JacksonDataFormat df = new JacksonDataFormat(MyClassA.class);
df.setEnableFeatures(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS.name());
df.setObjectMapper(new ObjectMapper());
df.getObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
df.addModule(new JavaTimeModule());
onException(Exception.class)
.handled(true)
.setHeader("CamelHttpResponseCode").constant("400")
.setBody().simple("resource:file:/etc/camel/resources/sample-error-response.json")
.log(LoggingLevel.ERROR, "exception", "${exception}").routeId("exception");
// GET
from("direct://getAccountById").routeId("getAccountById")
.log(LoggingLevel.INFO, "log-get", "headers: ${headers}; body: ${body}")
.setProperty("prop1").simple("${headers.prop1}")
.choice()
.when().simple("${exchangeProperty.prop1} != null")
.removeHeaders("*")
.toD("http://somewhere?bridgeEndpoint=false&connectTimeout=-1&connectionRequestTimeout=-1&disableStreamCache=true&httpMethod=GET&socketTimeout=-1&throwExceptionOnFailure=false")
.log(LoggingLevel.INFO, "body-log-1", "BODY BEFORE UNMARSHAL ${body}")
.unmarshal(df)
.log(LoggingLevel.INFO, "body-log-2", "BODY AFTER UNMARSHAL ${body}")
.to("bean:MyBean?method=handleMapping")
.marshal(df).convertBodyTo(String.class)
.endChoice()
.otherwise()
.throwException(new UnsupportedOperationException("The operation is not supported"))
.endChoice()
.end()
.log(LoggingLevel.INFO, "get-end-log", "headers: ${headers}; body: ${body}");
}
}
```
But I still received the same error when I called my `GET` endpoint:
```
{
"status": "Invalid request",
"message": "com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `com.myCompany.myProject.clients.model.MyClassA`: cannot deserialize from Object value (no delegate- or property-based Creator): this appears to be a native image, in which case you may need to configure reflection for the class that is to be deserialized
at [Source: (org.apache.camel.converter.stream.InputStreamCache); line: 2, column: 3
]",
"exchangeId": "A27AB4B2DF324A9-0000000000000001"
}
```
I suspected whether the reflection issue was regarding my POJOs or the `camel-jackson` dependency, so I added the `Quarkus` annotations to all my POJO classes (which is an approach we want to avoid in the future, as we have hundreds of POJO classes and they are all auto-generated from our OpenApi spec files. We don't want to take an auto-generated file and add a bunch of Quarkus annotations to all of them) and then I got the exact same error as before:
```
{
"status": "Invalid request",
"message": "com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `com.myCompany.myProject.clients.model.MyClassA`: cannot deserialize from Object value (no delegate- or property-based Creator): this appears to be a native image, in which case you may need to configure reflection for the class that is to be deserialized
at [Source: (org.apache.camel.converter.stream.InputStreamCache); line: 2, column: 3
]",
"exchangeId": "A27AB4B2DF324A9-0000000000000001"
}
```
Feeling stuck with this and would appreciate any direction/help. Thanks!
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org