Allow Progressive Download from a servlet? - java

I'm having an issue with a servlet that delivers multimedia data. I'm trying to use it from mobile safari on the iPhone and I get the "server not configured correctly" error. I server the same multi-media file using a web share on my Mac (Apache) and it works fine. I start looking at HTTP heades to see if the servlet is messing up a header. I notice that Apache sets an ETag as well as an Accept-Range. Then I Google around and learn that the iPhone works with progressive downloads. Long story short, I think I need to enable progressive downloads in my servleet and I think the ETag and Accept-Range headers are part of it. I've never done this before so I figured I'd ask here if anyone could point me in the right direction. Do I need to implement the entire progressive download stuff in my servlet? Should I use a Filter? Where should I start?

Take a look at this article. It goes over creating a file servlet that supports resuming the download, caching and gzipping the content.

Related

Reading network traffic from the browser using Java code

Folks,
I was looking for Java capability of reading thru the network tab.
I had a task of hitting a URL in the browser, reading and validate some tags which are fired on page load.
I Know to fetch the View Source Data of the page, but not sure on getting network tab data.
example:
Opening a URL in chrome browser and watching Network tab in the developer tool, i see bunch of Get requests(tags,js etc) getting fired & need to capture this data.
I wanted to know which is the best way to achieve this and great if any code snippet is available.
Cheers
You can use HttpClient to work on api testing. There are many tutorials to work on api testing using Java. For starter you can read about Apache Http client.

80mb Image/Video uploading to cloud storage / blobstore

I am a C# developer who recently decided to venture into the mobile dev world specifically android dev using java. It has been a smooth ride until now. While I'm usually able to follow the tutorials on the android developers site and other sites easily, uploading an image/video to the app engine blobstore or cloud storage seems to be a bit over my head. I cant seem to wrap my head around the process.
I have already done the necessary steps to get my app running on app engine. I am able to register devices and save basic entities to the cloud but I cant seem to get any of the tutorials to work form me.
Basically my app allows users to take images or videos and then have them posted to my back end as part of a file sharing type of game.
I am not asking for someone to give me code that can accomplish this, instead pointing me to a very thorough tutorial would be great!
1.I need understand the role of a servlet (most examples use this for uploading to blobstore)
2.Where should the servlet reside?
3.Is there another way to do this without using a .jsp page for the file uploading ?
4. I have set up the app engine back end for my project including endpoints. Is there a way to send the images/video that way to the server and still be able to retrieve a serving url to fetch the image/video later?
I have been stuck on this for a week now and I'm getting quite discouraged as I cannot seem to adapt any of the tutorials that I have read to suite my needs. There are a few dark spots in my mind where the entire process is concerned. Since I am not familiar with java, servlets etc I'm stumbling in the dark and I just need a lamp to light my path. I think i'm just a step or two away.
BTW I have looked at these questions and tried the code suggested to no avail before deciding to post my own.
Upload to Appengine Blobstore in Android
BlobStore vs Cloud Storage for storing user uploaded images
Upload image from Android to Google Cloud Storage or Google App Engine Blobstore
Please help!
NOTE: I don't have an interface where the user gets to choose the image/video as it is to be taken directly from the camera and sent to the server(not sure that makes a difference).
You need to do a lot more reading. First understand servlets in general. Then learn how to use the blobstore or cloud storage api. Then read how to post directly to blobstore (not to the servlet) with a post-save servlet callback.
Welcome to the world of Java!
I'll try my best to explain the Servlets/JSPs part. I dont know a whole lot about Google app engine.
1) Servlets are nothing but Java objects but with more priveleges. Servlets know how to handle a web request! There are many things that come to mind when we talk about web request processing:
who maps the URL to this servlet?
Who gives this servlet user request parameters?
How can I guarantee only authorized users can access this servlet?
list goes on......
Answer to all above questions is a web container. And in the world of Java only one web container rules (others might differ): Apache Tomcat.
In short, servlets are Java objects created for you by Tomcat.
Where should the servlet reside?
They reside in Tomcat.
Is there another way to do this without using a .jsp page for the file
uploading ?
You dont need a JSP to send requests to a servlet. You can use jquery, python or anything else. As long as its a valid web request.
I have set up the app engine back end for my project including
endpoints. Is there a way to send the images/video that way to the
server and still be able to retrieve a serving url to fetch the
image/video later?
See the tutorial here. Especially 'Implementing Tweet My Picture' section.
Google app engine has Java API (along with python) and the best way to submit web request to that API using Java is servlets. That's why many example are in servlets. I think.
Here's what i would do if I were you:
Setup tomcat. There are many options. So reply if you are not sure.
Deploy your handler servlet that'll use Google app engine Java API.
Send your image files to blobstore (not the servlet). See the tutorial. App engine will forward blob related information to the handler servlet you created in step 2.
Use Blobstoreservice in that servlet so that users can access that uploaded image.
Let us know if this helped.

