You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by li...@apache.org on 2011/06/09 01:14:53 UTC

svn commit: r1133596 - in /shindig/trunk: config/ java/common/src/main/java/org/apache/shindig/common/ java/common/src/main/java/org/apache/shindig/common/servlet/ java/common/src/test/java/org/apache/shindig/common/servlet/ java/gadgets/src/main/java/...

Author: lindner
Date: Wed Jun  8 23:14:52 2011
New Revision: 1133596

URL: http://svn.apache.org/viewvc?rev=1133596&view=rev
Log:
SHINDIG-1541 | Patch from Li Xu | Create default AuthorityProvider to support host/port

Added:
    shindig/trunk/java/common/src/main/java/org/apache/shindig/common/servlet/Authority.java
    shindig/trunk/java/common/src/main/java/org/apache/shindig/common/servlet/BasicAuthority.java
    shindig/trunk/java/common/src/main/java/org/apache/shindig/common/servlet/BasicAuthorityProvider.java
    shindig/trunk/java/common/src/test/java/org/apache/shindig/common/servlet/BasicAuthorityProviderTest.java
Modified:
    shindig/trunk/config/container.js
    shindig/trunk/java/common/src/main/java/org/apache/shindig/common/PropertiesModule.java
    shindig/trunk/java/common/src/main/java/org/apache/shindig/common/servlet/GuiceServletContextListener.java
    shindig/trunk/java/common/src/main/java/org/apache/shindig/common/servlet/HostFilter.java
    shindig/trunk/java/common/src/main/java/org/apache/shindig/common/servlet/ServletRequestContext.java
    shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/DefaultGuiceModule.java
    shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/uri/DefaultConcatUriManager.java
    shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/uri/DefaultIframeUriManager.java
    shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/uri/DefaultJsUriManager.java
    shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/uri/DefaultProxyUriManager.java
    shindig/trunk/java/server/src/main/webapp/WEB-INF/web.xml

Modified: shindig/trunk/config/container.js
URL: http://svn.apache.org/viewvc/shindig/trunk/config/container.js?rev=1133596&r1=1133595&r2=1133596&view=diff
==============================================================================
--- shindig/trunk/config/container.js (original)
+++ shindig/trunk/config/container.js Wed Jun  8 23:14:52 2011
@@ -103,13 +103,13 @@
 //"gadgets.securityTokenKeyFile" : "/path/to/key/file.txt",
 
 // URI for the default shindig test instance.
-"defaultShindigTestHost": "http://${SERVER_HOST}:${SERVER_PORT}",
-//"defaultShindigTestHost":"http://%host%",
+//"defaultShindigTestHost": "http://${SERVER_HOST}:${SERVER_PORT}",
+"defaultShindigTestHost":"http://%authority%",
 
 
 // Authority (host:port without scheme) for the proxy and concat servlets.
-"defaultShindigProxyConcatAuthority": "${SERVER_HOST}:${SERVER_PORT}",
-//"defaultShindigProxyConcatAuthority":"%host%",
+//"defaultShindigProxyConcatAuthority": "${SERVER_HOST}:${SERVER_PORT}",
+"defaultShindigProxyConcatAuthority":"%authority%",
 
 // OS 2.0 Gadget DOCTYPE: used in Gadgets with @specificationVersion 2.0 or greater and
 // quirksmode on Gadget has not been set.

