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

Velocity Support #837

Closed
dc2tom opened this issue Mar 3, 2020 · 13 comments
Closed

Velocity Support #837

dc2tom opened this issue Mar 3, 2020 · 13 comments
Labels
component extension help wanted Extra attention is needed
Milestone

Comments

@dc2tom
Copy link

dc2tom commented Mar 3, 2020

Our team make use of camel-velocity for running message transformations. It would be great to see a camel-quarkus extension supporting velocity.

@ppalaga ppalaga added component extension help wanted Extra attention is needed labels Mar 3, 2020
@ppalaga
Copy link
Contributor

ppalaga commented Mar 3, 2020

A contribution is welcome. You may want to follow https://camel.apache.org/camel-quarkus/latest/contributor-guide.html if you are interested. There is also a PR with Freemarker support under review #835 that may have vast similarities to velocity.

@zhfeng
Copy link
Contributor

zhfeng commented Mar 17, 2020

I can take a look at this issue.

@dc2tom
Copy link
Author

dc2tom commented Mar 17, 2020

Happy to collaborate on this @zhfeng if I get a chance - that Freemarker pull request does look to have a lot of similarities

@zhfeng
Copy link
Contributor

zhfeng commented Mar 18, 2020

@dc2tom it should be very similar to the freemarker component. At first, you need to create the velocity extension by mvn cq:create -N -Dcq.artifactIdBase=velocity. The followup steps could do

  • enable the reflective class of the Exchanges in VelocityProcessor.java
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, Exchanges.class);
    
    so the ${exchange.properties} can be used in the vm files.
  • add the option of quarkus.camel.velocity.classModules=<list of the classes which could be used in the template file> in the runtime of VelocityConfig just like freemarkers and process these class just like the Exchanges class above.
  • add the option to scan all of the vm files and add them into the native image resources.
  • check the integration test and make sure it work
  • re-gen the docs by mvn process-resources -Pformat

anyway, you are welcome to contribute a PR. Feel free to ask here and I will try my best to help you !

@dc2tom
Copy link
Author

dc2tom commented May 4, 2020

Hi, I've made a start with this following the Freemarker pull request as an example. I'm working on porting over the unit tests from camel-velocity but there is one thing I'm not getting.

When trying to run my test, against the below resource definition

@Path("/velocity")
@ApplicationScoped
public class VelocityLetterResource {

    @Inject
    ProducerTemplate producerTemplate;

    @Path("/velocityLetter")
    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.TEXT_PLAIN)
    public String post(String message) {
        Exchange exchange = producerTemplate.request("direct:a", new Processor() {
            @Override
            public void process(Exchange exchange) throws Exception {
                exchange.getIn().setHeader("firstName", "Claus");
                exchange.getIn().setHeader("lastName", "Ibsen");
                exchange.getIn().setHeader("item", "Camel in Action");
                exchange.getIn().setBody("PS: Next beer is on me, James");
            }
        });

        return (String) exchange.getOut().getBody();
    }

public static class VelocityRouteBuilder extends RouteBuilder {
        @Override
        public void configure() {
            from("direct:a")
                    .to("velocity:org/apache/camel/quarkus/component/velocity/letter.vm");
        }
    }

I see the following failure:

Caused by: org.apache.camel.NoSuchEndpointException: No endpoint could be found for: direct://a, please check your classpath contains the needed Camel component jar.

I can't work out how the RouteBuilder is invoked - my integration tests exist in the org.apache.camel.quarkus.component.velocity.it package.. I auto generated the velocity extension as per the contribution guide.

I expected that perhaps my extension would not be able to load the .vm file as I have yet to implement the functionality, but instead it seems the RouteBuilder is not being executed. Any advice appreciated :)

@ppalaga
Copy link
Contributor

ppalaga commented May 4, 2020

Sounds like your integration test module is missing the camel-quarkus-direct dependency.

@dc2tom
Copy link
Author

dc2tom commented May 4, 2020

Perfect, thanks for the quick response, I'm now in a position to work through porting the rest of the camel-velocity test over.

Hopefully I can have a pull request ready in the near future.

@ppalaga
Copy link
Contributor

ppalaga commented Aug 26, 2020

Any progress on this one @dc2tom? I am about to add an auto-generated JVM-only Velocity extension. If you had an integration test ready, going native would be easy.

@dc2tom
Copy link
Author

dc2tom commented Aug 26, 2020

I've created a pull request with what I had so far #1634

Unfortunately due to other commitments I wasn't able to progress this further than what I've just uploaded

@JiriOndrusek
Copy link
Contributor

@ppalaga I can look at this issue, please assign it to me.

@JiriOndrusek
Copy link
Contributor

@zhfeng I've missed your involvement at this issue. Do you plan to continue with it or are you working on it? May I help?

@zhfeng
Copy link
Contributor

zhfeng commented Sep 16, 2020

Hi @JiriOndrusek , feel free to take this issue.

JiriOndrusek added a commit to JiriOndrusek/camel-quarkus that referenced this issue Sep 17, 2020
JiriOndrusek added a commit to JiriOndrusek/camel-quarkus that referenced this issue Sep 17, 2020
JiriOndrusek added a commit to JiriOndrusek/camel-quarkus that referenced this issue Sep 22, 2020
JiriOndrusek added a commit to JiriOndrusek/camel-quarkus that referenced this issue Sep 22, 2020
JiriOndrusek added a commit to JiriOndrusek/camel-quarkus that referenced this issue Sep 22, 2020
JiriOndrusek added a commit to JiriOndrusek/camel-quarkus that referenced this issue Sep 22, 2020
JiriOndrusek added a commit to JiriOndrusek/camel-quarkus that referenced this issue Sep 23, 2020
JiriOndrusek added a commit to JiriOndrusek/camel-quarkus that referenced this issue Sep 23, 2020
JiriOndrusek added a commit to JiriOndrusek/camel-quarkus that referenced this issue Sep 23, 2020
JiriOndrusek added a commit to JiriOndrusek/camel-quarkus that referenced this issue Sep 24, 2020
JiriOndrusek added a commit to JiriOndrusek/camel-quarkus that referenced this issue Sep 25, 2020
ppalaga pushed a commit that referenced this issue Sep 25, 2020
@ppalaga
Copy link
Contributor

ppalaga commented Sep 25, 2020

Fixed via #1804

@ppalaga ppalaga closed this as completed Sep 25, 2020
@jamesnetherton jamesnetherton added this to the 1.2.0 milestone Sep 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component extension help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants