change exchange content in camel - java

I am trying to implement a scenario using camel which is as follows:-
Get File From JMS queue.
Store the file and crc value of the file in a directory
Move the file and crc file to the SFTP server and once it is successfull
delete the files from the directory.
My route is as follows
from("jms:queue")
.to(save the file)
.process(since I have the content of the file in exchange so generating crc)
.to(file system save the crc file)
.to(Push both the files to the sftp server);
But the file that is getting uploaded to the sftp server is only crc file as it was present in the exchange.
How should I solve this Situation?
If anyone of you have come across to this problem Please Guide me.
Thanks

I think you should use a wire tap to copy your exchange to a different route and have that new route save the file and sftp it to the correct location.
from("jms:queue")
.wireTap("direct:save-file")
.process(since I have the content of the file in exchange so generating crc)
.to(file system save the crc file)
.to(Push file to the sftp server);
from("direct:save-file")
.to(save the file)
.to(Push file to the sftp server);

Related

SpringBoot cannot upload large files after using Nignx

SpringBoot uses the Nginx reverse proxy and then opens the HTTPS protocol. If the file transfer exceeds 500KB, the data in the Request will not be received.
You need to edit your nginx.conf and add this line into the server block:
server {
client_max_body_size 10M;
}
It means setting file size upload to 10M.

How to copy a file in FTP server using FTPClient in Java?

I have a CSV file, and I need to copy it and rename it in the same path.
I tried this after the FTP login:
InputStream inputStream = ftpClient.retrieveFileStream(cvs_name +".csv");
ftpClient.storeFile(cvs_name2 + ".csv",inputStream);
But when I verify the file on the server, it's empty. How can I copy a file and rename it?
I believe your code cannot work. You cannot download and upload a file over a single FTP connection at the same time.
You have two options:
Download the file completely first (to a temporary file or to a memory).
The accepted answer to How to copy a file on the ftp server to a directory on the same server in java? shows the "to memory" solution. Note the outputStream.toByteArray() call.
Open two connections (two instances of the FTPClient) and copy the file between the instances.
InputStream inputStream = ftpClient1.retrieveFileStream(cvs_name + ".csv");
ftpClient2.storeFile(cvs_name2 + ".csv", inputStream);

Accessing Remote files using HTTP from a web application

we have a requirement where all file (text , image , PDF etc) uploaded in the Server1. Now we have a Java web application running in a different server (Server 2) which has to read these files and show it in the GUI.
FTP is blocked in web application server. So i am thinking of using HTTP.
The files in Server1 is not distributed .i.e not inside any ear or war.
I managed to get the code to read a file from HTTP.
My question is
- How do i access this file through HTTP when these files are not distributed
- When i write a code accessing the file like http://server1:port1/location of file , its says file not found .
- how do i expose these files , so that i can access it via HTTP from my web application
That means, you want to download the content of the file.
Well at very first, open up a browser. Enter http://server1:port1/FILE_PATH .
what do you get as a response ?
Second, if you get "FILE NOT FOUND" then you need to configure a virtual path mapped to real path in server1. After that, try the URL from browser again. When it works,
URL website = new URL("http://server1/file_location");
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream("file_name");
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
will help you to download the file to your local machine.

How do I get url of uploaded file

I'm using apache.commons library for uploading file to a ftp server. It uploads file successful, but then I want to have a link to that file, that anyone can download it. How do I get the URL of uploaded file ?
Thanks.
One of the great features of an FTP server is the ability to use direct FTP links. With a direct link, you can use links to files and directories in emails and on your websites. Think of this: instead of sending a big attachment in an email, send a link to the file instead.
The format is really simple:
ftp:// username [colon] password [at] server.exavault.com [slash] folder-or-filename
For example: ftp://links:pass#test.exavault.com/transfer.pdf
source : http://www.exavault.com/docs/help/faq/transferring/direct-links

xlsx file corrupted during downloading from server

Folks, here is the situation:
confirmed that the xlsx file is good on the disc.
I copied the file from server and can open without problems.
using FileInputStream and BufferedInputStream to handle the client side download function.
The download function i mean user can download the file by clicking a hyperlink, and a servelet call was made to the java class which uses FileInputStream and BufferedInputStream
Mime type was set correctly as application/vnd.openxmlformats-officedocument.spreadsheetml.shee
After download the file successfully, it will give a "converted failed" error while trying to use office 2003 to open this xlsx file.
any thoughts?
Thanks!
There are bytes which didn't belong in the HTTP response body or were simply missing there.
It's impossible to point out the actual root cause based on the information given as far. You have to check if the right bytes were written from local disk file system to the HTTP response body.

Categories

Resources