I have built a server application with netty that now needs to act as a ftp server as well. Basically I just need to support authentication/login and file upload via ftp.
Unfortunately there seems to be no pure java implementation of ftp so I could simply write my own decoder/encoder/handler set. Apache MINA provides a complete ftp server, but how could I do it simple and easy with netty?
I already integrated jetty for web service support, but I can't find ftp support for jetty neither.
It would be marvelous to get some hints. I think I checked out all google hits on "java ftp" but they just seem to provide ftp client stuff.
Best regards,
Martin
If it's Netty you're interested in, I found an open source FTP server based on it:
https://github.com/waarp/WaarpFtp
Maybe you could reuse some parts of the project? I guess this source file might be the most interesting to you:
https://github.com/waarp/WaarpFtp/blob/master/src/main/java/org/waarp/ftp/core/control/NetworkHandler.java
I wrote netty handler for receiving files over FTP - netty-ftp-receiver. It's small and straightforward and may be used as a starting point.
Related
Last time I think how can I connect my Java external program to Apache webserver.
I wanna send HTTP requests to process and then send output back as HTML file.
I thought about JNI but with multi-thread structure, it doesn't look good for me.
I think with help of Sockets it could be nice but I want to hear Your ideas.
Last but very important: should I use "normal" Apache or Tomcat for that?
For the level of integration you are looking for, JNI is way too low-level and involved.
Instead, take a look at:
FastCGI: on the Apache side use mod_fastcgi and jfastCGI on the Java side.
small HTTP servers: mod_proxy on the Apache side, which reverse proxies to a small HTTP server on the Java side such as Netty or Undertow.
Our project is a traditional project which is using RMI to do the communication between a Server and a Client (using Swing).
Recently, we want to change protocol from RMI to HTTP(for the firewall safety) without changing too much original code(keep original Server logic and Swing GUI).
Is there any good and mature way to do the transition? Thanks.
You can use your code as-is with the RMI/HTTP tunnelling that's built in to RMI. You just install the RMI-CGI servlet that's distributed with the sample code, configure it appropriately, and Bob's your auntie.
See the documentation. Thanks to #JoopEggen for the link.
Anyone has expirience on having Jruby project running on Jboss (using torquebox or whatever) with an ability to communicate with another "japps" not on the same jboss where jruby app is, i.e. some java project on another jboss?
I know there is an torque-messanging but dunno if it's possible to communicate with external(out of jruby-app's jboss) app?
Best practices are welcomed.
Thanks in advance.
P.S. placing that other app on the jboss where jruby app is not acceptible solution.
I can recommend you to use Thrift and build communication via them.
Thrift have generator for both your needed languages (Java and JRuby) and provide good and fast communication.
UPDATED:
Thrift is RPC (remote procedure call) framework developed at Facebook. In detail you can read about it in Wiki.
In few word to save you time, what it is and how to use it:
You describe you data structures and service interface in .thrift file(files). And generate from this file all needed source files(with all need serialization) for one or few languages(what you need). Than you can simple create server and client in few lines
Using it inside client will be looks like you just use simple class.
With Thrift you can use what protocol and transport used.
In most cases uses Binary or Compact protocol via Blocked or Not-blocked transport. So network communication will be light and fast + with fast serialization.
SOAP(based on XML on HTTP) packages, its in few times bigger, and inappropriate for sending binary data, but not only this. Also XML-serialization is very slow. So with SOAP you receive big overhead. Also with soap you need to write (or use third-party) lib for calling server(tiny network layer), thrift already made it for you.
SMTP and basically JMS is inappropriate for realtime and question-answer communication.
I mean if you need just to put some message in queue and someone sometime give this message and process it — you can (and should) use JMS or any other MQ services(Thrift can do this to, but MQ architecture is better for this issue).
But if you need realtime query-answer calls, you should use RPC, as protocol it can be HTTP(REST, SOAP), binary(Thrift, ProtoBuf, JDBC, etc) or any other.
Thrift (and ProtoBuf) provide framework for generate client and server, so it incapsulate you from low level issues.
P.S:
I made some example in past https://github.com/imysak/using-thrift (communication via Thrift Java server + Java Client or node.js client), maybe it will be useful for someone . But you can found more simple and better examples.
Torquebox supports JMS. The gem you specified torquebox-messaging allows for publishing and processing of HornetQ messages on the local JBoss AS server/cluster that the JRuby app is running in. I don't think it currently supports connecting to remote servers.
Using this functionality in your JRuby app you could then configure your Java app on another server to communicate with HornetQ running in the JBoss AS that the JRuby app is running on.
Alternatively you could always implement your own communication protocol or use another Java library - you have access to anything Java you want to run from JRuby.
You can use Web Services or JMS for that
In our Java web application, customer wants to upload some large files to a SFTP server and download directly from there. The customers do not want to use any third party tool rather they want this functionality in the application itself.
The file upload part has been taken care of by the JFileUpload applet component & libraries. Once the file gets uploaded I could figure out the exact location of the stored file. And that uploaded file will be shown to the users as a link which they will click to download (like an HTTP or FTP file link).
So I've to decide the strategy for downloading the file from the SFTP servers.
One option is to parse the request, then connect with the SFTP server and stream the file via HTTP server. But here the file will be downloaded over HTTP rather SFTP and moreover it will not serve the purpose of using SFTP.
Another option which I could think of is via an applet, again like upload. As soon as the request for the SFTP file comes to the HTTP server, it will launch a page containing an applet having a directory browser for users to decide the save path. Once the user selects the save location, the file will automatically start downloading to that location from the SFTP server. In this way the connection will be completely SFTP.
I want to know how much feasible the second approach is and if there are any important things I'll have to take care of. Which SFTP libraries are the best to use for this type of operations?
Moreover, please let me know if there are other better options to do mentioned activity.
Edit
It seems this post looks like a request for suggestion on ways to download from SFTP server (may be from the heading but I could not think of any other heading!!). Thank you for the suggestions on the APIs to do that but the more important issue for us is to figure out a way where a user's request to download a file from SFTP server is done over secure SSH rather than over HTTP. Now using the mentioned APIs we could very well download the files from the SFTP server to the HTTP server's filesystem but after that if we have to redirect the same file to the user's machine we have to use HTTP and that is what we want to avoid.
Our second thought approach of using a page with an applet which will initiate a SFTP session between user's client and SFTP server is to address the above concern.
How difficult will it be to implement and what should be our approach in this regard?
And if there is any other better & easier way to do the same task then please suggest.
I favor Commons-VFS for this kind of thing. It abstracts out the actual file system type and lets you work with a standard interface regardless of the underlying implementation. It in turn depends on other libraries for the actual systems, in particular JScsh for SFTP.
I recommend using JSch, Java Secure Channel. It is a pure Java implementation of SSH2. It has good examples for doing SFTP in addition to pretty much every other SSH2 option (XForwarding, port forwarding, etc.). We use it in a number of our projects, and have not had any issues. I have even tied it's GSS-API (Kerberos) support into a native Kerberos implementation and it worked well. It is BSD licensed, so commercial or not, you shouldn't have much issues with licensing.
I see building an applet using JSch to be pretty simple. Biggest issue will be to make sure your applet is signed and has permissions to write/read local files and connect to the SSH servers in question.
The customer is always right, so while the requirement screams bad architecture to me, I'll just extend my sympathy on that and try to help you with the problem.
The applet approach is OK, but seems kind of clunky for a web app. There are javascript sftp libraries out there. This one supports sftp and will give a much more natural feel to a web application than poping up an applet just for the sake of providing a file transfer. It isn't free, but it isn't that pricy either. It still uses an applet under the hood to effect the file transfer, it just doesn't present a java screen to the user.
Did you mean SFTP or FTPS (FTP over SSL)?
If you realy ment SFTP, have a look here: http://www.spindriftpages.net/blog/dave/2007/11/27/sshtools-j2ssh-java-sshsftp-library/comment-page-1/
I have Java and Flash client applications. What is the best way for the two to communicate without special Flash-specific servers such as BlazeDS or Red5? I am looking for a light client-only solution.
Well, you can make http requests from flash to any url... so if your java server has a point where it can listen to incoming requests and process XML or JSON, your flash client can just make the request to that url. BlazeDS and Red5 just aim to make it simpler by handling the translation for you making it possible to call the server-side functions transparently.
Are they running in a browser (applet and SWF), or are they standalone apps?
If they're running in a browser then you can use javascript. Both Flash and Java are can access javascript. It's fragile, but it works.
If they're running as actual applications then you can have Java open a socket connection on some port. Then Flash can connect to that and they can send XML data back and forth.
I've done both of these, so I know they both work. The javascript thing is fragile, but the socket stuff has worked great.
WebORB for Java may be of some help to you. It integrates with your J2EE code.
For more info:
http://www.themidnightcoders.com/weborb/java/
I'm sorry, I reread your question that you are only looking for a client side solution. In this case, WebORB will not help you. Sorry for the misunderstanding.
There's a Flash implementation of Caucho's Hessian web service protocol. This approach would be similar to using JSon or XML, but is more performant, since Hessian is a binary protocol. If you happen to be using Spring on your server, you can use the Spring/Hessian binding to call you Spring services directly from your Flash application with minimal work.
Merapi Bridge API
Merapi allows developers to connect Adobe AIR applications, written in Adobe Flex to Java applications running on the user's local computer.