You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "grgrzybek (via GitHub)" <gi...@apache.org> on 2023/05/05 14:17:49 UTC

[GitHub] [camel] grgrzybek opened a new pull request, #10000: Xml in jbang

grgrzybek opened a new pull request, #10000:
URL: https://github.com/apache/camel/pull/10000

   # Description
   
   This is first attempt at https://issues.apache.org/jira/browse/CAMEL-18189. `<beans>` element treated simply as root element of _Camel application_ is easy. The `<bean>` element in the Spring sense is hard, because Camel already uses `<bean>` element as bean processor.
   
   However, CAMEL-18189 is about
   * root element to collect routes, rests, templates, ...
   * add some (to be enhanced later) sort of bean registry population
   
   So I've taken existing `DIRegistry` implementation of `org.apache.camel.support.SupplierRegistry` and populated it by scanning (`org.apache.camel.spi.PackageScanClassResolver`) selected packages.
   
   Here's an example of working XML snippet:
   
   ```xml
   <camel-app>
   
       <component-scan base-package="org.apache.camel.dsl.xml.io.beans" />
   
       <route id="r2">
           <from uri="direct:x2"/>
           <bean ref="bean-from-registry" />
           <to uri="mock:y2"/>
       </route>
   
   </camel-app>
   ```
   
   where `bean-from-registry` is:
   
   ```java
   @Named("bean-from-registry")
   public class Greeter implements Processor {
   
       private final GreeterMessage message;
   
       @Inject
       public Greeter(GreeterMessage message) {
           this.message = message;
       }
   
       @Override
       public void process(Exchange exchange) throws Exception {
           String msg = exchange.getIn().getBody(String.class);
           exchange.getIn().setBody(message.getMsg() + " " + StringHelper.after(msg, "I'm "));
       }
   
   }
   ```
   
   And injected `GreeterMessage` is:
   
   ```java
   @Named
   public class GreeterMessage {
   
       private final String msg = "Hello";
   
       public String getMsg() {
           return msg;
       }
   
   }
   ```
   
   
   # Target
   
   - [+] I checked that the commit is targeting the correct branch (note that Camel 3 uses `camel-3.x`, whereas Camel 4 uses the `main` branch)
   
   # Tracking
   - [+] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it).
   
   <!--
   # *Note*: trivial changes like, typos, minor documentation fixes and other small items do not require a JIRA issue. In this case your pull request should address just this issue, without pulling in other changes.
   -->
   
   # Apache Camel coding standards and style
   
   - [+] I checked that each commit in the pull request has a meaningful subject line and body.
   
   <!--  
   If you're unsure, you can format the pull request title like `[CAMEL-XXX] Fixes bug in camel-file component`, where you replace `CAMEL-XXX` with the appropriate JIRA issue.
   -->
   
   - [+] I formatted the code using `mvn -Pformat,fastinstall install && mvn -Psourcecheck`
   
   <!-- 
   You can run the aforementioned command in your module so that the build auto-formats your code and the source check verifies that is complies with our coding style. This will also be verified as part of the checks and your PR may be rejected if the checkstyle does not pass.
   
   You can learn more about the contribution guidelines at https://github.com/apache/camel/blob/main/CONTRIBUTING.md
   -->
   
   


-- 
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] grgrzybek commented on pull request #10000: Xml in jbang

Posted by "grgrzybek (via GitHub)" <gi...@apache.org>.
grgrzybek commented on PR #10000:
URL: https://github.com/apache/camel/pull/10000#issuecomment-1537418064

   Sure, as I said - naming is work in progress. Package scanning is a must and we could simply:
   * register beans with default ctor
   * register beans with `@Named` and `@Inject` constructors
   
   Yaml dsl code is a bit weird for me (at this stage of grasping Camel changes), but definitely there must be one mechanism underneath.
   
   `<camel-app>` and `<beans>` are kind of aliases, but for now the first one looks more natural (as there are no `<bean>` element to justify `<beans>` :D).
   
   Another thought - if Spring's top-level `<beans>` would be supported, it should be able to use `<camelContext>` inside and it's more a work related to CAMEL-19041.
   
   Anyway - the hardest part for me is done (which was to actually write some initial code). I start slowly, but then it's easier for me ;)


-- 
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] grgrzybek merged pull request #10000: Xml in jbang

Posted by "grgrzybek (via GitHub)" <gi...@apache.org>.
grgrzybek merged PR #10000:
URL: https://github.com/apache/camel/pull/10000


-- 
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] davsclaus commented on pull request #10000: Xml in jbang

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on PR #10000:
URL: https://github.com/apache/camel/pull/10000#issuecomment-1537359239

   @grgrzybek great work so far.
   
   Yeah we need to think how to make `<bean>` work in `<camel-app>` for declaring beans ala Spring/Blueprint, and then also allow to use <bean> in the Camel route DSL.
   
   Since camel-app is in the model, then it gets exposed to yaml-dsl and other DSLs. Today the yaml-dsl have special "beans" support.
   
   And yeah I dont like the jsr-xxx number - nobody remember these numbers. So we need to come up with a better name. Also I wonder if its needed at all, as it can detect `@Inject` and the Camel annotations as well `@BeanInject` and so on.
   
   


-- 
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] github-actions[bot] commented on pull request #10000: Xml in jbang

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #10000:
URL: https://github.com/apache/camel/pull/10000#issuecomment-1554441139

   :no_entry_sign: There are (likely) no components to be tested in this PR


-- 
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] github-actions[bot] commented on pull request #10000: Xml in jbang

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #10000:
URL: https://github.com/apache/camel/pull/10000#issuecomment-1554462483

   :no_entry_sign: There are (likely) no components to be tested in this PR


-- 
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] davsclaus commented on a diff in pull request #10000: Xml in jbang

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on code in PR #10000:
URL: https://github.com/apache/camel/pull/10000#discussion_r1198829462


##########
tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/ModelXmlWriterGeneratorMojo.java:
##########
@@ -779,7 +800,7 @@ private Predicate<Member> accessible(Class<?> clazz) {
         } else if (accessType == XmlAccessType.FIELD) {
             return m -> m.getDeclaringClass() == clazz
                     && ((isSetter(m) || isGetter(m)) && isXmlBindAnnotated(m)
-                            || isField(m) && !Modifier.isStatic(m.getModifiers()) && !Modifier.isTransient(m.getModifiers()));
+                            || isField(m) && /*isNotAnyXml(m) && */!Modifier.isStatic(m.getModifiers()) && !Modifier.isTransient(m.getModifiers()));

Review Comment:
   I guess a little bit of code that was commented out



##########
tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/ModelXmlWriterGeneratorMojo.java:
##########
@@ -791,7 +812,13 @@ private Predicate<Member> accessible(Class<?> clazz) {
 
     private boolean isXmlBindAnnotated(Member m) {
         return Stream.of(((AnnotatedElement) m).getAnnotations())
-                .anyMatch(a -> a.getClass().getAnnotatedInterfaces()[0].getType().getTypeName().startsWith("jakarta.xml.bind.annotation."));
+                .anyMatch(a -> a.getClass().getAnnotatedInterfaces()[0].getType().getTypeName().startsWith("jakarta.xml.bind.annotation.")
+                        /*&& !a.getClass().getAnnotatedInterfaces()[0].getType().getTypeName().endsWith("XmlAnyElement")*/);

Review Comment:
   I guess a little bit of code that was commented out



-- 
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] davsclaus commented on a diff in pull request #10000: Xml in jbang

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on code in PR #10000:
URL: https://github.com/apache/camel/pull/10000#discussion_r1198828420


##########
dsl/camel-yaml-dsl/camel-yaml-dsl-maven-plugin/src/main/java/org/apache/camel/maven/dsl/yaml/GenerateYamlDeserializersMojo.java:
##########
@@ -847,7 +847,33 @@ private boolean generateSetValue(String modelName, CodeBlock.Builder cb, FieldIn
         cb.beginControlFlow("case $S:", fieldName);
 
         ClassInfo c = view.getClassByName(field.type().name());
-        if (c != null && c.isEnum()) {
+        if (hasAnnotation(field, XML_JAVA_TYPE_ADAPTER_CLASS)) {
+            // conversion using JAXB Adapter of known class
+            Optional<AnnotationValue> adapter = annotationValue(field, XML_JAVA_TYPE_ADAPTER_CLASS, "value");
+            if (adapter.isEmpty()) {
+                return false;
+            }
+            String adapterClass = adapter.get().asClass().name().toString();
+            ClassInfo adapterClassInfo = view.getClassByName(adapter.get().asClass().name());
+            if (adapterClassInfo.superClassType().kind() == Type.Kind.PARAMETERIZED_TYPE) {
+                List<Type> arguments = adapterClassInfo.superClassType().asParameterizedType().arguments();
+                if (arguments.size() == 2) {
+                    // extends XmlAdapter<BeanPropertiesDefinition, Map<String, Object>>

Review Comment:
   I guess there is some left over code here that has been disabled



-- 
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] grgrzybek commented on a diff in pull request #10000: Xml in jbang

Posted by "grgrzybek (via GitHub)" <gi...@apache.org>.
grgrzybek commented on code in PR #10000:
URL: https://github.com/apache/camel/pull/10000#discussion_r1198837275


##########
tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/ModelXmlWriterGeneratorMojo.java:
##########
@@ -791,7 +812,13 @@ private Predicate<Member> accessible(Class<?> clazz) {
 
     private boolean isXmlBindAnnotated(Member m) {
         return Stream.of(((AnnotatedElement) m).getAnnotations())
-                .anyMatch(a -> a.getClass().getAnnotatedInterfaces()[0].getType().getTypeName().startsWith("jakarta.xml.bind.annotation."));
+                .anyMatch(a -> a.getClass().getAnnotatedInterfaces()[0].getType().getTypeName().startsWith("jakarta.xml.bind.annotation.")
+                        /*&& !a.getClass().getAnnotatedInterfaces()[0].getType().getTypeName().endsWith("XmlAnyElement")*/);

Review Comment:
   done. force pushed to PR branch



-- 
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] github-actions[bot] commented on pull request #10000: Xml in jbang

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #10000:
URL: https://github.com/apache/camel/pull/10000#issuecomment-1536409880

   :no_entry_sign: There are (likely) no components to be tested in this PR


-- 
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] github-actions[bot] commented on pull request #10000: Xml in jbang

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #10000:
URL: https://github.com/apache/camel/pull/10000#issuecomment-1536332247

   :star2: Thank you for your contribution to the Apache Camel project! :star2: 
   
   :camel: Maintainers, please note that first-time contributors *require manual approval* for the GitHub Actions to run.
   
   :warning: Please note that the changes on this PR may be **tested automatically** if they change components.
   
   If necessary Apache Camel Committers may access logs and test results in the job summaries!


-- 
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] grgrzybek commented on pull request #10000: Xml in jbang

Posted by "grgrzybek (via GitHub)" <gi...@apache.org>.
grgrzybek commented on PR #10000:
URL: https://github.com/apache/camel/pull/10000#issuecomment-1536334351

   @davsclaus @oscerd Please have a look - the naming (`use-jsr-330`) is just temporary ;)
   If you like the approach, I'll continue.


-- 
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