The Artima Developer Community
Sponsored Link

Java Answers Forum
Cache problem with URLConnection class

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
radha maha lakshmi

Posts: 1
Nickname: radhaml
Registered: Dec, 2004

Cache problem with URLConnection class Posted: Dec 21, 2004 6:43 PM
Reply to this message Reply
Advertisement
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.



<BR>
here is my code

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

System.out.println(">>>>>>>>>>>filename:"+f ilename);
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.s etDefaultUseCaches(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("dataDat e:"+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
{

iConnectio nCount++;
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

Topic: Leading Zeros are dropped? Previous Topic   Next Topic Topic: JLIST

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use