You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by lr...@apache.org on 2008/05/13 20:51:11 UTC

svn commit: r655969 - in /incubator/shindig/trunk/java/gadgets/src: main/java/org/apache/shindig/gadgets/ main/java/org/apache/shindig/gadgets/oauth/ test/java/org/apache/shindig/gadgets/

Author: lryan
Date: Tue May 13 11:51:11 2008
New Revision: 655969

URL: http://svn.apache.org/viewvc?rev=655969&view=rev
Log:
Small refactor to move the creation of GadgetSpec and MessageBundles behind factory interfaces. This allows for caching of already parsed & transoformed products

Added:
    incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/BasicGadgetSpecFactory.java
    incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/BasicMessageBundleFactory.java
    incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetSpecFactory.java
    incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/MessageBundleFactory.java
Modified:
    incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/DefaultGuiceModule.java
    incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetServer.java
    incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth/BasicGadgetOAuthTokenStore.java
    incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth/OAuthFetcherFactory.java
    incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/GadgetTestFixture.java

Added: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/BasicGadgetSpecFactory.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/BasicGadgetSpecFactory.java?rev=655969&view=auto
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/BasicGadgetSpecFactory.java (added)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/BasicGadgetSpecFactory.java Tue May 13 11:51:11 2008
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shindig.gadgets;
+
+import org.apache.shindig.gadgets.http.HttpFetcher;
+import org.apache.shindig.gadgets.http.HttpRequest;
+import org.apache.shindig.gadgets.http.HttpResponse;
+import org.apache.shindig.gadgets.spec.GadgetSpec;
+
+import com.google.inject.Inject;
+
+import java.net.URI;
+
+/**
+ * Basic implementation of a gadget spec factory
+ */
+public class BasicGadgetSpecFactory implements GadgetSpecFactory {
+
+  private HttpFetcher specFetcher;
+
+  public GadgetSpec getGadgetSpec(GadgetContext context)
+      throws GadgetException {
+    return getGadgetSpec(context.getUrl(), context.getIgnoreCache());
+  }
+
+  public GadgetSpec getGadgetSpec(URI gadgetUri, boolean ignoreCache)
+      throws GadgetException {
+    HttpRequest request = HttpRequest.getRequest(
+        gadgetUri, ignoreCache);
+    HttpResponse response = specFetcher.fetch(request);
+    if (response.getHttpStatusCode() != HttpResponse.SC_OK) {
+      throw new GadgetException(
+          GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT,
+          "Unable to retrieve gadget xml. HTTP error " +
+              response.getHttpStatusCode());
+    }
+    GadgetSpec spec
+        = new GadgetSpec(gadgetUri, response.getResponseAsString());
+    return spec;
+  }
+
+  @Inject
+  public BasicGadgetSpecFactory(
+      @GadgetSpecFetcher HttpFetcher specFetcher) {
+    this.specFetcher = specFetcher;
+  }
+}

Added: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/BasicMessageBundleFactory.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/BasicMessageBundleFactory.java?rev=655969&view=auto
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/BasicMessageBundleFactory.java (added)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/BasicMessageBundleFactory.java Tue May 13 11:51:11 2008
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shindig.gadgets;
+
+import org.apache.shindig.gadgets.http.HttpFetcher;
+import org.apache.shindig.gadgets.http.HttpRequest;
+import org.apache.shindig.gadgets.http.HttpResponse;
+import org.apache.shindig.gadgets.spec.LocaleSpec;
+import org.apache.shindig.gadgets.spec.MessageBundle;
+
+import com.google.inject.Inject;
+
+import java.net.URI;
+
+/**
+ * Basic implementation of a message bundle factory
+ */
+public class BasicMessageBundleFactory implements MessageBundleFactory {
+
+  private HttpFetcher bundleFetcher;
+
+  public MessageBundle getBundle(LocaleSpec localeSpec, GadgetContext context)
+      throws GadgetException {
+    return getBundle(localeSpec.getMessages(), context.getIgnoreCache());
+  }
+
+  public MessageBundle getBundle(URI bundleUrl, boolean ignoreCache)
+      throws GadgetException {
+    HttpRequest request
+        = HttpRequest.getRequest(bundleUrl, ignoreCache);
+    HttpResponse response = bundleFetcher.fetch(request);
+    if (response.getHttpStatusCode() != HttpResponse.SC_OK) {
+      throw new GadgetException(
+          GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT,
+          "Unable to retrieve message bundle xml. HTTP error " +
+          response.getHttpStatusCode());
+    }
+    MessageBundle bundle
+        = new MessageBundle(bundleUrl, response.getResponseAsString());
+    return bundle;
+  }
+
+  @Inject
+  public BasicMessageBundleFactory(
+      @MessageBundleFetcher HttpFetcher bundleFetcher) {
+    this.bundleFetcher = bundleFetcher;
+  }
+}

Modified: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/DefaultGuiceModule.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/DefaultGuiceModule.java?rev=655969&r1=655968&r2=655969&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/DefaultGuiceModule.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/DefaultGuiceModule.java Tue May 13 11:51:11 2008
@@ -21,9 +21,9 @@
 import org.apache.shindig.common.util.ResourceLoader;
 import org.apache.shindig.gadgets.http.BasicHttpCache;
 import org.apache.shindig.gadgets.http.BasicHttpFetcher;
