Author: zhoresh
Date: Mon Aug 23 20:18:55 2010
New Revision: 988289

URL: http://svn.apache.org/viewvc?rev=988289&view=rev
Log:
url: http://codereview.appspot.com/1976047/
Fix proxy to handle uri generated by CssRewriter

Modified:
    
shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/MakeRequestHandler.java
    
shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/ProxyHandler.java
    
shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/uri/DefaultProxyUriManager.java
    
shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/uri/DefaultProxyUriManagerTest.java

Modified: 
shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/MakeRequestHandler.java
URL: 
http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/MakeRequestHandler.java?rev=988289&r1=988288&r2=988289&view=diff
==============================================================================
--- 
shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/MakeRequestHandler.java
 (original)
+++ 
shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/MakeRequestHandler.java
 Mon Aug 23 20:18:55 2010
@@ -266,7 +266,13 @@ public class MakeRequestHandler {
   private String processFeed(String url, HttpServletRequest req, String xml)
       throws GadgetException {
     boolean getSummaries = Boolean.parseBoolean(getParameter(req, 
GET_SUMMARIES_PARAM, "false"));
-    int numEntries = Integer.parseInt(getParameter(req, NUM_ENTRIES_PARAM, 
DEFAULT_NUM_ENTRIES));
+    int numEntries;
+    try {
+      numEntries = Integer.valueOf(getParameter(req, NUM_ENTRIES_PARAM, 
DEFAULT_NUM_ENTRIES));
+    } catch (NumberFormatException e) {
+      throw new GadgetException(GadgetException.Code.INVALID_PARAMETER,
+          "numEntries paramater is not a number", HttpResponse.SC_BAD_REQUEST);
+    }
     return new FeedProcessor().process(url, xml, getSummaries, 
numEntries).toString();
   }
 
@@ -304,7 +310,7 @@ public class MakeRequestHandler {
         refreshInterval =  
Integer.valueOf(request.getParameter(UriCommon.Param.REFRESH.getKey()));
       } catch (NumberFormatException nfe) {
         throw new GadgetException(GadgetException.Code.INVALID_PARAMETER,
-            "refresh parameter is not a number");
+            "refresh parameter is not a number", HttpResponse.SC_BAD_REQUEST);
       }
     } else {
       refreshInterval = Math.max(60 * 60, (int)(results.getCacheTtl() / 
1000L));

Modified: 
shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/ProxyHandler.java
URL: 
http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/ProxyHandler.java?rev=988289&r1=988288&r2=988289&view=diff
==============================================================================
--- 
shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/ProxyHandler.java
 (original)
+++ 
shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/ProxyHandler.java
 Mon Aug 23 20:18:55 2010
@@ -32,7 +32,6 @@ import org.apache.shindig.gadgets.http.R
 import org.apache.shindig.gadgets.rewrite.ResponseRewriterRegistry;
 import org.apache.shindig.gadgets.rewrite.RewritingException;
 import org.apache.shindig.gadgets.uri.ProxyUriManager;
-import org.apache.shindig.gadgets.uri.UriCommon;
 import org.apache.shindig.gadgets.uri.UriUtils;
 import org.apache.shindig.gadgets.uri.UriUtils.DisallowedHeaders;
 
@@ -134,7 +133,7 @@ public class ProxyHandler {
     return response.create();
   }
 
-  private void setResponseContentHeaders(HttpResponseBuilder response, 
HttpResponse results) {
+  protected void setResponseContentHeaders(HttpResponseBuilder response, 
HttpResponse results) {
     // We're skipping the content disposition header for flash due to an issue 
with Flash player 10
     // This does make some sites a higher value phishing target, but this can 
be mitigated by
     // additional referer checks.

Modified: 
shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/uri/DefaultProxyUriManager.java
URL: 
http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/uri/DefaultProxyUriManager.java?rev=988289&r1=988288&r2=988289&view=diff
==============================================================================
--- 
shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/uri/DefaultProxyUriManager.java
 (original)
+++ 
shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/uri/DefaultProxyUriManager.java
 Mon Aug 23 20:18:55 2010
@@ -26,6 +26,7 @@ import com.google.inject.name.Named;
 import org.apache.commons.lang.StringUtils;
 import org.apache.shindig.common.uri.Uri;
 import org.apache.shindig.common.uri.UriBuilder;
+import org.apache.shindig.common.util.Utf8UrlCoder;
 import org.apache.shindig.config.ContainerConfig;
 import org.apache.shindig.gadgets.GadgetException;
 import org.apache.shindig.gadgets.http.HttpResponse;
@@ -39,22 +40,22 @@ import java.util.Map;
 
 /**
  * Generates URIs for use by the Shindig proxy service.
- * 
+ *
  * URIs are generated on the host specified in ContainerConfig at key
  * "gadgets.uri.proxy.host".
- * 
+ *
  * The remainder of the URL may reference either chained or query-style
  * proxy syntax. The former is used when "gadgets.uri.proxy.path" has token
  * "%chained_params%" in it.
- * 
+ *
  * Chained: Returned URI contains query params in its path, with the proxied
  * resource's URI appended verbatim to the end. This enables proxied SWFs
  * to perform proxied, relative-URI resource loads. Example:
  * 
http://www.example.com/gadgets/proxy/refresh=1&.../http://www.foo.com/img.gif
- * 
+ *
  * Query param: All params are provided on the query string. Example:
  * 
http://www.example.com/gadgets/proxy?refresh=1&url=http://www.foo.com/img.gif&;...
- * 
+ *
  * This implementation supports batched versioning as well. The old-style "fp"
  * (fingerprint) parameter is not supported any longer; its functionality is 
assumed
  * to be subsumed into the version param.
@@ -67,30 +68,30 @@ public class DefaultProxyUriManager impl
   private final ContainerConfig config;
   private final Versioner versioner;
   private boolean strictParsing = false;
-  
+
   @Inject
   public DefaultProxyUriManager(ContainerConfig config,
                                 @Nullable Versioner versioner) {
     this.config = config;
     this.versioner = versioner;
   }
-  
+
   @Inject(optional = true)
   public void 
setUseStrictParsing(@Named("shindig.uri.proxy.use-strict-parsing") boolean 
useStrict) {
     this.strictParsing = useStrict;
   }
-  
+
   public List<Uri> make(List<ProxyUri> resources, Integer forcedRefresh) {
     if (resources.isEmpty()) {
       return Collections.emptyList();
     }
 
     List<Uri> resourceUris = Lists.newArrayListWithCapacity(resources.size());
-    
+
     for (ProxyUri puc : resources) {
       resourceUris.add(puc.getResource());
     }
-    
+
     Map<Uri, String> versions;
     if (versioner == null) {
       versions = Collections.emptyMap();
@@ -106,12 +107,12 @@ public class DefaultProxyUriManager impl
         }
       }
     }
-    
+
     List<Uri> result = Lists.newArrayListWithCapacity(resources.size());
     for (ProxyUri puc : resources) {
       result.add(makeProxiedUri(puc, forcedRefresh, 
versions.get(puc.getResource())));
     }
-    
+
     return result;
   }
 
@@ -121,7 +122,7 @@ public class DefaultProxyUriManager impl
     String container = puc.getContainer();
     UriBuilder uri = new UriBuilder();
     uri.setAuthority(getReqConfig(container, PROXY_HOST_PARAM));
-    
+
     // Chained vs. query-style syntax is determined by the presence of 
CHAINED_PARAMS_TOKEN
     String path = getReqConfig(container, PROXY_PATH_PARAM);
     if (path.contains(CHAINED_PARAMS_TOKEN)) {
@@ -132,20 +133,20 @@ public class DefaultProxyUriManager impl
       String curUri = uriStr + (!uriStr.endsWith("/") ? "/" : "") + 
puc.getResource().toString();
       return Uri.parse(curUri);
     }
-    
+
     // Query-style syntax. Use path as normal and append query params at the 
end.
     queryBuilder.addQueryParameter(Param.URL.getKey(), 
puc.getResource().toString());
     uri.setQuery(queryBuilder.getQuery());
     uri.setPath(path);
-    
+
     return uri.toUri();
   }
-  
+
   @SuppressWarnings("deprecation")
   public ProxyUri process(Uri uriIn) throws GadgetException {
     UriStatus status = UriStatus.BAD_URI;
     Uri uri = null;
-    
+
     // First determine if the URI is chained-syntax or query-style.
     String container = uriIn.getQueryParameter(Param.CONTAINER.getKey());
     if (container == null) {
@@ -163,6 +164,12 @@ public class DefaultProxyUriManager impl
       // Check for chained query string in the path.
       String containerStr = Param.CONTAINER.getKey() + '=';
       String path = uriIn.getPath();
+      // It is possible to get decoded url ('=' converted to %3d)
+      // for example from CssResponseRewriter, so we should support it
+      boolean doDecode = (!path.contains(containerStr));
+      if (doDecode) {
+        path = Utf8UrlCoder.decode(path);
+      }
       int start = path.indexOf(containerStr);
       if (start > 0) {
         start += containerStr.length();
@@ -177,8 +184,9 @@ public class DefaultProxyUriManager impl
         if (container != null) {
           String proxyPath = config.getString(container, PROXY_PATH_PARAM);
           if (proxyPath != null) {
-            String[] chainedChunks = 
StringUtils.splitByWholeSeparatorPreserveAllTokens(proxyPath, 
CHAINED_PARAMS_TOKEN);
-            
+            String[] chainedChunks = 
StringUtils.splitByWholeSeparatorPreserveAllTokens(
+                proxyPath, CHAINED_PARAMS_TOKEN);
+
             // Parse out the URI of the actual resource. This URI is found as 
the
             // substring of the "full" URI, after the chained proxy prefix. We
             // first search for the pre- and post-fixes of the original 
/pre/%chained_params%/post
@@ -188,24 +196,28 @@ public class DefaultProxyUriManager impl
             if (chainedChunks.length == 2 && chainedChunks[1].length() > 0) {
               endToken = chainedChunks[1];
             }
-            
+
             // Pull URI out of original inUri's full representation.
             String fullProxyUri = uriIn.toString();
             int startIx = fullProxyUri.indexOf(startToken) + 
startToken.length();
             int endIx = fullProxyUri.indexOf(endToken, startIx);
             if (startIx > 0 && endIx > 0) {
-              queryUri = new 
UriBuilder().setQuery(fullProxyUri.substring(startIx,endIx)).toUri();
+              String chainedQuery = fullProxyUri.substring(startIx, endIx);
+              if (doDecode) {
+                chainedQuery = Utf8UrlCoder.decode(chainedQuery);
+              }
+              queryUri = new UriBuilder().setQuery(chainedQuery).toUri();
               uriStr = fullProxyUri.substring(endIx + endToken.length());
               while (uriStr.startsWith("/")) {
                 uriStr = uriStr.substring(1);
               }
-              
+
             }
           }
         }
       }
     }
-    
+
     if (!strictParsing && container != null && StringUtils.isEmpty(uriStr)) {
       // Query-style despite the container being configured for chained style.
       uriStr = uriIn.getQueryParameter(Param.URL.getKey());
@@ -220,7 +232,7 @@ public class DefaultProxyUriManager impl
           (StringUtils.isEmpty(container) ? ' ' + Param.CONTAINER.getKey() : 
""),
           HttpResponse.SC_BAD_REQUEST);
     }
-    
+
     String queryHost = config.getString(container, PROXY_HOST_PARAM);
     if (strictParsing) {
       if (queryHost == null || 
!queryHost.equalsIgnoreCase(uriIn.getAuthority())) {
@@ -228,7 +240,7 @@ public class DefaultProxyUriManager impl
             HttpResponse.SC_BAD_REQUEST);
       }
     }
-    
+
     try {
       uri = Uri.parse(uriStr);
     } catch (Exception e) {
@@ -236,7 +248,7 @@ public class DefaultProxyUriManager impl
       throw new GadgetException(GadgetException.Code.INVALID_PARAMETER,
           "Invalid " + Param.URL.getKey() + ": " + uriStr, 
HttpResponse.SC_BAD_REQUEST);
     }
-    
+
     // URI is valid.
     status = UriStatus.VALID_UNVERSIONED;
 
@@ -244,7 +256,7 @@ public class DefaultProxyUriManager impl
     if (versioner != null && version != null) {
       status = versioner.validate(uri, container, version);
     }
-    
+
     return new ProxyUri(status, uri, queryUri);
   }
 

Modified: 
shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/uri/DefaultProxyUriManagerTest.java
URL: 
http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/uri/DefaultProxyUriManagerTest.java?rev=988289&r1=988288&r2=988289&view=diff
==============================================================================
--- 
shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/uri/DefaultProxyUriManagerTest.java
 (original)
+++ 
shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/uri/DefaultProxyUriManagerTest.java
 Mon Aug 23 20:18:55 2010
@@ -23,6 +23,7 @@ import static org.easymock.EasyMock.expe
 import static org.easymock.EasyMock.isA;
 import static org.easymock.EasyMock.createMock;
 import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
@@ -44,17 +45,17 @@ public class DefaultProxyUriManagerTest 
   private static final Uri RESOURCE_1 = 
Uri.parse("http://example.com/one.dat?param=value";);
   private static final Uri RESOURCE_2 = 
Uri.parse("http://gadgets.com/two.dat";);
   private static final Uri RESOURCE_3 = 
Uri.parse("http://foobar.com/three.dat";);
-  
+
   @Test
   public void basicProxyQueryStyle() throws Exception {
     checkQueryStyle(false, false, null);
   }
-  
+
   @Test
   public void altParamsProxyQueryStyle() throws Exception {
     checkQueryStyle(true, true, "version");
   }
-  
+
   private void checkQueryStyle(boolean debug, boolean noCache, String version) 
throws Exception {
     String host = "host.com";
     String path = "/proxy/path";
@@ -88,7 +89,7 @@ public class DefaultProxyUriManagerTest 
     List<ProxyUri> proxyUris = Lists.newLinkedList();
     proxyUris.add(new ProxyUri(refresh, debug, noCache, CONTAINER, 
SPEC_URI.toString(),
         RESOURCE_1));
-    
+
     List<Uri> uris = manager.make(proxyUris, null);
     assertEquals(1, uris.size());
     verifyQueryUriWithRefresh(RESOURCE_1, uris.get(0), debug, noCache,
@@ -126,7 +127,7 @@ public class DefaultProxyUriManagerTest 
     assertEquals(null, uris.get(1).getQueryParameter("resize_q"));
     assertEquals(null, uris.get(1).getQueryParameter("no_expand"));
   }
-  
+
   @Test
   public void verifyAddedParamsChained() throws Exception {
     String host = "host.com";
@@ -138,7 +139,7 @@ public class DefaultProxyUriManagerTest 
         RESOURCE_1);
     pUri.setResize(100, 10, 90, true);
     proxyUris.add(pUri);
-    
+
     List<Uri> uris = manager.make(proxyUris, null);
     assertEquals(1, uris.size());
     verifyChainedUri(RESOURCE_1, uris.get(0), false, true,
@@ -155,10 +156,10 @@ public class DefaultProxyUriManagerTest 
     ProxyUri uri = new ProxyUri(null, false, false, "open", 
"http://example.com/gadget";,
         Uri.parse("http://example.com/resource";));
     uri.setFallbackUrl("http://example.com/fallback";);
-    
+
     assertEquals("http://example.com/fallback";, 
uri.getFallbackUri().toString());
   }
-  
+
   @Test(expected = GadgetException.class)
   public void testBadFallbackUrl() throws Exception {
     ProxyUri uri = new ProxyUri(null, false, false, "open", 
"http://example.com/gadget";,
@@ -166,17 +167,17 @@ public class DefaultProxyUriManagerTest 
     uri.setFallbackUrl("bad url");
     uri.getFallbackUri(); // throws exception!
   }
-  
+
   @Test
   public void basicProxyChainedStyle() throws Exception {
     checkChainedStyle(false, false, null);
   }
-  
+
   @Test
   public void altParamsProxyChainedStyle() throws Exception {
     checkChainedStyle(true, true, "version");
   }
-  
+
   private void checkChainedStyle(boolean debug, boolean noCache, String 
version) throws Exception {
     String host = "host.com";
     String path = "/proxy/" + DefaultProxyUriManager.CHAINED_PARAMS_TOKEN + 
"/path";
@@ -185,17 +186,17 @@ public class DefaultProxyUriManagerTest 
     assertEquals(1, uris.size());
     verifyChainedUri(RESOURCE_1, uris.get(0), debug, noCache, version, false, 
host, path);
   }
-  
+
   @Test
   public void basicProxyChainedStyleEndOfPath() throws Exception {
     checkChainedStyleEndOfPath(false, false, null);
   }
-  
+
   @Test
   public void altParamsProxyChainedStyleEndOfPath() throws Exception {
     checkChainedStyleEndOfPath(true, true, "version");
   }
-  
+
   private void checkChainedStyleEndOfPath(boolean debug, boolean noCache, 
String version) throws Exception {
     String host = "host.com";
     String path = "/proxy/" + DefaultProxyUriManager.CHAINED_PARAMS_TOKEN;
@@ -204,7 +205,7 @@ public class DefaultProxyUriManagerTest 
     assertEquals(1, uris.size());
     verifyChainedUri(RESOURCE_1, uris.get(0), debug, noCache, version, true, 
host, path);
   }
-  
+
   @Test
   public void batchedProxyQueryStyle() throws Exception {
     String host = "host.com";
@@ -217,7 +218,7 @@ public class DefaultProxyUriManagerTest 
       verifyQueryUri(resources.get(i), uris.get(i), true, true, versions[i], 
host, path);
     }
   }
-  
+
   @Test
   public void batchedProxyChainedStyle() throws Exception {
     String host = "host.com";
@@ -248,24 +249,24 @@ public class DefaultProxyUriManagerTest 
     // Validate tests also serve as end-to-end tests: create, unpack.
     checkValidate("/proxy/path", UriStatus.VALID_UNVERSIONED, null);
   }
-  
+
   @Test
   public void validateChainedStyleUnversioned() throws Exception {
     checkValidate("/proxy/" + DefaultProxyUriManager.CHAINED_PARAMS_TOKEN + 
"/path",
         UriStatus.VALID_UNVERSIONED, null);
   }
-  
+
   @Test
   public void validateQueryStyleVersioned() throws Exception {
     checkValidate("/proxy/path", UriStatus.VALID_VERSIONED, "version");
   }
-  
+
   @Test
   public void validateChainedStyleVersioned() throws Exception {
     checkValidate("/proxy/" + DefaultProxyUriManager.CHAINED_PARAMS_TOKEN + 
"/path",
         UriStatus.VALID_VERSIONED, "version");
   }
-  
+
   private void checkValidate(String path, UriStatus status, String version) 
throws Exception {
     String host = "host.com";
     // Pass null for status if version is null, since null version shouldn't 
result
@@ -286,7 +287,7 @@ public class DefaultProxyUriManagerTest 
     assertEquals(false, proxyUri.isDebug());
     assertEquals(false, proxyUri.isNoCache());
   }
-  
+
   @Test
   public void containerFallsBackToSynd() throws Exception {
     String host = "host.com";
@@ -306,7 +307,7 @@ public class DefaultProxyUriManagerTest 
     assertEquals(false, proxyUri.isDebug());
     assertEquals(false, proxyUri.isNoCache());
   }
-  
+
   @Test(expected = GadgetException.class)
   public void mismatchedHostStrict() throws Exception {
     String host = "host.com";
@@ -317,7 +318,7 @@ public class DefaultProxyUriManagerTest 
         .addQueryParameter(Param.URL.getKey(), "http://foo.com";).toUri();
     manager.process(testUri);
   }
-  
+
   @Test
   public void mismatchedHostNonStrict() throws Exception {
     String host = "host.com";
@@ -328,7 +329,7 @@ public class DefaultProxyUriManagerTest 
         .addQueryParameter(Param.CONTAINER.getKey(), CONTAINER).toUri();
     manager.process(testUri);
   }
-  
+
   @Test(expected = GadgetException.class)
   public void missingContainerParamQuery() throws Exception {
     String host = "host.com";
@@ -338,7 +339,7 @@ public class DefaultProxyUriManagerTest 
         .addQueryParameter(Param.URL.getKey(), "http://foo.com";).toUri();
     manager.process(testUri);
   }
-  
+
   @Test(expected = GadgetException.class)
   public void missingContainerParamChained() throws Exception {
     String host = "host.com";
@@ -348,7 +349,7 @@ public class DefaultProxyUriManagerTest 
         "/proxy/refresh=123/path/http://foo.com";).toUri();
     manager.process(testUri);
   }
-  
+
   @Test(expected = GadgetException.class)
   public void missingUrlQuery() throws Exception {
     String host = "host.com";
@@ -358,7 +359,7 @@ public class DefaultProxyUriManagerTest 
         .addQueryParameter(Param.CONTAINER.getKey(), CONTAINER).toUri();
     manager.process(testUri);
   }
-  
+
   @Test(expected = GadgetException.class)
   public void missingUrlChained() throws Exception {
     String host = "host.com";
@@ -369,7 +370,7 @@ public class DefaultProxyUriManagerTest 
         CONTAINER + "/path/").toUri();
     manager.process(testUri);
   }
-  
+
   @Test(expected = GadgetException.class)
   public void invalidUrlParamQuery() throws Exception {
     // Only test query style, since chained style should be impossible.
@@ -386,7 +387,7 @@ public class DefaultProxyUriManagerTest 
       List<Uri> resources, String... version) {
     return makeAndGetWithRefresh(host, path, debug, noCache, resources, 123, 
version);
   }
-  
+
   private List<Uri> makeAndGetWithRefresh(String host, String path, boolean 
debug,
       boolean noCache, List<Uri> resources, Integer refresh, String... 
version) {
     ProxyUriManager.Versioner versioner = makeVersioner(null, version);
@@ -400,7 +401,7 @@ public class DefaultProxyUriManagerTest 
       String host, String path) throws Exception {
     verifyQueryUriWithRefresh(orig, uri, debug, noCache, version, 123, host, 
path);
   }
-  
+
   private void verifyQueryUriWithRefresh(Uri orig, Uri uri, boolean debug, 
boolean noCache,
       String version, Integer refresh, String host, String path) throws 
Exception {
     // Make sure the manager can parse out results.
@@ -412,7 +413,7 @@ public class DefaultProxyUriManagerTest 
     assertEquals(noCache ? Integer.valueOf(0) : refresh, 
proxyUri.getRefresh());
     assertEquals(CONTAINER, proxyUri.getContainer());
     assertEquals(SPEC_URI.toString(), proxyUri.getGadget());
-    
+
     // "Raw" query param verification.
     assertEquals(noCache || refresh == null ? null : refresh.toString(),
         uri.getQueryParameter(Param.REFRESH.getKey()));
@@ -433,24 +434,68 @@ public class DefaultProxyUriManagerTest 
     assertEquals(noCache ? 0 : 123, (int)proxyUri.getRefresh());
     assertEquals(CONTAINER, proxyUri.getContainer());
     assertEquals(SPEC_URI.toString(), proxyUri.getGadget());
-    
+
     // URI should end with the proxied content.
     String uriStr = uri.toString();
     assertTrue(uriStr.endsWith(orig.toString()));
-    
+
     int proxyEnd = uriStr.indexOf("/proxy/") + "/proxy/".length();
     String paramsUri = uriStr.substring(
         proxyEnd,
         (endOfPath ? uriStr.indexOf('/', proxyEnd) : uriStr.indexOf("/path")));
     uri = new UriBuilder().setQuery(paramsUri).toUri();
-    
+
     // "Raw" query param verification.
     assertEquals(noCache ? null : "123", 
uri.getQueryParameter(Param.REFRESH.getKey()));
     if (version != null) {
       assertEquals(version, uri.getQueryParameter(Param.VERSION.getKey()));
     }
   }
-  
+
+  @Test
+  public void testProxyGadgetsChainDecode() throws Exception {
+    String host = "host.com";
+    String path = "/proxy/" + DefaultProxyUriManager.CHAINED_PARAMS_TOKEN;
+    DefaultProxyUriManager uriManager = makeManager(host, path, null);
+    Uri uri = 
Uri.parse("http://host.com/gadgets/proxy/refresh%3d55%26container%3dcontainer/";
+        + "http://www.cnn.com/news?refresh=45";);
+    ProxyUri pUri = uriManager.process(uri);
+    assertEquals(new Integer(55), pUri.getRefresh());
+    assertEquals("http://www.cnn.com/news?refresh=45";, 
pUri.getResource().toString());
+    assertEquals(CONTAINER, pUri.getContainer());
+  }
+
+  @Test
+  public void testProxyGadgetsChainDecodeGif() throws Exception {
+    String host = "host.com";
+    String path = "/proxy/" + DefaultProxyUriManager.CHAINED_PARAMS_TOKEN;
+    DefaultProxyUriManager uriManager = makeManager(host, path, null);
+    Uri uri = 
Uri.parse("http://host.com/gadgets/proxy/container%3dcontainer%26"; +
+        "gadget%3dhttp%3A%2F%2Fwww.orkut.com%2Fcss%2Fgen%2Fbase054.css.int%26" 
+
+        
"debug%3d0%26nocache%3d0/http://www.orkut.com/img/castro/i%5freply.gif";);
+    ProxyUri pUri = uriManager.process(uri);
+    assertEquals(false, pUri.isDebug());
+    assertEquals("http://www.orkut.com/img/castro/i%5freply.gif";, 
pUri.getResource().toString());
+    assertEquals(CONTAINER, pUri.getContainer());
+    assertEquals("http://www.orkut.com/css/gen/base054.css.int";, 
pUri.getGadget());
+  }
+
+  @Test
+  public void testProxyGadgetsChainGif() throws Exception {
+
+    String host = "host.com";
+    String path = "/proxy/" + DefaultProxyUriManager.CHAINED_PARAMS_TOKEN;
+    DefaultProxyUriManager uriManager = makeManager(host, path, null);
+    Uri uri = Uri.parse("http://host.com/gadgets/proxy/container=container&"; +
+        "gadget=http%3A%2F%2Fwww.orkut.com%2Fcss%2Fgen%2Fbase054.css.int&" +
+        "debug=0&nocache=0/http://www.orkut.com/img/castro/i_reply.gif";);
+    ProxyUri pUri = uriManager.process(uri);
+    assertEquals(false, pUri.isDebug());
+    assertEquals("http://www.orkut.com/img/castro/i_reply.gif";, 
pUri.getResource().toString());
+    assertEquals(CONTAINER, pUri.getContainer());
+    assertEquals("http://www.orkut.com/css/gen/base054.css.int";, 
pUri.getGadget());
+  }
+
   private DefaultProxyUriManager makeManager(String host, String path,
       ProxyUriManager.Versioner versioner) {
     ContainerConfig config = createMock(ContainerConfig.class);
@@ -461,7 +506,7 @@ public class DefaultProxyUriManagerTest 
     replay(config);
     return new DefaultProxyUriManager(config, versioner);
   }
-  
+
   @SuppressWarnings("unchecked")
   private ProxyUriManager.Versioner makeVersioner(UriStatus status, String... 
versions) {
     ProxyUriManager.Versioner versioner = 
createMock(ProxyUriManager.Versioner.class);


Reply via email to