Camel File component: file not getting transferred on localdisk - apache-camel

I am new to Camel and I am doing something very basic. Trying to move a file from one directory to another, no processing.
try{
from("file:E:\\input").to("file:E:\\output");
}
catch (Exception e) {
e.printStackTrace();
}
No exceptions are being captured and the file path is absolute. Can anybody help me figure out what might be wrong.
Thanks

Please try this out
from("file://E:/input/?delete=true").to("file://E:/outputdir")

Related

Create Event-Driven Consumer on File Endpoint without RouteBuilder in Camel 2.24

I want to run a processor upon file appearance in a directory. My file url is like this:
file:{{file.root}}in?include=.*\.csv&charset=windows-1251&move=../out/done
A procedure that associates an url with a processor is like this:
MessageProcessor getOrCreateConsumer(CamelContext context, String uri) {
Endpoint endpoint = context.getEndpoint(uri);
endpoint.setCamelContext(context); // added this out of desperation, doesn't help
processor = new MessageProcessor();
try {
Consumer consumer = endpoint.createConsumer(processor);
endpoint.start(); // do we need this at all? works the same without it
consumer.start();
} catch (Exception e) {
throw new RuntimeException(e);
}
return processor;
}
}
MessageProcessor is a processor that does some things to an exchange.
Everything seems to work except the file doesn't get moved to the ../out/done directory. While debugging I can't get when the endpoint is configured to provide the file message exchange with this post operation.
I think I am missing some magic call that is normally invoked by a RouteBuilder and that will fully configure the file endpoint. Can you please help me out?

How to generate qrcode in codename one

I'm trying to generate qrcode code in my application with qrgen and then saved in specific file but there is a problem in the libary 'java.io.FileOutputStream' where it can not be found. i want to know how to replace the libary and if there is another way to generate qrcode please share it with me
ByteArrayOutputStream out =QRCode.from(s).to(ImageType.PNG).stream();
try {
FileOutputStream fout = new FileOutputStream(new File(
"C:\\Users\\Public\\Pictures\\Sample Pictures\\QR_Code.JPG"));
fout.write(out.toByteArray());
fout.flush();
fout.close();
} catch (Exception e) {
// Do Logging
}
That isn't supported. Mobile devices don't have a file system in the way desktops have so this logic just won't work. There is a file system but it's to a large part private to the application, see: https://www.codenameone.com/manual/files-storage-networking.html

How to prevent file overwriting?

I am working on an Arduino project using processing. There are some sensor values which should be logged, but unfortunately my processing code rewrites the file after each cycle so that I get the last sensor value only. How do I prevent this from happening? I am using the ordinary method by the way. PrintWriter command followed by createWriter.
You need to specify that you want to append to the file (otherwise, it will just overwrite). Something like this:
try(PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("myfile.txt", true)))) {
out.println("the text");
}
catch (IOException e) {
// couldn't open file
}
The true at the end of the PrintWriter line specifies appending.

Create an attachment from MVCPortlet - serveResource

I need to export a .property file when user clicks on a hyperlink. I am using liferay portal 6.1.1. When user clicks on hyperlink, I am making a jquery.get() to the serveResource method which is inside the MyMVCPortlet class. Here the code that always writes the content to response(verified on fiddler) but is not creating a downloadable file.
resourceResponse.reset();
resourceResponse.setContentType("text/plain");
resourceResponse.setProperty("content-disposition", "attachment; filename=test.txt");
OutputStream out = resourceResponse.getPortletOutputStream();
try {
out.write("key=value".getBytes());
}
catch(IOException e){
e.printStackTrace();
}
finally {
out.close();//Also tried out.flush(); - dint help
}
Do I need to set something on resourceResponse after the write is complete?
I tried different options and got exhausted. The same code on plain java servlet works but not on liferay. Is there anything I am missing? Thanks in advance!
Try to use one of PortletResponseUtil.sendFile() instead of manual operations on portletOutputStream. Eg.
PortletResponseUtil.sendFile(resourceRequest, resourceResponse, "test.txt", "key=value".getBytes())

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