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 2009/02/20 00:11:58 UTC

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

Author: lryan
Date: Thu Feb 19 23:11:57 2009
New Revision: 746051

URL: http://svn.apache.org/viewvc?rev=746051&view=rev
Log:
Move ImageRewriting out of fetcher and into pipeline. Cleanup injection

Modified:
    incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/BasicHttpFetcher.java
    incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/DefaultRequestPipeline.java
    incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/DefaultRequestPipelineTest.java

Modified: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/BasicHttpFetcher.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/BasicHttpFetcher.java?rev=746051&r1=746050&r2=746051&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/BasicHttpFetcher.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/BasicHttpFetcher.java Thu Feb 19 23:11:57 2009
@@ -17,16 +17,14 @@
  */
 package org.apache.shindig.gadgets.http;
 
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang.ArrayUtils;
+import org.apache.commons.lang.StringUtils;
+
 import com.google.common.collect.Maps;
 import com.google.inject.Inject;
 import com.google.inject.Provider;
 import com.google.inject.Singleton;
-import com.google.inject.name.Named;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang.ArrayUtils;
-import org.apache.commons.lang.StringUtils;
-import org.apache.shindig.gadgets.rewrite.image.ImageRewriter;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
@@ -59,8 +57,6 @@
 
   private Provider<Proxy> proxyProvider;
 
-  private ImageRewriter rewriter;
-
   /**
    * Creates a new fetcher for fetching HTTP objects.  Not really suitable
    * for production use.  Someone should probably go and implement maxObjSize,
@@ -89,11 +85,6 @@
     this.proxyProvider = proxyProvider;
   }
 
-  @Inject(optional = true)
-  public void setImageRewriter(@Named("org.apache.shindig.image-rewriter")ImageRewriter rewriter) {
-    this.rewriter = rewriter;
-  }
-
   /**
    * Initializes the connection.
    *
@@ -176,12 +167,7 @@
         fetcher.setDoOutput(true);
         IOUtils.copy(request.getPostBody(), fetcher.getOutputStream());
       }
-      HttpResponse response = makeResponse(fetcher);
-      if (rewriter != null && !request.getIgnoreCache() &&
-          request.getCacheTtl() != 0) {
-        response = rewriter.rewrite(request.getUri(), response);
-      }
-      return response;
+      return makeResponse(fetcher);
     } catch (IOException e) {
       if (e instanceof java.net.SocketTimeoutException ||
           e instanceof java.net.SocketException) {

Modified: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/DefaultRequestPipeline.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/DefaultRequestPipeline.java?rev=746051&r1=746050&r2=746051&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/DefaultRequestPipeline.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/DefaultRequestPipeline.java Thu Feb 19 23:11:57 2009
@@ -17,13 +17,14 @@
  */
 package org.apache.shindig.gadgets.http;
 
+import org.apache.shindig.gadgets.GadgetException;
+import org.apache.shindig.gadgets.oauth.OAuthRequest;
+import org.apache.shindig.gadgets.rewrite.image.ImageRewriter;
+
 import com.google.inject.Inject;
 import com.google.inject.Provider;
 import com.google.inject.Singleton;
 
-import org.apache.shindig.gadgets.GadgetException;
-import org.apache.shindig.gadgets.oauth.OAuthRequest;
-
 /**
  * A standard implementation of a request pipeline. Performs request caching and
  * signing on top of standard HTTP requests.
@@ -33,14 +34,17 @@
   private final HttpFetcher httpFetcher;
   private final HttpCache httpCache;
   private final Provider<OAuthRequest> oauthRequestProvider;
+  private final ImageRewriter imageRewriter;
 
   @Inject
   public DefaultRequestPipeline(HttpFetcher httpFetcher,
                                 HttpCache httpCache,
-                                Provider<OAuthRequest> oauthRequestProvider) {
+                                Provider<OAuthRequest> oauthRequestProvider,
+                                ImageRewriter imageRewriter) {
     this.httpFetcher = httpFetcher;
     this.httpCache = httpCache;
     this.oauthRequestProvider = oauthRequestProvider;
+    this.imageRewriter = imageRewriter;
   }
 
   public HttpResponse execute(HttpRequest request) throws GadgetException {
@@ -66,6 +70,10 @@
         return HttpResponse.error();
     }
 
+    if (!response.isError() && !request.getIgnoreCache() && request.getCacheTtl() != 0) {
+      response = imageRewriter.rewrite(request.getUri(), response);
+    }
+
     if (!request.getIgnoreCache()) {
       httpCache.addResponse(request, response);
     }

Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/DefaultRequestPipelineTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/DefaultRequestPipelineTest.java?rev=746051&r1=746050&r2=746051&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/DefaultRequestPipelineTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/DefaultRequestPipelineTest.java Thu Feb 19 23:11:57 2009
@@ -17,15 +17,16 @@
  */
 package org.apache.shindig.gadgets.http;
 
-import static org.junit.Assert.assertEquals;
-
-import com.google.common.collect.Maps;
-import com.google.inject.Provider;
-
 import org.apache.shindig.common.uri.Uri;
 import org.apache.shindig.gadgets.AuthType;
 import org.apache.shindig.gadgets.GadgetException;
 import org.apache.shindig.gadgets.oauth.OAuthRequest;
+import org.apache.shindig.gadgets.rewrite.image.NoOpImageRewriter;
+
+import com.google.common.collect.Maps;
+import com.google.inject.Provider;
+
+import static org.junit.Assert.assertEquals;
 import org.junit.Test;
 
 import java.util.Map;
@@ -37,7 +38,8 @@
   private final FakeHttpCache cache = new FakeHttpCache();
   private final FakeOAuthRequestProvider oauth = new FakeOAuthRequestProvider();
 
-  private final RequestPipeline pipeline = new DefaultRequestPipeline(fetcher, cache, oauth);
+  private final RequestPipeline pipeline = new DefaultRequestPipeline(fetcher, cache, oauth,
+      new NoOpImageRewriter());
 
   @Test
   public void authTypeNoneNotCached() throws Exception {