portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwat...@apache.org
Subject svn commit: r987332 - /portals/jetspeed-2/portal/trunk/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/impl/JetspeedCapabilities.java
Date Thu, 19 Aug 2010 22:15:15 GMT
Author: rwatler
Date: Thu Aug 19 22:15:14 2010
New Revision: 987332

URL: http://svn.apache.org/viewvc?rev=987332&view=rev
Log:
Properly handle DB related exceptions in Capabilities component to prevent bad CapabilitiesMap
instance from being cached for UserAgent

Modified:
    portals/jetspeed-2/portal/trunk/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/impl/JetspeedCapabilities.java

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/impl/JetspeedCapabilities.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/impl/JetspeedCapabilities.java?rev=987332&r1=987331&r2=987332&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/impl/JetspeedCapabilities.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/impl/JetspeedCapabilities.java
Thu Aug 19 22:15:14 2010
@@ -222,64 +222,82 @@ public class JetspeedCapabilities extend
                 }
             } else
             {
-                // Found Client entry start populating the capability map.
-                map = new CapabilityMapImpl();
+                bClientFound = true;
 
-                // Add client to CapabilityMap
-                map.setClient(entry);
-
-                // Add capabilities
-                Iterator capabilities = entry.getCapabilities().iterator();
-                while (capabilities.hasNext())
+                try
                 {
-                    map.addCapability((Capability) capabilities.next());
-                }
+                    // Found Client entry start populating the capability map.
+                    map = new CapabilityMapImpl();
 
-                Collection mediatypes =
-                    getMediaTypesForMimeTypes(entry.getMimetypes().iterator());
+                    // Add client to CapabilityMap
+                    map.setClient(entry);
 
-                // Add Mimetypes to map
-                Iterator mimetypes = entry.getMimetypes().iterator();
-                while (mimetypes.hasNext())
-                {
-                    map.addMimetype((MimeType) mimetypes.next());
-                }
+                    // Add capabilities
+                    Iterator capabilities = entry.getCapabilities().iterator();
+                    while (capabilities.hasNext())
+                    {
+                        map.addCapability((Capability) capabilities.next());
+                    }
 
-                Iterator media = mediatypes.iterator();
-                while (media.hasNext())
-                {
-                    map.addMediaType((MediaType) media.next());
-                }
+                    // Add Mimetypes to map
+                    Iterator mimetypes = entry.getMimetypes().iterator();
+                    while (mimetypes.hasNext())
+                    {
+                        map.addMimetype((MimeType) mimetypes.next());
+                    }
 
-                //Set preferred Mimetype
-                MediaType mtEntry =
-                    getMediaTypeForMimeType(map.getPreferredType().getName());
+                    // Add Mediatypes for Mimetype to map
+                    Collection mediatypes =
+                        getMediaTypesForMimeTypes(entry.getMimetypes().iterator());
+                    Iterator media = mediatypes.iterator();
+                    while (media.hasNext())
+                    {
+                        map.addMediaType((MediaType) media.next());
+                    }
 
-                map.setPreferredMediaType(mtEntry);
+                    // Validate preferred Mimetype
+                    MimeType mimeTypeEntry = map.getPreferredType();
+                    if (mimeTypeEntry == null)
+                    {
+                        throw new RuntimeException("Unable to get preferred Mimetype for
client: "+entry.getName());                        
+                    }
 
-                // Add map to cache
-                synchronized (capabilityMapCache)
-                {
-                    if (capabilityMapCache.put(userAgent, map) != null)
+                    // Set preferred Mediatype for Mimetype
+                    MediaType mediaTypeEntry = getMediaTypeForMimeType(mimeTypeEntry.getName());
+                    if (mediaTypeEntry == null)
                     {
-                        capabilityMapCacheKeyList.remove(userAgent);
+                        throw new RuntimeException("Unable to find preferred Mediatype for
Mimetype/client: "+mimeTypeEntry.getName()+"/"+entry.getName());
                     }
-                    capabilityMapCacheKeyList.addFirst(userAgent);
-                    if (defaultAgent != null)
+                    map.setPreferredMediaType(mediaTypeEntry);
+
+                    // Add map to cache
+                    synchronized (capabilityMapCache)
                     {
-                        if (capabilityMapCache.put(defaultAgent, map) != null)
+                        if (capabilityMapCache.put(userAgent, map) != null)
                         {
-                            capabilityMapCacheKeyList.remove(defaultAgent);
+                            capabilityMapCacheKeyList.remove(userAgent);
+                        }
+                        capabilityMapCacheKeyList.addFirst(userAgent);
+                        if (defaultAgent != null)
+                        {
+                            if (capabilityMapCache.put(defaultAgent, map) != null)
+                            {
+                                capabilityMapCacheKeyList.remove(defaultAgent);
+                            }
+                            capabilityMapCacheKeyList.addFirst(defaultAgent);
+                        }
+                        while (capabilityMapCache.size() > MAX_CACHE_SIZE)
+                        {
+                            String reapAgent = (String)capabilityMapCacheKeyList.removeLast();
+                            capabilityMapCache.remove(reapAgent);
                         }
-                        capabilityMapCacheKeyList.addFirst(defaultAgent);
-                    }
-                    while (capabilityMapCache.size() > MAX_CACHE_SIZE)
-                    {
-                        String reapAgent = (String)capabilityMapCacheKeyList.removeLast();
-                        capabilityMapCache.remove(reapAgent);
                     }
                 }
-                return map;
+                catch (Exception e)
+                {
+                    log.error("Unable to build capability map for "+userAgent+": "+e, e);
+                    map = null;
+                }
             }
 
         }



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message