• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Problem with URLConnection class

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic