Author: ruwan
Date: Tue Dec 18 00:02:39 2007
New Revision: 11334

Log:

fixing issues for the WSAS module

Modified:
   
trunk/commons/caching/modules/core/src/main/java/org/wso2/caching/CacheConfiguration.java
   
trunk/commons/caching/modules/core/src/main/java/org/wso2/caching/CachedObject.java
   
trunk/commons/caching/modules/core/src/main/java/org/wso2/caching/policy/CachingPolicyProcessor.java
   trunk/commons/caching/modules/mar/pom.xml
   
trunk/commons/caching/modules/mar/src/main/java/org/wso2/caching/handlers/CachingInHandler.java
   
trunk/commons/caching/modules/mar/src/main/java/org/wso2/caching/handlers/CachingOutHandler.java

Modified: 
trunk/commons/caching/modules/core/src/main/java/org/wso2/caching/CacheConfiguration.java
==============================================================================
--- 
trunk/commons/caching/modules/core/src/main/java/org/wso2/caching/CacheConfiguration.java
   (original)
+++ 
trunk/commons/caching/modules/core/src/main/java/org/wso2/caching/CacheConfiguration.java
   Tue Dec 18 00:02:39 2007
@@ -34,7 +34,7 @@
      * for this time period enless there is a explicit value set by the 
response
      * from the server. (For example through http cache-control headers)
      */
