How do I manage to configure the File component of my Camel Context, so that all directory paths provided to its endpoints are prepended with some base path?
For example, if someone writes
file:input/customer12?include=.*\.csv
it will effectively be
file:/usr/local/share/app/exchange/input/customer12?include=.*\.csv
For example, I get the component during the Camel Context initialization like this:
FileComponent file = CAMELCONTEXT.getComponent("file", FileComponent.class);
What do I do next? createComponentConfiguration()?
addition: It's a standalone cli app which I want to be runnable from any directory
The easiest solution is start your app under folder /usr/local/share/app/exchange , but this is not an option as state in addition requirement
If you have a layer between your user input and your code, then you could inject the path. For example, Java DSL with RouteBuilder.
The last solution is override Camel's file component in component class before it create the actual endpoint.
Related
My requirement as below,
Starting camel,then processing all of the files with file component ,which is located some folder once.this route is just used once.
So how to configure with spring DSL?
Thanks advance.
Split your requirement as follow
Starting camel
Your research item, cover this will be off-topic in stackoverflow
processing all of the files with file component
Use file component by from, i.e. from("file://...")
is located some folder once
Set a proper parent directory and then use recursive option in file component to enable sub-directories lookup. For further control, you may check following options minDepth, maxDepth, filterDirectory, filter
this route is just used once
Use repeatCount option in file component to control fire count, i.e. repeatCount=1
Combine them together, you have
from("file://path/to/parent/directory?repeatCount=1&recursive=true")
... // follow by your route logic
I have header with filename with extension like this
<setHeader>
<simple>Test.txt</simple>
</setHeader>
I need to fetch only filename ie. Test alone in another header. Can anyone help me to achieve this.
Thanks.
You have multiple options. The examples take the full filename from a header and write the filename without extension into another header.
You write a Java Bean to use full Java power (for example Apache Commons FilenameUtils.getBaseName) and call it from your route. See this Camel documentation how to inject header values into your bean methods. In the route you call the bean like this
.setHeader("filename", method(beanReference, "methodName"))
Or you add camel-groovy to your dependencies to get more scripting power than with Camel Simple. Then you can do it directly in the Camel route
setHeader("filename").groovy("request.headers.get('fullFilename')
.take(request.headers.get('fullFilename').lastIndexOf('.'))")
I've written a basic route builder that pulls a file a from a location, does some message transformations, and then sends it somewhere else. The start and endpoints I currently have set in a .properties file.
The goal of my project is to be able to have a static camel route that consumes .properties file and creates the routes from the route builder that I've already written with the start and endpoints being specified in the properties file. How would I go about doing something like this? Am I approaching the problem incorrectly?
Thanks in advance guys!
EDIT with more explaination:
So currently my camel routes look something like this:
{{fileInput}} -> camel routes -> {{fileOutputs}}
I have a .properties file that specifies a single input endpoint and a single output endpoint. However, I would like my end code to be something like this:
{{fileInput1}} -> camel routes -> {{fileOutputs1}}
{{fileInput2}} -> camel routes -> {{fileOutputs2}}
{{fileInput3}} -> camel routes -> {{fileOutputs3}}
.
.
.
{{fileInputN}} -> camel routes -> {{fileOutputsN}}
My original idea was to have a separate static camel route that polls a specific file location. If I needed a new route I would just drop a .properties file in there and the route would consume the .properties file and generate one of the above routes. Is there an easier way to do this?
You can simply load the property file inside your RouteBuilder.
InputStream input = new FileInputStream("config.properties");
Properties prop = new Properties();
prop.load(input);
Then use them.
prop.getProperty("MySuperProperty");
Yet I don't understand what you are trying to achieve.
I am able to successfully download one/all files from a sftp directory using the following uri in canmel route definition
Download all files
"sftp://userName#serverName/directoryName?knownHostsFile=./known_hosts&privateKeyFile=./id_rsa&proxy=#proxy&noop=true"
Download one file
"sftp://userName#serverName/directoryName?knownHostsFile=./known_hosts&privateKeyFile=./id_rsa&proxy=#proxy&noop=true&fileName=one.txt"
My requirement is to download a specific list of files = one.text, two.text.
How can I pass list of fileNames to the Camel route? Preferablly I am looking for a solution where in I can specify something like the below
"sftp://userName#serverName/directoryName?knownHostsFile=./known_hosts&privateKeyFile=./id_rsa&proxy=#proxy&noop=true&fileName=one.txt,two.txt"
The Camel FTP component extends the File component and many of the options from file is also applicable for the FTP component, so read this page
http://camel.apache.org/file2
You can for example use include to specify a regular expression that matches the files you want. Or implement a custom filter class and use the filter option, etc.
I'm looking to implement a custom Valve and configuring it using META-INF/context.xml.
At the moment though, when context.xml is parsed during deployment, Tomcat (6.0.32) dies with a ClassNotFoundException on my custom Valve implementation.
I'm under the impression that I'm running into a class loading context issue and I'm not 100% sure I understand it.
Is my class not found because it is located in the WEB-INF/classes file and the Context level class loader is unable to locate the class because of the hierarchy?
Thanks in advance.
You can not load Valves from inside the webapp class loader. If you look at http://tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.html it shows the available class loaders. You must use one of the Bootstrap, System or Common classloaders because Valve definitions are processed BEFORE the individual webapp classloaders are created: the Context has to be processed before the webapp is available.
Package your Valve in a jar by itself and copy it into the $CATALINA_HOME/lib folder and you should be all set.