How to talk to Tomcat server from a PHP application

I am developing a new report engine for my company, our main web application is writing by PHP 5 and running on an Apache server. The new report server which I designed to use Apache FOP 1.0 ruing on Tomcat7,so far I created My own XSLT stylesheets and I can manage to generate a PDF report from the URL and let it display in my web browser.My goal on this project is to generate dynamic report from xml file which export from the PHP application.
Could anyone explain to me the logic behind How I can give those two talk to each others. I understand I could POST the XML and XSLT as string to the report server and POST it back the result I want(like PDF).
I know this will need Java involved,and as a PHP dev. I really don't have much background about Java,if you could show me some examples or links, it would be much appreciate.
I am using Saxon-B with Fop 1.0 on Tomcat 7 for the report server.
if you need more info from me,please also leave a comment. I will add it soon.
Thanks
There are two things your going to need to study.
http://www.w3schools.com/php/php_ajax_intro.asp This is a tutorial on using the XHR object from php. You should go through that. Also, if you aren't familiar with the XHR object, I would read this as well: http://www.w3schools.com/XML/xml_http.asp
You're going to have to create a servlet capable of responding to these requests. There are various tutorials on how to create a servlet.
Here is a link to a youtube video I fall back on when I forget how to do servlets: http://www.youtube.com/watch?v=EOkN5IPoJVs
In the video, he just uses straight up javascript; so you're php code is going to be doing what the javascript did in the video (item 1 on my list).
The video uses an older version of eclipse (I think ganymede), but it is pretty close to the same process in the newest version of eclipse.
Just to be blunt, this isn't something you're going to be able to figure out and make work properly. You've probably got at least a day to a weeks worth of learning here depending on your experience and aptitude; and this will only get you something basic. The servlet you make won't be secure, it won't have user authentication...my point is don't take anything for granted.

How to use Flex and Java to download files from a server?

I'm building a Flex web application where there is an option to export data from a table to a CSV format (theoreitcally, so far, haha). Since it's a web application, I assumed the best way to go about this would be to send a request to the server to generate the file, and then either send that file (or a link to it) back to the Flex application, and use a FileReference to download the file. Is this the correct way to go about this?
Could anyone give me some pointers on how to do this, however? There are some exisitng remote objects in place that call Java functions on the server, so I thought I'd try something along those lines?
I did a bunch of research, and stumbled across things like HttpResponses and HttpServletResponses in Java, but have no idea how to bridge the gap between the client-side and server-side to use that effectively. Haha.
Thanks!
What I have done is have Flex open a new tab/window and navigate it to a servlet.
navigateToURL(new URLRequest(url),'_blank');
Then use a HttpServletResponse to write the file out to the client, which will then be displayed in the browser. This was for a PDF, though.
In order to use an HttpServletResponse you'll need to write a HttpServlet and configure it in your web.xml. Here is a basic tutorial. Google has a lot more.

Best way to upload multiple files from a browser