+import org.apache.shindig.gadgets.http.ContentFetcherFactory;
 import org.apache.shindig.gadgets.http.HttpCache;
 import org.apache.shindig.gadgets.http.HttpFetcher;
-import org.apache.shindig.gadgets.http.ContentFetcherFactory;
 import org.apache.shindig.gadgets.http.RemoteContentFetcherFactory;
 import org.apache.shindig.gadgets.oauth.OAuthFetcherFactory;
 
@@ -57,19 +57,20 @@
 
     bind(RemoteContentFetcherFactory.class);
     bind(SigningFetcherFactory.class);
-    // Needed becuase OAuth fetcher factory fetches its config
-    bind(HttpFetcher.class)
-        .annotatedWith(OAuthFetcherFactory.OAuthConfigFetcher.class)
-        .to(BasicHttpFetcher.class);
     bind(OAuthFetcherFactory.class);
     bind(ContentFetcherFactory.class);
 
     bind(HttpFetcher.class)
         .annotatedWith(GadgetSpecFetcher.class)
         .toProvider(ContentFetcherFactory.class);
+    bind(GadgetSpecFactory.class)
+        .to(BasicGadgetSpecFactory.class);
+
     bind(HttpFetcher.class)
         .annotatedWith(MessageBundleFetcher.class)
         .toProvider(ContentFetcherFactory.class);
+    bind(MessageBundleFactory.class)
+        .to(BasicMessageBundleFactory.class);
 
     bind(GadgetBlacklist.class).to(BasicGadgetBlacklist.class);
     bind(Executor.class).toInstance(Executors.newCachedThreadPool());

Modified: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetServer.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetServer.java?rev=655969&r1=655968&r2=655969&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetServer.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetServer.java Tue May 13 11:51:11 2008
@@ -17,10 +17,9 @@
  */
 package org.apache.shindig.gadgets;
 
-import org.apache.shindig.gadgets.http.HttpFetcher;
 import org.apache.shindig.gadgets.http.ContentFetcherFactory;
-import org.apache.shindig.gadgets.http.HttpResponse;
 import org.apache.shindig.gadgets.http.HttpRequest;
+import org.apache.shindig.gadgets.http.HttpResponse;
 import org.apache.shindig.gadgets.spec.Auth;
 import org.apache.shindig.gadgets.spec.Feature;
 import org.apache.shindig.gadgets.spec.GadgetSpec;
@@ -30,7 +29,6 @@
 
 import com.google.inject.Inject;
 
-import java.net.URI;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedList;
@@ -53,22 +51,23 @@
   private final GadgetBlacklist blacklist;
 
   private ContentFetcherFactory preloadFetcherFactory;
-  private HttpFetcher gadgetSpecFetcher;
-  private HttpFetcher messageBundleFetcher;
+  private GadgetSpecFactory specFactory;
+  private MessageBundleFactory bundleFactory;
+
 
   @Inject
   public GadgetServer(Executor executor,
       GadgetFeatureRegistry registry,
       GadgetBlacklist blacklist,
       ContentFetcherFactory preloadFetcherFactory,
-      @GadgetSpecFetcher HttpFetcher gadgetSpecFetcher,
-      @MessageBundleFetcher HttpFetcher messageBundleFetcher) {
+      GadgetSpecFactory specFactory,
+      MessageBundleFactory bundleFactory) {
     this.executor = executor;
     this.registry = registry;
     this.blacklist = blacklist;
     this.preloadFetcherFactory = preloadFetcherFactory;
-    this.gadgetSpecFetcher = gadgetSpecFetcher;
-    this.messageBundleFetcher = messageBundleFetcher;
+    this.specFactory = specFactory;
+    this.bundleFactory = bundleFactory;
   }
 
   /**
@@ -82,19 +81,7 @@
     if (blacklist.isBlacklisted(context.getUrl())) {
       throw new GadgetException(GadgetException.Code.BLACKLISTED_GADGET);
     }
-
-    HttpRequest request = HttpRequest.getRequest(
-        context.getUrl(), context.getIgnoreCache());
-    HttpResponse response = gadgetSpecFetcher.fetch(request);
-    if (response.getHttpStatusCode() != HttpResponse.SC_OK) {
-      throw new GadgetException(
-          GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT,
-          "Unable to retrieve gadget xml. HTTP error " +
-          response.getHttpStatusCode());
-    }
-    GadgetSpec spec
-        = new GadgetSpec(context.getUrl(), response.getResponseAsString());
-    return createGadgetFromSpec(spec, context);
+    return createGadgetFromSpec(specFactory.getGadgetSpec(context), context);
   }
 
   /**
@@ -106,19 +93,7 @@
    */
   private MessageBundle getBundle(LocaleSpec localeSpec, GadgetContext context)
       throws GadgetException {
-    URI bundleUrl = localeSpec.getMessages();
-    HttpRequest request
-        = HttpRequest.getRequest(bundleUrl, context.getIgnoreCache());
-    HttpResponse response = messageBundleFetcher.fetch(request);
-    if (response.getHttpStatusCode() != HttpResponse.SC_OK) {
-      throw new GadgetException(
-          GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT,
-          "Unable to retrieve message bundle xml. HTTP error " +
-          response.getHttpStatusCode());
-    }
-    MessageBundle bundle
-        = new MessageBundle(bundleUrl, response.getResponseAsString());
-    return bundle;
+    return bundleFactory.getBundle(localeSpec, context);
   }
 
   /**

Added: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetSpecFactory.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetSpecFactory.java?rev=655969&view=auto
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetSpecFactory.java (added)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetSpecFactory.java Tue May 13 11:51:11 2008
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shindig.gadgets;
+
+import org.apache.shindig.gadgets.spec.GadgetSpec;
+
+import java.net.URI;
+
+/** Factory of gadget specs */
+public interface GadgetSpecFactory {
+
+  /** Return a gadget spec for a context */
+  public GadgetSpec getGadgetSpec(GadgetContext context) throws GadgetException;
+
+  /** Return a gadget spec for a URI */
+  public GadgetSpec getGadgetSpec(URI gadgetUri, boolean ignoreCache)
+      throws GadgetException;
+
+}

Added: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/MessageBundleFactory.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/MessageBundleFactory.java?rev=655969&view=auto
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/MessageBundleFactory.java (added)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/MessageBundleFactory.java Tue May 13 11:51:11 2008
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shindig.gadgets;
+
+import org.apache.shindig.gadgets.spec.LocaleSpec;
+import org.apache.shindig.gadgets.spec.MessageBundle;
+
+import java.net.URI;
+
+/**
+ * Factory of message bundles
+ */
+public interface MessageBundleFactory {
+
+  MessageBundle getBundle(LocaleSpec localeSpec, GadgetContext context)
+      throws GadgetException;
+
+  MessageBundle getBundle(URI bundleUri, boolean ignoreCache)
+      throws GadgetException;
+}

Modified: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth/BasicGadgetOAuthTokenStore.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth/BasicGadgetOAuthTokenStore.java?rev=655969&r1=655968&r2=655969&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth/BasicGadgetOAuthTokenStore.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth/BasicGadgetOAuthTokenStore.java Tue May 13 11:51:11 2008
@@ -20,10 +20,7 @@
 
 import org.apache.shindig.common.util.ResourceLoader;
 import org.apache.shindig.gadgets.GadgetException;
-import org.apache.shindig.gadgets.http.HttpFetcher;
-import org.apache.shindig.gadgets.http.HttpResponse;
-import org.apache.shindig.gadgets.http.HttpRequest;
-import org.apache.shindig.gadgets.spec.GadgetSpec;
+import org.apache.shindig.gadgets.GadgetSpecFactory;
 import org.json.JSONException;
 import org.json.JSONObject;
 
@@ -45,7 +42,7 @@
     super(store);
   }
 
-  public void initFromConfigFile(HttpFetcher fetcher)
+  public void initFromConfigFile(GadgetSpecFactory specFactory)
   throws GadgetException {
     // Read our consumer keys and secrets from config/oauth.js
     // This actually involves fetching gadget specs
@@ -57,7 +54,7 @@
       for (Iterator<?> i = oauthConfigs.keys(); i.hasNext();) {
         String url = (String) i.next();
         URI gadgetUri = new URI(url);
-        storeProviderInfos(fetcher, gadgetUri);
+        storeProviderInfos(specFactory, gadgetUri);
 
         JSONObject oauthConfig = oauthConfigs.getJSONObject(url);
         storeConsumerInfos(gadgetUri, oauthConfig);
@@ -71,14 +68,10 @@
     }
   }
 
-  private void storeProviderInfos(HttpFetcher fetcher, URI gadgetUri)
+  private void storeProviderInfos(GadgetSpecFactory specFactory, URI gadgetUri)
       throws GadgetException {
-    HttpRequest request = HttpRequest.getRequest(
-        gadgetUri, false);
-    HttpResponse response = fetcher.fetch(request);
-    GadgetSpec spec
-        = new GadgetSpec(gadgetUri, response.getResponseAsString());
-    storeServiceInfoFromGadgetSpec(gadgetUri, spec);
+    storeServiceInfoFromGadgetSpec(gadgetUri,
+        specFactory.getGadgetSpec(gadgetUri, false));
   }
 
   private void storeConsumerInfos(URI gadgetUri, JSONObject oauthConfig)

Modified: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth/OAuthFetcherFactory.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth/OAuthFetcherFactory.java?rev=655969&r1=655968&r2=655969&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth/OAuthFetcherFactory.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth/OAuthFetcherFactory.java Tue May 13 11:51:11 2008
@@ -23,15 +23,11 @@
 import org.apache.shindig.common.crypto.BlobCrypter;
 import org.apache.shindig.common.crypto.Crypto;
 import org.apache.shindig.gadgets.GadgetException;
+import org.apache.shindig.gadgets.GadgetSpecFactory;
 import org.apache.shindig.gadgets.http.HttpFetcher;
 
-import com.google.inject.BindingAnnotation;
 import com.google.inject.Inject;
 
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -54,14 +50,14 @@
    * BlobCrypter and consumer keys/secrets read from oauth.js
    */
   @Inject
-  public OAuthFetcherFactory(@OAuthConfigFetcher HttpFetcher fetcher) {
+  public OAuthFetcherFactory(GadgetSpecFactory specFactory) {
     try {
       this.oauthCrypter = new BasicBlobCrypter(
           Crypto.getRandomBytes(BasicBlobCrypter.MASTER_KEY_MIN_LEN));
 
       BasicGadgetOAuthTokenStore basicStore =
           new BasicGadgetOAuthTokenStore(new BasicOAuthStore());
-      basicStore.initFromConfigFile(fetcher);
+      basicStore.initFromConfigFile(specFactory);
       tokenStore = basicStore;
     } catch (Throwable t) {
       // Since this happens at startup, we don't want to kill the server just
@@ -102,10 +98,4 @@
     fetcher.init();
     return fetcher;
   }
-
-  @Retention(RetentionPolicy.RUNTIME)
-  @Target({ElementType.FIELD, ElementType.PARAMETER})
-  @BindingAnnotation
-  public @interface OAuthConfigFetcher {
-  }
 }

Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/GadgetTestFixture.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/GadgetTestFixture.java?rev=655969&r1=655968&r2=655969&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/GadgetTestFixture.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/GadgetTestFixture.java Tue May 13 11:51:11 2008
@@ -20,8 +20,8 @@
 package org.apache.shindig.gadgets;
 
 import org.apache.shindig.common.SecurityTokenDecoder;
-import org.apache.shindig.gadgets.http.HttpFetcher;
 import org.apache.shindig.gadgets.http.ContentFetcherFactory;
+import org.apache.shindig.gadgets.http.HttpFetcher;
 
 import java.util.concurrent.Executor;
 
@@ -38,6 +38,10 @@
       = mock(ContentFetcherFactory.class);
   public final HttpFetcher fetcher = mock(HttpFetcher.class);
   public final GadgetBlacklist blacklist = mock(GadgetBlacklist.class);
+  public final GadgetSpecFactory specFactory =
+      new BasicGadgetSpecFactory(fetcher);
+  public final MessageBundleFactory bundleFactory =
+      new BasicMessageBundleFactory(fetcher);
   public GadgetFeatureRegistry registry;
   public ContainerConfig containerConfig;
   public final Executor executor = new Executor() {
@@ -63,6 +67,6 @@
     }
 
     gadgetServer = new GadgetServer(executor, registry, blacklist,
-        fetcherFactory, fetcher, fetcher);
+        fetcherFactory, specFactory, bundleFactory);
   }
 }



Re: svn commit: r655969 - in /incubator/shindig/trunk/java/gadgets/src: main/java/org/apache/shindig/gadgets/ main/java/org/apache/shindig/gadgets/oauth/ test/java/org/apache/shindig/gadgets/

Posted by Kevin Brown <et...@google.com>.
I think we should prefer the term "Default" for implementations rather than
"Basic" -- Basic implies "not good enough for real-world use". I think we
can make them useful for real-world use, though.

Also, GadgetSpecFetcher and MessageBundleFetcher annotations can be
discarded.

This lets me check one of the items off of my todo list. Thanks!

On Tue, May 13, 2008 at 11:51 AM, <lr...@apache.org> wrote:

