Author: cmailleux
Date: Wed Oct 17 11:37:31 2007
New Revision: 418

URL: https://svndev.jahia.net/websvn/listing.php?sc=3D1&rev=3D418&repname=
=3Desi_server
Log:
Correct issue ESI-370,ESI-372,ESI-373

Add also redirect management for cache/bypass url like the one in webapps (=
tested with pluto portlet-suite and jforum (still an issue with the wizard =
when changing languages there is a ; in the url which seems to redirect to =
home remove the ; and it will work)

Modified:
    trunk/WEB-INF/config/data.xml
    trunk/src/net/sf/j2ep/model/ResponseHandler.java
    trunk/src/net/sf/j2ep/responsehandlers/ResponseHandlerBase.java
    trunk/src/org/jahia/esi/FetcherTask.java
    trunk/src/org/jahia/esi/settings/ConfigParser.java
    trunk/src/org/jahia/esi/settings/SettingsBean.java

Modified: trunk/WEB-INF/config/data.xml
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/WEB-INF/config/=
data.xml&rev=3D418&repname=3Desi_server
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/WEB-INF/config/data.xml (original)
+++ trunk/WEB-INF/config/data.xml Wed Oct 17 11:37:31 2007
@@ -297,7 +297,7 @@
         <activateInvalidationServer>true</activateInvalidationServer>
         <!-- Sets the timeout in milliseconds a connection to the remote s=
erver or an invalidation message connection is held. A value of
         zero means the timeout is not used. -->
-        <connectionTimeout>120000</connectionTimeout>
+        <connectionTimeout>60000</connectionTimeout>
         <!-- maximum time to wait for a remote server reply (in seconds) b=
efore an error is returned
         to the client -->
         <maxFetchThreadWait>120</maxFetchThreadWait>
@@ -329,7 +329,7 @@
              verifying a passthrough-rule (see later) -->
         <requestThrottlePOSTs>false</requestThrottlePOSTs>
         <!-- the number of allowed by the throttling of simultaneous reque=
sts for the same resource. -->
-        <requestThrottleMaxParallelRequests>1</requestThrottleMaxParallelR=
equests>
+        <requestThrottleMaxParallelRequests>2</requestThrottleMaxParallelR=
equests>
         <!-- the minimum amount of time a request should be stalled -at ea=
ch wait loop iteration- before we can check again if
              it is now in cache or if a slot has freed up in the throttler=
. (in Milliseconds) -->
         <requestThrottleMinWait>100</requestThrottleMinWait>
@@ -340,6 +340,9 @@
         <enableTemplateCaching>true</enableTemplateCaching>
         <!-- name of esi cookie (should be identical to esiCookieCookieNam=
e in jahia.properties) -->
         <userCookieName>jesid</userCookieName>
+        <!--This force esi to make a request against the server for a new =
session colud be used on ntlm authentification if the default
+            behavior is not working-->
+        <forceAuthentification>false</forceAuthentification>
         <!-- defines the maximum number of simultaenous threads to fetch c=
acheable content (such as pages and images) from all
         the remote servers. -->
         <maxCacheableContentFetchers>30</maxCacheableContentFetchers>
@@ -350,6 +353,11 @@
         <maxHttpConnectionsPerHost>150</maxHttpConnectionsPerHost>
         <!-- defines the total maximum number of simultaneous HTTP connect=
ions across all hosts -->
         <maxTotalHttpConnections>200</maxTotalHttpConnections>
+        <!-- This will specify the timeout for request going through passt=
hrough rules in seconds-->
+        <passthroughTimeout>3600</passthroughTimeout>
+        <!-- Here we will introduce some specific Jahia parameters for pas=
sthrough rules-->
+        <passthroughEngineKeyword>engineName</passthroughEngineKeyword>
+        <passthroughEngineTimeout>14400</passthroughEngineTimeout>
         <!-- During heavy loads or remote server timeouts, the ESI server =
will return a default page with a Meta Refresh Tag
              in it so that the browser will try again the request at a lat=
er time.
              This frees up resources on the ESI server to finish the other=
 queued tasks.

Modified: trunk/src/net/sf/j2ep/model/ResponseHandler.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/src/net/sf/j2ep=
/model/ResponseHandler.java&rev=3D418&repname=3Desi_server
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/src/net/sf/j2ep/model/ResponseHandler.java (original)
+++ trunk/src/net/sf/j2ep/model/ResponseHandler.java Wed Oct 17 11:37:31 20=
07
@@ -23,6 +23,8 @@
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpServletRequest;
 =

+import org.jahia.esi.exceptions.RedirectException;
+
 /**
  * A handler for all responses. Will set the headers, process any
  * output stream and do any method specific actions.
@@ -39,7 +41,7 @@
      * @param response The response to process
      * @throws IOException An exception is thrown when there is a problem =
with writing the output
      */
-    public void process(HttpServletResponse response, HttpServletRequest c=
lientRequest, ServerContainer server) throws IOException, MethodNotAllowedE=
xception;
+    public void process(HttpServletResponse response, HttpServletRequest c=
lientRequest, ServerContainer server) throws IOException, MethodNotAllowedE=
xception, RedirectException;
 =

     /**
      * Returns the HTTP status code we received from the server

Modified: trunk/src/net/sf/j2ep/responsehandlers/ResponseHandlerBase.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/src/net/sf/j2ep=
/responsehandlers/ResponseHandlerBase.java&rev=3D418&repname=3Desi_server
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/src/net/sf/j2ep/responsehandlers/ResponseHandlerBase.java (origin=
al)
+++ trunk/src/net/sf/j2ep/responsehandlers/ResponseHandlerBase.java Wed Oct=
 17 11:37:31 2007
@@ -40,6 +40,7 @@
 import org.apache.commons.httpclient.methods.GetMethod;
 import org.apache.commons.httpclient.*;
 import org.apache.commons.httpclient.params.HostParams;
+import org.apache.commons.httpclient.params.HttpMethodParams;
 import org.apache.commons.logging.LogFactory;
 import org.apache.commons.logging.Log;
 import org.jahia.esi.*;
@@ -503,13 +504,36 @@
             //Utils.printResponseHeaders(methodToServer,  " for POST");
 =

             //TODO: port this code to FetcherTask
-            if (methodToServer.getStatusCode() =3D=3D 405) {
+            int statusCode =3D methodToServer.getStatusCode();
+            if (statusCode =3D=3D HttpStatus.SC_METHOD_NOT_ALLOWED) {
                 Header allow =3D methodToServer.getResponseHeader("allow");
                 String value =3D allow.getValue();
                 throw new MethodNotAllowedException(
                         "Status code 405 from server", AllowedMethodHandler
                         .processAllowHeader(value));
             }
+            if (statusCode =3D=3D HttpStatus.SC_MOVED_TEMPORARILY || statu=
sCode =3D=3D HttpStatus.SC_MOVED_PERMANENTLY ||
+                statusCode =3D=3D HttpStatus.SC_SEE_OTHER || statusCode =
=3D=3D HttpStatus.SC_TEMPORARY_REDIRECT) {
+                if(log.isDebugEnabled()) {
+                    log.debug("We follow a redirection ");
+                }
+                String redirectLocation;
+                Header locationHeader =3D methodToServer.getResponseHeader=
("location");
+                if (locationHeader !=3D null) {
+                    redirectLocation =3D locationHeader.getValue();
+                    if(redirectLocation!=3DmethodToServer.getURI().toStrin=
g() && redirectLocation.indexOf("/cache/bypass")>0) {
+                    if(log.isDebugEnabled()) {
+                        log.debug("redirected to : "+redirectLocation);
+                    }
+                    int i =3D redirectLocation.indexOf("?");
+                    URL newURL =3D new URL(redirectLocation);
+                    methodToServer.setPath(newURL.getPath());
+                    methodToServer.setQueryString(i > 0 ? redirectLocation=
.substring(i + 1, redirectLocation.length()) : "");
+                    beginServerRequest();
+                    return;
+                    }
+                }
+            }
         }
         else
             log.info(" NOT  executing  httpClient.executeMethod(newMethod)=
");
@@ -522,7 +546,7 @@
      * @see net.sf.j2ep.model.ResponseHandler#process(javax.servlet.http.H=
ttpServletResponse, javax.servlet.http.HttpServletRequest, ServerContainer)
      */
 =

-    public void process(HttpServletResponse clientResponse, HttpServletReq=
uest _clientRequest, ServerContainer server) throws IOException, MethodNotA=
llowedException {
+    public void process(HttpServletResponse clientResponse, HttpServletReq=
uest _clientRequest, ServerContainer server) throws IOException, MethodNotA=
llowedException, RedirectException {
 =

         initOrigRequestUrl(_clientRequest, server);
 =

@@ -574,7 +598,9 @@
                     }
                 }
                 //TODO: Note that ESI Surrogate-Capabilities header are no=
t appended here
-
+                methodToServer.getParams().setSoTimeout(settingsBean.getPa=
ssthroughTimeout()*1000);
+                if(methodToServer.getURI().getPath().contains(settingsBean=
.getPassthroughEngineKeyword()))
+                    methodToServer.getParams().setSoTimeout(settingsBean.g=
etPassthroughEngineTimeout()*1000);
                 beginServerRequest();
                 copyHeadersFromServerResponseToClientResponse(clientRespon=
se, clientRequest, methodToServer);
                 clientResponse.setStatus(getStatusCode());
@@ -599,7 +625,7 @@
                 boolean userAclDeclaredForCurrentRequest=3Dfalse;
 =

                 if (settingsBean.isEnableTemplateCaching()) {
-                    String[] userInfo =3D retrieveUserInfo(clientRequest);
+                    String[] userInfo =3D retrieveUserInfo(clientRequest,c=
lientResponse);
                     userName =3D userInfo[0];
                     userAclGroupKey =3D userInfo[1];
                     requestInfoKey =3D CacheKeyGenerator.getInstance().gen=
erateRequestInfoKey(server, clientRequest,
@@ -998,7 +1024,7 @@
         if (urlObj=3D=3Dnull //not in cache?
                 || urlObj.getExpirationDateInSecs() <  System.currentTimeM=
illis()/1000 //expired? //TODO: when implemented add "+ urlObj.getMaxRemova=
lDelayInSecs()"
                 || !urlObj.isValid()  //invalid ?
-                ) {
+                || (settings.forceAuthentification()&&clientRequest.getSes=
sion(true).isNew())) {
             fetchedNewData =3D true;
             //TODO:Need to support all other methods such as POST !
             fetchingSkeleton =3D true;
@@ -1680,7 +1706,7 @@
         return false;
     }
 =

-    private String[] retrieveUserInfo(HttpServletRequest clientRequest) th=
rows URIException {
+    private String[] retrieveUserInfo(HttpServletRequest clientRequest, Ht=
tpServletResponse clientResponse) throws URIException, RedirectException {
         String userName =3D  null;
         String userAclGroupKey =3D null;
 =


Modified: trunk/src/org/jahia/esi/FetcherTask.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/src/org/jahia/e=
si/FetcherTask.java&rev=3D418&repname=3Desi_server
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/src/org/jahia/esi/FetcherTask.java (original)
+++ trunk/src/org/jahia/esi/FetcherTask.java Wed Oct 17 11:37:31 2007
@@ -1450,8 +1450,17 @@
                  if (log.isDebugEnabled()) log.debug(errorMsg);
                 throw new DetailedServerException(errorMsg, bytes, statusC=
ode);
             case HttpStatus.SC_UNAUTHORIZED:
-                if(methodToServer.getResponseHeader("WWW-Authenticate").ge=
tValue().startsWith("NTLM"))
+                if(log.isDebugEnabled()) {
+                    Header[] headers =3D methodToServer.getResponseHeaders=
();
+                    for (int i =3D 0; i < headers.length; i++) {
+                        Header header =3D headers[i];
+                        log.debug("Header : " + header.getName() + " value=
 : " + header.getValue());
+                    }
+                }
+                if(methodToServer.getResponseHeader("WWW-Authenticate").ge=
tValue().startsWith("NTLM")) {
+                    log.debug("Send redirect exception");
                     throw new RedirectException( "Not authorized.",urlKey,=
 statusCode);
+                }
                 else throw new TransferFailedException("Not authorized.",u=
rlKey,statusCode);
             case HttpStatus.SC_MOVED_TEMPORARILY :
             case HttpStatus.SC_MOVED_PERMANENTLY :

Modified: trunk/src/org/jahia/esi/settings/ConfigParser.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/src/org/jahia/e=
si/settings/ConfigParser.java&rev=3D418&repname=3Desi_server
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/src/org/jahia/esi/settings/ConfigParser.java (original)
+++ trunk/src/org/jahia/esi/settings/ConfigParser.java Wed Oct 17 11:37:31 =
2007
@@ -251,6 +251,10 @@
         digester.addBeanPropertySetter( "config/generalsettings/webDavUrlM=
arker", "webDavUrlMarker" );
         digester.addBeanPropertySetter( "config/generalsettings/contextPat=
h", "contextPath" );
         digester.addBeanPropertySetter( "config/generalsettings/cacheProvi=
der", "cacheProvider" );
+        digester.addBeanPropertySetter( "config/generalsettings/forceAuthe=
ntification", "forceAuthentification" );
+        digester.addBeanPropertySetter( "config/generalsettings/passthroug=
hTimeout", "passthroughTimeout" );
+        digester.addBeanPropertySetter( "config/generalsettings/passthroug=
hEngineKeyword", "passthroughEngineKeyword" );
+        digester.addBeanPropertySetter( "config/generalsettings/passthroug=
hEngineTimeout", "passthroughEngineTimeout" );
 =

         SettingsBean settingsBean =3D (SettingsBean) digester.parse(data);
         SettingsBean.setInstance(settingsBean);

Modified: trunk/src/org/jahia/esi/settings/SettingsBean.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/src/org/jahia/e=
si/settings/SettingsBean.java&rev=3D418&repname=3Desi_server
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/src/org/jahia/esi/settings/SettingsBean.java (original)
+++ trunk/src/org/jahia/esi/settings/SettingsBean.java Wed Oct 17 11:37:31 =
2007
@@ -189,9 +189,17 @@
      * list of remote Esi Server to relay invalidations to
      */
     private LinkedList remoteEsiServers;
-
-    private String cacheProvider =3D "EHCACHE";
-
+    /**
+     * Cache provider use in esi : REFERENCECACHE or EHCACHE
+     */
+    private String cacheProvider =3D "REFERENCECACHE";
+    /**
+     * Allow to force a check on skeleton for new session on esi (useful f=
or ntlm only)
+     */
+    private Boolean forceAuthentification =3D Boolean.FALSE;
+    private int passthroughTimeout =3D 3600;
+    private int passthroughEngineTimeout =3D 14400;
+    private String passthroughEngineKeyword =3D "engineName";
     public SettingsBean() {
         //set default value in case it is not set in data.xml
         //The default value is set to the value used in the -Xmx parameter
@@ -928,4 +936,35 @@
                 "}";
     }
 =

+    public boolean forceAuthentification() {
+        return forceAuthentification.booleanValue();
+    }
+
+    public void setForceAuthentification(Boolean forceAuthentification) {
+        this.forceAuthentification =3D forceAuthentification;
+    }
+
+    public String getPassthroughEngineKeyword() {
+        return passthroughEngineKeyword;
+    }
+
+    public void setPassthroughEngineKeyword(String passthroughEngineKeywor=
d) {
+        this.passthroughEngineKeyword =3D passthroughEngineKeyword;
+    }
+
+    public int getPassthroughEngineTimeout() {
+        return passthroughEngineTimeout;
+    }
+
+    public void setPassthroughEngineTimeout(int passthroughEngineTimeout) {
+        this.passthroughEngineTimeout =3D passthroughEngineTimeout;
+    }
+
+    public int getPassthroughTimeout() {
+        return passthroughTimeout;
+    }
+
+    public void setPassthroughTimeout(int passthroughTimeout) {
+        this.passthroughTimeout =3D passthroughTimeout;
+    }
 }

_______________________________________________
cvs_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/cvs_list

Reply via email to