Note that there are some explanatory texts on larger screens.

plurals
  1. POUploading a file from java using HTTP connection
    text
    copied!<p>I am trying to upload a file(log file) from an applet, running in a browser. I am reading the file in a String. Following function, given a String data and a string URL (e.g: <a href="http://192.168.0.166:8380/app/customer/UploadData.do" rel="nofollow">http://192.168.0.166:8380/app/customer/UploadData.do</a>), uploads the data to a URL. Since, after a timeout, session with the server is lost. Therefore I am appending username and password with the URL, to avoid any session expire issue (since this uploading is supposed to be automatic, without any manual input etc.). The URL(not public) looks something like :</p> <blockquote> <p><a href="http://192.168.0.166:8380/app/customer/UploadData.do?username=uname&amp;password=pword" rel="nofollow">http://192.168.0.166:8380/app/customer/UploadData.do?username=uname&amp;password=pword</a></p> </blockquote> <pre><code>public static void sendData(String aData, String aURL) throws Exception { try { byte[] myData = aData.getBytes(); /* Uploading the data */ URL myURL = new URL(aURL); HttpURLConnection myConnection = (HttpURLConnection) myURL.openConnection(); myConnection.setDoOutput(true); myConnection.setUseCaches(false); myConnection.setDefaultUseCaches(false); myConnection.setRequestProperty("Content-type", "application/octet-stream"); OutputStream myOutputStream = myConnection.getOutputStream(); myOutputStream.write(myData); myOutputStream.flush(); myOutputStream.close(); int status = ((HttpURLConnection) myConnection).getResponseCode(); } catch (Exception exception) { throw exception } } </code></pre> <p>This function works absolutely fine as long as the session with the server is live. It doesn't work when for example the session is expired or user logs out( applet runs 24/7). Please note the the above URL works fine when accessed via web browser. Its this java code (applet) which isn't able connect again when the session expires. It would be of great help if anyone could point out what am I doing wrong here. Any help will be highly appreciated.</p> <p><strong>Environment:</strong> Jboss as application server and JBoss Secured Realm for login.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload