File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Problem with URLConnection class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Problem with URLConnection class" Watch "Problem with URLConnection class" New topic
Author

Problem with URLConnection class

Radha MahaLakshmi
Ranch Hand

Joined: Mar 28, 2003
Posts: 45
Hi

I am using URLConnection class to read some data from a specific website where the data gewts updated everyday.We are accessing this through our proxy server.Some times when we access the site through out program we are gettgin old data where as if we access the same url form a browser we are getting latest data.

is there anyway we can get rid of this cacheing problem.

i am tryimg to open this url for 50 times just to ensure its gettgin refreshed.but no use.

Could you please suggest me some solution.

here is my code

---------------------------------------
private boolean fileDownload(String fromurl,String local,String filename) throws Exception {

System.out.println(">>>>>>>>>>>filename:"+filename);
try {
if (proxyHost !=null && !proxyHost.trim().equals("") && proxyPort !=null && !proxyPort.trim().equals("")) {
Properties props = System.getProperties();
props.put("http.proxyHost", proxyHost);
props.put("http.proxyPort", proxyPort);
}

String sCurrBussDay = getCurrBussinessDay();

sCurrBussDay = sCurrBussDay.substring(0,4)+sCurrBussDay.substring(5,7)+sCurrBussDay.substring(8,10);

while(iConnectionCount<=30)
{
URL url = new URL(fromurl);
URLConnection urlConn = url.openConnection();

urlConn.setDefaultAllowUserInteraction(false);
urlConn.setDefaultUseCaches(false);
urlConn.setUseCaches(false);
urlConn.setDoInput(true);


InputStream stream = urlConn.getInputStream();
BufferedReader reader = new BufferedReader (new InputStreamReader(stream));
String line = reader.readLine();
dataDate = line.substring(0,8);

cat.info("sCurrBussDay:"+sCurrBussDay);
cat.info("dataDate:"+dataDate);
if(sCurrBussDay.equals(dataDate))
{
BufferedWriter writer = new BufferedWriter(new FileWriter(new File(local+"/"+filename)));
while (line != null)
{
writer.write(line);
writer.newLine();
line = reader.readLine();
}
writer.flush();
writer.close();
reader.close();
cat.info("fileDownload: for dataDate="+dataDate+" Today: "+processDate.substring(0,10));
iConnectionCount++;
break;
}
else
{

iConnectionCount++;
continue;
}


}


cat.info("fileDownload from: "+fromurl+" save to: "+local+"/"+filename);
cat.info("Total Attempts to get latestData :"+iConnectionCount);
cat.info("dataDate:"+dataDate);
cat.info("sCurrBussDay:"+sCurrBussDay);

if(!sCurrBussDay.equals(dataDate))
return false;
else
return true;


} catch (MalformedURLException ue) {
throw new Exception ("fileDownload: MalformedURLException: "+ue.getMessage());
} catch (IOException ioe) {
throw new Exception ("fileDownload: IOException: "+ioe.getMessage());
}
}
---------------------------------------------

Thanks and regards
Radha
[ December 21, 2004: Message edited by: Radha MahaLakshmi ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with URLConnection class