Simple Camel Route takes no action - apache-camel

The following code sample is from what I understand the most basic "Hello World" Apache-Camel example. However, I am having difficulties with it.
When I run this project nothing happens; the files remain in the original location and my IDE does not return an exception. I would like to move all .txt files from one directory to another. The directories mentioned do exist on my machine as well. (C:/camels/inner)(C:/testing)
I feel there is a foolish mistake someplace in this code, any help would be appreciated.
package CamelProject;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args ) throws Exception
{
CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder()
{
public void configure() throws Exception
{
from("file:C:\\testing?delete=true&include=.*.txt").to("file:C:\\camels\\inner");
}
});
context.start();
Thread.sleep(10000);
context.stop();
}
}

This should work. It's likely due to a case sensitivity issue.
Please have a look that your files end with .txt, not .TXT.
If so, the regular expression just needs adjustment (I leave that as a challenge to you...)

Thank you for all the responses. I ended up removing my ~/.m2/repository and re-compiling Camel.
When re-compiling I had to make sure to use set MAVEN_OPTS=-Xmx1024m -XX:MaxPermSize=512m and mvn install -Pfastinstall from the directory where Camel's POM.xml file was located.
After this process I copied the above code into a new project and it worked like a charm.

For me the problem was the sleep time. It was too short that the main running thread didn't let Camel threads start.
I changed the sleep time to 100000 (100,000) and it worked just fine.

Related

Playing regular and looping sounds with JDK 11?

I am using Java JDK 11.0.8 ("Installed JREs" under Eclipse is set to jdk-11.0.8), Eclipse 2020-06, and Codename One 6.0.0.
I have recently switched from JDK 8 to JDK 11 and noticed that playing sounds option in my app does not work anymore...
Note that I uncheck "Java 8" when I create my app and I am only trying to work things out in the simulator (I am not trying to deploy the app to an actual mobile device).
I want to play a "regular sound" (I want to play a sound from beginning to end, and when it ends I do not need to replay it from the beginning) and also a "looping sound" (the sound should come to its beginning when it ends and hence, I can continuously play it in the background).
Hence I have two questions:
Question1 - About "regular sounds"
I would like to create Media object just once and then re-use it whenever I need to play the same regular sound.
For that purpose I am encapsulating a Media creation inside a class as follows:
public class RegularSound {
private Media m;
public RegularSound(String fileName) {
try{
InputStream is = Display.getInstance().getResourceAsStream(getClass(), "/"+fileName);
m = MediaManager.createMedia(is, "audio/wav");
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void play() {
m.setTime(0);
m.play();
}
}
Then I instantiate the RegularSound object and play it as follows:
mySound = new RegularSound("example.wav");
mySound.play();
Please note that example.wav is copied directly under the "src" directory of my project.
This code used to work with JDK 8, but with JDK 11, I get the following build errors:
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: javax/media/ControllerListener
at com.codename1.impl.javase.JavaJMFSEPort$1.run(JavaJMFSEPort.java:67)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Caused by: java.lang.ClassNotFoundException: javax.media.ControllerListener
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at java.base/java.lang.ClassLoader.findSystemClass(ClassLoader.java:1247)
at com.codename1.impl.javase.ClassPathLoader.findClass(ClassPathLoader.java:269)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
at com.codename1.impl.javase.ClassPathLoader.loadClass(ClassPathLoader.java:115)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at com.codename1.impl.javase.ClassPathLoader.loadClass(ClassPathLoader.java:107)
... 14 more
Question2- About "looping sounds"
For looping sound I have created another class as follows:
public class LoopingSound implements Runnable{
private Media m;
String fileName;
public LoopingSound(String fileName){
try{
InputStream is = Display.getInstance().getResourceAsStream(getClass(), "/"+fileName);
m = MediaManager.createMedia(is, "audio/wav",this);
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void pause()
{
m.pause();
}
public void play()
{
m.play();
}
public void run() {
m.setTime(0);
m.play();
}
}
But I again get build errors when I instantiate an object of LoopingSound and try to play it...
So could you please let me know how to change code for regular and looping sounds so that I do not receive above-mentioned errors when using JDK 11?
UPDATE
Thanks for the reply #shai-almog. I have installed CEF. But I am receiving some messages on the console in runtime and I can't hear the sound playing... I run the following code:
try {
InputStream is = Display.getInstance().getResourceAsStream(getClass(), "/example.wav");
Media m = MediaManager.createMedia(is, "audio/wav");
m.play();
} catch (IOException e) {
e.printStackTrace();
}
and I receive the following messages on console when I run this code (it throws an exception at the end):
Adding CEF to classpath
Retina Scale: 2.0
CEF Args: [--disable-gpu, --disable-software-rasterizer, --disable-gpu-compositing, --touch-events=enabled, --enable-media-stream, --device-scale-factor=4, --force-device-scale-factor=4, --autoplay-policy=no-user-gesture-required, --enable-usermedia-screen-capturing]
Using:
JCEF Version = 83.4.0.260
CEF Version = 83.4.0
Chromium Version = 83.0.4103.106
AppHandler.stateHasChanged: INITIALIZING
initialize on Thread[AWT-EventQueue-0,6,main] with library path C:\Users\pmuyan\.codenameone\cef\lib\win64
Added scheme search://
Added scheme client://
Added scheme cn1stream://
DevTools listening on ws://127.0.0.1:8088/devtools/browser/591d3502-6fd6-4997-9131-9a2a352e47b1
AppHandler.stateHasChanged: INITIALIZED
Running ready callbacks
Exception in thread "AWT-EventQueue-0" Address changed to data:text/html,%3C!doctype%20html%3E%3Chtml%3E%3Chead%3E%3Cstyle%20type%3D'text%2Fcss'%3Edocument%2C%20body%20%7Bpadding%3A0%3Bmargin%3A0%3B%20width%3A100%25%3B%20height%3A%20100%25%7D%20video%2C%20audio%20%7Bmargin%3A0%3B%20padding%3A0%3B%20width%3A100%25%3B%20height%3A%20100%25%7D%3C%2Fstyle%3E%3C%2Fhead%3E%3Cbody%3E%3Caudio%20id%3D'cn1Media'%20width%3D'640'%20height%3D'480'%20style%3D'width%3A100%25%3Bheight%3A100%25'%20src%3D'https%3A%2F%2Fcn1app%2Fstreams%2F1'%2F%3E%3Cscript%3Ewindow.cn1Media%20%3D%20document.getElementById('cn1Media')%3Bfunction%20callback(data)%7B%20cefQuery(%7Brequest%3A'shouldNavigate%3A'%2BJSON.stringify(data)%2C%20onSuccess%3A%20function(response)%7B%7D%2C%20onFailure%3Afunction(error_code%2C%20error_message)%20%7B%20console.log(error_message)%7D%7D)%3B%7Dcn1Media.addEventListener('pause'%2C%20function()%7B%20callback(%7B'state'%3A'paused'%7D)%7D)%3Bcn1Media.addEventListener('play'%2C%20function()%7B%20callback(%7B'state'%3A'playing'%7D)%7D)%3Bcn1Media.addEventListener('ended'%2C%20function()%7B%20callback(%7B'state'%3A'ended'%7D)%7D)%3Bcn1Media.addEventListener('durationchange'%2C%20function()%7B%20callback(%7B'duration'%3A%20Math.floor(cn1Media.duration%20*%201000)%7D)%7D)%3Bcn1Media.addEventListener('timeupdate'%2C%20function()%7B%20callback(%7B'time'%3A%20Math.floor(cn1Media.currentTime%20*%201000)%7D)%7D)%3Bcn1Media.addEventListener('volumechange'%2C%20function()%7B%20callback(%7B'volume'%3A%20Math.round(cn1Media.volume%20*%20100)%7D)%7D)%3Bcn1Media.addEventListener('error'%2C%20function()%7B%20var%20msg%20%3D%20'Unknown%20Error'%3B%20try%20%7Bmsg%20%3D%20cn1Media.error.message%20%2B%20'.%20Code%3D'%2Bcn1Media.error.code%3B%7Dcatch(e)%7B%7D%20callback(%7B'error'%3A%20msg%7D)%7D)%3B%3C%2Fscript%3E%20%3C%2Fbody%3E%3C%2Fhtml%3E
UPDATE 2
I could manually add Open JavaFX 11 to Eclipse and to Codename One app running under Eclipse while using JDK 11 as follows:
Step1) Create JavaFX11 user library under Eclipse
Download JavaFX 11 from https://gluonhq.com/products/javafx/
unzip it -> creates javafx-sdk-11.0.2 folder
Create a User Library: Eclipse -> Window -> Preferences -> Java -> Build Path -> User Libraries -> New.
Name it JavaFX11.
Hit "Add External JARs" and include all the jars under javafx-sdk-11.0.2\lib
Step 2) Add the JavaFX11 library to the project:
Right click on project.
Select Build path -> Configure Build Path
Goto Library tab->Add Library->User Library->Check JavaFX11->Apply and Close
Now, I can hear sounds playing in my Codename One application.
However, I need to run my application from command prompt and regular command line to run the apps does not work anymore (the app cannot find the JavaFX related classes from the command prompt and I get the same errors listed above). So could you please tell me how to modify the command line so that Codename One project that uses JavaFX would run from command prompt?
Here is the regular command line I use:
java -cp dist\Proj.jar;JavaSE.jar com.codename1.impl.javase.Simulator com.mycompany.hi.Main
BTW, I have tried to add javafx.media.jar under javafx-sdk-11.0.2\lib to the classpath (-cp) in the command line, but this did not work...
UPDATE 3
We have solved the issue by using the following command line:
java --module-path C:\javafx-sdk-11.0.2\lib\ --add-modules= ALL-MODULE-PATH -cp dist\Proj.jar;JavaSE.jar com.codename1.impl.javase.Simulator com.mycompany.hi.Main
(where C:\javafx-sdk-11.0.2\lib\ is our )
Thanks!
The TL;DR
Either install CEF as explained here or switch to ZuluFX 11 for your VM.
The explanation:
This used to work until we integrated CEF support we would download JavaFX dynamically for JDK 11 installs but this caused a lot of related problems. So we decided to migrate to CEF, this is still in progress and while it's ongoing JavaFX dynamic download is broken. Once it's done CEF will be auto-installed and this will be seamless again.
This impacts browser component and media which are the two components implemented by JavaFX.

Apache Camel File End point: Camel test invokes direct component route to copy files from folderA to folderB

I am new to apache camel and writing the camel test to validate the route. My use case is,
From camel test invoke route which copies files from folderA to folderB.
Camel route is invoked using direct component from test route.
This doesn't work for me,
from("direct:waitingForVideoFiles").routeId("waitingForVideoFiles")
.to("file:E://folderA?noop=true")
.to("file:D://folderB?FileName=ready-${file:name}")
My camel test direct component looks like this,
template.sendBody("direct:waitingForVideoFiles",null);
Here i can see CamelFileName is set to null.
This code works for me.
from("file:E://folderA?noop=true&include=.*.mov|.*.ts").routeId("VideoFilesAvailable")
.setHeader("statusVideoFile", simple("failed"))
.log(LoggingLevel.INFO, "header is ${headers}")
.to("file:D://folderB")
files are getting copied without direct component.
you are passing body as null, try with some content
If you haven't mentioned the fileName, camel will create its own file with the content you are passing.
I tried your example and that works for me
#Test
public void testSendMatchingMessage() throws Exception {
template.sendBody("direct:waitingForVideoFiles", "some content");
}
#Override
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
from("direct:waitingForVideoFiles")
.routeId("waitingForVideoFiles")
.to("file:///Users/sucheth.shivakumar/Desktop/folderA");
}
};
}
Just in case if you want to send your own file name, You can use something like this
template.sendBodyAndHeader("direct:waitingForVideoFiles", "some body content", Exchange.FILE_NAME, "such.txt");
You need a PollEnrich:
from("direct:waitingForVideoFiles").routeId("waitingForVideoFiles")
.loopDoWhile(body().isNotNull())
.pollEnrich("file:E://folderA?noop=true")
.toD("file:D://folderB?FileName=ready-${file:name}")
.end();
Note that I've changed "to" to "toD" because of "${file:name}".
Hope it helps.
R.

VisualSVN post-commit hook not executing .jar file to perform backup task

This is my first question on here so apologies if its not detailed enough. I am trying to set up a post-commit batch job for work that I am doing. I am using VisualSVN to manage my repository. I have the following post-commit.bat file:
REM Get the commit variables
SET REPOSITORY_PATH=%1
SET REVISION=%2
CD "C:\ProgramData\Oracle\Java\javapath"
java -jar "C:\Users\Nick\Developer\Repository\Restaurant_System\hooks\post_commit_hook.jar"
I then have the following jar file:
/**
*
*/
package svn.hooks;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Map;
/**
* Name: post_commit_hook Purpose/Description: TODO
*/
public abstract class post_commit_hook {
/**
* Name: main Description: The main entry point of the program Returns: void
*/
public static void main(String[] args) {
try {
System.err.println("We're In!"); //This should send a message to the client committer (but it doesn't)
String[] command = { "CMD", "/C", "call", "C:/Scripts/svn-backup.bat"};
ProcessBuilder probuilder = new ProcessBuilder(command);
Map<String, String> env = probuilder.environment();
PrintWriter writer = new PrintWriter("C:/Users/Nick/Desktop/test.txt", "UTF-8");
writer.println(env.get("Path"));
writer.close();
Process process = probuilder.start();
// I have stream readers and such here, but not to bore you with that!
// Wait to get exit value
int exitValue = process.waitFor();
System.out.println("\n\nExit Value is " + exitValue);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
When I run this jar file independently on the server, it does its job correctly. Though when I perform a commit (hence triggering a post-commit event) the jar does not run. I have done the following to help work out the problem:
Checked the .jar is being referenced correctly in the post-commit.bat file by changing the directory to a non-existent one (J:\Users\Nick\Devel........\post_commit_hook.jar). I get an error client side showing the following: (Warning: post-commit failed on exit code 1, unable to access jarfile)
Client-side Commit Response (Eclipse)
So this seems to indicate to me that the post-commit script is referencing the .jar file and knows what to do with it? As when it references the file correctly (C:\Users...) there's no error...
I have checked that both 'VisualSVNServer Admins' and NETWORK-SERVICE have permission to execute the .jar:
.jar permissions
The permissions are in place...
I am aware that there may be PATH environment issues, and so I have included code in the JAR file to print the variable... But this doesn't help if it can't even run under the VisualSVN hook!
I have spent days on this issue and am getting nowhere close to a solution, having scoured various forums and not found anything that works :(
I hope someone can help me with this!

why can't i write this camel route?

from("e1")
.split()
.method("bean", "m1")
.to("e2")
.end()
.split()
.method("bean", "m2")
.to("e3");
The compiler complains about the 2nd to. The reason is that for some reason, it thinks the second split returns ExpressionCaluse rather than ExpressionClause<SplitDefinition>, which causes the following method return type to be Object rather than SplitDefinition.
I tried it in Eclipse, and first I got the same result as you (with the eclipse code completion showing an error). Then I rewrote the route (e.g. splitting it up with assignments to
ProcessorDefinition pd = from("e1")....
pd.split()...
Then, back to the original code, so finally Eclipse got the idea correct and the error marker disappeared. I don't know if you was trying eclipse too?
#Override
public void configure() throws Exception {
from("e1")
.split()
.method("bean", "m1")
.to("e2")
.end()
.split().method("bean", "m2")
.to("e3");
}
I mean, it should work. The signature of split() in ProcessorDefinition is correct:
public ExpressionClause<SplitDefinition> split()
I guess this is a glitch somewhere in my dev. env. and probably yours too.. or something. Odd, anyway.

Java mail IMAPFolder class cast exception when using Jetty embedded

I have a problem which seems really strange to me! I am working with java mail api in some POJOs and servlets/jsps running on an embedded Jetty server. The problem is that after I retrieve all the folders, but when trying to cast an individual folder from Folder type to IMAPFolder type, this fails.
The strangest thing is that my JUnit tests work just fine the folder is casted and all the messages are retrieved. However, when running the application, it failed.
I just have the error message
500 ([Lcom.sun.mail.imap.IMAPMessage; cannot be cast to [Lcom.sun.mail.imap.IMAPMessage;)
The code is simple:
//...
for(Folder fl:mailFolders){
try {
if((fl.getType() & Folder.HOLDS_MESSAGES) != 0){
Folder f = fetch.connectToInbox(st, fl.getFullName());
fetch.processAllMessages(f);
}
} catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//.. }
public synchronized void processAllMessages(Folder fldr){
IMAPFolder fl = (IMAPFolder) fldr ;
}
Can anyone please help me?
You've got two copies of the JavaMail classes available to your application and they're being loaded by different class loaders, which is why you're getting the strange exception.

Resources