Modified: shindig/trunk/java/common/src/main/java/org/apache/shindig/common/PropertiesModule.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/PropertiesModule.java?rev=1133596&r1=1133595&r2=1133596&view=diff
==============================================================================
--- shindig/trunk/java/common/src/main/java/org/apache/shindig/common/PropertiesModule.java (original)
+++ shindig/trunk/java/common/src/main/java/org/apache/shindig/common/PropertiesModule.java Wed Jun  8 23:14:52 2011
@@ -57,7 +57,7 @@ public class PropertiesModule extends Ab
 
   @Override
   protected void configure() {
-	this.binder().bindConstant().annotatedWith(Names.named("shindig.contextroot")).to(getContextRoot());
+    this.binder().bindConstant().annotatedWith(Names.named("shindig.contextroot")).to(getContextRoot());
     Names.bindProperties(this.binder(), getProperties());
     // This could be generalized to inject any system property...
     this.binder().bindConstant().annotatedWith(Names.named("shindig.port")).to(getServerPort());
@@ -70,30 +70,23 @@ public class PropertiesModule extends Ab
    * @return an context path as a string.
    */
   private String getContextRoot() {
-	  return System.getProperty("shindig.contextroot") != null ? System.getProperty("shindig.contextroot") : "";
+    return System.getProperty("shindig.contextroot") != null ? System.getProperty("shindig.contextroot") : "";
   }
 
   /**
-   * Should return the port that the current server is running on.  Useful for testing and working out of the box configs.
-   * Looks for a port in system properties "shindig.port" then "jetty.port", if not set uses fixed value of "8080"
+   * Should return the default port set as system property. Return empty string if it's not set.
    * @return an integer port number as a string.
    */
   protected String getServerPort() {
-    return System.getProperty("shindig.port") != null ? System.getProperty("shindig.port") :
-           System.getProperty("jetty.port") != null ? System.getProperty("jetty.port") :
-           "8080";
+    return System.getProperty("shindig.port") != null ? System.getProperty("shindig.port") : "";
   }
 
   /*
-   * Should return the hostname that the current server is running on.  Useful for testing and working out of the box configs.
-   * Looks for a hostname in system properties "shindig.host", if not set uses fixed value of "localhost"
+   * Should return the hostname set as system property. Return empty string  if its' not set. 
    * @return a hostname
    */
-
   protected String getServerHostname() {
-    return System.getProperty("shindig.host") != null ? System.getProperty("shindig.host") :
-           System.getProperty("jetty.host") != null ? System.getProperty("jetty.host") :
-           "localhost";
+    return System.getProperty("shindig.host") != null ? System.getProperty("shindig.host") : "";
   }
 
   protected static String getDefaultPropertiesPath() {
@@ -114,13 +107,12 @@ public class PropertiesModule extends Ab
       properties.load(is);
       
       String value = null;
-      for(Object key : properties.keySet()){
+      for (Object key : properties.keySet()) {
         value = (String)properties.get((String)key);
-    	if (value != null && value.indexOf("%contextRoot%") >=0 ){
+        if (value != null && value.indexOf("%contextRoot%") >=0 ){
           properties.put(key, value.replace(("%contextRoot%"),contextRoot));
-    	}
+        }
       }
-
     } catch (IOException e) {
       throw new CreationException(Arrays.asList(
           new Message("Unable to load properties: " + propertyFile)));

Added: shindig/trunk/java/common/src/main/java/org/apache/shindig/common/servlet/Authority.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/servlet/Authority.java?rev=1133596&view=auto
==============================================================================
--- shindig/trunk/java/common/src/main/java/org/apache/shindig/common/servlet/Authority.java (added)
+++ shindig/trunk/java/common/src/main/java/org/apache/shindig/common/servlet/Authority.java Wed Jun  8 23:14:52 2011
@@ -0,0 +1,38 @@
+/*
+ * 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.common.servlet;
+
+/**
+ * Interface to return Authority and Origin of a hierarchical URI . Shindig server components
+ * would use the information to construct URI.
+ *
+ */
+public interface Authority {
+
+  /**
+   * The authority part of the hierarchical URI. Eg "localhost:8080"
+   * @return the authority part of the hierarchical URI
+   */
+  public String getAuthority();
+
+  /**
+   * The scheme and authority part of the hierarchical URI. Eg "http://localhost:8080"
+   * @return the scheme and authority part of the hierarchical URI
+   */
+  public String getOrigin();
+}

Added: shindig/trunk/java/common/src/main/java/org/apache/shindig/common/servlet/BasicAuthority.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/servlet/BasicAuthority.java?rev=1133596&view=auto
==============================================================================
--- shindig/trunk/java/common/src/main/java/org/apache/shindig/common/servlet/BasicAuthority.java (added)
+++ shindig/trunk/java/common/src/main/java/org/apache/shindig/common/servlet/BasicAuthority.java Wed Jun  8 23:14:52 2011
@@ -0,0 +1,76 @@
+/*
+ * 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.common.servlet;
+
+import org.apache.shindig.common.Nullable;
+import org.apache.shindig.common.servlet.ServletRequestContext;
+
+import com.google.inject.Inject;
+import com.google.inject.name.Named;
+
+import com.google.common.base.Joiner;
+import com.google.common.base.Objects;
+import com.google.common.base.Strings;
+
+/**
+ * Basic implementation for Authority Interface.
+ *
+ * Authority information is calculated based on following procedure.
+ * 1. Optionally default host and default port can be provided as ServletContext Parameters in web.xml. Once it's provided,
+ *    default host and default port are used to construct authority information.
+ * 2. If default host and default port are not provided, host and port from current HttpServletRequest will be used if available.
+ * 3. If HttpServletRequest is not available, jetty host/port will be used. This is required for junit tests.
+ */
+public class BasicAuthority implements Authority {
+  private String host;
+  private String port;
+  public final static String JETTY_HOST = "jetty.host";
+  public final static String JETTY_PORT = "jetty.port";
+
+  @Inject
+  public BasicAuthority(@Nullable @Named("shindig.host") String defaultHost,
+      @Nullable @Named("shindig.port") String defaultPort) {
+    if (!Strings.isNullOrEmpty(defaultHost)) {
+      this.host = defaultHost;
+    }
+    if (!Strings.isNullOrEmpty(defaultPort)) {
+      this.port = defaultPort;
+    }
+  }
+
+  public String getAuthority() {
+    return Joiner.on(':').join(
+        Objects.firstNonNull(host, getServerHostname()),
+        Objects.firstNonNull(port, getServerPort()));
+  }
+
+  public String getOrigin(){
+    return Objects.firstNonNull(ServletRequestContext.getScheme(), "http")
+        "://" + getAuthority();
+  }
+
+  private String getServerPort() {
+    return Objects.firstNonNull(ServletRequestContext.getPort(),
+        Objects.firstNonNull(System.getProperty(JETTY_PORT), "8080"));
+  }
+
+  private String getServerHostname() {
+    return Objects.firstNonNull(ServletRequestContext.getHost(),
+        Objects.firstNonNull(System.getProperty(JETTY_HOST), "localhost"));
+  }
+}

Added: shindig/trunk/java/common/src/main/java/org/apache/shindig/common/servlet/BasicAuthorityProvider.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/servlet/BasicAuthorityProvider.java?rev=1133596&view=auto
==============================================================================
--- shindig/trunk/java/common/src/main/java/org/apache/shindig/common/servlet/BasicAuthorityProvider.java (added)
+++ shindig/trunk/java/common/src/main/java/org/apache/shindig/common/servlet/BasicAuthorityProvider.java Wed Jun  8 23:14:52 2011
@@ -0,0 +1,55 @@
+/*
+ * 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.common.servlet;
+
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+import com.google.inject.Singleton;
+import com.google.inject.name.Named;
+
+import org.apache.shindig.common.Nullable;
+
+
+/**
+ * Simple provider of Authority information.
+ * Optionally default host and default port can be provided as ServletContext Parameters in web.xml.
+ * If default host/port are not provided, host/port from Current HttpServletRequest will be used if available.
+ * If HttpServletRequest is not available, jetty host/port will be used.
+ */
+@Singleton
+public  class BasicAuthorityProvider implements Provider<Authority> {
+
+  private  final BasicAuthority basicAuthority;
+
+  @Inject
+  public BasicAuthorityProvider(BasicAuthority basicAuthority) {
+    this.basicAuthority = basicAuthority;
+  }
+
+  /**
+   * Constructor for test purpose
+   *
+   */
+  public BasicAuthorityProvider(String host, String port) {
+    this.basicAuthority = new BasicAuthority(host, port);
+  }
+
+  public Authority get() {
+    return basicAuthority;
+  }
+}

Modified: shindig/trunk/java/common/src/main/java/org/apache/shindig/common/servlet/GuiceServletContextListener.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/servlet/GuiceServletContextListener.java?rev=1133596&r1=1133595&r2=1133596&view=diff
==============================================================================
--- shindig/trunk/java/common/src/main/java/org/apache/shindig/common/servlet/GuiceServletContextListener.java (original)
+++ shindig/trunk/java/common/src/main/java/org/apache/shindig/common/servlet/GuiceServletContextListener.java Wed Jun  8 23:14:52 2011
@@ -46,16 +46,16 @@ public class GuiceServletContextListener
 
   // From guice-servlet-2.0
   public static final String INJECTOR_NAME = Injector.class.getName();
-  
+
   // HNN- constant name matched system.properties <contextparam> specified in the web.xml
   private static final String SYSTEM_PROPERTIES = "system.properties";
 
   public void contextInitialized(ServletContextEvent event) {
     ServletContext context = event.getServletContext();
-    setSystemProperties(context);     
+    setSystemProperties(context);
     String moduleNames = context.getInitParameter(MODULES_ATTRIBUTE);
     List<Module> modules = Lists.newLinkedList();
-    
+
     if (moduleNames != null) {
       for (String moduleName : Splitter.on(':').split(moduleNames)) {
         try {

Modified: shindig/trunk/java/common/src/main/java/org/apache/shindig/common/servlet/HostFilter.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/servlet/HostFilter.java?rev=1133596&r1=1133595&r2=1133596&view=diff
==============================================================================
--- shindig/trunk/java/common/src/main/java/org/apache/shindig/common/servlet/HostFilter.java (original)
+++ shindig/trunk/java/common/src/main/java/org/apache/shindig/common/servlet/HostFilter.java Wed Jun  8 23:14:52 2011
@@ -36,7 +36,7 @@ import javax.servlet.ServletResponse;
  * A Filter that can cache ServletRequest information in ThreadLocal variable
  */
 public class HostFilter implements Filter {
-  
+
   public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {	
     ServletRequestContext.setRequestInfo(request);
     chain.doFilter(request, response);

Modified: shindig/trunk/java/common/src/main/java/org/apache/shindig/common/servlet/ServletRequestContext.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/servlet/ServletRequestContext.java?rev=1133596&r1=1133595&r2=1133596&view=diff
==============================================================================
--- shindig/trunk/java/common/src/main/java/org/apache/shindig/common/servlet/ServletRequestContext.java (original)
+++ shindig/trunk/java/common/src/main/java/org/apache/shindig/common/servlet/ServletRequestContext.java Wed Jun  8 23:14:52 2011
@@ -16,90 +16,55 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.shindig.common.servlet;
 
+import com.google.common.base.Objects;
+
 import javax.servlet.ServletRequest;
 
 public class ServletRequestContext {
 
-  public static void setRequestInfo(ServletRequest req) {
-    String auth = req.getServerName() + ":" + req.getServerPort();
-	String fullAuth = req.getScheme() + "://" + auth;
-	authority.set(auth);
-	fullAuthority.set(fullAuth);
+  public final static String HOST = "host";
+  public final static String PORT = "port";
+  public final static String SCHEME = "scheme";
 
-	System.setProperty("authority",auth);
-	System.setProperty("fullAuthority", fullAuth);
+  public static void setRequestInfo(ServletRequest req) {
+    host.set(req.getServerName());
+    port.set("" + req.getServerPort());
+    scheme.set(req.getScheme());
+
+    // Temporary solution since variables are not available in forked thread during js processing
+    System.setProperty(HOST, req.getServerName());
+    System.setProperty(PORT, "" + req.getServerPort());
+    System.setProperty(SCHEME, req.getScheme());
   }
   
   /**
-   * A Thread Local holder for authority -- host + port
+   * A Thread Local holder for host
    */
-  private static ThreadLocal<String> authority = new ThreadLocal<String>();
+  private static ThreadLocal<String> host = new ThreadLocal<String>();
   
   /**
-   * A Thread Local holder for full authority -- scheme + host + port
+   * A Thread Local holder for port
    */
-  private static ThreadLocal<String> fullAuthority = new ThreadLocal<String>();
+  private static ThreadLocal<String> port = new ThreadLocal<String>();
   
- 
-  public static String getAuthority() {
+  /**
+   * A Thread Local holder for scheme
+   */
+  private static ThreadLocal<String> scheme = new ThreadLocal<String>();
   
-    String retVal = authority.get();
-    if (retVal == null) {
-      retVal = System.getProperty("authority");
-      if (retVal == null){
-    	retVal = getDefaultAuthority();
-      }
-    }
-    return retVal;
-  }
- 
-  private static String getDefaultAuthority() {
-    
-    String retVal = System.getProperty("defaultAuthority");
-	if (retVal == null){
-	  retVal = getServerHostname()+":"+getServerPort();
-	  System.setProperty("defaultAuthority", retVal);
-	}
-	return retVal;
-	
-  }
-
-  public static String getFullAuthority() {
- 
-  	String retVal = fullAuthority.get();
-    if (retVal == null) {
-      retVal = System.getProperty("fullAuthority");
-      if (retVal == null){
-        retVal = getDefaultFullAuthority();
-  	  }
-  	}
-    return retVal;
-    
-  }
   
-  private static String getDefaultFullAuthority() {
-	  
-    String retVal = System.getProperty("defaultFullAuthority");
-    if ( retVal != null ){
-	  retVal = "http://"+getServerHostname()+":"+getServerPort();
-	  System.setProperty("defaultFullAuthority", retVal);
-	}
-	return retVal;
-	
+  public static String getHost(){
+    return host.get() != null ? host.get() : System.getProperty(HOST);
   }
   
-  private static String getServerPort() {
-	return System.getProperty("shindig.port") != null ? System.getProperty("shindig.port") :
-	  System.getProperty("jetty.port") != null ? System.getProperty("jetty.port") :
-	  "8080";
+  public static String getPort(){
+    return port.get() != null ? port.get() : System.getProperty(PORT);
   }
   
-  private static String getServerHostname() {
-	return System.getProperty("shindig.host") != null ? System.getProperty("shindig.host") :
-	  System.getProperty("jetty.host") != null ? System.getProperty("jetty.host") :
-	  "localhost";
+  public static String getScheme(){
+    return scheme.get() != null ? scheme.get() : System.getProperty(SCHEME);
   }
-
 }

Added: shindig/trunk/java/common/src/test/java/org/apache/shindig/common/servlet/BasicAuthorityProviderTest.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/servlet/BasicAuthorityProviderTest.java?rev=1133596&view=auto
==============================================================================
--- shindig/trunk/java/common/src/test/java/org/apache/shindig/common/servlet/BasicAuthorityProviderTest.java (added)
+++ shindig/trunk/java/common/src/test/java/org/apache/shindig/common/servlet/BasicAuthorityProviderTest.java Wed Jun  8 23:14:52 2011
@@ -0,0 +1,59 @@
+/*
+ * 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.common.servlet;
+
+import org.apache.shindig.common.EasyMockTestCase;
+
+import org.junit.Test;
+
+import org.apache.shindig.common.servlet.BasicAuthorityProvider;
+
+/**
+ * Simple test for AuthorityProvider.
+ */
+public class BasicAuthorityProviderTest extends EasyMockTestCase {
+
+  @Test
+  public void testProviderWorks() {
+    String host = "myhost";
+    String port = "9080";
+    BasicAuthorityProvider provider = new BasicAuthorityProvider(host,port);
+    assertEquals( "myhost:9080", provider.get().getAuthority());
+  }
+
+  @Test
+  public void testDefaultHostAndPort() {
+	String host = "";
+	String port = "";
+	BasicAuthorityProvider provider = new BasicAuthorityProvider(host,port);
+	assertEquals("localhost:8080", provider.get().getAuthority() );
+  }
+
+  @Test
+  public void testJettyHostAndPort() {
+	String host = "";
+	String port = "";
+	System.setProperty("jetty.host", "localhost");
+	System.setProperty("jetty.port", "9003");
+	BasicAuthorityProvider provider = new BasicAuthorityProvider(host,port);
+	assertEquals("localhost:9003", provider.get().getAuthority() );
+	System.clearProperty("jetty.host");
+	System.clearProperty("jetty.port");
+  }
+
+}

Modified: shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/DefaultGuiceModule.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/DefaultGuiceModule.java?rev=1133596&r1=1133595&r2=1133596&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/DefaultGuiceModule.java (original)
+++ shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/DefaultGuiceModule.java Wed Jun  8 23:14:52 2011
@@ -23,6 +23,7 @@ import com.google.common.collect.Immutab
 
 import com.google.inject.AbstractModule;
 import com.google.inject.Inject;
+import com.google.inject.Provider;
 import com.google.inject.Provides;
 import com.google.inject.Singleton;
 import com.google.inject.multibindings.Multibinder;
@@ -46,6 +47,9 @@ import org.apache.shindig.gadgets.templa
 import org.apache.shindig.gadgets.uri.ProxyUriBase;
 import org.apache.shindig.gadgets.uri.UriModule;
 
+import org.apache.shindig.common.servlet.Authority;
+import org.apache.shindig.common.servlet.BasicAuthorityProvider;
+
 import org.apache.shindig.gadgets.variables.SubstituterModule;
 
 import java.util.List;
@@ -67,6 +71,8 @@ public class DefaultGuiceModule extends 
     bind(ExecutorService.class).to(ShindigExecutorService.class);
     bind(Executor.class).annotatedWith(Names.named("shindig.concat.executor")).to(ShindigExecutorService.class);
 
+    bind(Authority.class).toProvider(BasicAuthorityProvider.class);
+
     bindConstant().annotatedWith(Names.named("shindig.jsload.ttl-secs")).to(60 * 60); // 1 hour
     bindConstant().annotatedWith(Names.named("shindig.jsload.require-onload-with-jsload")).to(true);
 

Modified: shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/uri/DefaultConcatUriManager.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/uri/DefaultConcatUriManager.java?rev=1133596&r1=1133595&r2=1133596&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/uri/DefaultConcatUriManager.java (original)
+++ shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/uri/DefaultConcatUriManager.java Wed Jun  8 23:14:52 2011
@@ -25,11 +25,13 @@ import com.google.inject.Provider;
 import com.google.inject.name.Named;
 
 import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.shindig.common.servlet.Authority;
 import org.apache.shindig.common.uri.Uri;
 import org.apache.shindig.common.uri.UriBuilder;
 import org.apache.shindig.config.ContainerConfig;
 import org.apache.shindig.gadgets.uri.UriCommon.Param;
 
+
 // Temporary replacement of javax.annotation.Nullable
 import org.apache.shindig.common.Nullable;
 
@@ -54,7 +56,7 @@ public class DefaultConcatUriManager imp
   private final ContainerConfig config;
   private final Versioner versioner;
   private boolean strictParsing;
-  private Provider<String> hostProvider;
+  private Provider<Authority> hostProvider;
   private static int DEFAULT_URL_MAX_LENGTH = 2048;
   private int urlMaxLength = DEFAULT_URL_MAX_LENGTH;
   private static final float URL_LENGTH_BUFFER_MARGIN = .8f;
@@ -76,9 +78,9 @@ public class DefaultConcatUriManager imp
       @Named("org.apache.shindig.gadgets.uri.urlMaxLength") int urlMaxLength) {
     this.urlMaxLength = urlMaxLength;
   }
-  
+
   @Inject(optional = true)
-  public void setHostProvider(@Named("shindig.host-provider") Provider<String> hostProvider) {
+  public void setHostProvider(Provider<Authority> hostProvider) {
     this.hostProvider = hostProvider;
   }
 
@@ -117,7 +119,7 @@ public class DefaultConcatUriManager imp
 
     List<Uri> resourceUris = ctx.getBatch();
     Map<Uri, String> snippets = Maps.newHashMapWithExpectedSize(resourceUris.size());
-    
+
     String splitParam = config.getString(ctx.getContainer(), CONCAT_JS_SPLIT_PARAM);
 
     boolean doSplit = false;
@@ -135,7 +137,7 @@ public class DefaultConcatUriManager imp
     // batchUris holds uris for the current batch of uris being concatenated.
     List<Uri> batchUris = Lists.newArrayList();
 
-    // uris holds the concatenated uris formed from batches which satisfy the 
+    // uris holds the concatenated uris formed from batches which satisfy the
     // GET URL limit constraint.
     List<Uri> uris = Lists.newArrayList();
 
@@ -231,7 +233,7 @@ public class DefaultConcatUriManager imp
           "Missing required config '" + key + "' for container: " + container);
     }
     if (hostProvider != null) {
-      val = val.replace("%host%", hostProvider.get());
+      val = val.replace("%authority%", hostProvider.get().getAuthority());
     }
 
     return val;

Modified: shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/uri/DefaultIframeUriManager.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/uri/DefaultIframeUriManager.java?rev=1133596&r1=1133595&r2=1133596&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/uri/DefaultIframeUriManager.java (original)
+++ shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/uri/DefaultIframeUriManager.java Wed Jun  8 23:14:52 2011
@@ -38,6 +38,8 @@ import org.apache.shindig.gadgets.spec.U
 import org.apache.shindig.gadgets.spec.View;
 import org.apache.shindig.gadgets.uri.UriCommon.Param;
 
+import org.apache.shindig.common.servlet.Authority;
+
 import java.util.Collection;
 import java.util.List;
 import java.util.Set;
@@ -58,7 +60,7 @@ public class DefaultIframeUriManager imp
   private boolean ldEnabled = true;
   private TemplatingSignal tplSignal = null;
   private Versioner versioner = null;
-  private Provider<String> hostProvider;
+  private Provider<Authority> hostProvider;
 
   private final ContainerConfig config;
   private final LockedDomainPrefixGenerator ldGen;
@@ -104,9 +106,9 @@ public class DefaultIframeUriManager imp
   public void setTemplatingSignal(TemplatingSignal tplSignal) {
     this.tplSignal = tplSignal;
   }
-  
+
   @Inject(optional = true)
-  public void setHostProvider(@Named("shindig.host-provider") Provider<String> hostProvider) {
+  public void setHostProvider( Provider<Authority> hostProvider) {
     this.hostProvider = hostProvider;
   }
 
@@ -349,13 +351,13 @@ public class DefaultIframeUriManager imp
 
   private String getReqVal(String container, String key) {
     String val = config.getString(container, key);
- 
+
     if (val == null) {
       throw new RuntimeException("Missing required container config param, key: "
           + key + ", container: " + container);
     }
     if (hostProvider != null) {
-      val = val.replace("%host%", hostProvider.get());
+      val = val.replace("%authority%", hostProvider.get().getAuthority());
     }
 
     return val;

Modified: shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/uri/DefaultJsUriManager.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/uri/DefaultJsUriManager.java?rev=1133596&r1=1133595&r2=1133596&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/uri/DefaultJsUriManager.java (original)
+++ shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/uri/DefaultJsUriManager.java Wed Jun  8 23:14:52 2011
@@ -34,6 +34,8 @@ import org.apache.shindig.gadgets.JsComp
 import org.apache.shindig.gadgets.http.HttpResponse;
 import org.apache.shindig.gadgets.uri.UriCommon.Param;
 
+import org.apache.shindig.common.servlet.Authority;
+
 import java.util.Collection;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -42,7 +44,7 @@ import java.util.logging.Logger;
  * Generates and validates URLs serviced by a gadget JavaScript service (JsServlet).
  */
 public class DefaultJsUriManager implements JsUriManager {
-  
+
   static final String JS_HOST_PARAM = "gadgets.uri.js.host";
   static final String JS_PATH_PARAM = "gadgets.uri.js.path";
   static final JsUri INVALID_URI = new JsUri(UriStatus.BAD_URI);
@@ -50,19 +52,19 @@ public class DefaultJsUriManager impleme
   protected static final String JS_DELIMITER = ":";
 
   private static final Logger LOG = Logger.getLogger(DefaultJsUriManager.class.getName());
-  
+
   private final ContainerConfig config;
   private final Versioner versioner;
-  private Provider<String> hostProvider;
+  private Provider<Authority> hostProvider;
 
   @Inject
   public DefaultJsUriManager(ContainerConfig config, Versioner versioner) {
     this.config = config;
     this.versioner = versioner;
   }
-  
+
   @Inject(optional = true)
-  public void setHostProvider(@Named("shindig.host-provider") Provider<String> hostProvider) {
+  public void setHostProvider(Provider<Authority> hostProvider) {
     this.hostProvider = hostProvider;
   }
 
@@ -80,12 +82,12 @@ public class DefaultJsUriManager impleme
       jsPath.append('/');
     }
     jsPath.append(addJsLibs(ctx.getLibs()));
-    
+
     // Add the list of already-loaded libs
     if (!ctx.getLoadedLibs().isEmpty()) {
       jsPath.append("!").append(addJsLibs(ctx.getLoadedLibs()));
     }
-    
+
     jsPath.append(JS_SUFFIX);
     uri.setPath(jsPath.toString());
 
@@ -189,7 +191,7 @@ public class DefaultJsUriManager impleme
 
     String[] splits = path.split("!");
     Collection<String> libs = getJsLibs(splits.length >= 1 ? splits[0] : "");
-    
+
     String haveString = (splits.length >= 2 ? splits[1] : "");
     String haveQueryParam = uri.getQueryParameter(Param.LOADED.getKey());
     if (haveQueryParam == null) {
@@ -200,7 +202,7 @@ public class DefaultJsUriManager impleme
     }
     haveString = haveString + JS_DELIMITER + haveQueryParam;
     Collection<String> have = getJsLibs(haveString);
-    
+
     UriStatus status = UriStatus.VALID_UNVERSIONED;
     String version = uri.getQueryParameter(Param.VERSION.getKey());
     if (version != null && versioner != null) {
@@ -231,7 +233,7 @@ public class DefaultJsUriManager impleme
       }
     }
     if (hostProvider != null) {
-      ret = ret.replace("%host%", hostProvider.get());
+      ret = ret.replace("%authority%", hostProvider.get().getAuthority());
     }
     return ret;
   }

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=1133596&r1=1133595&r2=1133596&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 Wed Jun  8 23:14:52 2011
@@ -34,6 +34,8 @@ import org.apache.shindig.gadgets.Gadget
 import org.apache.shindig.gadgets.http.HttpResponse;
 import org.apache.shindig.gadgets.uri.UriCommon.Param;
 
+import org.apache.shindig.common.servlet.Authority;
+
 // Temporary replacement of javax.annotation.Nullable
 import org.apache.shindig.common.Nullable;
 import java.util.Collections;
@@ -73,7 +75,7 @@ public class DefaultProxyUriManager impl
   private final ContainerConfig config;
   private final Versioner versioner;
   private boolean strictParsing = false;
-  private Provider<String> hostProvider;
+  private Provider<Authority> hostProvider;
 
   @Inject
   public DefaultProxyUriManager(ContainerConfig config,
@@ -86,9 +88,9 @@ public class DefaultProxyUriManager impl
   public void setUseStrictParsing(@Named("shindig.uri.proxy.use-strict-parsing") boolean useStrict) {
     this.strictParsing = useStrict;
   }
-  
+
   @Inject(optional = true)
-  public void setHostProvider(@Named("shindig.host-provider") Provider<String> hostProvider) {
+  public void setHostProvider(Provider<Authority> hostProvider) {
     this.hostProvider = hostProvider;
   }
 
@@ -287,7 +289,12 @@ public class DefaultProxyUriManager impl
           "container: " + container);
     }
     if (hostProvider != null) {
-      val = val.replace("%host%", hostProvider.get());
+      val = val.replace("%authority%", hostProvider.get().getAuthority());
+    }else{
+      //require this for test purpose, %host% needs to be replaced with default value eg. StyleTagProxyEmbeddedUrlsVisitorTest
+      if (val.indexOf("%authority%") >= 0){
+        val = val.replace("%authority%", "localhost:8080");
+      }
     }
     return val;
   }

Modified: shindig/trunk/java/server/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/shindig/trunk/java/server/src/main/webapp/WEB-INF/web.xml?rev=1133596&r1=1133595&r2=1133596&view=diff
==============================================================================
--- shindig/trunk/java/server/src/main/webapp/WEB-INF/web.xml (original)
+++ shindig/trunk/java/server/src/main/webapp/WEB-INF/web.xml Wed Jun  8 23:14:52 2011
@@ -43,28 +43,28 @@
     </param-value>
   </context-param>
 
-  <!-- 
+  <!--
   Syntax: <key>=<value> separated by a newline
-  
+
   system.properties specifies the environmental variables that will be set to the JVM System Properties at server startup time.
   Alternatively, you may add these values in your app server (ex: Tomcat) as
   VM arguments like this: -Dshindig.host="my.production.shindig.server.com".
-  
+
   Here are a few properties that can be set for Shindig:
   shindig.host: the server name that Shindig is deployed and running on
   shindig.port: the port number of shindig.host server
-  
+
   Make sure you escape all HTML values for the web.xml to be parsed correctly.
   -->
    <context-param>
   	<param-name>system.properties</param-name>
      <param-value>
-        shindig.host=localhost
+        shindig.host=
         shindig.port=
     	aKey=/shindig/gadgets/proxy?container=default&amp;url=    	
      </param-value>
-  </context-param>  
-  
+  </context-param>
+
   <filter>
     <filter-name>hostFilter</filter-name>
     <filter-class>org.apache.shindig.common.servlet.HostFilter</filter-class>
@@ -78,7 +78,7 @@
     <url-pattern>/rpc/*</url-pattern>
     <url-pattern>/rest/*</url-pattern>
   </filter-mapping>
-    
+
     <filter>
         <filter-name>ShiroFilter</filter-name>
         <filter-class>org.apache.shiro.web.servlet.IniShiroFilter</filter-class>
@@ -111,7 +111,7 @@
     <filter-name>authFilter</filter-name>
     <filter-class>org.apache.shindig.auth.AuthenticationServletFilter</filter-class>
   </filter>
-  
+
   <filter>
     <filter-name>etagFilter</filter-name>
     <filter-class>org.apache.shindig.gadgets.servlet.ETagFilter</filter-class>