mcardle 2005/12/14 17:38:22 CET
Modified files:
src/org/jahia/esi GetThread.java
Log:
* support for first step in rewrite of backend cache code
* fix for http://www.jahia.net/jira/browse/JAHIA-582 to correctly close tag
* pages with "cache/off" param in url will now generate a cache entry
* refactorings
Revision Changes Path
1.15 +30 -22 esi_server/src/org/jahia/esi/GetThread.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/esi_server/src/org/jahia/esi/GetThread.java.diff?r1=1.14&r2=1.15&f=h
Index: GetThread.java
===================================================================
RCS file: /home/cvs/repository/esi_server/src/org/jahia/esi/GetThread.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- GetThread.java 6 Dec 2005 14:43:00 -0000 1.14
+++ GetThread.java 14 Dec 2005 16:38:22 -0000 1.15
@@ -61,7 +61,7 @@
import org.jahia.esi.cache.UrlCacheObject;
import org.jahia.esi.tags.EsiIncludeTag;
import org.jahia.esi.tags.EsiRemoveTag;
-import org.jahia.esi.settings.GeneralSettings;
+import org.jahia.esi.settings.SettingsBean;
import org.jahia.esi.exceptions.*;
import org.jahia.esi.exceptions.RedirectException;
import net.sf.j2ep.ProxyFilter;
@@ -98,7 +98,7 @@
private HttpServletResponse clientResponse;
private HttpServletRequest clientRequest;
private String urlKey;
- private UrlCacheObject urlObj;
+ private UrlCacheObject urlObj; //TODO: never really used. Get rid of it
private String urlToServer;
private String clientRequestUrl;
@@ -127,8 +127,8 @@
String urlKey,
UrlCacheObject urlObj,
String clientRequestUrl) {
- expirationInSecs =
GeneralSettings.getInstance().getDefaultExpiration();
- maxRemovalDelayInSecs =
GeneralSettings.getInstance().getDefaultMaxRemovalDelay();
+ expirationInSecs = SettingsBean.getInstance().getDefaultExpiration();
+ maxRemovalDelayInSecs =
SettingsBean.getInstance().getDefaultMaxRemovalDelay();
this.clientRequestUrl = clientRequestUrl;
this.httpClient = httpClient;
@@ -312,6 +312,7 @@
String urlKey =
CacheAdministrator.getInstance().generateEntryKey("GET" , clientRequestUrl
);//urlToServer);
+ //TODO: extract expiration from Expires/Cache-Control-maxage
headers (if present) instead of setting to default expiration as below
fragmentCache.add ( urlKey , this.methodToServer , bytes ,
this.clientRequestUrl ,
null, null, null ,null); //will set default expirations
for the moment
@@ -374,9 +375,10 @@
}
tagGetMethod.setFollowRedirects(false);
- UrlCacheObject tagUrlObj = (UrlCacheObject)
fragmentCache.getHashCache().get(tagCacheKey);
+ UrlCacheObject tagUrlObj = (UrlCacheObject)
fragmentCache.getUrlCacheObject(tagCacheKey);
- GetThread thread = new
GetThread(ProxyFilter.getHttpClient(),
+ GetThread thread = new GetThread(
+ ProxyFilter.getHttpClient(),
tagGetMethod,
responseHandlerBase,
clientResponse,
@@ -389,9 +391,7 @@
thread.setName("from:GetThread-"+id+",["+
tagCacheKey.substring(tagCacheKey.length()-15)+"]id:"+thread.getId());
thread.start();
}
-
-
- }
+ }
}
//wait for each thread to finish before continuing
Enumeration threadEnum = threads.elements();
@@ -451,8 +451,8 @@
if (log.isDebugEnabled()) log.debug(id + " replacing node :
"+esiTag.toHtml()+" with cached content of length
["+cachedByteContent.length+"]");
//TODO: should really implement a NodeList.replace method
+ esiTag.getEndTag().setTagName("/WAS:ESIINCLUDE_"+pos);
esiTag.setTagName ("WAS:ESIINCLUDE_"+pos);
- esiTag.getEndTag().setTagName("WAS:END_ESIINCLUDE_"+pos);
removeAllAttributes(esiTag, "WAS:ESIINCLUDE_"+pos);
TextNode fragContentTextNode = new TextNode (new
String(cachedByteContent));
NodeList children = new NodeList (fragContentTextNode);
@@ -472,12 +472,13 @@
//get rid of esi:comment tag contents
Enumeration commentTagsEnum = removeTagsToReplace.elements();
while (commentTagsEnum.hasMoreElements()) {
+
EsiRemoveTag esiRemoveTag = (EsiRemoveTag)
commentTagsEnum.nextElement();
if (log.isDebugEnabled()) log.debug(id + "clearing
esi:REMOVE node : "+esiRemoveTag.toHtml()+" ");
+ esiRemoveTag.getEndTag().setTagName("/WAS:ESIREMOVE");
esiRemoveTag.setTagName ("WAS:ESIREMOVE");
- esiRemoveTag.getEndTag().setTagName("WAS:END_ESIREMOVE");
TextNode blankContentTextNode = new TextNode (new
String(""));
NodeList children = new NodeList (blankContentTextNode);
esiRemoveTag.setChildren (children);
@@ -498,15 +499,22 @@
// due to presence of /cache/ param in url
if (Utils.isCacheUrlParamPresent(urlToServer)) {
//rewrite (or add) the associated cache entry which doesn't
- // contain the "/cache/offonce" parameter in its URL, and
still keep current expirations
- if (Utils.isCacheOffOnce(urlToServer)) {
- fragmentCache.add ( Utils.removeCacheOffOnce(urlKey),
methodToServer , finalContents.toString().getBytes()
- , Utils.removeCacheOffOnce(urlToServer),
- Utils.removeCacheOffOnce(refObjs),
Utils.removeCacheOffOnce(refObjsUrls),
+ // contain the "/cache/offonce" or "/cache/offonce" parameter
+ // in its URL, and still keep current expirations
+ boolean isCacheOffOnce = Utils.isCacheOffOnce(urlToServer);
+ boolean isCacheOff = Utils.isCacheOff(urlToServer);
+ if (isCacheOffOnce || isCacheOff ) {
+ fragmentCache.add (
+ Utils.removeCacheParam(urlKey, isCacheOffOnce),
+ methodToServer ,
+ finalContents.toString().getBytes(),
+ Utils.removeCacheParam(urlToServer,
isCacheOffOnce),
+ Utils.removeCacheParam(refObjs, isCacheOffOnce),
+ Utils.removeCacheParam(refObjsUrls,
isCacheOffOnce),
referencedObjsStartIndex ,referencedObjsEndIndex,
this.expirationInSecs,
this.expirationDateInSecs, this.maxRemovalDelayInSecs );
}
-
+ //for "/cache/bypass" we just don't store it (by setting
expiration to 0)
if (log.isDebugEnabled()) log.debug("Setting expiration to 0
for "+urlKey);
this.expirationInSecs = 4;
this.expirationDateInSecs = 4;
@@ -538,7 +546,7 @@
try {
// We will retry up to NumberOfAttempts times.
- while ( statusCode == SC_NULL && attempt <
GeneralSettings.getInstance().getNumberOfAttempts() )
+ while ( statusCode == SC_NULL && attempt <
SettingsBean.getInstance().getNumberOfAttempts() )
{
try
{
@@ -587,20 +595,20 @@
//catch ( HttpRecoverableException e )
{
attempt++;
- log.error(id + " -Error retrieving ["+urlToServer+"] on
attempt ["+attempt+" of
"+GeneralSettings.getInstance().getNumberOfAttempts()+"] due to
HttpException:"+e+", but trying again.");
+ log.error(id + " -Error retrieving ["+urlToServer+"] on
attempt ["+attempt+" of "+SettingsBean.getInstance().getNumberOfAttempts()+"]
due to HttpException:"+e+", but trying again.");
}
catch ( IOException e )
{
attempt++;
- String errorMsg = id + " -Error retrieving
["+urlToServer+"] on attempt ["+attempt+" of
"+GeneralSettings.getInstance().getNumberOfAttempts()+"] \n due to
IOException:"+e;
+ String errorMsg = id + " -Error retrieving
["+urlToServer+"] on attempt ["+attempt+" of
"+SettingsBean.getInstance().getNumberOfAttempts()+"] \n due to IOException:"+e;
log.error(errorMsg);
throw new TransferFailedException(errorMsg, e ,
HttpStatus.SC_INTERNAL_SERVER_ERROR);
}
}
- if (attempt >=
GeneralSettings.getInstance().getNumberOfAttempts()) {
- String errorMsg = id + " - Error retrieving [" + urlToServer
+ "] after [" + attempt + " of
"+GeneralSettings.getInstance().getNumberOfAttempts()+"] attempts.";
+ if (attempt >= SettingsBean.getInstance().getNumberOfAttempts())
{
+ String errorMsg = id + " - Error retrieving [" + urlToServer
+ "] after [" + attempt + " of
"+SettingsBean.getInstance().getNumberOfAttempts()+"] attempts.";
log.error(errorMsg);
throw new TransferFailedException(errorMsg
, HttpStatus.SC_INTERNAL_SERVER_ERROR);