Author: etnu
Date: Tue Dec 16 12:00:26 2008
New Revision: 727124

URL: http://svn.apache.org/viewvc?rev=727124&view=rev
Log:
Applied partial fix for SHINDIG-786. MessageBundleFactory requires an API 
change to propagate all values correctly.


Modified:
    
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/DefaultGadgetSpecFactory.java
    
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/DefaultGadgetSpecFactoryTest.java

Modified: 
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/DefaultGadgetSpecFactory.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/DefaultGadgetSpecFactory.java?rev=727124&r1=727123&r2=727124&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/DefaultGadgetSpecFactory.java
 (original)
+++ 
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/DefaultGadgetSpecFactory.java
 Tue Dec 16 12:00:26 2008
@@ -18,6 +18,7 @@
  */
 package org.apache.shindig.gadgets;
 
+import org.apache.shindig.common.ContainerConfig;
 import org.apache.shindig.common.cache.Cache;
 import org.apache.shindig.common.cache.CacheProvider;
 import org.apache.shindig.common.cache.SoftExpiringCache;
@@ -69,16 +70,22 @@
       // gadget whose spec is hosted non-locally.
       return new GadgetSpec(RAW_GADGET_URI, rawxml);
     }
-    return getGadgetSpec(context.getUrl(), context.getIgnoreCache());
+    return getGadgetSpec(context.getUrl(), context.getContainer(), 
context.getIgnoreCache());
   }
 
   /**
    * Retrieves a gadget specification from the cache or from the Internet.
+   * TODO: This should be removed. Too much context is missing from this 
request.
    */
   public GadgetSpec getGadgetSpec(URI gadgetUri, boolean ignoreCache) throws 