-    private long timeout = Long.MAX_VALUE;
+    private long timeout = 0L;
 
     public DigestGenerator getDigestGenerator() {
         return digestGenerator;

Modified: 
trunk/commons/caching/modules/core/src/main/java/org/wso2/caching/CachedObject.java
==============================================================================
--- 
trunk/commons/caching/modules/core/src/main/java/org/wso2/caching/CachedObject.java
 (original)
+++ 
trunk/commons/caching/modules/core/src/main/java/org/wso2/caching/CachedObject.java
 Tue Dec 18 00:02:39 2007
@@ -35,13 +35,13 @@
      * because the SOAPEnvelope or OMElement is not serializable response 
envelope
      * has kept as its serilaized format as a byte[]
      */
-    private byte[] responseEnvelope = null;
+    private byte[] responseEnvelope;
 
     /**
      * This holds the hash value of the request payload which is calculated 
form
      * the specified DigestGenerator, and is used to index the cached response
      */
-    private String requestHash = null;
+    private String requestHash;
 
     /**
      * This holds the hash value of the response which is calculated from the
@@ -51,19 +51,19 @@
      * the server can respond with the not-modified http header (or the 
equivalent
      * SOAP header) to the client without sending the response.
      */
-    private String responseHash = null;
+    private String responseHash;
 
     /**
      * This holds the time at which this particular cached response expires, in
      * the standard java system time format (i.e. System.currentTimeMillis())
      */
-    private long expireTimeMillis = 0L;
+    private long expireTimeMillis;
 
     /**
      * This holds the timeout period of the cached response which will be used
      * at the next expire time in order to generate the expireTimeMillis
      */
-    private long timeout = 0L;
+    private long timeout;
 
     /**
      * This method checks whether this cached respose is expired or not
@@ -71,7 +71,7 @@
      * @return boolean true if expired and false if not
      */
     public boolean isExpired() {
-        return expireTimeMillis < System.currentTimeMillis();
+        return timeout > 0 && expireTimeMillis < System.currentTimeMillis();
     }
 
     /**

Modified: 
trunk/commons/caching/modules/core/src/main/java/org/wso2/caching/policy/CachingPolicyProcessor.java
==============================================================================
--- 
trunk/commons/caching/modules/core/src/main/java/org/wso2/caching/policy/CachingPolicyProcessor.java
        (original)
+++ 
trunk/commons/caching/modules/core/src/main/java/org/wso2/caching/policy/CachingPolicyProcessor.java
        Tue Dec 18 00:02:39 2007
@@ -60,101 +60,135 @@
 
             List topLevelAssertionList = policy.getPolicyComponents();
             for (Iterator topLevelAssertionsIterator
-                    = topLevelAssertionList.iterator(); 
topLevelAssertionsIterator.hasNext();) {
+                = topLevelAssertionList.iterator(); 
topLevelAssertionsIterator.hasNext();) {
 
                 Object topLevelAssertionObject = 
topLevelAssertionsIterator.next();
                 // Validating the policy 
                 if (topLevelAssertionObject instanceof XmlPrimtiveAssertion) {
 
                     XmlPrimtiveAssertion topLevelXmlPrimtiveAssertion
-                            = (XmlPrimtiveAssertion) topLevelAssertionObject;
+                        = (XmlPrimtiveAssertion) topLevelAssertionObject;
                     QName qName = topLevelXmlPrimtiveAssertion.getName();
                     // validating the Caching assertion
                     if 
(qName.equals(CachingConstants.CACHING_ASSERTION_QNAME)) {
 
-                        Policy cachingPolicy
-                                = 
PolicyEngine.getPolicy(topLevelXmlPrimtiveAssertion.getValue());
-                        List assertionList = 
cachingPolicy.getPolicyComponents();
+                        Policy cachingPolicyComponent
+                            = 
PolicyEngine.getPolicy(topLevelXmlPrimtiveAssertion.getValue());
+                        List assertionList = 
cachingPolicyComponent.getPolicyComponents();
                         for (Iterator configDataAssertionIterator = 
assertionList.iterator();
                              configDataAssertionIterator.hasNext();) {
 
                             Object aConfigDataAssertionObject = 
configDataAssertionIterator.next();
                             // Validating the caching policy
-                            if (aConfigDataAssertionObject instanceof All) {
+                            if (aConfigDataAssertionObject instanceof Policy) {
 
-                                long expireTime = -1;
-                                DigestGenerator digestGenerator
-                                    = CachingConstants.DEFAULT_XML_IDENTIFIER;
+                                long expireTime;
+                                DigestGenerator digestGenerator;
+                                int maxMessageSize;
+                                int maxCacheSize;
 
-                                All all = (All) aConfigDataAssertionObject;
-                                List childAssertionsList = 
all.getPolicyComponents();
+                                Policy cachingPolicy = (Policy) 
aConfigDataAssertionObject;
+                                List childAssertionsList = 
cachingPolicy.getPolicyComponents();
                                 for (Iterator childAssertionSIterator = 
childAssertionsList
-                                        .iterator(); 
childAssertionSIterator.hasNext();) {
+                                    .iterator(); 
childAssertionSIterator.hasNext();) {
 
-                                    Object childAssertionObject = 
childAssertionSIterator.next();
-                                    if (childAssertionObject instanceof 
XmlPrimtiveAssertion) {
-
-                                        XmlPrimtiveAssertion 
cachingPrimtiveAssertion
-                                                = (XmlPrimtiveAssertion) 
childAssertionObject;
-                                        //todo : break the processing
-                                        // Is Identifier specified?
-                                        if 
(cachingPrimtiveAssertion.getName().equals(
-                                                
CachingConstants.CACHING_XML_IDENTIFIER_QNAME)) {
-
-                                            String value
-                                                    = 
cachingPrimtiveAssertion.getValue().getText();
-                                            try {
-
-                                                // Loading the class using 
Reflection
-                                                digestGenerator = 
(DigestGenerator)
-                                                        
Class.forName(value).newInstance();
-                                                
cacheConfig.setDigestGenerator(digestGenerator);
-
-                                            } catch (ClassNotFoundException e) 
{
-
-                                                handleException("Unable to 
find the " +
-                                                        "DigestGenerator 
implementation \"" +
-                                                        value + "\"", e);
-
-                                            } catch (IllegalAccessException e) 
{
-
-                                                handleException("Unable to 
load the " +
-                                                        "DigestGenerator 
implementation \"" +
-                                                        value + "\"", e);
-
-                                            } catch (InstantiationException e) 
{
-
-                                                handleException("Unable to 
instantiate the " +
-                                                        "DigestGenerator 
implementation \"" +
-                                                        value + "\"", e);
+                                    Object configData = 
childAssertionSIterator.next();
+                                    if (configData instanceof All) {
 
+                                        All all = (All) configData;
+                                        List configDataList = 
all.getPolicyComponents();
+                                        for (Iterator configIterator = 
configDataList
+                                            .iterator(); 
childAssertionSIterator.hasNext();) {
+
+                                            Object configDtaObject = 
configIterator.next();
+                                            if (configDtaObject instanceof 
XmlPrimtiveAssertion) {
+
+                                                XmlPrimtiveAssertion 
cachingPrimtiveAssertion
+                                                    = (XmlPrimtiveAssertion) 
configDtaObject;
+                                                //todo : break the processing
+                                                // Is Identifier specified?
+                                                if 
(cachingPrimtiveAssertion.getName().equals(
+                                                    
CachingConstants.CACHING_XML_IDENTIFIER_QNAME)) {
+
+                                                    String value
+                                                        = 
cachingPrimtiveAssertion.getValue().getText();
+                                                    try {
+
+                                                        // Loading the class 
using Reflection
+                                                        digestGenerator = 
(DigestGenerator)
+                                                            
Class.forName(value).newInstance();
+                                                        
cacheConfig.setDigestGenerator(digestGenerator);
+
+                                                    } catch 
(ClassNotFoundException e) {
+
+                                                        
handleException("Unable to find the " +
+                                                            "DigestGenerator 
implementation \"" +
+                                                            value + "\"", e);
+
+                                                    } catch 
(IllegalAccessException e) {
+
+                                                        
handleException("Unable to load the " +
+                                                            "DigestGenerator 
implementation \"" +
+                                                            value + "\"", e);
+
+                                                    } catch 
(InstantiationException e) {
+
+                                                        
handleException("Unable to instantiate the " +
+                                                            "DigestGenerator 
implementation \"" +
+                                                            value + "\"", e);
+
+                                                    }
+                                                }
+
+                                                // Is expiration time 
specified?
+                                                if 
(cachingPrimtiveAssertion.getName().equals(
+                                                    
CachingConstants.CACHE_EXPIRATION_TIME_QNAME) &&
+                                                    
cachingPrimtiveAssertion.getValue() != null) {
+
+                                                    expireTime = 
Long.parseLong(
+                                                        
cachingPrimtiveAssertion.getValue().getText());
+                                                    
cacheConfig.setTimeout(expireTime);
+                                                }
+
+                                                // Is max message size 
specified?
+                                                if 
(cachingPrimtiveAssertion.getName().equals(
+                                                    
CachingConstants.MAX_MESSAGE_SIZE_QNAME) &&
+                                                    
cachingPrimtiveAssertion.getValue() != null) {
+
+                                                    maxMessageSize = 
Integer.parseInt(
+                                                        
cachingPrimtiveAssertion.getValue().getText());
+                                                    
cacheConfig.setMaxMessageSize(maxMessageSize);
+                                                }
+
+                                                // Is max cache size specified?
+                                                if 
(cachingPrimtiveAssertion.getName().equals(
+                                                    
CachingConstants.MAX_CACHE_SIZE_QNAME) &&
+                                                    
cachingPrimtiveAssertion.getValue() != null) {
+
+                                                    maxCacheSize = 
Integer.parseInt(
+                                                        
cachingPrimtiveAssertion.getValue().getText());
+                                                    
cacheConfig.setMaxCacheSize(maxCacheSize);
+                                                }
+                                                
+                                            } else {
+                                                // invalid caching policy
+                                                handleException("Unexpected 
caching policy " +
+                                                    "assertion for the caching 
module");
                                             }
                                         }
-
-                                        // Is expiration time specified?
-                                        if 
(cachingPrimtiveAssertion.getName().equals(
-                                                
CachingConstants.CACHE_EXPIRATION_TIME_QNAME) &&
-                                                
cachingPrimtiveAssertion.getValue() != null) {
-                                            
-                                            expireTime = Long.parseLong(
-                                                    
cachingPrimtiveAssertion.getValue().getText());
-                                            cacheConfig.setTimeout(expireTime);
-                                        }
-
-                                        // todo: max message size and the max 
cache size
                                     } else {
-                                        // invalid caching policy
-                                        handleException("Unexpected caching 
policy, " +
-                                                "Wrong policy assertion for 
the caching module");
+                                        // caching policy All not found
+                                        handleException("Unexpected caching " +
+                                            "policy, \"wsp:All\" expected");
                                     }
                                 }
                             } else {
-                                // caching policy ExactlyOne not found
-                                handleException("Unexpected caching " +
-                                        "policy, \"wsp:ExactlyOne\" expected");
+                                // handle policy
                             }
                         }
                     }
+                } else {
+                    // handle top level
                 }
             }
         }

Modified: trunk/commons/caching/modules/mar/pom.xml
==============================================================================
--- trunk/commons/caching/modules/mar/pom.xml   (original)
+++ trunk/commons/caching/modules/mar/pom.xml   Tue Dec 18 00:02:39 2007
@@ -28,10 +28,21 @@
                         <phase>package</phase>
                         <configuration>
                             <tasks>
-                                <copy 
file="target/${pom.artifactId}-${wso2caching.version}.jar"
-                                      
tofile="target/wso2caching-${wso2caching.version}.mar"/>
+                                <mkdir dir="target/temp"/>
+                                <copy toDir="target/temp">
+                                    <fileset dir="target/classes">
+                                        <include name="**/*.class"/>
+                                        <include name="**/*.xml"/>
+                                    </fileset>
+                                </copy>
+                                <mkdir dir="target/temp/lib"/>
+                                <copy 
file="../core/target/wso2caching-core-${wso2caching.version}.jar"
+                                      
tofile="target/temp/lib/wso2caching-core-${wso2caching.version}.jar"/>
+                                <jar 
destfile="target/wso2caching-${wso2caching.version}.mar">
+                                    <fileset dir="target/temp"/>
+                                </jar>
                                 <!--<copy 
file="target/${pom.artifactId}-${wso2caching.version}.jar"-->
-                                <!--tofile="target/wso2caching.mar"/>-->
+                                
<!--tofile="target/wso2caching-${wso2caching.version}.mar"/>-->
                             </tasks>
                         </configuration>
                         <goals>

Modified: 
trunk/commons/caching/modules/mar/src/main/java/org/wso2/caching/handlers/CachingInHandler.java
==============================================================================
--- 
trunk/commons/caching/modules/mar/src/main/java/org/wso2/caching/handlers/CachingInHandler.java
     (original)
+++ 
trunk/commons/caching/modules/mar/src/main/java/org/wso2/caching/handlers/CachingInHandler.java
     Tue Dec 18 00:02:39 2007
@@ -43,18 +43,18 @@
             log.debug("Starting the execution of the CachingInHandler");
         }
 
