Please suggest some solutions for building a download service - java

I'm planning a web service providing file download service for handheld devices.
The requirement I have is use HTTP or FTP Protocol to build a server, use database, store files and provide Command Line Interface for devices to download requested files. No platforms and languages limit.
I'm a student and I'm learning Java Web(practicing Structs2, haven't started learnning Spring or Hibernate), and this is just a simulate project which may be required in a E-Book company. So I'm feeling like to use Java to build the service.
I'm now doing the requirement analysis, please give me some suggestions. About how to design the structure, book files stored in database or filesystem, any open source library to refer to... About any aspect is OK.
I just want to know what can I do to make it better and where I should be paying attention to.

You could implement a simple Servlet, which returns files based on request arguments.
Then, use your command line client to call the Servlet with the correct parameters, depending on what the user typed.
EDIT: more info on Java Servlet technology here. If you are learning Struts, you could implement your servlet there, but it might be a bit of overkill.

Related

Getting info about external processes in linux using JNA- Ptrace?

I'm on a student research team currently working on a Java project in which we want to be able to gather some info about specific external programs in CentOS 7. Some potential examples of data we might want to gather would be the URL from firefox, or the coordinates from Google Earth. Thus far, looking into how to implement this has mostly led me to using JNA and ptrace.
Is this a good route to take to tackle this problem? And if so, what can I use to find the location of specific information about the programs in memory?
JNA and ptrace are quite low level things. To run system applications you should use:
exec method of Runtime class
Apache Common Exec
Last one is more useful.
But it seems you don't need to run any application at all. To get information from Google Earth you can just use special web API - Google Maps APIs Web Services. If you want to send HTTP request you should try Apache Http Client. It's very powerful library and i'm pretty sure it's all for you need.
PS. More convenient client Java Client for Google Maps Services
PS1. I think java is the worst choice to work with OS and native applications. I see 2 ways to use it:
write agent on C/C++ which will be gather this information for java manager. It's a hard way
use hacks and tricks like here is there a way to get the url from current tab in google-chrome or here Possible to catch URLs in linux?. It's more easy but you will have restricted amount these hacks. And it will work not for all applications and cases.

Implementing authentication in uploaded files in java

I have application where various files are uploaded in server. And the application has various users. Now, I want to implement authentication so that only privileged users can access to those uploaded documents. So, is there any document manager api in java to manage these documents. I have looked into alfresco, knowledgetree but those are separate applications. I want an api to implement in my application.
We do not have enough information to suggest a solution, but I think that you can still think to use Alfresco if you embed it in your application.
Look at the following url: Deployment options that shows some deployment options.
Of course, this makes sense only if you need all the power of Alfresco.

Creating websocket Java APIs

I want to create a websocket Java API for these requirements:
"When the user logs into my application, if he enters a page which has constant updates from the server, then the Java API should identify the user and keep pushing the contents on a regular interval"
So for this I want to get started in creating a generic Java API so that for other pages, which requires push from server, I can use the APIs instead of reinventing the wheel everytime
What are the things I should take into consideration and how should I approach this problem
Please key in your thoughts
Thanks in advance
GitHub has a number of libraries which deal with Java and WebSocket. You can build your application on top of one of them. Examples are vert.x, SockJS, Atmosphere etc.
At the SockJS page you can see a list of clients/servers for working with it.
IMHO It is better to re-use one of the existing libraries/frameworks than building your own, because yours is a common usecase and working with web sockets, providing corss browser compatibility etc are not trivial as of now.

Efficient way to implement a client multiple file upload service

What is an efficient way to implement a multiple file client upload service?
Are there any popular libraries for that?
Basically I'm looking at a Web view, served a client, that would allow them to upload files: i.e browse their file system and choose say up to 6 files.
Is implementing the above service better than a single file upload-service. i.e allowing only one upload at a time?
If so what is an efficient way to implement that or again what popular libraries are there to use.
I'm building a Java Dynamic Web to be deployed on Tomcat.
Thanks
If you're looking to do multiple file uploads on the web, I would strongly recommend SWFUpload. It's totally customizable, and it can use whatever back end technology you'd like. Take a look at some of the demos on the site for some use cases involving multiple files at once. I've only used it in one project so far, but it beats some of the other third party upload controls I've used hands down.
If your clients can use modern builds of browsers, you can use multiple file upload field support that mozilla/webkit offers. Otherwise, YUIUpload from latest YUI3. Much cleaner/faster/easier than SWFUpload.

How to deliver a Java program locally through a browser

I want to write an application that runs entirely locally on one machine - there is no need for connection to the internet or to any external machines.
I was thinking that it would be a good idea to use a web browser as the platform for this application so that I would not have to mess around with lots of UI stuff - I could just knock together the web pages fairly quickly and take advantage of CSS to get consistent styles throughout the application.
However I want to interact with a MYSQL database on the machine in question. With this in mind I was thinking that I could somehow use Java to process the information that the user inputs from the application and communicate it to the database via JDBC.
I know that I could use an applet to do this but the downside to that is that I would like the user to be able to save files to the local machine - and I have read that applets run in a sandbox which prevents them from gaining any access to the local machine.
I also know that I could use PHP but I would like to take advantage of object oriented design which Java is perfect for.
Does anyone have any thoughts, suggestions or links to tutorials/webpages which could help me to decide how best to go about this.
Any thoughts are very much appreciated..
I know you said you don't want to mess around with GUI stuff in java, but have you looked in to java web start? It does almost exactly what you need; a user clicks a link through a web browser and your application is deployed on their machine, it even checks to make sure the right JVM is used. Because it is a full application and not an applet, your app won't be sandboxed, and you don't have any access restrictions in your program (other than the normal java stuff..), and for example, it would be easy to do what you mentioned and talk to a mySQL DB. The only downside, is what I mentioned earlier, is that you would have to design a UI in java.
Web Start Wikipedia Page
Sun FAQ on Web Start
Grails may be a useful starting point. It'll provide you with a web server solution that's standalone, and it'll look after the JDBC requirements and the CRUD (create-read-update-delete) capability via dynamically generated web pages. It should take minimal effort to put together an app providing your database interfacing via web pages.
(fyi. Grails is the Java equivalent of Rails)
If you feel comfortable with Java EE-based web development, you could probably just bundle your application with Tomcat or Jetty.
If you do not want to run standalone servlet container just for one application, you can also embed Jetty into a runnable Java application (see documentation here).
Either way you can leverage existing Java EE frameworks (Spring JDBC, Hibernate, all those web frameworks) for abstracting away technical complexities, although with embedded Jetty, you'd probably need to write some kind of integration layer for the web application framework of your choice.
I think you should give Restlet, a lightweight rest framework a try. The tutorial shows you how to start a local webserver, and by that deliver a "Hello World" through the browser within minutes (no joke!), and there's plenty of extensions for any kind of need.
In combination with Java Web Start by which you can deploy and start the application to the local host this should be what you need.
as someone suggested already you can use embbeded jetty server on your application and just let your user to start it using somekind of shell script or batch script. You only need to make your layour directory complaint with a Java Web Application and your on it. ie:
MyApplication
app/
WEB-INF/
lib/
classes/
web.xml
start.bat |
start.cmd - depends on your client OS
start.sh |
Then you should only need to take care of launching Jetty in your start.[bat|cmd|sh] with your app as your webaplication context and your done!
Using JDBC doesn't mean that you have to write an applet, you can use JDBC in any kind of application: a desktop application, a web application, EJBs, MDBs, etc.
You want to use a browser and Java on the server side? Then go for it and use Servlets / JSPs. Consider maybe using an presentation framework (Wicket, Struts2, Spring MVC,...), Hibernate for data access and Spring for other facilities and wiring. Grails is a good idea too.
BTW, I'm not a PHP specialist but PHP has object-oriented capabilities (introduced in PHP4 , enhanced in PHP5) so you won't sacrifice everything if you choose PHP.
So it really depends of what you want to do. If you want to write some Java (webapp or desktop app): choose Java. If you want to put quickly a few web pages in place and have an apache server, choose PHP. If you look for really high productivity, go for RoR or Grails.
You can try GWT + Google Gears
GWT is a GUI toolkit similar to Swing for the browser. Google Gears is a browser side database. Your app is completely in Javascript in a single HTML file and cross-browser compatible.
GWT app can make Server calls and Gears can sync up with a Server database. So you need not restrict your app data completely to the local desktop.
If you're interested in some experimentation, like new stuff and would like to reuse the plethora of Java libs (including JDBC) then you might be interested in the lift web framework, which is Scala-based.
If you want to do it as an applet you can. Sign the applet and give it permissions to the local network (to connect to the MYSQL server that way)... that should be possible. Here is a tutorial on it.

Categories

Resources