Author: woodser
Date: Thu May 19 18:02:04 2011
New Revision: 1125023
URL: http://svn.apache.org/viewvc?rev=1125023&view=rev
Log:
Enables Shindig to run on arbitrary context root:
https://issues.apache.org/jira/browse/SHINDIG-1525
This is a very nice addition. Thanks Li.
Modified:
shindig/trunk/config/container.js
shindig/trunk/content/samplecontainer/examples/commoncontainer/assembler.js
shindig/trunk/content/samplecontainer/examples/commoncontainer/index.html
shindig/trunk/content/samplecontainer/examples/commoncontainer/viewController.js
shindig/trunk/content/samplecontainer/samplecontainer.html
shindig/trunk/content/samplecontainer/samplecontainer.js
shindig/trunk/features/src/main/javascript/features/container/gadget_holder.js
shindig/trunk/features/src/main/javascript/features/shindig.container/feature.xml
shindig/trunk/features/src/main/javascript/features/shindig.container/shindig-container.js
shindig/trunk/features/src/main/javascript/features/shindig.uri/uri.js
shindig/trunk/java/common/conf/shindig.properties
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/config/JsonContainerConfig.java
shindig/trunk/java/common/src/main/java/org/apache/shindig/config/JsonContainerConfigLoader.java
shindig/trunk/java/common/src/test/java/org/apache/shindig/config/JsonContainerConfigLoaderTest.java
shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/SocialApiTestsGuiceModule.java
Modified: shindig/trunk/config/container.js
URL:
http://svn.apache.org/viewvc/shindig/trunk/config/container.js?rev=1125023&r1=1125022&r2=1125023&view=diff
==============================================================================
--- shindig/trunk/config/container.js (original)
+++ shindig/trunk/config/container.js Thu May 19 18:02:04 2011
@@ -69,25 +69,25 @@
// iframeBaseUri will automatically have the host inserted
// if locked domain is enabled and the implementation supports it.
// query parameters will be added.
-"gadgets.iframeBaseUri" : "/gadgets/ifr",
-"gadgets.uri.iframe.basePath" : "/gadgets/ifr",
+"gadgets.iframeBaseUri" : "${CONTEXT_ROOT}/gadgets/ifr",
+"gadgets.uri.iframe.basePath" : "${CONTEXT_ROOT}/gadgets/ifr",
// jsUriTemplate will have %host% and %js% substituted.
// No locked domain special cases, but jsUriTemplate must
// never conflict with a lockedDomainSuffix.
-"gadgets.jsUriTemplate" : "http://%host%/gadgets/js/%js%",
+"gadgets.jsUriTemplate" : "http://%host%${CONTEXT_ROOT}/gadgets/js/%js%",
//New configuration for iframeUri generation:
"gadgets.uri.iframe.lockedDomainSuffix" : "-a.example.com:8080",
"gadgets.uri.iframe.unlockedDomain" : "www.example.com:8080",
-"gadgets.uri.iframe.basePath" : "/gadgets/ifr",
+"gadgets.uri.iframe.basePath" : "${CONTEXT_ROOT}/gadgets/ifr",
"gadgets.uri.js.host" : "http://www.example.com/",
-"gadgets.uri.js.path" : "/gadgets/js",
+"gadgets.uri.js.path" : "${CONTEXT_ROOT}/gadgets/js",
// Callback URL. Scheme relative URL for easy switch between https/http.
-"gadgets.uri.oauth.callbackTemplate" : "//%host%/gadgets/oauthcallback",
+"gadgets.uri.oauth.callbackTemplate" :
"//%host%${CONTEXT_ROOT}/gadgets/oauthcallback",
// Use an insecure security token by default
"gadgets.securityTokenType" : "insecure",
@@ -95,7 +95,7 @@
// Config param to load Opensocial data for social
// preloads in data pipelining. %host% will be
// substituted with the current host.
-"gadgets.osDataUri" : "http://%host%/rpc",
+"gadgets.osDataUri" : "http://%host%${CONTEXT_ROOT}/rpc",
// Uncomment these to switch to a secure version
//
@@ -123,16 +123,16 @@
// Default Js Uri config: also must be overridden.
"gadgets.uri.js.host": "${Cur['defaultShindigTestHost']}",
-"gadgets.uri.js.path": "/gadgets/js",
+"gadgets.uri.js.path": "${CONTEXT_ROOT}/gadgets/js",
// Default concat Uri config; used for testing.
"gadgets.uri.concat.host" : "${Cur['defaultShindigProxyConcatAuthority']}",
-"gadgets.uri.concat.path" : "/gadgets/concat",
+"gadgets.uri.concat.path" : "${CONTEXT_ROOT}/gadgets/concat",
"gadgets.uri.concat.js.splitToken" : "false",
// Default proxy Uri config; used for testing.
"gadgets.uri.proxy.host" : "${Cur['defaultShindigProxyConcatAuthority']}",
-"gadgets.uri.proxy.path" : "/gadgets/proxy",
+"gadgets.uri.proxy.path" : "${CONTEXT_ROOT}/gadgets/proxy",
// This config data will be passed down to javascript. Please
// configure your object using the feature name rather than
@@ -144,18 +144,19 @@
"core.io" : {
// Note: /proxy is an open proxy. Be careful how you expose this!
// Note: Here // is replaced with the current protocol http/https
- "proxyUrl" :
"//%host%/gadgets/proxy?container=default&refresh=%refresh%&url=%url%%rewriteMime%",
- "jsonProxyUrl" : "//%host%/gadgets/makeRequest"
+ //"proxyUrl" :
"//%host%${CONTEXT_ROOT}/gadgets/proxy?container=%container%%rewriteMime%&refresh=%refresh%&gadget=%gadget%/%rawurl%",
+ "proxyUrl" :
"//%host%${CONTEXT_ROOT}/gadgets/proxy?container=%container%&refresh=%refresh%&url=%url%%rewriteMime%",
+ "jsonProxyUrl" : "//%host%${CONTEXT_ROOT}/gadgets/makeRequest"
},
"views" : {
"profile" : {
"isOnlyVisible" : false,
- "urlTemplate" : "http://localhost/gadgets/profile?{var}",
+ "urlTemplate" : "http://localhost${CONTEXT_ROOT}/gadgets/profile?{var}",
"aliases": ["DASHBOARD", "default"]
},
"canvas" : {
"isOnlyVisible" : true,
- "urlTemplate" : "http://localhost/gadgets/canvas?{var}",
+ "urlTemplate" : "http://localhost${CONTEXT_ROOT}/gadgets/canvas?{var}",
"aliases" : ["FULL_PAGE"]
}
},
@@ -256,9 +257,9 @@
"opensocial" : {
// Path to fetch opensocial data from
// Must be on the same domain as the gadget rendering server
- "path" : "http://%host%/rpc",
+ "path" : "http://%host%${CONTEXT_ROOT}/rpc",
// Path to issue invalidate calls
- "invalidatePath" : "http://%host%/rpc",
+ "invalidatePath" : "http://%host%${CONTEXT_ROOT}/rpc",
"domain" : "shindig",
"enableCaja" : false,
"supportedFields" : {
@@ -286,11 +287,17 @@
},
"osapi" : {
// The endpoints to query for available JSONRPC/REST services
- "endPoints" : [ "http://%host%/rpc" ]
+ "endPoints" : [ "http://%host%${CONTEXT_ROOT}/rpc" ]
},
"osml": {
// OSML library resource. Can be set to null or the empty string to
disable OSML
// for a container.
"library": "config/OSML_library.xml"
+ },
+ "shindig-container": {
+ "serverBase": "${CONTEXT_ROOT}/gadgets/"
+ },
+ "container" : {
+ "relayPath": "${CONTEXT_ROOT}/gadgets/files/container/rpc_relay.html"
}
}}
Modified:
shindig/trunk/content/samplecontainer/examples/commoncontainer/assembler.js
URL:
http://svn.apache.org/viewvc/shindig/trunk/content/samplecontainer/examples/commoncontainer/assembler.js?rev=1125023&r1=1125022&r2=1125023&view=diff
==============================================================================
--- shindig/trunk/content/samplecontainer/examples/commoncontainer/assembler.js
(original)
+++ shindig/trunk/content/samplecontainer/examples/commoncontainer/assembler.js
Thu May 19 18:02:04 2011
@@ -17,8 +17,12 @@
* under the License.
*/
+// url base should be <host>:<port>//<contextRoot>
+var urlBase =
location.href.substr(0,location.href.indexOf("/samplecontainer/examples/commoncontainer/"));
+var contextRoot =
urlBase.substr(urlBase.indexOf(location.port)+location.port.length);
+
var testConfig = testConfig || {};
-testConfig[osapi.container.ServiceConfig.API_PATH] = '/rpc';
+testConfig[osapi.container.ServiceConfig.API_PATH] = contextRoot+'/rpc';
testConfig[osapi.container.ContainerConfig.RENDER_DEBUG] = "1";
// Create the new CommonContainer
Modified:
shindig/trunk/content/samplecontainer/examples/commoncontainer/index.html
URL:
http://svn.apache.org/viewvc/shindig/trunk/content/samplecontainer/examples/commoncontainer/index.html?rev=1125023&r1=1125022&r2=1125023&view=diff
==============================================================================
--- shindig/trunk/content/samplecontainer/examples/commoncontainer/index.html
(original)
+++ shindig/trunk/content/samplecontainer/examples/commoncontainer/index.html
Thu May 19 18:02:04 2011
@@ -21,9 +21,9 @@
<head>
<!-- My OpenSocial Beginnings -->
- <link rel="stylesheet" href="/container/gadgets.css">
- <script type="text/javascript"
-
src="/gadgets/js/container:rpc:pubsub-2.js?c=1&debug=1&container=default"></script>
+ <link rel="stylesheet" href="../../../container/gadgets.css">
+ <script
src="../../../gadgets/js/container:rpc:pubsub-2.js?c=1&debug=1&container=default"></script>
+ </script>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<script
Modified:
shindig/trunk/content/samplecontainer/examples/commoncontainer/viewController.js
URL:
http://svn.apache.org/viewvc/shindig/trunk/content/samplecontainer/examples/commoncontainer/viewController.js?rev=1125023&r1=1125022&r2=1125023&view=diff
==============================================================================
---
shindig/trunk/content/samplecontainer/examples/commoncontainer/viewController.js
(original)
+++
shindig/trunk/content/samplecontainer/examples/commoncontainer/viewController.js
Thu May 19 18:02:04 2011
@@ -37,7 +37,7 @@ $(function() {
// ID used to associate gadget site
var curId = 0;
- // Load the defaultl collections stored and update the options with
the collection name
+ // Load the default collections stored and update the options with the
collection name
$.ajax({
url: './gadgetCollections.json',
dataType: 'json',
@@ -45,8 +45,8 @@ $(function() {
$.each(data.collections, function(i,data){
var optionVal = [];
$.each(data.apps, function(i,data){
- if (data.url.indexOf("http") < 0){
-
optionVal.push(location.protocol+"//"+location.host+data.url);
+ if (data.url.indexOf("http") < 0 &&
data.url.indexOf("/") == 0 ){
+ optionVal.push(urlBase+data.url);
}else{
optionVal.push(data.url);
}
Modified: shindig/trunk/content/samplecontainer/samplecontainer.html
URL:
http://svn.apache.org/viewvc/shindig/trunk/content/samplecontainer/samplecontainer.html?rev=1125023&r1=1125022&r2=1125023&view=diff
==============================================================================
--- shindig/trunk/content/samplecontainer/samplecontainer.html (original)
+++ shindig/trunk/content/samplecontainer/samplecontainer.html Thu May 19
18:02:04 2011
@@ -51,7 +51,7 @@
</style>
-<script type="text/javascript"
src="/gadgets/js/core:rpc:pubsub:shindig-container.js?c=1&debug=1"></script>
+<script type="text/javascript"
src="../gadgets/js/core:rpc:pubsub:shindig-container.js?c=1&debug=1"></script>
<script type="text/javascript" src="samplecontainer.js"></script>
</head>
Modified: shindig/trunk/content/samplecontainer/samplecontainer.js
URL:
http://svn.apache.org/viewvc/shindig/trunk/content/samplecontainer/samplecontainer.js?rev=1125023&r1=1125022&r2=1125023&view=diff
==============================================================================
--- shindig/trunk/content/samplecontainer/samplecontainer.js (original)
+++ shindig/trunk/content/samplecontainer/samplecontainer.js Thu May 19
18:02:04 2011
@@ -37,20 +37,19 @@ shindig.samplecontainer = {};
*/
var parentUrl = document.location.href;
- var baseUrl = parentUrl.substring(0,
parentUrl.indexOf('samplecontainer.html'));
+ var baseUrl = parentUrl.substring(0, parentUrl.indexOf('samplecontainer'));
// TODO: This is gross, it needs to use the config just like the gadget js
does
- var socialDataPath = document.location.protocol + "//" +
document.location.host
- + "/social/rest/samplecontainer/";
+ var socialDataPath = baseUrl + "social/rest/samplecontainer/";
var gadgetUrlMatches = /[?&]url=((?:[^#&]+|&)+)/.exec(parentUrl);
var gadgetUrl = (gadgetUrlMatches)
? gadgetUrlMatches[1]
- : baseUrl + 'examples/SocialHelloWorld.xml';
+ : baseUrl + 'samplecontainer/examples/SocialHelloWorld.xml';
var gadgetUrlCookie = 'sampleContainerGadgetUrl';
- var stateFileUrl = baseUrl + '../sampledata/canonicaldb.json';
+ var stateFileUrl = baseUrl + 'sampledata/canonicaldb.json';
var stateFileUrlCookie = 'sampleContainerStateFileUrl';
var useCaja;
@@ -159,7 +158,7 @@ shindig.samplecontainer = {};
// Shindigs rpc code uses direct javascript calls when running on the
same domain
// to simulate cross-domain when running sample container we replace
// 'localhost' with '127.0.0.1'
- var iframeBaseUrl = baseUrl.replace("localhost", "127.0.0.1") +
'../../gadgets/';
+ var iframeBaseUrl = baseUrl.replace("localhost", "127.0.0.1") +
'gadgets/';
gadget.setServerBase(iframeBaseUrl);
gadget.secureToken = escape(generateSecureToken());
@@ -200,7 +199,7 @@ shindig.samplecontainer = {};
}]
};
- sendRequestToServer("/gadgets/metadata", "POST",
+ sendRequestToServer(baseUrl+"gadgets/metadata", "POST",
gadgets.json.stringify(request), opt_callback, true);
}
Modified:
shindig/trunk/features/src/main/javascript/features/container/gadget_holder.js
URL:
http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/container/gadget_holder.js?rev=1125023&r1=1125022&r2=1125023&view=diff
==============================================================================
---
shindig/trunk/features/src/main/javascript/features/container/gadget_holder.js
(original)
+++
shindig/trunk/features/src/main/javascript/features/container/gadget_holder.js
Thu May 19 18:02:04 2011
@@ -82,6 +82,10 @@ osapi.container.GadgetHolder = function(
this.onConstructed();
};
+/**
+ * Url points to the rpc_relay.html which allows cross-domain communication
between a gadget and container
+ */
+osapi.container.GadgetHolder.prototype.relayPath_ = null;
/**
* Callback that occurs after instantiation/construction of this. Override to
@@ -204,7 +208,8 @@ osapi.container.GadgetHolder.prototype.d
var relayUri = shindig.uri()
.setSchema(iframeUri.getSchema())
.setAuthority(iframeUri.getAuthority())
- .setPath('/gadgets/files/container/rpc_relay.html');
+ //.setPath('/test1/gadgets/files/container/rpc_relay.html');
+ .setPath(this.relayPath_);
gadgets.rpc.setupReceiver(this.iframeId_, relayUri.toString(),
iframeUri.getFP('rpctoken'));
};
@@ -244,7 +249,8 @@ osapi.container.GadgetHolder.prototype.d
IframeContainer: {
parent: this.el_,
uri: this.getIframeUrl_(),
- tunnelURI: shindig.uri('/gadgets/' +
'../container/rpc_relay.html').resolve(shindig.uri(window.location.href)),
+ //tunnelURI: shindig.uri('/test1/gadgets/' +
'../container/rpc_relay.html').resolve(shindig.uri(window.location.href)),
+ tunnelURI:
shindig.uri(this.relayPath_).resolve(shindig.uri(window.location.href)),
iframeAttrs: iframeParams
}
}
@@ -374,3 +380,16 @@ osapi.container.GadgetHolder.prototype.u
}
}
};
+
+function init(config) {
+ if (config.container){
+ var rpath = config["container"]["relayPath"];
+ osapi.container.GadgetHolder.prototype.relayPath_ = rpath;
+ }
+};
+
+// We do run this in the container mode in the new common container
+if (gadgets.config) {
+ gadgets.config.register("container", null, init);
+
+};
Modified:
shindig/trunk/features/src/main/javascript/features/shindig.container/feature.xml
URL:
http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/shindig.container/feature.xml?rev=1125023&r1=1125022&r2=1125023&view=diff
==============================================================================
---
shindig/trunk/features/src/main/javascript/features/shindig.container/feature.xml
(original)
+++
shindig/trunk/features/src/main/javascript/features/shindig.container/feature.xml
Thu May 19 18:02:04 2011
@@ -25,6 +25,7 @@ A map of view names to view attributes.
-->
<name>shindig-container</name>
<dependency>globals</dependency>
+ <dependency>core.config</dependency>
<dependency>rpc</dependency>
<dependency>osapi</dependency>
<dependency>shindig.uri.ext</dependency>
Modified:
shindig/trunk/features/src/main/javascript/features/shindig.container/shindig-container.js
URL:
http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/shindig.container/shindig-container.js?rev=1125023&r1=1125022&r2=1125023&view=diff
==============================================================================
---
shindig/trunk/features/src/main/javascript/features/shindig.container/shindig-container.js
(original)
+++
shindig/trunk/features/src/main/javascript/features/shindig.container/shindig-container.js
Thu May 19 18:02:04 2011
@@ -402,6 +402,15 @@ shindig.Gadget = function(params) {
}
};
+shindig.Gadget.prototype.setServerBase = function(url) {
+ this.serverBase_ = url;
+}
+
+shindig.Gadget.prototype.getServerBase = function() {
+ return this.serverBase_;
+};
+
+
shindig.Gadget.prototype.getUserPrefs = function() {
return this.userPrefs;
};
@@ -479,8 +488,11 @@ shindig.Gadget.prototype.getAdditionalPa
shindig.BaseIfrGadget = function(opt_params) {
shindig.Gadget.call(this, opt_params);
+
if(!this.serverBase_){
this.serverBase_ = '/gadgets/'; // default gadget server
+ } else if(this.serverBase_.indexOf('/gadgets')<0) {
+ this.serverBase_ += '/gadgets/';
}
this.queryIfrGadgetType_();
};
@@ -526,13 +538,7 @@ shindig.BaseIfrGadget.prototype.getUserP
this.cssClassGadgetUserPrefsDialog + '"></div>');
};
-shindig.BaseIfrGadget.prototype.setServerBase = function(url) {
- this.serverBase_ = url;
-};
-shindig.BaseIfrGadget.prototype.getServerBase = function() {
- return this.serverBase_;
-};
shindig.BaseIfrGadget.prototype.getMainContent = function(continuation) {
// proper sub-class has not been mixed-in yet
@@ -964,6 +970,17 @@ shindig.IfrContainer.prototype.renderGad
gadget.render(chrome);
};
+function init(config) {
+ var sbase = config["shindig-container"];
+ shindig.Gadget.prototype.setServerBase(sbase.serverBase);
+
+};
+
+// We do run this in the container mode in the new common container
+if (gadgets.config) {
+ gadgets.config.register("shindig-container", null, init);
+};
+
/**
* Default container.
*/
Modified: shindig/trunk/features/src/main/javascript/features/shindig.uri/uri.js
URL:
http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/shindig.uri/uri.js?rev=1125023&r1=1125022&r2=1125023&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/shindig.uri/uri.js
(original)
+++ shindig/trunk/features/src/main/javascript/features/shindig.uri/uri.js Thu
May 19 18:02:04 2011
@@ -227,7 +227,7 @@ shindig.uri = (function() {
// Setters
setSchema: function(schema) { schema_ = schema; return bundle; },
setAuthority: function(authority) { authority_ = authority; return
bundle; },
- setPath: function(path) { path_ = (path[0] === '/' ? '' : '/') + path;
return bundle; },
+ setPath: function(path) { if (typeof path !== 'undefined' && path !=
null) { path_ = (path[0] === '/' ? '' : '/') + path; } return bundle; },
setQuery: function(query) { qparms_ = null; query_ = stripPrefix(query,
'?'); return bundle; },
setFragment: function(fragment) { fparms_ = null; fragment_ =
stripPrefix(fragment, '#'); return bundle; },
setQP: setQP,
Modified: shindig/trunk/java/common/conf/shindig.properties
URL:
http://svn.apache.org/viewvc/shindig/trunk/java/common/conf/shindig.properties?rev=1125023&r1=1125022&r2=1125023&view=diff
==============================================================================
--- shindig/trunk/java/common/conf/shindig.properties (original)
+++ shindig/trunk/java/common/conf/shindig.properties Thu May 19 18:02:04 2011
@@ -35,7 +35,7 @@ shindig.oauth.validator-max-timestamp-ag
shindig.signing.state-key=
shindig.signing.key-name=
shindig.signing.key-file=
-shindig.signing.global-callback-url=http://localhost:8080/gadgets/oauthcallback
+shindig.signing.global-callback-url=http://localhost:8080%contextRoot%/gadgets/oauthcallback
shindig.signing.enable-signed-callbacks=true
# Set to true if you want to allow the use of 3-legged OAuth tokens when
viewer != owner.
@@ -52,8 +52,8 @@ shindig.content-rewrite.include-urls=.*
shindig.content-rewrite.exclude-urls=
shindig.content-rewrite.include-tags=body,embed,img,input,link,script,style
shindig.content-rewrite.expires=86400
-shindig.content-rewrite.proxy-url=/gadgets/proxy?container=default&url=
-shindig.content-rewrite.concat-url=/gadgets/concat?container=default&
+shindig.content-rewrite.proxy-url=%contextRoot%/gadgets/proxy?container=default&url=
+shindig.content-rewrite.concat-url=%contextRoot%/gadgets/concat?container=default&
shindig.content-rewrite.enable-split-js-concat=true
shindig.content-rewrite.enable-single-resource-concat=false
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=1125023&r1=1125022&r2=1125023&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
Thu May 19 18:02:04 2011
@@ -57,6 +57,7 @@ public class PropertiesModule extends Ab
@Override
protected void configure() {
+
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());
@@ -64,6 +65,15 @@ public class PropertiesModule extends Ab
}
/**
+ * Should return the context root where the current web module is deployed
with. Useful for testing and working out of the box configs.
+ * If not set uses fixed value of "".
+ * @return an context path as a string.
+ */
+ private String getContextRoot() {
+ 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"
* @return an integer port number as a string.
@@ -94,12 +104,23 @@ public class PropertiesModule extends Ab
return properties;
}
+
private Properties readPropertyFile(String propertyFile) {
Properties properties = new Properties();
InputStream is = null;
+ String contextRoot = getContextRoot();
try {
is = ResourceLoader.openResource(propertyFile);
properties.load(is);
+
+ String value = null;
+ for(Object key : properties.keySet()){
+ value = (String)properties.get((String)key);
+ 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)));
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=1125023&r1=1125022&r2=1125023&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
Thu May 19 18:02:04 2011
@@ -21,11 +21,13 @@ package org.apache.shindig.common.servle
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
+import com.google.inject.Binder;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Module;
import com.google.inject.Singleton;
import com.google.inject.Stage;
+import com.google.inject.name.Names;
import org.apache.commons.lang.StringUtils;
import java.util.List;
@@ -48,12 +50,15 @@ public class GuiceServletContextListener
// HNN- constant name matched system.properties <contextparam> specified in
the web.xml
private static final String SYSTEM_PROPERTIES = "system.properties";
+ private String contextRoot = "";
public void contextInitialized(ServletContextEvent event) {
ServletContext context = event.getServletContext();
- //HNN setting all system.properties specified in the web.xml
+
+
setSystemProperties(context);
String moduleNames = context.getInitParameter(MODULES_ATTRIBUTE);
List<Module> modules = Lists.newLinkedList();
+
if (moduleNames != null) {
for (String moduleName : Splitter.on(':').split(moduleNames)) {
try {
@@ -99,6 +104,13 @@ public class GuiceServletContextListener
* @param context the ServletContext
*/
private void setSystemProperties(ServletContext context){
+ try{
+ contextRoot = context.getContextPath();
+ }
+ catch(Exception e){
+ contextRoot= "";
+ }
+ System.setProperty("shindig.contextroot", contextRoot);
String systemProperties = context.getInitParameter(SYSTEM_PROPERTIES);
String key=null;
String value=null;
Modified:
shindig/trunk/java/common/src/main/java/org/apache/shindig/config/JsonContainerConfig.java
URL:
http://svn.apache.org/viewvc/shindig/trunk/java/common/src/main/java/org/apache/shindig/config/JsonContainerConfig.java?rev=1125023&r1=1125022&r2=1125023&view=diff
==============================================================================
---
shindig/trunk/java/common/src/main/java/org/apache/shindig/config/JsonContainerConfig.java
(original)
+++
shindig/trunk/java/common/src/main/java/org/apache/shindig/config/JsonContainerConfig.java
Thu May 19 18:02:04 2011
@@ -47,7 +47,7 @@ public class JsonContainerConfig extends
// Used by tests
public JsonContainerConfig(String containers, Expressions expressions)
throws ContainerConfigException {
- this(containers, "localhost", "8080", expressions);
+ this(containers, "localhost", "8080", "",expressions);
}
/**
* Creates a new configuration from files.
@@ -57,10 +57,11 @@ public class JsonContainerConfig extends
public JsonContainerConfig(@Named("shindig.containers.default") String
containers,
@Nullable @Named("shindig.host") String host,
@Nullable @Named("shindig.port") String port,
+ @Nullable @Named("shindig.contextroot") String
contextRoot,
Expressions expressions)
throws ContainerConfigException {
super(expressions);
- JsonContainerConfigLoader.getTransactionFromFile(containers, host, port,
this).commit();
+ JsonContainerConfigLoader.getTransactionFromFile(containers, host, port,
contextRoot, this).commit();
}
/**
Modified:
shindig/trunk/java/common/src/main/java/org/apache/shindig/config/JsonContainerConfigLoader.java
URL:
http://svn.apache.org/viewvc/shindig/trunk/java/common/src/main/java/org/apache/shindig/config/JsonContainerConfigLoader.java?rev=1125023&r1=1125022&r2=1125023&view=diff
==============================================================================
---
shindig/trunk/java/common/src/main/java/org/apache/shindig/config/JsonContainerConfigLoader.java
(original)
+++
shindig/trunk/java/common/src/main/java/org/apache/shindig/config/JsonContainerConfigLoader.java
Thu May 19 18:02:04 2011
@@ -62,6 +62,7 @@ public class JsonContainerConfigLoader {
public static final char FILE_SEPARATOR = ',';
public static final String SERVER_PORT = "SERVER_PORT";
public static final String SERVER_HOST = "SERVER_HOST";
+ public static final String CONTEXT_ROOT = "CONTEXT_ROOT";
private JsonContainerConfigLoader() {
}
@@ -74,15 +75,16 @@ public class JsonContainerConfigLoader {
* the container configurations from.
* @param host The hostname where Shindig is running.
* @param port The port number where Shindig is receiving requests.
+ * @param contextRoot contextRoot where Shindig module is deployed
* @param containerConfig The container configuration to add the contents of
* the file to.
* @return A transaction to add the new containers to the configuration.
* @throws ContainerConfigException If there was a problem reading the files.
*/
public static Transaction getTransactionFromFile(
- String containers, String host, String port, ContainerConfig
containerConfig)
+ String containers, String host, String port, String
contextRoot,ContainerConfig containerConfig)
throws ContainerConfigException {
- return addToTransactionFromFile(containers, host, port,
containerConfig.newTransaction());
+ return addToTransactionFromFile(containers, host, port,
contextRoot,containerConfig.newTransaction());
}
/**
@@ -97,10 +99,10 @@ public class JsonContainerConfigLoader {
* @throws ContainerConfigException If there was a problem reading the files.
*/
public static Transaction addToTransactionFromFile(
- String containers, String host, String port, Transaction transaction)
+ String containers, String host, String port, String contextRoot,
Transaction transaction)
throws ContainerConfigException {
List<Map<String, Object>> config = loadContainers(containers);
- addHostAndPortToDefaultContainer(config, host, port);
+ addHostAndPortToDefaultContainer(config, host, port,contextRoot);
addContainersToTransaction(transaction, config);
return transaction;
}
@@ -272,7 +274,7 @@ public class JsonContainerConfigLoader {
}
private static void addHostAndPortToDefaultContainer(
- List<Map<String, Object>> config, String host, String port) {
+ List<Map<String, Object>> config, String host, String port,String
contextRoot) {
for (int i = 0, j = config.size(); i < j; ++i) {
Map<String, Object> container = config.get(i);
@SuppressWarnings("unchecked")
@@ -282,10 +284,13 @@ public class JsonContainerConfigLoader {
newContainer.putAll(container);
newContainer.put(SERVER_PORT, port);
newContainer.put(SERVER_HOST, host);
+ newContainer.put(CONTEXT_ROOT,contextRoot);
config.set(i, Collections.unmodifiableMap(newContainer));
}
}
}
+
+
private static void addContainersToTransaction(
Transaction transaction, List<Map<String, Object>> config) {
Modified:
shindig/trunk/java/common/src/test/java/org/apache/shindig/config/JsonContainerConfigLoaderTest.java
URL:
http://svn.apache.org/viewvc/shindig/trunk/java/common/src/test/java/org/apache/shindig/config/JsonContainerConfigLoaderTest.java?rev=1125023&r1=1125022&r2=1125023&view=diff
==============================================================================
---
shindig/trunk/java/common/src/test/java/org/apache/shindig/config/JsonContainerConfigLoaderTest.java
(original)
+++
shindig/trunk/java/common/src/test/java/org/apache/shindig/config/JsonContainerConfigLoaderTest.java
Thu May 19 18:02:04 2011
@@ -84,7 +84,7 @@ public class JsonContainerConfigLoaderTe
private void createConfigForTest(String containers) throws
ContainerConfigException {
JsonContainerConfigLoader
- .getTransactionFromFile(containers, "localhost", "8080",
config).commit();
+ .getTransactionFromFile(containers, "localhost", "8080",
"",config).commit();
}
@Before
Modified:
shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/SocialApiTestsGuiceModule.java
URL:
http://svn.apache.org/viewvc/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/SocialApiTestsGuiceModule.java?rev=1125023&r1=1125022&r2=1125023&view=diff
==============================================================================
---
shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/SocialApiTestsGuiceModule.java
(original)
+++
shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/SocialApiTestsGuiceModule.java
Thu May 19 18:02:04 2011
@@ -80,6 +80,7 @@ public class SocialApiTestsGuiceModule e
.to("res://containers/default/container.js");
bindConstant().annotatedWith(Names.named("shindig.port")).to("8080");
bindConstant().annotatedWith(Names.named("shindig.host")).to("localhost");
+ bindConstant().annotatedWith(Names.named("shindig.contextroot")).to("");
bind(ContainerConfig.class).to(JsonContainerConfig.class);
bind(Integer.class).annotatedWith(