Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

string-template:bean Bean Injection: camel quarkus cannot find resource error #2849

Closed
nelreina opened this issue Jun 25, 2021 · 4 comments
Closed

Comments

@nelreina
Copy link

nelreina commented Jun 25, 2021

camel quarkus cannot find resource error

  // Hee is the Bean

      @ApplicationScoped
      @Named("StringTemplateBean")
      @RegisterForReflection
      public class TemplateBean {
        
      
          public String getTemplate(@Header("template") String template) {
      
              return template;
          }
      
      }

     ...
     // THIS IS OK no problem here 
       from("timer:timer?period=5s")
                .routeId(this.getClass().getName())
                .setHeader("template", constant("Hi my name is <headers.name>"))
                .setHeader("name", constant("Stop di Hode>"))
                .to("bean:StringTemplateBean")
                .log("${body}");


     // This route give me above mentioned error
       from("timer:timer?period=5s")
                .routeId(this.getClass().getName())
                .setHeader("template", constant("Hi my name is <headers.name>"))
                .setHeader("name", constant("Stop di Hode>"))
                .to("string-template:bean:StringTemplateBean")
                .log("${body}");
 

Quarkus Version 1.13.7.Final
I added camel extension linked to this version

@jamesnetherton
Copy link
Contributor

AFAIK there is no support in the stringtemplate component to do bean lookups in the way you're describing. The URI path is meant to be the location of the template on the classpath.

@nelreina
Copy link
Author

Hi @jamesnetherton thank you for your response , in the doc's it says it is possible , look at the last line

Required Path to the resource. You can prefix with: classpath, file, http, ref, or bean. classpath, file and http loads the resource using these protocols (classpath is default). ref will lookup the resource in the registry. bean will call a method on a bean to be used as the resource. For bean you can specify the method name after dot, eg bean:myBean.myMethod.

@davsclaus
Copy link
Contributor

You are using the bean the wrong way, its not to lookup a bean and dynamic call a method on that bean. The bean should be a string or input stream that has the template.

So its often a bit useless. If you want to use a dynamic template then use stringtemplate header support
https://camel.apache.org/components/latest/string-template-component.html

You need to turn on allow from template, see this unit test
https://github.com/apache/camel/blob/main/components/camel-stringtemplate/src/test/java/org/apache/camel/component/stringtemplate/StringTemplateViaHeaderTest.java

@nelreina
Copy link
Author

nelreina commented Jul 3, 2021

Hi @davsclaus thanks for your response. Okay I understand now and did not see that option on the string template (my bad). But you understand why I came to that conclusion to use the bean that way. In the mean time I solved my route another way.

@ppalaga ppalaga added this to the No fix/wont't fix milestone Oct 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants