Sadly, I'm almost certain that this does not work:/
Looking at the code:
========org.apache.camel.component.velocity.VelocityEndpoint============
private synchronized VelocityEngine getVelocityEngine() throws Exception {
if (velocityEngine == null) {
velocityEngine = new VelocityEngine();
...
==============
So the velocity engine is always created, as opposed to what the docs say:
camel.component.velocity.velocity-engine - To use the VelocityEngine otherwise
a new engine is created. The option is a org.apache.velocity.app.VelocityEngine
type.
Gonna have to figure out some other way to do it...
W dniu 23.01.2019 o 08:27, Piotr Kaczmarski pisze:
Hi and thanks for help!
I do use spring boot and I did what you said, but still nothing:
=========application.yml=======
camel:
component:
velocity:
velocity-engine: velocityEngineTest
============VelocityEngineTest.java=============
package pl.altkom.software.dpc.camelrider.cc.module.dpc.dpcapi.route;
import javax.annotation.PostConstruct;
import org.apache.velocity.Template;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;
import org.springframework.stereotype.Component;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Component("velocityEngineTest")
public class VelocityEngineTest extends VelocityEngine {
@PostConstruct
public void init(){
log.error("STARTED");
}
@Override
public Template getTemplate(String name) throws
ResourceNotFoundException, ParseErrorException {
log.error("TEST");
return super.getTemplate(name);
}
@Override
public Template getTemplate(String name, String encoding) throws
ResourceNotFoundException, ParseErrorException {
log.error("TEST");
return super.getTemplate(name, encoding);
}
}
=============================================
The log in the init() shows up, so the component is created by spring.
What mistake did I make this time?
W dniu 22.01.2019 o 23:14, Claus Ibsen pisze:
Hi
If you are using spring boot then you likely need to add @Bean or
@Component to have that custom engine registered in spring boot
registry, and then refer to its bean id in that properties file.
Its not the FQN classname you set.
On Tue, Jan 22, 2019 at 7:23 PM Piotr Kaczmarski
<[email protected]><mailto:[email protected]>
wrote:
Hello,
I'm using Camel 2.23.1 to create camel based application.
I use velocity component of camel.
My requirement is to somehow override template reading logic, so I can
inject a template from DB if it's defined and if not - use a file, the
usual way.
Also, the camel velocity cache should be used to speed things up, so the
injection should be pretty high in the call tree.
I've decided to try to use the functionality of overriding
VelocityEngine as described here:
https://github.com/apache/camel/blob/master/components/camel-velocity/src/main/docs/velocity-component.adoc
So I've added this into the properties file:
camel:
component:
velocity:
velocity-engine:
pl.altkom.software.dpc.camelrider.cc.module.dpc.dpcapi.route.VelocityEngineTest
And I've created this VelocityEngine implementation:
=============================================
package pl.altkom.software.dpc.camelrider.cc.module.dpc.dpcapi.route;
import org.apache.velocity.Template;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class VelocityEngineTest extends VelocityEngine {
@Override
public Template getTemplate(String name) throws
ResourceNotFoundException, ParseErrorException {
log.error("TEST");
return super.getTemplate(name);
}
@Override
public Template getTemplate(String name, String encoding) throws
ResourceNotFoundException, ParseErrorException {
log.error("TEST");
return super.getTemplate(name, encoding);
}
}
=========================================================
Unfortunately, the test message isn't shown. I've done some more tests,
and the class is not used by camel.
I tried to search the source code of camel to find this property and
figure out how to properly use it.
It seems as it's not used by camel to initialize the velocity engine:(
Am I wrong? Is it a bug or I just can't properly use it?
Can you guys help me use it properly? Or maybe can you guide me on how
to do the thing I want to do some other way?
I'll be very grateful.
Piotr Kaczmarski