Downloading files via a webView - java

I am currently implementing a webview that uses the default behavior of opening the browser. When the page loads in the browser and I click the download link that is on the page that was loaded, the download starts, and quickly fails. I guess its an unsupported file type. How would I go about setting the WebView so that I may handle when a user downloads a file, and process the file myself? The reason I am going through a webview is that using httpclient, I was unable to spoof the headers after trying unsuccessfully for 30 or so hours. So what I would like to be able to do is handle the saving, and unzipping of the file myself. Can anyone write me some code to get started?
Thanks a million.

Related

opening of file(pdf,png,jpeg) asscoiation with browser

I am having a function which on calling window.open(URL),that URLis returning me a file. On clicking, once it's downloaded , i want to associate it with browser, means that file should only open in browser, but not with any default application preset by OS. Any leads on this is highly appreciated.

Can Java webstart dialog caption be overridden?

I have an Angular web application as well as a client JavaFX program that I host on an IIS 7 web server. When user clicks on a link on a page in the web app, I construct the proper JNLP file and send it down to the browser. The client browser then opens the JNLP file and the app loads and then opens properly. No issues.
But the webstart dialog that appears after clicking on the link shows a progress bar as it downloads the java application from the server, and it's got a caption that says 'JavaFX Application Preview'. I'd much rather have it say the name of the software the user is downloading. Is this possible? If so, where should I start looking?
I hunted online and couldn't find a single mention of this, which I find really surprising. Surely this has come up before?
Create a custom Preloader and in the start method of the preloader, set the title of the preloader stage.

Slow file upload: Can I remove file attachment from multipart POST data on the fly and just submit form text fields?

I have a regular JSP/Servlet/Java web application that is used for uploading pictures from a mobile device. I am using Apache Commons library for the upload. Application is hosted on WebSphere Application Server 7.0.
Everything is working fine and the user can upload several images totaling 8MB or more if he has a really good/strong signal/connection or on a good WiFi.
The problem arises when the user is at a location with poor 3G/4G signal/connection. He gets errors like "Illegal state exception" or some time-out error, and in some cases the mobile browser just stays on the submit page with the progress bar no longer moving.
Any suggestions on how to "gracefully" handle this? Like is there a way to intervene after a set amount of time and give the the user an option to submit the form without the file attachment (i.e. just submit the form text fields)? Any other suggestions are welcome too.
UPDATE: The setTimeout solution below worked for me. The other missing piece was that I have to issue a "browser stop" command to stop the original submission that's in progress before I can issue a re-submit. Otherwise, my re-submit command will just be ignored by the browser.
The usecase here is simple - if the upload didn't finish in N minutes, remove/clear the field using javascript and resend the form.
You don't need to control the upload in the basic implementation, just safely asume that if you set a timeout to resend, it won't happen if the first attempt was successful and the page reloaded.
jQuery pseudocode:
setTimeout(function(){
$imageFieldNode.remove();
$form.trigger('submit');
},30000);//after 30 seconds
The more advanced way is to use a ready solution for controlled upload. They work like that:
upload starts
js prompts the server in intervals with a GET query to get the size of content that was already received.
everytime it gets the info - it reports progress.
You can do a lot with these libs.
You can think about the approach used in popular webmail clients (when attaching files to a message):
The files are uploaded independently (i.e. before) of the form submit, using javascript. Each of the files are stored in a temporary directory, and after the upload succeeds the user can proceed with the action.
The upload status is displayed to the user, and if it fails the main action (form fill/submit) does not get interrupted.

Content Syncing on Android

I am writing an application for android and i wish to be able to sync content from a web server, IE: The layouts XML to the device and cache it so that if the device is not connected to the internet it uses an old version of the XML so as soon as the device is on the internet is able to update and gather the latest XML.
Couldn't find much on the internet, so if someone could point me in the right direction or give me some ideas this would be quite helpful.
Cheers,
Alex
This is how it works with a normal xml file:
Create an on your device HTTP Client
Prepare a GET request to your server
Send the request and retrieve the HTTP Response
Read the content using an InputStreamReader
Write the Stream to a file on the external storage name it e.g. newes_version.xml
catch all exception, and just use the file newest_version.xml file.
But it can't work for Layout files
Why? Every time you load your app on an device, everything (except /raw) in the /res folder is being compiled. Therefore your 'stylsheets' doesn't exist anymore the way they did in your IDE. It's not as simple as in html/css where you can just exchange on file. (Well, you can, put not an runtime)
Solution
If you really want to change your layout on Run time, you would have to load the xml (see above), parse it, and apply the information given by file using the R.id reference of the View elements.

identify the page load successful on the server side java

I am preparing a program in java and its purpose is to make the HttpWebRequest for a url which can open in any browser (i am planning to use watij for opening the page in different browser).Now my program should take the screen shot of the presently opened url once the page has loaded successfully.I need to run a piece of code after the browser has loaded successfully in the browser.I dont want to use the javascript document.ready function for identifying if the page is loaded successfully or not.I should be able to know the page load complete status in the server side (s0 that i can execute that piece of code for taking the screenshot).How can i do it in java.Or is there any other way to do achieve that if its not possible in java.May be create some plugins.
An early reply is highly valued,
Regards,Sagar.
you can do it using applet, [just taking snapshot i meant that you want.]

Categories