GadgetException {
+    return getGadgetSpec(gadgetUri, ContainerConfig.DEFAULT_CONTAINER, 
ignoreCache);
+  }
+
+  private GadgetSpec getGadgetSpec(URI gadgetUri, String container, boolean 
ignoreCache)
+      throws GadgetException {
     Uri uri = Uri.fromJavaUri(gadgetUri);
     if (ignoreCache) {
-      return fetchObjectAndCache(uri, ignoreCache);
+      return fetchObjectAndCache(uri, container, ignoreCache);
     }
 
     SoftExpiringCache.CachedObject<GadgetSpec> cached = cache.getElement(uri);
@@ -86,7 +93,7 @@
     GadgetSpec spec = null;
     if (cached == null || cached.isExpired) {
       try {
-        spec = fetchObjectAndCache(uri, ignoreCache);
+        spec = fetchObjectAndCache(uri, container, ignoreCache);
       } catch (GadgetException e) {
         // Enforce negative caching.
         if (cached != null) {
@@ -115,8 +122,13 @@
    * Retrieves a gadget specification from the Internet, processes its views 
and
    * adds it to the cache.
    */
-  private GadgetSpec fetchObjectAndCache(Uri url, boolean ignoreCache) throws 
GadgetException {
-    HttpRequest request = new HttpRequest(url).setIgnoreCache(ignoreCache);
+  private GadgetSpec fetchObjectAndCache(Uri url, String container, boolean 
ignoreCache)
+      throws GadgetException {
+    HttpRequest request = new HttpRequest(url)
+        .setIgnoreCache(ignoreCache)
+        .setGadget(url)
+        .setContainer(container);
+
     // Since we don't allow any variance in cache time, we should just force 
the cache time
     // globally. This ensures propagation to shared caches when this is set.
     request.setCacheTtl((int) (refresh / 1000));

Modified: 
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/DefaultGadgetSpecFactoryTest.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/DefaultGadgetSpecFactoryTest.java?rev=727124&r1=727123&r2=727124&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/DefaultGadgetSpecFactoryTest.java
 (original)
+++ 
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/DefaultGadgetSpecFactoryTest.java
 Tue Dec 16 12:00:26 2008
@@ -23,6 +23,7 @@
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
 
+import org.apache.shindig.common.ContainerConfig;
 import org.apache.shindig.common.cache.CacheProvider;
 import org.apache.shindig.common.cache.LruCacheProvider;
 import org.apache.shindig.common.uri.Uri;
@@ -108,9 +109,22 @@
   private final DefaultGadgetSpecFactory specFactory
       = new DefaultGadgetSpecFactory(fetcher, cacheProvider, MAX_AGE);
 
+  private static HttpRequest createIgnoreCacheRequest() {
+    return new HttpRequest(SPEC_URL)
+        .setIgnoreCache(true)
+        .setGadget(SPEC_URL)
+        .setContainer(ContainerConfig.DEFAULT_CONTAINER);
+  }
+
+  private static HttpRequest createCacheableRequest() {
+    return new HttpRequest(SPEC_URL)
+        .setGadget(SPEC_URL)
+        .setContainer(ContainerConfig.DEFAULT_CONTAINER);
+  }
+
   @Test
   public void specFetched() throws Exception {
-    HttpRequest request = new HttpRequest(SPEC_URL).setIgnoreCache(true);
+    HttpRequest request = createIgnoreCacheRequest();
     HttpResponse response = new HttpResponse(LOCAL_SPEC_XML);
     expect(fetcher.fetch(request)).andReturn(response);
     replay(fetcher);
@@ -122,7 +136,8 @@
 
   @Test
   public void specFetchedWithContext() throws Exception {
-    HttpRequest request = new HttpRequest(SPEC_URL).setIgnoreCache(true);
+    HttpRequest request = createIgnoreCacheRequest();
+
     HttpResponse response = new HttpResponse(LOCAL_SPEC_XML);
     expect(fetcher.fetch(request)).andReturn(response);
     replay(fetcher);
@@ -136,7 +151,7 @@
   public void specFetchedFromParam() throws Exception {
     // Set up request as if it's a regular spec request, and ensure that
     // the return value comes from rawxml, not the fetcher.
-    HttpRequest request = new HttpRequest(SPEC_URL).setIgnoreCache(false);
+    HttpRequest request = createIgnoreCacheRequest();
     HttpResponse response = new HttpResponse(LOCAL_SPEC_XML);
     expect(fetcher.fetch(request)).andReturn(response);
     replay(fetcher);
@@ -149,8 +164,9 @@
 
   @Test
   public void staleSpecIsRefetched() throws Exception {
-    HttpRequest request = new HttpRequest(SPEC_URL).setIgnoreCache(true);
-    HttpRequest retriedRequest = new 
HttpRequest(SPEC_URL).setIgnoreCache(false);
+    HttpRequest request = createIgnoreCacheRequest();
+    HttpRequest retriedRequest = createCacheableRequest();
+
     HttpResponse expiredResponse = new HttpResponseBuilder()
         .addHeader("Pragma", "no-cache")
         .setResponse(LOCAL_SPEC_XML.getBytes("UTF-8"))
@@ -168,8 +184,9 @@
 
   @Test
   public void staleSpecReturnedFromCacheOnError() throws Exception {
-    HttpRequest request = new HttpRequest(SPEC_URL).setIgnoreCache(true);
-    HttpRequest retriedRequest = new 
HttpRequest(SPEC_URL).setIgnoreCache(false);
+    HttpRequest request = createIgnoreCacheRequest();
+    HttpRequest retriedRequest = createCacheableRequest();
+
     HttpResponse expiredResponse = new HttpResponseBuilder()
         .setResponse(LOCAL_SPEC_XML.getBytes("UTF-8"))
         .addHeader("Pragma", "no-cache")
@@ -198,7 +215,7 @@
 
   @Test
   public void typeUrlNotFetchedRemote() throws Exception {
-    HttpRequest request = new HttpRequest(SPEC_URL).setIgnoreCache(true);
+    HttpRequest request = createIgnoreCacheRequest();
     HttpResponse response = new HttpResponse(URL_SPEC_XML);
     expect(fetcher.fetch(request)).andReturn(response);
     replay(fetcher);
@@ -211,7 +228,7 @@
 
   @Test(expected = GadgetException.class)
   public void badFetchThrows() throws Exception {
-    HttpRequest request = new HttpRequest(SPEC_URL).setIgnoreCache(true);
+    HttpRequest request = createIgnoreCacheRequest();
     expect(fetcher.fetch(request)).andReturn(HttpResponse.error());
     replay(fetcher);
 
@@ -220,9 +237,9 @@
 
   @Test(expected = GadgetException.class)
   public void badFetchServesCached() throws Exception {
-    HttpRequest firstRequest = new HttpRequest(SPEC_URL).setIgnoreCache(false);
+    HttpRequest firstRequest = createCacheableRequest();
     expect(fetcher.fetch(firstRequest)).andReturn(new 
HttpResponse(LOCAL_SPEC_XML)).once();
-    HttpRequest secondRequest = new HttpRequest(SPEC_URL).setIgnoreCache(true);
+    HttpRequest secondRequest = createIgnoreCacheRequest();
     
expect(fetcher.fetch(secondRequest)).andReturn(HttpResponse.error()).once();
     replay(fetcher);
 
@@ -235,7 +252,7 @@
 
   @Test(expected = GadgetException.class)
   public void malformedGadgetSpecThrows() throws Exception {
-    HttpRequest request = new HttpRequest(SPEC_URL).setIgnoreCache(true);
+    HttpRequest request = createIgnoreCacheRequest();
     expect(fetcher.fetch(request)).andReturn(new HttpResponse("malformed 
junk"));
     replay(fetcher);
 
@@ -244,7 +261,7 @@
 
   @Test(expected = GadgetException.class)
   public void malformedGadgetSpecIsCachedAndThrows() throws Exception {
-    HttpRequest request = new HttpRequest(SPEC_URL).setIgnoreCache(false);
+    HttpRequest request = createCacheableRequest();
     expect(fetcher.fetch(request)).andReturn(new HttpResponse("malformed 
junk")).once();
     replay(fetcher);
 
@@ -259,7 +276,7 @@
 
   @Test(expected = GadgetException.class)
   public void throwingFetcherRethrows() throws Exception {
-    HttpRequest request = new HttpRequest(SPEC_URL).setIgnoreCache(true);
+    HttpRequest request = createIgnoreCacheRequest();
     expect(fetcher.fetch(request)).andThrow(
         new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT));
     replay(fetcher);


Reply via email to