-        try {
-            if 
(TransportProcessorFactory.getInTransportProcessor(msgContext).isCachingDisabled())
 {
-                if (log.isDebugEnabled()) {
-                    log.debug("Caching is forcelly disabled by the transport : 
SKIP the cache");
-                }
-                return InvocationResponse.CONTINUE;
-            }
-        } catch (CachingException e) {
-            if (log.isDebugEnabled()) {
-                log.debug("Unable to check the transport headers to infer 
cache-control", e);
-            }
-        }
+//        try {
+//            if 
(TransportProcessorFactory.getInTransportProcessor(msgContext).isCachingDisabled())
 {
+//                if (log.isDebugEnabled()) {
+//                    log.debug("Caching is forcelly disabled by the transport 
: SKIP the cache");
+//                }
+//                return InvocationResponse.CONTINUE;
+//            }
+//        } catch (CachingException e) {
+//            if (log.isDebugEnabled()) {
+//                log.debug("Unable to check the transport headers to infer 
cache-control", e);
+//            }
+//        }
         
         CacheConfiguration chCfg = null;
         Parameter ccfgParam
@@ -125,6 +125,7 @@
                         } else {
                             // cache exists, but has expired...
                             cachedObj.expire();
+                            cachedObj.setTimeout(chCfg.getTimeout());
                             if (log.isDebugEnabled()) {
                                 log.debug("Existing cached " +
                                     "response has expired. Reset cache 
element");
@@ -157,6 +158,7 @@
                         CachedObject cachedObj = new CachedObject();
                         cachedObj.setRequestHash(requestHash);
                         cachedObj.setTimeout(chCfg.getTimeout());
+                        System.out.println(chCfg.getTimeout());
                         cacheManager.addResponseWithKey(requestHash, 
cachedObj, cfgCtx);
                         opCtx.setProperty(CachingConstants.CACHED_OBJECT, 
null);
                         return InvocationResponse.CONTINUE;

Modified: 
trunk/commons/caching/modules/mar/src/main/java/org/wso2/caching/handlers/CachingOutHandler.java
==============================================================================
--- 
trunk/commons/caching/modules/mar/src/main/java/org/wso2/caching/handlers/CachingOutHandler.java
    (original)
+++ 
trunk/commons/caching/modules/mar/src/main/java/org/wso2/caching/handlers/CachingOutHandler.java
    Tue Dec 18 00:02:39 2007
@@ -45,20 +45,20 @@
             log.debug("Starting the execution of the CachingOutHandler");
         }
 
-        try {
-            if (TransportProcessorFactory.getOutTransportProcessor(
-                msgContext).isCachingDisabled()) {
-                
-                if (log.isDebugEnabled()) {
-                    log.debug("Caching is forcelly disabled by the transport : 
SKIP the cache");
-                }
-                return InvocationResponse.CONTINUE;
-            }
-        } catch (CachingException e) {
-            if (log.isDebugEnabled()) {
-                log.debug("Unable to check the transport headers to infer 
cache-control", e);
-            }
-        }
+//        try {
+//            if (TransportProcessorFactory.getOutTransportProcessor(
+//                msgContext).isCachingDisabled()) {
+//
+//                if (log.isDebugEnabled()) {
+//                    log.debug("Caching is forcelly disabled by the transport 
: SKIP the cache");
+//                }
+//                return InvocationResponse.CONTINUE;
+//            }
+//        } catch (CachingException e) {
+//            if (log.isDebugEnabled()) {
+//                log.debug("Unable to check the transport headers to infer 
cache-control", e);
+//            }
+//        }
 
         CacheConfiguration cachCfg = null;
         Parameter chCfgParam = msgContext.getAxisMessage()
@@ -104,6 +104,10 @@
                                 
cachedObject.setResponseEnvelope(outStream.toByteArray());
                                 cachedObject.setResponseHash(
                                     
cachCfg.getDigestGenerator().getDigest(msgContext));
+                                if (cachedObject.getTimeout() > 0) {
+                                    
cachedObject.setExpireTimeMillis(System.currentTimeMillis()
+                                        + cachedObject.getTimeout());
+                                }
                             } catch (XMLStreamException e) {
                                 handleException("Unable to store the cached 
response : " +
                                     "Error in serializing the response", e);

_______________________________________________
Commons-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/commons-dev

Reply via email to