I'm working on a web application. There is one place where the user can upload files with the HTTP protocol. There is a choice between the classic HTML file upload control and a Java applet to upload the files.
The classic HTML file upload isn't great because you can only select one file at a time, and it's quite hard to get any progress indication during the actual upload (I finally got it using a timer refreshing a progress indicator with data fetched from the server via an AJAX call). The advantage: it's always working.
With the Java applet I can do more things: select multiple files at once (even a folder), compress the files, get a real progress bar, drag'n'drop files on the applet, etc...
BUT there are a few drawbacks:
it's a nightmare to get it to work properly on Mac Safari and Mac Firefox (Thanks Liveconnect)
the UI isn't exactly the native UI and some people notice that
the applet isn't as responsive as it should (could be my fault, but everything looks ok to me)
there are bugs in the Java UrlConnection class with HTTPS, so I use the Apache common HTTP client to do the actual HTTP upload. It's quite big a package and slows down the download of the .jar file
the Apache common HTTP client has sometimes trouble going through proxies
the Java runtime is quite big
I've been maintaining this Java applet for a while but now I'm fed up with all the drawbacks, and considering writing/buying a completely new component to upload theses files.
Question
If you had the following requirements:
upload multiple files easily from a browser, through HTTP or HTTPS
compress the files to reduce the upload time
upload should work on any platform, with native UI
must be able to upload huge files, up to 2gb at least
you have carte blanche on the technology
What technology/compontent would you use?
Edit :
Drag'n'Drop of files on the component would be a great plus.
It looks like there are a lot of issues related to bugs with the Flash Player (swfupload known issues). Proper Mac support and upload through proxies with authentication are options I can not do without. This would probably rule out all Flash-based options :-( .
I rule out all HTML/Javascript-only options because you can't select more than one file at a time with the classic HTML control. It's a pain to click n-times the "browse" button when you want to select multiple files in a folder.
I implemented something very recently in Silverlight.
Basically uses HttpWebRequest to send a chunk of data to a GenericHandler.
On the first post, 4KB of data is sent. On the 2nd chunk, I send another 4K chunk.
When the 2nd chunk is received, I calculate the round trip it took between first and 2nd chunk and so now
the 3rd chunk when sent will know to increase speed.
Using this method I can upload files of ANY size and I can resume.
Each post I send along this info:
[PARAMETERS]
[FILEDATA]
Here, parameters contain the following:
[Chunk #]
[Filename]
[Session ID]
After each chunk is received, I send a response back to my Silverlight saying how fast it took so that it can now send a larger
chunk.
Hard to put my explaination without code but that's basically how I did it.
At some point I will put together a quick writeup on how I did this.
I've never used it with files of 2GB in size, but the YUI File Uploader worked pretty well on a previous project. You may also be interested in this jQuery Plugin.
That said, I still think the Java Applet is the way to go. I think you'll end up with less portability and UI issues than you expect and Drag/Drop works great. For the record, Box.net uses a Java Applet for their multi-file quick uploads.
OK this is my take on this
I did some testing with swfupload, and I have my previous experience with Java, and my conclusion is that whatever technology is used there is no perfect solution to do uploads on the browser : you'll always end up with bugs when uploading huge files, going through proxies, with ssl, etc...
BUT :
a flash uploader (a la swfupload) is really lightweight, doesn't need authorization from the user and has a native interface which is REALLY cool, me thinks
a java uploader needs authorization but you can do whatever you want with the files selected by the user (aka compression if needed), and drag and drop works well. Be prepared for some epic bugs debuggin' though.
I didn't get a change to play with Silverlight as long as I'd like maybe that's the real answer, though the technology is still quite young so ... I'll edit this post if I get a chance to fiddle a bit with Silverlight
Thanks for all the answers !!
There are a number of free flash components that exist with nice multiple file upload capability. They make use of ActionScripts FileReference class with a PHP (or whatever) receiver on the server side. Some have recently broken with the launch of FP10 but I know for certain that swfupload will work :)
Hope this helps!
What about these two
Jupload
http://jupload.sourceforge.net/
and
jumploader
http://jumploader.com/
Both are java applets but they are also both really easy to use and implement.
what about google gears?
There are HTTP/HTTPS upload controls that allow multi-file upload. Here is one from Telerik, which I have found to be solid and reliable. The latest version looks to have most if not all of your feature requirements.
You can upload multiple files with HTTP forms as well, as Dave already pointed out, but if you're set on using something beyond what HTTP and Javascript offers I would heavily consider Flash. There are even some pre-existing solutions for it such as MultiPowUpload and it offers many of the features you're looking for. It's also easier to obtain progress information using a Flash client than with AJAX calls from Javascript since you have a little more flexibility.
You may check the Apache Commons FileUpload package. It allows you to upload multiple files, monitor the progress of the upload, and more. You can find more information here:
http://commons.apache.org/fileupload/
http://commons.apache.org/fileupload/using.html
Good luck

Categories

Resources