> Author: lryan
> Date: Tue May 13 11:51:11 2008
> New Revision: 655969
>
> URL: http://svn.apache.org/viewvc?rev=655969&view=rev
> Log:
> Small refactor to move the creation of GadgetSpec and MessageBundles
> behind factory interfaces. This allows for caching of already parsed &
> transoformed products
>
> Added:
>
>  incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/BasicGadgetSpecFactory.java
>
>  incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/BasicMessageBundleFactory.java
>
>  incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetSpecFactory.java
>
>  incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/MessageBundleFactory.java
> Modified:
>
>  incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/DefaultGuiceModule.java
>
>  incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetServer.java
>
>  incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth/BasicGadgetOAuthTokenStore.java
>
>  incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth/OAuthFetcherFactory.java
>
>  incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/GadgetTestFixture.java
>
> Added:
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/BasicGadgetSpecFactory.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/BasicGadgetSpecFactory.java?rev=655969&view=auto
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/BasicGadgetSpecFactory.java
> (added)
> +++
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/BasicGadgetSpecFactory.java
> Tue May 13 11:51:11 2008
> @@ -0,0 +1,63 @@
> +/*
> + * Licensed to the Apache Software Foundation (ASF) under one
> + * or more contributor license agreements.  See the NOTICE file
> + * distributed with this work for additional information
> + * regarding copyright ownership.  The ASF licenses this file
> + * to you under the Apache License, Version 2.0 (the
> + * "License"); you may not use this file except in compliance
> + * with the License.  You may obtain a copy of the License at
> + *
> + *   http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing,
> + * software distributed under the License is distributed on an
> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + * KIND, either express or implied.  See the License for the
> + * specific language governing permissions and limitations
> + * under the License.
> + */
> +package org.apache.shindig.gadgets;
> +
> +import org.apache.shindig.gadgets.http.HttpFetcher;
> +import org.apache.shindig.gadgets.http.HttpRequest;
> +import org.apache.shindig.gadgets.http.HttpResponse;
> +import org.apache.shindig.gadgets.spec.GadgetSpec;
> +
> +import com.google.inject.Inject;
> +
> +import java.net.URI;
> +
> +/**
> + * Basic implementation of a gadget spec factory
> + */
> +public class BasicGadgetSpecFactory implements GadgetSpecFactory {
> +
> +  private HttpFetcher specFetcher;
> +
> +  public GadgetSpec getGadgetSpec(GadgetContext context)
> +      throws GadgetException {
> +    return getGadgetSpec(context.getUrl(), context.getIgnoreCache());
> +  }
> +
> +  public GadgetSpec getGadgetSpec(URI gadgetUri, boolean ignoreCache)
> +      throws GadgetException {
> +    HttpRequest request = HttpRequest.getRequest(
> +        gadgetUri, ignoreCache);
> +    HttpResponse response = specFetcher.fetch(request);
> +    if (response.getHttpStatusCode() != HttpResponse.SC_OK) {
> +      throw new GadgetException(
> +          GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT,
> +          "Unable to retrieve gadget xml. HTTP error " +
> +              response.getHttpStatusCode());
> +    }
> +    GadgetSpec spec
> +        = new GadgetSpec(gadgetUri, response.getResponseAsString());
> +    return spec;
> +  }
> +
> +  @Inject
> +  public BasicGadgetSpecFactory(
> +      @GadgetSpecFetcher HttpFetcher specFetcher) {
> +    this.specFetcher = specFetcher;
> +  }
> +}
>
> Added:
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/BasicMessageBundleFactory.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/BasicMessageBundleFactory.java?rev=655969&view=auto
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/BasicMessageBundleFactory.java
> (added)
> +++
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/BasicMessageBundleFactory.java
> Tue May 13 11:51:11 2008
> @@ -0,0 +1,64 @@
> +/*
> + * Licensed to the Apache Software Foundation (ASF) under one
> + * or more contributor license agreements.  See the NOTICE file
> + * distributed with this work for additional information
> + * regarding copyright ownership.  The ASF licenses this file
> + * to you under the Apache License, Version 2.0 (the
> + * "License"); you may not use this file except in compliance
> + * with the License.  You may obtain a copy of the License at
> + *
> + *     http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing,
> + * software distributed under the License is distributed on an
> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + * KIND, either express or implied.  See the License for the
> + * specific language governing permissions and limitations
> + * under the License.
> + */
> +package org.apache.shindig.gadgets;
> +
> +import org.apache.shindig.gadgets.http.HttpFetcher;
> +import org.apache.shindig.gadgets.http.HttpRequest;
> +import org.apache.shindig.gadgets.http.HttpResponse;
> +import org.apache.shindig.gadgets.spec.LocaleSpec;
> +import org.apache.shindig.gadgets.spec.MessageBundle;
> +
> +import com.google.inject.Inject;
> +
> +import java.net.URI;
> +
> +/**
> + * Basic implementation of a message bundle factory
> + */
> +public class BasicMessageBundleFactory implements MessageBundleFactory {
> +
> +  private HttpFetcher bundleFetcher;
> +
> +  public MessageBundle getBundle(LocaleSpec localeSpec, GadgetContext
> context)
> +      throws GadgetException {
> +    return getBundle(localeSpec.getMessages(), context.getIgnoreCache());
> +  }
> +
> +  public MessageBundle getBundle(URI bundleUrl, boolean ignoreCache)
> +      throws GadgetException {
> +    HttpRequest request
> +        = HttpRequest.getRequest(bundleUrl, ignoreCache);
> +    HttpResponse response = bundleFetcher.fetch(request);
> +    if (response.getHttpStatusCode() != HttpResponse.SC_OK) {
> +      throw new GadgetException(
> +          GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT,
> +          "Unable to retrieve message bundle xml. HTTP error " +
> +          response.getHttpStatusCode());
> +    }
> +    MessageBundle bundle
> +        = new MessageBundle(bundleUrl, response.getResponseAsString());
> +    return bundle;
> +  }
> +
> +  @Inject
> +  public BasicMessageBundleFactory(
> +      @MessageBundleFetcher HttpFetcher bundleFetcher) {
> +    this.bundleFetcher = bundleFetcher;
> +  }
> +}
>
> Modified:
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/DefaultGuiceModule.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/DefaultGuiceModule.java?rev=655969&r1=655968&r2=655969&view=diff
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/DefaultGuiceModule.java
> (original)
> +++
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/DefaultGuiceModule.java
> Tue May 13 11:51:11 2008
> @@ -21,9 +21,9 @@
>  import org.apache.shindig.common.util.ResourceLoader;
>  import org.apache.shindig.gadgets.http.BasicHttpCache;
>  import org.apache.shindig.gadgets.http.BasicHttpFetcher;
> +import org.apache.shindig.gadgets.http.ContentFetcherFactory;
>  import org.apache.shindig.gadgets.http.HttpCache;
>  import org.apache.shindig.gadgets.http.HttpFetcher;
> -import org.apache.shindig.gadgets.http.ContentFetcherFactory;
>  import org.apache.shindig.gadgets.http.RemoteContentFetcherFactory;
>  import org.apache.shindig.gadgets.oauth.OAuthFetcherFactory;
>
> @@ -57,19 +57,20 @@
>
>     bind(RemoteContentFetcherFactory.class);
>     bind(SigningFetcherFactory.class);
> -    // Needed becuase OAuth fetcher factory fetches its config
> -    bind(HttpFetcher.class)
> -        .annotatedWith(OAuthFetcherFactory.OAuthConfigFetcher.class)
> -        .to(BasicHttpFetcher.class);
>     bind(OAuthFetcherFactory.class);
>     bind(ContentFetcherFactory.class);
>
>     bind(HttpFetcher.class)
>         .annotatedWith(GadgetSpecFetcher.class)
>         .toProvider(ContentFetcherFactory.class);
> +    bind(GadgetSpecFactory.class)
> +        .to(BasicGadgetSpecFactory.class);
> +
>     bind(HttpFetcher.class)
>         .annotatedWith(MessageBundleFetcher.class)
>         .toProvider(ContentFetcherFactory.class);
> +    bind(MessageBundleFactory.class)
> +        .to(BasicMessageBundleFactory.class);
>
>     bind(GadgetBlacklist.class).to(BasicGadgetBlacklist.class);
>     bind(Executor.class).toInstance(Executors.newCachedThreadPool());
>
> Modified:
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetServer.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetServer.java?rev=655969&r1=655968&r2=655969&view=diff
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetServer.java
> (original)
> +++
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetServer.java
> Tue May 13 11:51:11 2008
> @@ -17,10 +17,9 @@
>  */
>  package org.apache.shindig.gadgets;
>
> -import org.apache.shindig.gadgets.http.HttpFetcher;
>  import org.apache.shindig.gadgets.http.ContentFetcherFactory;
> -import org.apache.shindig.gadgets.http.HttpResponse;
>  import org.apache.shindig.gadgets.http.HttpRequest;
> +import org.apache.shindig.gadgets.http.HttpResponse;
>  import org.apache.shindig.gadgets.spec.Auth;
>  import org.apache.shindig.gadgets.spec.Feature;
>  import org.apache.shindig.gadgets.spec.GadgetSpec;
> @@ -30,7 +29,6 @@
>
>  import com.google.inject.Inject;
>
> -import java.net.URI;
>  import java.util.HashMap;
>  import java.util.HashSet;
>  import java.util.LinkedList;
> @@ -53,22 +51,23 @@
>   private final GadgetBlacklist blacklist;
>
>   private ContentFetcherFactory preloadFetcherFactory;
> -  private HttpFetcher gadgetSpecFetcher;
> -  private HttpFetcher messageBundleFetcher;
> +  private GadgetSpecFactory specFactory;
> +  private MessageBundleFactory bundleFactory;
> +
>
>   @Inject
>   public GadgetServer(Executor executor,
>       GadgetFeatureRegistry registry,
>       GadgetBlacklist blacklist,
>       ContentFetcherFactory preloadFetcherFactory,
> -      @GadgetSpecFetcher HttpFetcher gadgetSpecFetcher,
> -      @MessageBundleFetcher HttpFetcher messageBundleFetcher) {
> +      GadgetSpecFactory specFactory,
> +      MessageBundleFactory bundleFactory) {
>     this.executor = executor;
>     this.registry = registry;
>     this.blacklist = blacklist;
>     this.preloadFetcherFactory = preloadFetcherFactory;
> -    this.gadgetSpecFetcher = gadgetSpecFetcher;
> -    this.messageBundleFetcher = messageBundleFetcher;
> +    this.specFactory = specFactory;
> +    this.bundleFactory = bundleFactory;
>   }
>
>   /**
> @@ -82,19 +81,7 @@
>     if (blacklist.isBlacklisted(context.getUrl())) {
>       throw new GadgetException(GadgetException.Code.BLACKLISTED_GADGET);
>     }
> -
> -    HttpRequest request = HttpRequest.getRequest(
> -        context.getUrl(), context.getIgnoreCache());
> -    HttpResponse response = gadgetSpecFetcher.fetch(request);
> -    if (response.getHttpStatusCode() != HttpResponse.SC_OK) {
> -      throw new GadgetException(
> -          GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT,
> -          "Unable to retrieve gadget xml. HTTP error " +
> -          response.getHttpStatusCode());
> -    }
> -    GadgetSpec spec
> -        = new GadgetSpec(context.getUrl(),
> response.getResponseAsString());
> -    return createGadgetFromSpec(spec, context);
> +    return createGadgetFromSpec(specFactory.getGadgetSpec(context),
> context);
>   }
>
>   /**
> @@ -106,19 +93,7 @@
>    */
>   private MessageBundle getBundle(LocaleSpec localeSpec, GadgetContext
> context)
>       throws GadgetException {
> -    URI bundleUrl = localeSpec.getMessages();
> -    HttpRequest request
> -        = HttpRequest.getRequest(bundleUrl, context.getIgnoreCache());
> -    HttpResponse response = messageBundleFetcher.fetch(request);
> -    if (response.getHttpStatusCode() != HttpResponse.SC_OK) {
> -      throw new GadgetException(
> -          GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT,
> -          "Unable to retrieve message bundle xml. HTTP error " +
> -          response.getHttpStatusCode());
> -    }
> -    MessageBundle bundle
> -        = new MessageBundle(bundleUrl, response.getResponseAsString());
> -    return bundle;
> +    return bundleFactory.getBundle(localeSpec, context);
>   }
>
>   /**
>
> Added:
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetSpecFactory.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetSpecFactory.java?rev=655969&view=auto
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetSpecFactory.java
> (added)
> +++
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetSpecFactory.java
> Tue May 13 11:51:11 2008
> @@ -0,0 +1,35 @@
> +/*
> + * Licensed to the Apache Software Foundation (ASF) under one
> + * or more contributor license agreements.  See the NOTICE file
> + * distributed with this work for additional information
> + * regarding copyright ownership.  The ASF licenses this file
> + * to you under the Apache License, Version 2.0 (the
> + * "License"); you may not use this file except in compliance
> + * with the License.  You may obtain a copy of the License at
> + *
> + *     http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing,
> + * software distributed under the License is distributed on an
> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + * KIND, either express or implied.  See the License for the
> + * specific language governing permissions and limitations
> + * under the License.
> + */
> +package org.apache.shindig.gadgets;
> +
> +import org.apache.shindig.gadgets.spec.GadgetSpec;
> +
> +import java.net.URI;
> +
> +/** Factory of gadget specs */
> +public interface GadgetSpecFactory {
> +
> +  /** Return a gadget spec for a context */
> +  public GadgetSpec getGadgetSpec(GadgetContext context) throws
> GadgetException;
> +
> +  /** Return a gadget spec for a URI */
> +  public GadgetSpec getGadgetSpec(URI gadgetUri, boolean ignoreCache)
> +      throws GadgetException;
> +
> +}
>
> Added:
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/MessageBundleFactory.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/MessageBundleFactory.java?rev=655969&view=auto
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/MessageBundleFactory.java
> (added)
> +++
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/MessageBundleFactory.java
> Tue May 13 11:51:11 2008
> @@ -0,0 +1,36 @@
> +/*
> + * Licensed to the Apache Software Foundation (ASF) under one
> + * or more contributor license agreements.  See the NOTICE file
> + * distributed with this work for additional information
> + * regarding copyright ownership.  The ASF licenses this file
> + * to you under the Apache License, Version 2.0 (the
> + * "License"); you may not use this file except in compliance
> + * with the License.  You may obtain a copy of the License at
> + *
> + *     http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing,
> + * software distributed under the License is distributed on an
> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + * KIND, either express or implied.  See the License for the
> + * specific language governing permissions and limitations
> + * under the License.
> + */
> +package org.apache.shindig.gadgets;
> +
> +import org.apache.shindig.gadgets.spec.LocaleSpec;
> +import org.apache.shindig.gadgets.spec.MessageBundle;
> +
> +import java.net.URI;
> +
> +/**
> + * Factory of message bundles
> + */
> +public interface MessageBundleFactory {
> +
> +  MessageBundle getBundle(LocaleSpec localeSpec, GadgetContext context)
> +      throws GadgetException;
> +
> +  MessageBundle getBundle(URI bundleUri, boolean ignoreCache)
> +      throws GadgetException;
> +}
>
> Modified:
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth/BasicGadgetOAuthTokenStore.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth/BasicGadgetOAuthTokenStore.java?rev=655969&r1=655968&r2=655969&view=diff
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth/BasicGadgetOAuthTokenStore.java
> (original)
> +++
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth/BasicGadgetOAuthTokenStore.java
> Tue May 13 11:51:11 2008
> @@ -20,10 +20,7 @@
>
>  import org.apache.shindig.common.util.ResourceLoader;
>  import org.apache.shindig.gadgets.GadgetException;
> -import org.apache.shindig.gadgets.http.HttpFetcher;
> -import org.apache.shindig.gadgets.http.HttpResponse;
> -import org.apache.shindig.gadgets.http.HttpRequest;
> -import org.apache.shindig.gadgets.spec.GadgetSpec;
> +import org.apache.shindig.gadgets.GadgetSpecFactory;
>  import org.json.JSONException;
>  import org.json.JSONObject;
>
> @@ -45,7 +42,7 @@
>     super(store);
>   }
>
> -  public void initFromConfigFile(HttpFetcher fetcher)
> +  public void initFromConfigFile(GadgetSpecFactory specFactory)
>   throws GadgetException {
>     // Read our consumer keys and secrets from config/oauth.js
>     // This actually involves fetching gadget specs
> @@ -57,7 +54,7 @@
>       for (Iterator<?> i = oauthConfigs.keys(); i.hasNext();) {
>         String url = (String) i.next();
>         URI gadgetUri = new URI(url);
> -        storeProviderInfos(fetcher, gadgetUri);
> +        storeProviderInfos(specFactory, gadgetUri);
>
>         JSONObject oauthConfig = oauthConfigs.getJSONObject(url);
>         storeConsumerInfos(gadgetUri, oauthConfig);
> @@ -71,14 +68,10 @@
>     }
>   }
>
> -  private void storeProviderInfos(HttpFetcher fetcher, URI gadgetUri)
> +  private void storeProviderInfos(GadgetSpecFactory specFactory, URI
> gadgetUri)
>       throws GadgetException {
> -    HttpRequest request = HttpRequest.getRequest(
> -        gadgetUri, false);
> -    HttpResponse response = fetcher.fetch(request);
> -    GadgetSpec spec
> -        = new GadgetSpec(gadgetUri, response.getResponseAsString());
> -    storeServiceInfoFromGadgetSpec(gadgetUri, spec);
> +    storeServiceInfoFromGadgetSpec(gadgetUri,
> +        specFactory.getGadgetSpec(gadgetUri, false));
>   }
>
>   private void storeConsumerInfos(URI gadgetUri, JSONObject oauthConfig)
>
> Modified:
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth/OAuthFetcherFactory.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth/OAuthFetcherFactory.java?rev=655969&r1=655968&r2=655969&view=diff
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth/OAuthFetcherFactory.java
> (original)
> +++
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth/OAuthFetcherFactory.java
> Tue May 13 11:51:11 2008
> @@ -23,15 +23,11 @@
>  import org.apache.shindig.common.crypto.BlobCrypter;
>  import org.apache.shindig.common.crypto.Crypto;
>  import org.apache.shindig.gadgets.GadgetException;
> +import org.apache.shindig.gadgets.GadgetSpecFactory;
>  import org.apache.shindig.gadgets.http.HttpFetcher;
>
> -import com.google.inject.BindingAnnotation;
>  import com.google.inject.Inject;
>
> -import java.lang.annotation.ElementType;
> -import java.lang.annotation.Retention;
> -import java.lang.annotation.RetentionPolicy;
> -import java.lang.annotation.Target;
>  import java.util.logging.Level;
>  import java.util.logging.Logger;
>
> @@ -54,14 +50,14 @@
>    * BlobCrypter and consumer keys/secrets read from oauth.js
>    */
>   @Inject
> -  public OAuthFetcherFactory(@OAuthConfigFetcher HttpFetcher fetcher) {
> +  public OAuthFetcherFactory(GadgetSpecFactory specFactory) {
>     try {
>       this.oauthCrypter = new BasicBlobCrypter(
>           Crypto.getRandomBytes(BasicBlobCrypter.MASTER_KEY_MIN_LEN));
>
>       BasicGadgetOAuthTokenStore basicStore =
>           new BasicGadgetOAuthTokenStore(new BasicOAuthStore());
> -      basicStore.initFromConfigFile(fetcher);
> +      basicStore.initFromConfigFile(specFactory);
>       tokenStore = basicStore;
>     } catch (Throwable t) {
>       // Since this happens at startup, we don't want to kill the server
> just
> @@ -102,10 +98,4 @@
>     fetcher.init();
>     return fetcher;
>   }
> -
> -  @Retention(RetentionPolicy.RUNTIME)
> -  @Target({ElementType.FIELD, ElementType.PARAMETER})
> -  @BindingAnnotation
> -  public @interface OAuthConfigFetcher {
> -  }
>  }
>
> Modified:
> incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/GadgetTestFixture.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/GadgetTestFixture.java?rev=655969&r1=655968&r2=655969&view=diff
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/GadgetTestFixture.java
> (original)
> +++
> incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/GadgetTestFixture.java
> Tue May 13 11:51:11 2008
> @@ -20,8 +20,8 @@
>  package org.apache.shindig.gadgets;
>
>  import org.apache.shindig.common.SecurityTokenDecoder;
> -import org.apache.shindig.gadgets.http.HttpFetcher;
>  import org.apache.shindig.gadgets.http.ContentFetcherFactory;
> +import org.apache.shindig.gadgets.http.HttpFetcher;
>
>  import java.util.concurrent.Executor;
>
> @@ -38,6 +38,10 @@
>       = mock(ContentFetcherFactory.class);
>   public final HttpFetcher fetcher = mock(HttpFetcher.class);
>   public final GadgetBlacklist blacklist = mock(GadgetBlacklist.class);
> +  public final GadgetSpecFactory specFactory =
> +      new BasicGadgetSpecFactory(fetcher);
> +  public final MessageBundleFactory bundleFactory =
> +      new BasicMessageBundleFactory(fetcher);
>   public GadgetFeatureRegistry registry;
>   public ContainerConfig containerConfig;
>   public final Executor executor = new Executor() {
> @@ -63,6 +67,6 @@
>     }
>
>     gadgetServer = new GadgetServer(executor, registry, blacklist,
> -        fetcherFactory, fetcher, fetcher);
> +        fetcherFactory, specFactory, bundleFactory);
>   }
>  }
>
>
>