You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by et...@apache.org on 2008/05/13 11:19:03 UTC
svn commit: r655788 [1/2] - in /incubator/shindig/trunk/java/gadgets/src:
main/java/org/apache/shindig/gadgets/
main/java/org/apache/shindig/gadgets/http/
main/java/org/apache/shindig/gadgets/oauth/
main/java/org/apache/shindig/gadgets/servlet/ test/ja...
Author: etnu
Date: Tue May 13 02:19:01 2008
New Revision: 655788
URL: http://svn.apache.org/viewvc?rev=655788&view=rev
Log:
Next step of http fetcher refactoring -- renaming to appropriate classes. Classes that haven't been renamed will be removed.
Added:
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/AbstractHttpCache.java
- copied, changed from r655783, incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/AbstractContentCache.java
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/BasicHttpCache.java
- copied, changed from r655783, incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/BasicContentCache.java
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/BasicHttpFetcher.java
- copied, changed from r655783, incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/BasicRemoteContentFetcher.java
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/HttpCache.java
- copied, changed from r655783, incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/ContentCache.java
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/HttpFetcher.java
- copied, changed from r655783, incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/ContentFetcher.java
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/HttpRequest.java
- copied, changed from r655783, incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/RemoteContentRequest.java
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/HttpResponse.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/BasicHttpCacheTest.java
- copied, changed from r655783, incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/BasicContentCacheTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/BasicHttpFetcherTest.java
- copied, changed from r655783, incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/BasicRemoteContentFetcherTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/HttpRequestTest.java
- copied, changed from r655783, incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/RemoteContentRequestTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/HttpResponseTest.java
- copied, changed from r655783, incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/RemoteContentTest.java
Removed:
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/AbstractContentCache.java
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/BasicContentCache.java
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/BasicRemoteContentFetcher.java
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/ContentCache.java
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/ContentFetcher.java
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/RemoteContent.java
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/RemoteContentRequest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/BasicContentCacheTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/BasicRemoteContentFetcherTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/RemoteContentRequestTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/RemoteContentTest.java
Modified:
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/ChainedContentFetcher.java
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/DefaultGuiceModule.java
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/Gadget.java
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetFeatureRegistry.java
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetServer.java
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/JsFeatureLoader.java
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/JsLibrary.java
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/SigningFetcher.java
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/SigningFetcherFactory.java
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/ContentFetcherFactory.java
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/RemoteContentFetcherFactory.java
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth/BasicGadgetOAuthTokenStore.java
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth/OAuthFetcher.java
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth/OAuthFetcherFactory.java
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/GadgetRenderingTask.java
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/ProxyHandler.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/GadgetServerTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/GadgetTestFixture.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/InterceptingContentFetcher.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/JsFeatureLoaderTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/JsLibraryTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/SigningFetcherTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth/FakeOAuthServiceProvider.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth/OAuthFetcherTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/GadgetRenderingTaskTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/JsonRpcHandlerTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/ProxyHandlerTest.java
Modified: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/ChainedContentFetcher.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/ChainedContentFetcher.java?rev=655788&r1=655787&r2=655788&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/ChainedContentFetcher.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/ChainedContentFetcher.java Tue May 13 02:19:01 2008
@@ -17,22 +17,22 @@
*/
package org.apache.shindig.gadgets;
-import org.apache.shindig.gadgets.http.ContentFetcher;
+import org.apache.shindig.gadgets.http.HttpFetcher;
/**
- * Fetches RemoteContent
+ * Fetches HttpResponse
*
* Subclasses can use a chain-of-responsibility pattern to add functionality
* to the fetching process. For example, a SigningFetcher can talk to a
* CachingFetcher can talk to a ThrottlingFetcher that talks to a
* RemoteFetcher that gets the actual data.
*/
-public abstract class ChainedContentFetcher implements ContentFetcher {
+public abstract class ChainedContentFetcher implements HttpFetcher {
/** next fetcher in the chain, may be null */
- protected ContentFetcher nextFetcher;
+ protected HttpFetcher nextFetcher;
- protected ChainedContentFetcher(ContentFetcher nextFetcher) {
+ protected ChainedContentFetcher(HttpFetcher nextFetcher) {
this.nextFetcher = nextFetcher;
}
}
Modified: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/DefaultGuiceModule.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/DefaultGuiceModule.java?rev=655788&r1=655787&r2=655788&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/DefaultGuiceModule.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/DefaultGuiceModule.java Tue May 13 02:19:01 2008
@@ -19,10 +19,10 @@
package org.apache.shindig.gadgets;
import org.apache.shindig.common.util.ResourceLoader;
-import org.apache.shindig.gadgets.http.BasicContentCache;
-import org.apache.shindig.gadgets.http.BasicRemoteContentFetcher;
-import org.apache.shindig.gadgets.http.ContentCache;
-import org.apache.shindig.gadgets.http.ContentFetcher;
+import org.apache.shindig.gadgets.http.BasicHttpCache;
+import org.apache.shindig.gadgets.http.BasicHttpFetcher;
+import org.apache.shindig.gadgets.http.HttpCache;
+import org.apache.shindig.gadgets.http.HttpFetcher;
import org.apache.shindig.gadgets.http.ContentFetcherFactory;
import org.apache.shindig.gadgets.http.RemoteContentFetcherFactory;
import org.apache.shindig.gadgets.oauth.OAuthFetcherFactory;
@@ -52,22 +52,22 @@
protected void configure() {
Names.bindProperties(this.binder(), properties);
- bind(ContentFetcher.class).to(BasicRemoteContentFetcher.class);
- bind(ContentCache.class).to(BasicContentCache.class);
+ bind(HttpFetcher.class).to(BasicHttpFetcher.class);
+ bind(HttpCache.class).to(BasicHttpCache.class);
bind(RemoteContentFetcherFactory.class);
bind(SigningFetcherFactory.class);
// Needed becuase OAuth fetcher factory fetches its config
- bind(ContentFetcher.class)
+ bind(HttpFetcher.class)
.annotatedWith(OAuthFetcherFactory.OAuthConfigFetcher.class)
- .to(BasicRemoteContentFetcher.class);
+ .to(BasicHttpFetcher.class);
bind(OAuthFetcherFactory.class);
bind(ContentFetcherFactory.class);
- bind(ContentFetcher.class)
+ bind(HttpFetcher.class)
.annotatedWith(GadgetSpecFetcher.class)
.toProvider(ContentFetcherFactory.class);
- bind(ContentFetcher.class)
+ bind(HttpFetcher.class)
.annotatedWith(MessageBundleFetcher.class)
.toProvider(ContentFetcherFactory.class);
Modified: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/Gadget.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/Gadget.java?rev=655788&r1=655787&r2=655788&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/Gadget.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/Gadget.java Tue May 13 02:19:01 2008
@@ -17,7 +17,7 @@
*/
package org.apache.shindig.gadgets;
-import org.apache.shindig.gadgets.http.RemoteContent;
+import org.apache.shindig.gadgets.http.HttpResponse;
import org.apache.shindig.gadgets.spec.GadgetSpec;
import org.apache.shindig.gadgets.spec.MessageBundle;
import org.apache.shindig.gadgets.spec.Preload;
@@ -57,9 +57,9 @@
return jsLibraries;
}
- private final Map<Preload, Future<RemoteContent>> preloads
- = new HashMap<Preload, Future<RemoteContent>>();
- public Map<Preload, Future<RemoteContent>> getPreloadMap() {
+ private final Map<Preload, Future<HttpResponse>> preloads
+ = new HashMap<Preload, Future<HttpResponse>>();
+ public Map<Preload, Future<HttpResponse>> getPreloadMap() {
return preloads;
}
Modified: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetFeatureRegistry.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetFeatureRegistry.java?rev=655788&r1=655787&r2=655788&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetFeatureRegistry.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetFeatureRegistry.java Tue May 13 02:19:01 2008
@@ -17,7 +17,7 @@
*/
package org.apache.shindig.gadgets;
-import org.apache.shindig.gadgets.http.ContentFetcher;
+import org.apache.shindig.gadgets.http.HttpFetcher;
import com.google.inject.Inject;
import com.google.inject.name.Named;
@@ -54,17 +54,17 @@
/**
* Creates a new feature registry and loads the specified features.
*
- * @param contentFetcher
+ * @param httpFetcher
* @param featureFiles
* @throws GadgetException
*/
@Inject
public GadgetFeatureRegistry(@Named("features.default") String featureFiles,
- ContentFetcher contentFetcher) throws GadgetException {
+ HttpFetcher httpFetcher) throws GadgetException {
features = new HashMap<String, Entry>();
core = new HashMap<String, Entry>();
if (featureFiles != null) {
- JsFeatureLoader loader = new JsFeatureLoader(contentFetcher);
+ JsFeatureLoader loader = new JsFeatureLoader(httpFetcher);
loader.loadFeatures(featureFiles, this);
}
}
Modified: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetServer.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetServer.java?rev=655788&r1=655787&r2=655788&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetServer.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetServer.java Tue May 13 02:19:01 2008
@@ -17,10 +17,10 @@
*/
package org.apache.shindig.gadgets;
-import org.apache.shindig.gadgets.http.ContentFetcher;
+import org.apache.shindig.gadgets.http.HttpFetcher;
import org.apache.shindig.gadgets.http.ContentFetcherFactory;
-import org.apache.shindig.gadgets.http.RemoteContent;
-import org.apache.shindig.gadgets.http.RemoteContentRequest;
+import org.apache.shindig.gadgets.http.HttpResponse;
+import org.apache.shindig.gadgets.http.HttpRequest;
import org.apache.shindig.gadgets.spec.Auth;
import org.apache.shindig.gadgets.spec.Feature;
import org.apache.shindig.gadgets.spec.GadgetSpec;
@@ -53,16 +53,16 @@
private final GadgetBlacklist blacklist;
private ContentFetcherFactory preloadFetcherFactory;
- private ContentFetcher gadgetSpecFetcher;
- private ContentFetcher messageBundleFetcher;
+ private HttpFetcher gadgetSpecFetcher;
+ private HttpFetcher messageBundleFetcher;
@Inject
public GadgetServer(Executor executor,
GadgetFeatureRegistry registry,
GadgetBlacklist blacklist,
ContentFetcherFactory preloadFetcherFactory,
- @GadgetSpecFetcher ContentFetcher gadgetSpecFetcher,
- @MessageBundleFetcher ContentFetcher messageBundleFetcher) {
+ @GadgetSpecFetcher HttpFetcher gadgetSpecFetcher,
+ @MessageBundleFetcher HttpFetcher messageBundleFetcher) {
this.executor = executor;
this.registry = registry;
this.blacklist = blacklist;
@@ -83,10 +83,10 @@
throw new GadgetException(GadgetException.Code.BLACKLISTED_GADGET);
}
- RemoteContentRequest request = RemoteContentRequest.getRequest(
+ HttpRequest request = HttpRequest.getRequest(
context.getUrl(), context.getIgnoreCache());
- RemoteContent response = gadgetSpecFetcher.fetch(request);
- if (response.getHttpStatusCode() != RemoteContent.SC_OK) {
+ HttpResponse response = gadgetSpecFetcher.fetch(request);
+ if (response.getHttpStatusCode() != HttpResponse.SC_OK) {
throw new GadgetException(
GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT,
"Unable to retrieve gadget xml. HTTP error " +
@@ -107,10 +107,10 @@
private MessageBundle getBundle(LocaleSpec localeSpec, GadgetContext context)
throws GadgetException {
URI bundleUrl = localeSpec.getMessages();
- RemoteContentRequest request
- = RemoteContentRequest.getRequest(bundleUrl, context.getIgnoreCache());
- RemoteContent response = messageBundleFetcher.fetch(request);
- if (response.getHttpStatusCode() != RemoteContent.SC_OK) {
+ HttpRequest request
+ = HttpRequest.getRequest(bundleUrl, context.getIgnoreCache());
+ HttpResponse response = messageBundleFetcher.fetch(request);
+ if (response.getHttpStatusCode() != HttpResponse.SC_OK) {
throw new GadgetException(
GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT,
"Unable to retrieve message bundle xml. HTTP error " +
@@ -203,8 +203,8 @@
// we want them to run in parallel
RenderingContext renderContext = gadget.getContext().getRenderingContext();
if (RenderingContext.GADGET.equals(renderContext)) {
- CompletionService<RemoteContent> preloadProcessor
- = new ExecutorCompletionService<RemoteContent>(executor);
+ CompletionService<HttpResponse> preloadProcessor
+ = new ExecutorCompletionService<HttpResponse>(executor);
for (Preload preload : gadget.getSpec().getModulePrefs().getPreloads()) {
// Cant execute signed/oauth preloads without the token
if ((preload.getAuth() == Auth.NONE ||
@@ -213,7 +213,7 @@
preload.getViews().contains(gadget.getContext().getView()))) {
PreloadTask task = new PreloadTask(gadget.getContext(), preload,
preloadFetcherFactory);
- Future<RemoteContent> future = preloadProcessor.submit(task);
+ Future<HttpResponse> future = preloadProcessor.submit(task);
gadget.getPreloadMap().put(preload, future);
}
}
@@ -345,13 +345,13 @@
/**
* Provides a task for preloading data into the gadget content
*/
-class PreloadTask implements Callable<RemoteContent> {
+class PreloadTask implements Callable<HttpResponse> {
private final Preload preload;
private final ContentFetcherFactory preloadFetcherFactory;
private final GadgetContext context;
- public RemoteContent call() {
- RemoteContentRequest request = new RemoteContentRequest(preload.getHref());
+ public HttpResponse call() {
+ HttpRequest request = new HttpRequest(preload.getHref());
request.getOptions().ownerSigned = preload.isSignOwner();
request.getOptions().viewerSigned = preload.isSignViewer();
try {
@@ -362,10 +362,10 @@
return preloadFetcherFactory.getSigningFetcher(context.getToken())
.fetch(request);
default:
- return RemoteContent.ERROR;
+ return HttpResponse.ERROR;
}
} catch (GadgetException e) {
- return RemoteContent.ERROR;
+ return HttpResponse.ERROR;
}
}
Modified: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/JsFeatureLoader.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/JsFeatureLoader.java?rev=655788&r1=655787&r2=655788&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/JsFeatureLoader.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/JsFeatureLoader.java Tue May 13 02:19:01 2008
@@ -20,7 +20,7 @@
import org.apache.shindig.common.util.ResourceLoader;
import org.apache.shindig.common.xml.XmlException;
import org.apache.shindig.common.xml.XmlUtil;
-import org.apache.shindig.gadgets.http.ContentFetcher;
+import org.apache.shindig.gadgets.http.HttpFetcher;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
@@ -48,7 +48,7 @@
*/
public class JsFeatureLoader {
- private final ContentFetcher fetcher;
+ private final HttpFetcher fetcher;
private static final Logger logger
= Logger.getLogger("org.apache.shindig.gadgets");
@@ -287,7 +287,7 @@
/**
* @param fetcher
*/
- public JsFeatureLoader(ContentFetcher fetcher) {
+ public JsFeatureLoader(HttpFetcher fetcher) {
this.fetcher = fetcher;
}
}
Modified: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/JsLibrary.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/JsLibrary.java?rev=655788&r1=655787&r2=655788&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/JsLibrary.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/JsLibrary.java Tue May 13 02:19:01 2008
@@ -18,9 +18,9 @@
package org.apache.shindig.gadgets;
import org.apache.shindig.common.util.ResourceLoader;
-import org.apache.shindig.gadgets.http.ContentFetcher;
-import org.apache.shindig.gadgets.http.RemoteContent;
-import org.apache.shindig.gadgets.http.RemoteContentRequest;
+import org.apache.shindig.gadgets.http.HttpFetcher;
+import org.apache.shindig.gadgets.http.HttpResponse;
+import org.apache.shindig.gadgets.http.HttpRequest;
import java.io.File;
import java.io.IOException;
@@ -119,7 +119,7 @@
* @throws GadgetException
*/
public static JsLibrary create(Type type, String content, String feature,
- ContentFetcher fetcher) throws GadgetException {
+ HttpFetcher fetcher) throws GadgetException {
String optimizedContent = null;
String debugContent;
switch (type) {
@@ -175,13 +175,13 @@
* @throws GadgetException
*/
private static String loadDataFromUrl(String url,
- ContentFetcher fetcher) throws GadgetException {
+ HttpFetcher fetcher) throws GadgetException {
try {
logger.info("Attempting to load js from: " + url);
URI uri = new URI(url);
- RemoteContentRequest request = new RemoteContentRequest(uri);
- RemoteContent response = fetcher.fetch(request);
- if (response.getHttpStatusCode() == RemoteContent.SC_OK) {
+ HttpRequest request = new HttpRequest(uri);
+ HttpResponse response = fetcher.fetch(request);
+ if (response.getHttpStatusCode() == HttpResponse.SC_OK) {
return response.getResponseAsString();
} else {
logger.warning("Unable to retrieve remote library from " + url);
Modified: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/SigningFetcher.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/SigningFetcher.java?rev=655788&r1=655787&r2=655788&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/SigningFetcher.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/SigningFetcher.java Tue May 13 02:19:01 2008
@@ -17,10 +17,10 @@
import org.apache.shindig.common.SecurityToken;
import org.apache.shindig.common.crypto.Crypto;
import org.apache.shindig.common.util.TimeSource;
-import org.apache.shindig.gadgets.http.ContentCache;
-import org.apache.shindig.gadgets.http.ContentFetcher;
-import org.apache.shindig.gadgets.http.RemoteContent;
-import org.apache.shindig.gadgets.http.RemoteContentRequest;
+import org.apache.shindig.gadgets.http.HttpCache;
+import org.apache.shindig.gadgets.http.HttpFetcher;
+import org.apache.shindig.gadgets.http.HttpResponse;
+import org.apache.shindig.gadgets.http.HttpRequest;
import net.oauth.OAuth;
import net.oauth.OAuth.Parameter;
@@ -85,14 +85,14 @@
/**
* The cache to fetch results in.
*/
- protected final ContentCache cache;
+ protected final HttpCache cache;
/**
* Constructor for subclasses that don't want this code to use their
* keys.
*/
- protected SigningFetcher(ContentCache cache,
- ContentFetcher next, SecurityToken authToken) {
+ protected SigningFetcher(HttpCache cache,
+ HttpFetcher next, SecurityToken authToken) {
this(cache, next, authToken, null, null);
}
@@ -103,8 +103,8 @@
* @param keyName name of the key to include in the request
* @param privateKey the key to use for the signing
*/
- public static SigningFetcher makeFromPrivateKey(ContentCache cache,
- ContentFetcher next, SecurityToken authToken,
+ public static SigningFetcher makeFromPrivateKey(HttpCache cache,
+ HttpFetcher next, SecurityToken authToken,
String keyName, PrivateKey privateKey) {
return new SigningFetcher(cache, next, authToken, keyName, privateKey);
}
@@ -116,8 +116,8 @@
* @param keyName name of the key to include in the request
* @param privateKey base64 encoded private key
*/
- public static SigningFetcher makeFromB64PrivateKey(ContentCache cache,
- ContentFetcher next,
+ public static SigningFetcher makeFromB64PrivateKey(HttpCache cache,
+ HttpFetcher next,
SecurityToken authToken, String keyName, String privateKey) {
return new SigningFetcher(cache, next, authToken, keyName, privateKey);
}
@@ -130,13 +130,13 @@
* @param privateKey DER encoded private key
*/
public static SigningFetcher makeFromPrivateKeyBytes(
- ContentCache cache, ContentFetcher next,
+ HttpCache cache, HttpFetcher next,
SecurityToken authToken, String keyName,
byte[] privateKey) {
return new SigningFetcher(cache, next, authToken, keyName, privateKey);
}
- protected SigningFetcher(ContentCache cache, ContentFetcher next,
+ protected SigningFetcher(HttpCache cache, HttpFetcher next,
SecurityToken authToken, String keyName, Object privateKeyObject) {
super(next);
this.cache = cache;
@@ -145,23 +145,23 @@
this.privateKeyObject = privateKeyObject;
}
- public RemoteContent fetch(RemoteContentRequest request)
+ public HttpResponse fetch(HttpRequest request)
throws GadgetException {
try {
- RemoteContentRequest cacheableRequest = makeCacheableRequest(request);
- RemoteContent result = cache.getContent(cacheableRequest);
+ HttpRequest cacheableRequest = makeCacheableRequest(request);
+ HttpResponse result = cache.getResponse(cacheableRequest);
if (result != null) {
return result;
}
- RemoteContentRequest signedRequest = signRequest(request);
+ HttpRequest signedRequest = signRequest(request);
// Signed requests are not externally cacehable
signedRequest.getOptions().ignoreCache = true;
result = nextFetcher.fetch(signedRequest);
// Try and cache the response
- cache.addContent(cacheableRequest, result);
+ cache.addResponse(cacheableRequest, result);
return result;
} catch (GadgetException e) {
@@ -171,8 +171,8 @@
}
}
- private RemoteContentRequest makeCacheableRequest(
- RemoteContentRequest request)
+ private HttpRequest makeCacheableRequest(
+ HttpRequest request)
throws IOException, URISyntaxException, RequestSigningException {
// Create a request without the OAuth params which includes the
// OpenSocial ones and see if we can find it in the cache
@@ -187,12 +187,12 @@
resource.getHost(),
resource.getPort(),
resource.getRawPath() + "?" + cacheableQuery);
- RemoteContentRequest cacheableRequest =
- new RemoteContentRequest(url.toURI(), request);
+ HttpRequest cacheableRequest =
+ new HttpRequest(url.toURI(), request);
return cacheableRequest;
}
- private RemoteContentRequest signRequest(RemoteContentRequest req)
+ private HttpRequest signRequest(HttpRequest req)
throws GadgetException {
try {
// Parse the request into parameters for OAuth signing, stripping out
@@ -244,7 +244,7 @@
resource.getHost(),
resource.getPort(),
resource.getRawPath() + "?" + finalQuery);
- return new RemoteContentRequest(url.toURI(), req);
+ return new HttpRequest(url.toURI(), req);
} catch (GadgetException e) {
throw e;
} catch (Exception e) {
@@ -264,7 +264,7 @@
}
- private void addOpenSocialParams(RemoteContentRequest.Options options,
+ private void addOpenSocialParams(HttpRequest.Options options,
List<Parameter> msgParams) {
String owner = authToken.getOwnerId();
if (owner != null && options.ownerSigned) {
Modified: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/SigningFetcherFactory.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/SigningFetcherFactory.java?rev=655788&r1=655787&r2=655788&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/SigningFetcherFactory.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/SigningFetcherFactory.java Tue May 13 02:19:01 2008
@@ -21,8 +21,8 @@
import org.apache.shindig.common.SecurityToken;
import org.apache.shindig.common.util.InputStreamConsumer;
import org.apache.shindig.common.util.ResourceLoader;
-import org.apache.shindig.gadgets.http.ContentCache;
-import org.apache.shindig.gadgets.http.ContentFetcher;
+import org.apache.shindig.gadgets.http.HttpCache;
+import org.apache.shindig.gadgets.http.HttpFetcher;
import com.google.inject.Inject;
import com.google.inject.name.Named;
@@ -33,7 +33,7 @@
* Produces Signing content fetchers for input tokens.
*/
public class SigningFetcherFactory {
- private final ContentCache cache;
+ private final HttpCache cache;
private final String keyName;
private final String privateKey;
@@ -47,8 +47,8 @@
* @throws GadgetException
*/
@SuppressWarnings("unused")
- public ContentFetcher getSigningFetcher(
- ContentFetcher networkFetcher, SecurityToken token)
+ public HttpFetcher getSigningFetcher(
+ HttpFetcher networkFetcher, SecurityToken token)
throws GadgetException {
return SigningFetcher.makeFromB64PrivateKey(cache,
networkFetcher, token, keyName, privateKey);
@@ -58,7 +58,7 @@
* Dummy ctor for implementations that produce custom fetchers.
*
*/
- protected SigningFetcherFactory(ContentCache cache) {
+ protected SigningFetcherFactory(HttpCache cache) {
this.cache = cache;
this.keyName = null;
this.privateKey = null;
@@ -69,7 +69,7 @@
* @param keyFile The file containing your private key for signing requests.
*/
@Inject
- public SigningFetcherFactory(ContentCache cache,
+ public SigningFetcherFactory(HttpCache cache,
@Named("signing.key-name") String keyName,
@Named("signing.key-file") String keyFile) {
this.cache = cache;
Copied: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/AbstractHttpCache.java (from r655783, incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/AbstractContentCache.java)
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/AbstractHttpCache.java?p2=incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/AbstractHttpCache.java&p1=incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/AbstractContentCache.java&r1=655783&r2=655788&rev=655788&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/AbstractContentCache.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/AbstractHttpCache.java Tue May 13 02:19:01 2008
@@ -30,49 +30,49 @@
*
* TODO: Move cache checking code into HttpUtil
*/
-public abstract class AbstractContentCache implements ContentCache {
+public abstract class AbstractHttpCache implements HttpCache {
- public final RemoteContent getContent(RemoteContentRequest request) {
+ public final HttpResponse getResponse(HttpRequest request) {
if (canCacheRequest(request)) {
- return getContent(request.getUri());
+ return getResponse(request.getUri());
}
return null;
}
- public final RemoteContent getContent(URI uri) {
+ public final HttpResponse getResponse(URI uri) {
if (uri == null) return null;
- return checkContent(getContentImpl(uri));
+ return checkResponse(getResponseImpl(uri));
}
- protected abstract RemoteContent getContentImpl(URI uri);
+ protected abstract HttpResponse getResponseImpl(URI uri);
- public void addContent(RemoteContentRequest request, RemoteContent content) {
+ public void addResponse(HttpRequest request, HttpResponse response) {
if (canCacheRequest(request)) {
- addContent(request.getUri(), content);
+ addResponse(request.getUri(), response);
}
}
- public void addContent(URI uri, RemoteContent content) {
- content = checkContent(content);
- if (uri == null || content == null) return;
+ public void addResponse(URI uri, HttpResponse response) {
+ response = checkResponse(response);
+ if (uri == null || response == null) return;
// Clone the URI to prevent outside references from preventing collection
- addContentImpl(URI.create(uri.toString()), content);
+ addResponseImpl(URI.create(uri.toString()), response);
}
- protected abstract void addContentImpl(URI uri, RemoteContent content);
+ protected abstract void addResponseImpl(URI uri, HttpResponse response);
- public RemoteContent removeContent(RemoteContentRequest request) {
- return removeContent(request.getUri());
+ public HttpResponse removeResponse(HttpRequest request) {
+ return removeResponse(request.getUri());
}
- public RemoteContent removeContent(URI uri) {
+ public HttpResponse removeResponse(URI uri) {
if (uri == null) return null;
- RemoteContent content = getContentImpl(uri);
- removeContentImpl(uri);
- return checkContent(content);
+ HttpResponse response = getResponseImpl(uri);
+ removeResponseImpl(uri);
+ return checkResponse(response);
}
- protected abstract RemoteContent removeContentImpl(URI uri);
+ protected abstract HttpResponse removeResponseImpl(URI uri);
/**
* Utility function to verify that an entry is cacheable and not expired
@@ -81,7 +81,7 @@
* @param request
* @return content or null
*/
- protected boolean canCacheRequest(RemoteContentRequest request) {
+ protected boolean canCacheRequest(HttpRequest request) {
return ("GET".equals(request.getMethod()) &&
!request.getOptions().ignoreCache);
}
@@ -90,17 +90,17 @@
* Utility function to verify that an entry is cacheable and not expired
* Returns null if the content is no longer cacheable.
*
- * @param content
+ * @param response
* @return content or null
*/
- protected RemoteContent checkContent(RemoteContent content) {
- if (content == null) return null;
+ protected HttpResponse checkResponse(HttpResponse response) {
+ if (response == null) return null;
- if (content.getHttpStatusCode() != 200) return null;
+ if (response.getHttpStatusCode() != 200) return null;
long now = System.currentTimeMillis();
- String expires = content.getHeader("Expires");
+ String expires = response.getHeader("Expires");
if (expires != null) {
Date expiresDate = HttpUtil.parseDate(expires);
if (expiresDate == null) {
@@ -109,7 +109,7 @@
}
long expiresMs = expiresDate.getTime();
if (expiresMs > now) {
- return content;
+ return response;
} else {
return null;
}
@@ -117,7 +117,7 @@
// Cache-Control headers may be an explicit max-age, or no-cache, which
// means we use a default expiration time.
- String cacheControl = content.getHeader("Cache-Control");
+ String cacheControl = response.getHeader("Cache-Control");
if (cacheControl != null) {
String[] directives = cacheControl.split(",");
for (String directive : directives) {
@@ -134,9 +134,9 @@
// absolute expiration
long maxAgeMs = Long.parseLong(parts[1]) * 1000;
Date newExpiry = new Date(now + maxAgeMs);
- content.getAllHeaders()
+ response.getAllHeaders()
.put("Expires", Arrays.asList(HttpUtil.formatDate(newExpiry)));
- return content;
+ return response;
} catch (NumberFormatException e) {
return null;
}
@@ -146,7 +146,7 @@
}
// Look for Pragma: no-cache. If present, return null.
- List<String> pragmas = content.getHeaders("Pragma");
+ List<String> pragmas = response.getHeaders("Pragma");
if (pragmas != null) {
for (String pragma : pragmas) {
if ("no-cache".equals(pragma)) {
@@ -158,9 +158,9 @@
// Assume the content is cacheable for the default TTL
// if no other directives exist
Date newExpiry = new Date(now + getDefaultTTL());
- content.getAllHeaders()
+ response.getAllHeaders()
.put("Expires", Arrays.asList(HttpUtil.formatDate(newExpiry)));
- return content;
+ return response;
}
/**
Copied: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/BasicHttpCache.java (from r655783, incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/BasicContentCache.java)
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/BasicHttpCache.java?p2=incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/BasicHttpCache.java&p1=incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/BasicContentCache.java&r1=655783&r2=655788&rev=655788&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/BasicContentCache.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/BasicHttpCache.java Tue May 13 02:19:01 2008
@@ -22,25 +22,25 @@
import java.util.WeakHashMap;
/**
- * Simple cache of RemoteContent. Uses WeakHashMap for memory management
+ * Simple cache of HttpResponse. Uses WeakHashMap for memory management
*/
-public class BasicContentCache extends AbstractContentCache {
+public class BasicHttpCache extends AbstractHttpCache {
- private final Map<URI, RemoteContent> cache
- = new WeakHashMap<URI, RemoteContent>();
+ private final Map<URI, HttpResponse> cache
+ = new WeakHashMap<URI, HttpResponse>();
@Override
- protected RemoteContent getContentImpl(URI uri) {
+ protected HttpResponse getResponseImpl(URI uri) {
return cache.get(uri);
}
@Override
- protected void addContentImpl(URI uri, RemoteContent content) {
- cache.put(uri, content);
+ protected void addResponseImpl(URI uri, HttpResponse response) {
+ cache.put(uri, response);
}
@Override
- protected RemoteContent removeContentImpl(URI uri) {
+ protected HttpResponse removeResponseImpl(URI uri) {
return cache.remove(uri);
}
}
Copied: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/BasicHttpFetcher.java (from r655783, incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/BasicRemoteContentFetcher.java)
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/BasicHttpFetcher.java?p2=incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/BasicHttpFetcher.java&p1=incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/BasicRemoteContentFetcher.java&r1=655783&r2=655788&rev=655788&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/BasicRemoteContentFetcher.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/BasicHttpFetcher.java Tue May 13 02:19:01 2008
@@ -39,19 +39,19 @@
* annotate it as a Singleton to resolve Guice injection limitations.
*/
@Singleton
-public class BasicRemoteContentFetcher implements ContentFetcher {
+public class BasicHttpFetcher implements HttpFetcher {
private static final int CONNECT_TIMEOUT_MS = 5000;
private static final int DEFAULT_MAX_OBJECT_SIZE = 1024 * 1024;
private final int maxObjSize;
- private final ContentCache cache;
+ private final HttpCache cache;
/**
* Creates a new fetcher capable of retrieving objects {@code maxObjSize}
* bytes or smaller in size.
* @param maxObjSize Maximum size, in bytes, of object to fetch
*/
- public BasicRemoteContentFetcher(ContentCache cache, int maxObjSize) {
+ public BasicHttpFetcher(HttpCache cache, int maxObjSize) {
this.maxObjSize = maxObjSize;
this.cache = cache;
}
@@ -60,7 +60,7 @@
* Creates a new fetcher using the default maximum object size.
*/
@Inject
- public BasicRemoteContentFetcher(ContentCache cache) {
+ public BasicHttpFetcher(HttpCache cache) {
this(cache, DEFAULT_MAX_OBJECT_SIZE);
}
@@ -71,7 +71,7 @@
* @return The opened connection
* @throws IOException
*/
- private URLConnection getConnection(RemoteContentRequest request)
+ private URLConnection getConnection(HttpRequest request)
throws IOException {
URLConnection fetcher;
fetcher = request.getUri().toURL().openConnection();
@@ -105,17 +105,17 @@
/**
* @param fetcher
- * @return A RemoteContent object made by consuming the response of the
+ * @return A HttpResponse object made by consuming the response of the
* given HttpURLConnection.
*/
- private RemoteContent makeResponse(URLConnection fetcher)
+ private HttpResponse makeResponse(URLConnection fetcher)
throws IOException {
Map<String, List<String>> headers = fetcher.getHeaderFields();
int responseCode;
if (fetcher instanceof HttpURLConnection) {
responseCode = ((HttpURLConnection)fetcher).getResponseCode();
} else {
- responseCode = RemoteContent.SC_OK;
+ responseCode = HttpResponse.SC_OK;
}
String encoding = fetcher.getContentEncoding();
@@ -131,13 +131,13 @@
}
byte[] body = InputStreamConsumer.readToByteArray(is, maxObjSize);
- return new RemoteContent(responseCode, body, headers);
+ return new HttpResponse(responseCode, body, headers);
}
/** {@inheritDoc} */
- public RemoteContent fetch(RemoteContentRequest request) {
- RemoteContent content = cache.getContent(request);
- if (content != null) return content;
+ public HttpResponse fetch(HttpRequest request) {
+ HttpResponse response = cache.getResponse(request);
+ if (response != null) return response;
try {
URLConnection fetcher = getConnection(request);
if ("POST".equals(request.getMethod()) &&
@@ -151,14 +151,14 @@
InputStreamConsumer.pipe(request.getPostBody(),
fetcher.getOutputStream());
}
- content = makeResponse(fetcher);
- cache.addContent(request, content);
- return content;
+ response = makeResponse(fetcher);
+ cache.addResponse(request, response);
+ return response;
} catch (IOException e) {
if (e instanceof FileNotFoundException) {
- return RemoteContent.NOT_FOUND;
+ return HttpResponse.NOT_FOUND;
}
- return RemoteContent.ERROR;
+ return HttpResponse.ERROR;
}
}
}
Modified: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/ContentFetcherFactory.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/ContentFetcherFactory.java?rev=655788&r1=655787&r2=655788&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/ContentFetcherFactory.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/ContentFetcherFactory.java Tue May 13 02:19:01 2008
@@ -27,9 +27,11 @@
import com.google.inject.Provider;
/**
- * A factory of the supported ContentFetcher types.
+ * A factory of the supported HttpFetcher types.
+ *
+ * TODO: Remove this.
*/
-public class ContentFetcherFactory implements Provider<ContentFetcher> {
+public class ContentFetcherFactory implements Provider<HttpFetcher> {
private final RemoteContentFetcherFactory remoteContentFetcherFactory;
private final SigningFetcherFactory signingFetcherFactory;
@@ -49,7 +51,7 @@
* @return A signing content fetcher
* @throws GadgetException
*/
- public ContentFetcher getSigningFetcher(SecurityToken token)
+ public HttpFetcher getSigningFetcher(SecurityToken token)
throws GadgetException {
return signingFetcherFactory.getSigningFetcher(
remoteContentFetcherFactory.get(), token);
@@ -61,7 +63,7 @@
* @return an OAuth fetcher
* @throws GadgetException
*/
- public ContentFetcher getOAuthFetcher(
+ public HttpFetcher getOAuthFetcher(
SecurityToken token,
OAuthRequestParams params)
throws GadgetException {
@@ -72,7 +74,7 @@
/**
* @return a standard fetcher
*/
- public ContentFetcher get() {
+ public HttpFetcher get() {
return remoteContentFetcherFactory.get();
}
}
Copied: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/HttpCache.java (from r655783, incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/ContentCache.java)
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/HttpCache.java?p2=incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/HttpCache.java&p1=incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/ContentCache.java&r1=655783&r2=655788&rev=655788&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/ContentCache.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/HttpCache.java Tue May 13 02:19:01 2008
@@ -20,19 +20,19 @@
import java.net.URI;
/**
- * Cache of RemoteContent keyed by URI/RemoteContentRequest
+ * Cache of HttpResponse keyed by URI/HttpRequest
*/
-public interface ContentCache {
+public interface HttpCache {
- public RemoteContent getContent(URI uri);
+ public HttpResponse getResponse(URI uri);
- public RemoteContent getContent(RemoteContentRequest request);
+ public HttpResponse getResponse(HttpRequest request);
- public void addContent(URI uri, RemoteContent content);
+ public void addResponse(URI uri, HttpResponse response);
- public void addContent(RemoteContentRequest request, RemoteContent content);
+ public void addResponse(HttpRequest request, HttpResponse response);
- public RemoteContent removeContent(URI uri);
+ public HttpResponse removeResponse(URI uri);
- public RemoteContent removeContent(RemoteContentRequest request);
+ public HttpResponse removeResponse(HttpRequest request);
}
Copied: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/HttpFetcher.java (from r655783, incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/ContentFetcher.java)
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/HttpFetcher.java?p2=incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/HttpFetcher.java&p1=incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/ContentFetcher.java&r1=655783&r2=655788&rev=655788&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/ContentFetcher.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/HttpFetcher.java Tue May 13 02:19:01 2008
@@ -20,17 +20,17 @@
import org.apache.shindig.gadgets.GadgetException;
/**
- * Provide RemoteContent for a RemoteContentRequest
+ * Provide HttpResponse for a HttpRequest
*/
-public interface ContentFetcher {
+public interface HttpFetcher {
/**
* Fetch HTTP content.
*
* @param request The request to fetch.
- * @return RemoteContent
+ * @return HttpResponse
* @throws org.apache.shindig.gadgets.GadgetException
*/
- RemoteContent fetch(RemoteContentRequest request)
+ HttpResponse fetch(HttpRequest request)
throws GadgetException;
}
Copied: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/HttpRequest.java (from r655783, incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/RemoteContentRequest.java)
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/HttpRequest.java?p2=incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/HttpRequest.java&p1=incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/RemoteContentRequest.java&r1=655783&r2=655788&rev=655788&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/RemoteContentRequest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/HttpRequest.java Tue May 13 02:19:01 2008
@@ -37,7 +37,7 @@
* TODO: This naming seems really ridiculous now. Why don't we just call it
* what it is -- an HTTP request?
*/
-public class RemoteContentRequest {
+public class HttpRequest {
private final byte[] postBody;
/**
@@ -137,10 +137,10 @@
* @param uri
* @param ignoreCache
*/
- public static RemoteContentRequest getRequest(URI uri, boolean ignoreCache) {
+ public static HttpRequest getRequest(URI uri, boolean ignoreCache) {
Options options = new Options();
options.ignoreCache = ignoreCache;
- return new RemoteContentRequest(uri, options);
+ return new HttpRequest(uri, options);
}
/**
@@ -151,7 +151,7 @@
* @param postBody
* @param options
*/
- public RemoteContentRequest(String method,
+ public HttpRequest(String method,
URI uri,
Map<String, List<String>> headers,
byte[] postBody,
@@ -210,7 +210,7 @@
* @param uri
* @param base The base request to copy data from.
*/
- public RemoteContentRequest(URI uri, RemoteContentRequest base) {
+ public HttpRequest(URI uri, HttpRequest base) {
this.uri = uri;
this.method = base.method;
this.options = new Options(base.options);
@@ -224,7 +224,7 @@
*
* @param uri
*/
- public RemoteContentRequest(URI uri) {
+ public HttpRequest(URI uri) {
this("GET", uri, null, null, DEFAULT_OPTIONS);
}
@@ -234,7 +234,7 @@
* @param uri
* @param options
*/
- public RemoteContentRequest(URI uri, Options options) {
+ public HttpRequest(URI uri, Options options) {
this("GET", uri, null, null, options);
}
@@ -243,7 +243,7 @@
* @param uri
* @param headers
*/
- public RemoteContentRequest(URI uri, Map<String, List<String>> headers) {
+ public HttpRequest(URI uri, Map<String, List<String>> headers) {
this("GET", uri, headers, null, DEFAULT_OPTIONS);
}
@@ -253,7 +253,7 @@
* @param headers
* @param options
*/
- public RemoteContentRequest(URI uri, Map<String, List<String>> headers,
+ public HttpRequest(URI uri, Map<String, List<String>> headers,
Options options) {
this("GET", uri, headers, null, options);
}
@@ -263,7 +263,7 @@
* @param uri
* @param postBody
*/
- public RemoteContentRequest(URI uri, byte[] postBody) {
+ public HttpRequest(URI uri, byte[] postBody) {
this("POST", uri, null, postBody, DEFAULT_OPTIONS);
}
@@ -273,7 +273,7 @@
* @param postBody
* @param options
*/
- public RemoteContentRequest(URI uri, byte[] postBody, Options options) {
+ public HttpRequest(URI uri, byte[] postBody, Options options) {
this("POST", uri, null, postBody, options);
}
@@ -283,7 +283,7 @@
* @param headers
* @param postBody
*/
- public RemoteContentRequest(URI uri, Map<String, List<String>> headers,
+ public HttpRequest(URI uri, Map<String, List<String>> headers,
byte[] postBody) {
this("POST", uri, headers, postBody, DEFAULT_OPTIONS);
}
@@ -295,7 +295,7 @@
* @param postBody
* @param options
*/
- public RemoteContentRequest(URI uri, Map<String, List<String>> headers,
+ public HttpRequest(URI uri, Map<String, List<String>> headers,
byte[] postBody, Options options) {
this("POST", uri, headers, postBody, options);
}
@@ -329,8 +329,8 @@
@Override
public boolean equals(Object rhs) {
if (rhs == this) {return true;}
- if (rhs instanceof RemoteContentRequest) {
- RemoteContentRequest req = (RemoteContentRequest)rhs;
+ if (rhs instanceof HttpRequest) {
+ HttpRequest req = (HttpRequest)rhs;
return method.equals(req.method) &&
uri.equals(req.uri) &&
Arrays.equals(postBody, req.postBody) &&
@@ -349,7 +349,7 @@
* Bag of options for making a request.
*
* This object is mutable to keep us sane. Don't mess with it once you've
- * sent it to RemoteContentRequest or bad things might happen.
+ * sent it to HttpRequest or bad things might happen.
*/
public static class Options {
public boolean ignoreCache = false;
Added: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/HttpResponse.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/HttpResponse.java?rev=655788&view=auto
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/HttpResponse.java (added)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/HttpResponse.java Tue May 13 02:19:01 2008
@@ -0,0 +1,205 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.shindig.gadgets.http;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Represents the results of an HTTP content retrieval operation.
+ */
+public class HttpResponse {
+ // Replicate HTTP status codes here.
+ public final static int SC_OK = 200;
+ public final static int SC_NOT_FOUND = 404;
+ public final static int SC_INTERNAL_SERVER_ERROR = 500;
+
+ private final int httpStatusCode;
+ private static final String DEFAULT_ENCODING = "UTF-8";
+ private final String encoding;
+
+ public static final HttpResponse ERROR
+ = new HttpResponse(SC_INTERNAL_SERVER_ERROR);
+ public static final HttpResponse NOT_FOUND = new HttpResponse(SC_NOT_FOUND);
+
+ // Used to lazily convert to a string representation of the input.
+ private String responseString = null;
+ private final byte[] responseBytes;
+ private final Map<String, List<String>> headers;
+ private final Map<String, String> metadata;
+
+ /**
+ * Create a dummy empty map. Access via HttpResponse.ERROR
+ */
+ private HttpResponse(int statusCode) {
+ this.httpStatusCode = statusCode;
+ this.responseBytes = new byte[0];
+ this.encoding = DEFAULT_ENCODING;
+ this.headers = Collections.emptyMap();
+ this.metadata = new HashMap<String, String>();
+ }
+
+ /**
+ * @param httpStatusCode
+ * @param responseBytes
+ * @param headers May be null.
+ */
+ public HttpResponse(int httpStatusCode, byte[] responseBytes,
+ Map<String, List<String>> headers) {
+ this.httpStatusCode = httpStatusCode;
+ if (responseBytes == null) {
+ this.responseBytes = new byte[0];
+ } else {
+ this.responseBytes = new byte[responseBytes.length];
+ System.arraycopy(
+ responseBytes, 0, this.responseBytes, 0, responseBytes.length);
+ }
+
+ if (headers == null) {
+ this.headers = Collections.emptyMap();
+ } else {
+ Map<String, List<String>> tmpHeaders
+ = new HashMap<String, List<String>>();
+ for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
+ List<String> newList = new ArrayList<String>(entry.getValue());
+ tmpHeaders.put(entry.getKey(), Collections.unmodifiableList(newList));
+ }
+ this.headers = tmpHeaders;
+ }
+ this.metadata = new HashMap<String, String>();
+ this.encoding = detectEncoding();
+ }
+
+ /**
+ * Simple constructor for setting a basic response from a string. Mostly used
+ * for testing.
+ *
+ * @param body
+ */
+ public HttpResponse(String body) {
+ this(SC_OK, body.getBytes(), null);
+ }
+
+ /**
+ * Attempts to determine the encoding of the body. If it can't be determined,
+ * we use DEFAULT_ENCODING instead.
+ * @return The detected encoding or DEFAULT_ENCODING.
+ */
+ private String detectEncoding() {
+ String contentType = getHeader("Content-Type");
+ if (contentType != null) {
+ String[] parts = contentType.split(";");
+ if (parts.length == 2) {
+ int offset = parts[1].indexOf("charset=");
+ if (offset != -1) {
+ return parts[1].substring(offset + 8);
+ }
+ }
+ }
+ return DEFAULT_ENCODING;
+ }
+
+ public int getHttpStatusCode() {
+ return httpStatusCode;
+ }
+
+ /**
+ * @return The encoding of the response body, if we're able to determine it.
+ */
+ public String getEncoding() {
+ return encoding;
+ }
+
+ /**
+ * @return An input stream suitable for reading the entirety of the response.
+ */
+ public InputStream getResponse() {
+ return new ByteArrayInputStream(responseBytes);
+ }
+
+ /**
+ * Attempts to convert the response body to a string using the Content-Type
+ * header. If no Content-Type header is specified (or it doesn't include an
+ * encoding), we will assume it is UTF-8.
+ *
+ * @return The body as a string.
+ */
+ public String getResponseAsString() {
+ if (responseString == null) {
+ try {
+ String response = new String(responseBytes, encoding);
+ // Strip BOM.
+ if (response.length() > 0 && response.codePointAt(0) == 0xFEFF) {
+ responseString = response.substring(1);
+ } else {
+ responseString = response;
+ }
+ } catch (UnsupportedEncodingException e) {
+ responseString = "Unable to convert from encoding: " + encoding;
+ }
+ }
+ return responseString;
+ }
+
+ /**
+ * @return All headers for this object.
+ */
+ public Map<String, List<String>> getAllHeaders() {
+ return headers;
+ }
+
+ /**
+ * @param name
+ * @return All headers with the given name.
+ */
+ public List<String> getHeaders(String name) {
+ List<String> ret = headers.get(name);
+ if (ret == null) {
+ return Collections.emptyList();
+ } else {
+ return ret;
+ }
+ }
+
+ /**
+ * @param name
+ * @return The first set header with the given name or null if not set. If
+ * you need multiple values for the header, use getHeaders().
+ */
+ public String getHeader(String name) {
+ List<String> headerList = getHeaders(name);
+ if (headerList.size() == 0) {
+ return null;
+ } else {
+ return headerList.get(0);
+ }
+ }
+
+ /**
+ * @return additional data to embed in responses sent from the JSON proxy.
+ */
+ public Map<String, String> getMetadata() {
+ return this.metadata;
+ }
+}
Modified: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/RemoteContentFetcherFactory.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/RemoteContentFetcherFactory.java?rev=655788&r1=655787&r2=655788&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/RemoteContentFetcherFactory.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/RemoteContentFetcherFactory.java Tue May 13 02:19:01 2008
@@ -21,19 +21,21 @@
import com.google.inject.Provider;
/**
- * Factory for ContentFetcher's that retrieve remote content
+ * Factory for HttpFetcher's that retrieve remote content
+ *
+ * TODO: Remove this.
*/
-public class RemoteContentFetcherFactory implements Provider<ContentFetcher> {
+public class RemoteContentFetcherFactory implements Provider<HttpFetcher> {
- private ContentCache cache;
+ private HttpCache cache;
@Inject
- public RemoteContentFetcherFactory(ContentCache cache) {
+ public RemoteContentFetcherFactory(HttpCache cache) {
this.cache = cache;
}
- public ContentFetcher get() {
- return new BasicRemoteContentFetcher(cache);
+ public HttpFetcher get() {
+ return new BasicHttpFetcher(cache);
}
}
Modified: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth/BasicGadgetOAuthTokenStore.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth/BasicGadgetOAuthTokenStore.java?rev=655788&r1=655787&r2=655788&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth/BasicGadgetOAuthTokenStore.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth/BasicGadgetOAuthTokenStore.java Tue May 13 02:19:01 2008
@@ -20,9 +20,9 @@
import org.apache.shindig.common.util.ResourceLoader;
import org.apache.shindig.gadgets.GadgetException;
-import org.apache.shindig.gadgets.http.ContentFetcher;
-import org.apache.shindig.gadgets.http.RemoteContent;
-import org.apache.shindig.gadgets.http.RemoteContentRequest;
+import org.apache.shindig.gadgets.http.HttpFetcher;
+import org.apache.shindig.gadgets.http.HttpResponse;
+import org.apache.shindig.gadgets.http.HttpRequest;
import org.apache.shindig.gadgets.spec.GadgetSpec;
import org.json.JSONException;
import org.json.JSONObject;
@@ -45,7 +45,7 @@
super(store);
}
- public void initFromConfigFile(ContentFetcher fetcher)
+ public void initFromConfigFile(HttpFetcher fetcher)
throws GadgetException {
// Read our consumer keys and secrets from config/oauth.js
// This actually involves fetching gadget specs
@@ -71,11 +71,11 @@
}
}
- private void storeProviderInfos(ContentFetcher fetcher, URI gadgetUri)
+ private void storeProviderInfos(HttpFetcher fetcher, URI gadgetUri)
throws GadgetException {
- RemoteContentRequest request = RemoteContentRequest.getRequest(
+ HttpRequest request = HttpRequest.getRequest(
gadgetUri, false);
- RemoteContent response = fetcher.fetch(request);
+ HttpResponse response = fetcher.fetch(request);
GadgetSpec spec
= new GadgetSpec(gadgetUri, response.getResponseAsString());
storeServiceInfoFromGadgetSpec(gadgetUri, spec);
Modified: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth/OAuthFetcher.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth/OAuthFetcher.java?rev=655788&r1=655787&r2=655788&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth/OAuthFetcher.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth/OAuthFetcher.java Tue May 13 02:19:01 2008
@@ -21,10 +21,10 @@
import org.apache.shindig.common.crypto.BlobCrypterException;
import org.apache.shindig.gadgets.ChainedContentFetcher;
import org.apache.shindig.gadgets.GadgetException;
-import org.apache.shindig.gadgets.http.ContentFetcher;
-import org.apache.shindig.gadgets.http.RemoteContent;
-import org.apache.shindig.gadgets.http.RemoteContentRequest;
-import org.apache.shindig.gadgets.http.RemoteContentRequest.Options;
+import org.apache.shindig.gadgets.http.HttpFetcher;
+import org.apache.shindig.gadgets.http.HttpResponse;
+import org.apache.shindig.gadgets.http.HttpRequest;
+import org.apache.shindig.gadgets.http.HttpRequest.Options;
import net.oauth.OAuth;
import net.oauth.OAuthAccessor;
@@ -108,7 +108,7 @@
/**
* The request the client really wants to make.
*/
- private RemoteContentRequest realRequest;
+ private HttpRequest realRequest;
/**
* State to cache on the client.
@@ -132,7 +132,7 @@
public OAuthFetcher(
GadgetOAuthTokenStore tokenStore,
BlobCrypter oauthCrypter,
- ContentFetcher nextFetcher,
+ HttpFetcher nextFetcher,
SecurityToken authToken,
OAuthRequestParams params) {
super(nextFetcher);
@@ -198,7 +198,7 @@
return tokenKey;
}
- public RemoteContent fetch(RemoteContentRequest request)
+ public HttpResponse fetch(HttpRequest request)
throws GadgetException {
this.realRequest = request;
if (needApproval()) {
@@ -327,7 +327,7 @@
return result.toString();
}
- private RemoteContentRequest createRemoteContentRequest(
+ private HttpRequest createHttpRequest(
List<Map.Entry<String, String>> oauthParams, String method,
String url, Map<String, List<String>> headers, String contentType,
String postBody, Options options)
@@ -377,7 +377,7 @@
? null
: postBody.getBytes("UTF-8");
- return new RemoteContentRequest(method, new URI(url), newHeaders,
+ return new HttpRequest(method, new URI(url), newHeaders,
postBodyBytes, options);
}
@@ -387,18 +387,18 @@
private OAuthMessage sendOAuthMessage(OAuthMessage request)
throws IOException, URISyntaxException, GadgetException {
- RemoteContentRequest rcr =
- createRemoteContentRequest(filterOAuthParams(request),
+ HttpRequest rcr =
+ createHttpRequest(filterOAuthParams(request),
request.method,
request.URL,
null,
- RemoteContentRequest.DEFAULT_CONTENT_TYPE,
+ HttpRequest.DEFAULT_CONTENT_TYPE,
null,
- RemoteContentRequest.DEFAULT_OPTIONS);
+ HttpRequest.DEFAULT_OPTIONS);
- RemoteContent content = nextFetcher.fetch(rcr);
+ HttpResponse response = nextFetcher.fetch(rcr);
OAuthMessage reply = new OAuthMessage(null, null, null);
- reply.addParameters(OAuth.decodeForm(content.getResponseAsString()));
+ reply.addParameters(OAuth.decodeForm(response.getResponseAsString()));
return reply;
}
@@ -438,18 +438,18 @@
aznUrl = azn.toString();
}
- private RemoteContent buildOAuthApprovalResponse() {
- RemoteContent content = new RemoteContent(0, null, null);
- addResponseMetadata(content);
- return content;
+ private HttpResponse buildOAuthApprovalResponse() {
+ HttpResponse response = new HttpResponse(0, null, null);
+ addResponseMetadata(response);
+ return response;
}
- private void addResponseMetadata(RemoteContent content) {
+ private void addResponseMetadata(HttpResponse response) {
if (newClientState != null) {
- content.getMetadata().put(CLIENT_STATE, newClientState);
+ response.getMetadata().put(CLIENT_STATE, newClientState);
}
if (aznUrl != null) {
- content.getMetadata().put(APPROVAL_URL, aznUrl);
+ response.getMetadata().put(APPROVAL_URL, aznUrl);
}
}
@@ -514,7 +514,7 @@
/**
* Get honest-to-goodness user data.
*/
- private RemoteContent fetchData() throws GadgetException {
+ private HttpResponse fetchData() throws GadgetException {
try {
List<OAuth.Parameter> msgParams =
OAuth.isFormEncoded(realRequest.getContentType())
@@ -527,8 +527,8 @@
OAuthMessage oauthRequest = newRequestMessage(
method, realRequest.getUri().toASCIIString(), msgParams);
- RemoteContent content = nextFetcher.fetch(
- createRemoteContentRequest(
+ HttpResponse response = nextFetcher.fetch(
+ createHttpRequest(
filterOAuthParams(oauthRequest),
realRequest.getMethod(),
realRequest.getUri().toASCIIString(),
@@ -538,8 +538,8 @@
realRequest.getOptions()));
// Track metadata on the response
- addResponseMetadata(content);
- return content;
+ addResponseMetadata(response);
+ return response;
} catch (UnsupportedEncodingException e) {
throw new GadgetException(GadgetException.Code.INTERNAL_SERVER_ERROR, e);
} catch (IOException e) {
Modified: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth/OAuthFetcherFactory.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth/OAuthFetcherFactory.java?rev=655788&r1=655787&r2=655788&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth/OAuthFetcherFactory.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/oauth/OAuthFetcherFactory.java Tue May 13 02:19:01 2008
@@ -23,7 +23,7 @@
import org.apache.shindig.common.crypto.BlobCrypter;
import org.apache.shindig.common.crypto.Crypto;
import org.apache.shindig.gadgets.GadgetException;
-import org.apache.shindig.gadgets.http.ContentFetcher;
+import org.apache.shindig.gadgets.http.HttpFetcher;
import com.google.inject.BindingAnnotation;
import com.google.inject.Inject;
@@ -54,7 +54,7 @@
* BlobCrypter and consumer keys/secrets read from oauth.js
*/
@Inject
- public OAuthFetcherFactory(@OAuthConfigFetcher ContentFetcher fetcher) {
+ public OAuthFetcherFactory(@OAuthConfigFetcher HttpFetcher fetcher) {
try {
this.oauthCrypter = new BasicBlobCrypter(
Crypto.getRandomBytes(BasicBlobCrypter.MASTER_KEY_MIN_LEN));
@@ -94,7 +94,7 @@
* @throws GadgetException
*/
public OAuthFetcher getOAuthFetcher(
- ContentFetcher nextFetcher,
+ HttpFetcher nextFetcher,
SecurityToken token,
OAuthRequestParams params) throws GadgetException {
OAuthFetcher fetcher = new OAuthFetcher(
Modified: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/GadgetRenderingTask.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/GadgetRenderingTask.java?rev=655788&r1=655787&r2=655788&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/GadgetRenderingTask.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/GadgetRenderingTask.java Tue May 13 02:19:01 2008
@@ -29,7 +29,7 @@
import org.apache.shindig.gadgets.GadgetServer;
import org.apache.shindig.gadgets.JsLibrary;
import org.apache.shindig.gadgets.LockedDomainService;
-import org.apache.shindig.gadgets.http.RemoteContent;
+import org.apache.shindig.gadgets.http.HttpResponse;
import org.apache.shindig.gadgets.spec.Feature;
import org.apache.shindig.gadgets.spec.LocaleSpec;
import org.apache.shindig.gadgets.spec.MessageBundle;
@@ -438,11 +438,11 @@
// Output preloads. We will allow the gadget render to continue
// even if a preload fails
JSONObject resp = new JSONObject();
- for (Map.Entry<Preload, Future<RemoteContent>> entry
+ for (Map.Entry<Preload, Future<HttpResponse>> entry
: gadget.getPreloadMap().entrySet()) {
Preload preload = entry.getKey();
try {
- RemoteContent response = entry.getValue().get();
+ HttpResponse response = entry.getValue().get();
// Use raw param as key as URL may have to be decoded
JSONObject jsonEntry = new JSONObject();
jsonEntry.put("body", response.getResponseAsString())
Modified: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/ProxyHandler.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/ProxyHandler.java?rev=655788&r1=655787&r2=655788&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/ProxyHandler.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/ProxyHandler.java Tue May 13 02:19:01 2008
@@ -24,10 +24,10 @@
import org.apache.shindig.common.util.InputStreamConsumer;
import org.apache.shindig.gadgets.GadgetException;
import org.apache.shindig.gadgets.LockedDomainService;
-import org.apache.shindig.gadgets.http.ContentFetcher;
+import org.apache.shindig.gadgets.http.HttpFetcher;
import org.apache.shindig.gadgets.http.ContentFetcherFactory;
-import org.apache.shindig.gadgets.http.RemoteContent;
-import org.apache.shindig.gadgets.http.RemoteContentRequest;
+import org.apache.shindig.gadgets.http.HttpResponse;
+import org.apache.shindig.gadgets.http.HttpRequest;
import org.apache.shindig.gadgets.oauth.OAuthRequestParams;
import org.apache.shindig.gadgets.spec.Auth;
import org.apache.shindig.gadgets.spec.Preload;
@@ -117,13 +117,13 @@
throws IOException, GadgetException {
// Build up the request to make
- RemoteContentRequest rcr = buildRemoteContentRequest(request);
+ HttpRequest rcr = buildHttpRequest(request);
// Build the chain of fetchers that will handle the request
- ContentFetcher fetcher = getContentFetcher(request, response);
+ HttpFetcher fetcher = getHttpFetcher(request, response);
// Do the fetch
- RemoteContent results = fetcher.fetch(rcr);
+ HttpResponse results = fetcher.fetch(rcr);
// Serialize the response
String output = serializeJsonResponse(request, results);
@@ -148,7 +148,7 @@
* @throws GadgetException
*/
@SuppressWarnings("unchecked")
- private RemoteContentRequest buildRemoteContentRequest(
+ private HttpRequest buildHttpRequest(
HttpServletRequest request) throws GadgetException {
try {
String encoding = request.getCharacterEncoding();
@@ -197,8 +197,8 @@
removeUnsafeHeaders(headers);
- RemoteContentRequest.Options options =
- new RemoteContentRequest.Options();
+ HttpRequest.Options options =
+ new HttpRequest.Options();
options.ignoreCache = "1".equals(request.getParameter(NOCACHE_PARAM));
if (request.getParameter(SIGN_VIEWER) != null) {
options.viewerSigned = Boolean
@@ -209,7 +209,7 @@
.parseBoolean(request.getParameter(SIGN_OWNER));
}
- return new RemoteContentRequest(
+ return new HttpRequest(
method, url, headers, postBody, options);
} catch (UnsupportedEncodingException e) {
throw new GadgetException(GadgetException.Code.INTERNAL_SERVER_ERROR, e);
@@ -223,7 +223,7 @@
* Whatever we do needs to return a reference to the OAuthFetcher, if it is
* present, so we can pull data out as needed.
*/
- private ContentFetcher getContentFetcher(HttpServletRequest request,
+ private HttpFetcher getHttpFetcher(HttpServletRequest request,
HttpServletResponse response) throws GadgetException {
String authzType = getParameter(request, Preload.AUTHZ_ATTR, "");
@@ -251,7 +251,7 @@
* chained content fetchers.
*/
private String serializeJsonResponse(HttpServletRequest request,
- RemoteContent results) {
+ HttpResponse results) {
try {
JSONObject resp = new JSONObject();
@@ -300,8 +300,8 @@
return;
}
- RemoteContentRequest rcr = buildRemoteContentRequest(request);
- RemoteContent results = contentFetcherFactory.get().fetch(rcr);
+ HttpRequest rcr = buildHttpRequest(request);
+ HttpResponse results = contentFetcherFactory.get().fetch(rcr);
// Default interval of 1 hour
int refreshInterval = 60 * 60;
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/GadgetServerTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/GadgetServerTest.java?rev=655788&r1=655787&r2=655788&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/GadgetServerTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/GadgetServerTest.java Tue May 13 02:19:01 2008
@@ -20,8 +20,8 @@
import org.apache.shindig.common.BasicSecurityToken;
import org.apache.shindig.common.SecurityToken;
import org.apache.shindig.common.crypto.BlobCrypterException;
-import org.apache.shindig.gadgets.http.RemoteContent;
-import org.apache.shindig.gadgets.http.RemoteContentRequest;
+import org.apache.shindig.gadgets.http.HttpResponse;
+import org.apache.shindig.gadgets.http.HttpRequest;
import org.apache.shindig.gadgets.spec.GadgetSpec;
import static org.easymock.EasyMock.eq;
import static org.easymock.EasyMock.expect;
@@ -33,11 +33,11 @@
public class GadgetServerTest extends GadgetTestFixture {
private final static URI SPEC_URL = URI.create("http://example.org/g.xml");
- private final static RemoteContentRequest SPEC_REQUEST
- = new RemoteContentRequest(SPEC_URL);
+ private final static HttpRequest SPEC_REQUEST
+ = new HttpRequest(SPEC_URL);
private final static URI BUNDLE_URL = URI.create("http://example.org/m.xml");
- private final static RemoteContentRequest BUNDLE_REQUEST
- = new RemoteContentRequest(BUNDLE_URL);
+ private final static HttpRequest BUNDLE_REQUEST
+ = new HttpRequest(BUNDLE_URL);
private final static GadgetContext BASIC_CONTEXT = new GadgetContext() {
@Override
public URI getUrl() {
@@ -71,8 +71,8 @@
"</messagebundle>";
public void testGadgetSpecLookup() throws Exception {
- RemoteContentRequest req = new RemoteContentRequest(SPEC_URL);
- RemoteContent resp = new RemoteContent(BASIC_SPEC_XML);
+ HttpRequest req = new HttpRequest(SPEC_URL);
+ HttpResponse resp = new HttpResponse(BASIC_SPEC_XML);
expect(fetcher.fetch(req)).andReturn(resp);
replay();
@@ -107,8 +107,8 @@
}
};
- RemoteContent spec = new RemoteContent(gadgetXml);
- RemoteContent bundle = new RemoteContent(BASIC_BUNDLE_XML);
+ HttpResponse spec = new HttpResponse(gadgetXml);
+ HttpResponse bundle = new HttpResponse(BASIC_BUNDLE_XML);
expect(fetcher.fetch(SPEC_REQUEST)).andReturn(spec);
expect(fetcher.fetch(BUNDLE_REQUEST)).andReturn(bundle);
@@ -127,8 +127,8 @@
public void testPreloadsFetched() throws Exception {
String preloadUrl = "http://example.org/preload.txt";
String preloadData = "Preload Data";
- RemoteContentRequest preloadRequest
- = new RemoteContentRequest(URI.create(preloadUrl));
+ HttpRequest preloadRequest
+ = new HttpRequest(URI.create(preloadUrl));
String gadgetXml
= "<Module>" +
@@ -139,9 +139,9 @@
"</Module>";
expect(fetcherFactory.get()).andReturn(fetcher);
expect(fetcher.fetch(SPEC_REQUEST))
- .andReturn(new RemoteContent(gadgetXml));
+ .andReturn(new HttpResponse(gadgetXml));
expect(fetcher.fetch(preloadRequest))
- .andReturn(new RemoteContent(preloadData));
+ .andReturn(new HttpResponse(preloadData));
replay();
Gadget gadget = gadgetServer.processGadget(BASIC_CONTEXT);
@@ -153,8 +153,8 @@
public void testPreloadViewMatch() throws Exception {
String preloadUrl = "http://example.org/preload.txt";
String preloadData = "Preload Data";
- RemoteContentRequest preloadRequest
- = new RemoteContentRequest(URI.create(preloadUrl));
+ HttpRequest preloadRequest
+ = new HttpRequest(URI.create(preloadUrl));
String gadgetXml
= "<Module>" +
@@ -165,9 +165,9 @@
"</Module>";
expect(fetcherFactory.get()).andReturn(fetcher);
expect(fetcher.fetch(SPEC_REQUEST))
- .andReturn(new RemoteContent(gadgetXml));
+ .andReturn(new HttpResponse(gadgetXml));
expect(fetcher.fetch(preloadRequest))
- .andReturn(new RemoteContent(preloadData));
+ .andReturn(new HttpResponse(preloadData));
replay();
GadgetContext context = new GadgetContext() {
@@ -190,8 +190,8 @@
public void testPreloadAntiMatch() throws Exception {
String preloadUrl = "http://example.org/preload.txt";
String preloadData = "Preload Data";
- RemoteContentRequest preloadRequest
- = new RemoteContentRequest(URI.create(preloadUrl));
+ HttpRequest preloadRequest
+ = new HttpRequest(URI.create(preloadUrl));
String gadgetXml
= "<Module>" +
@@ -202,9 +202,9 @@
"</Module>";
expect(fetcherFactory.get()).andReturn(fetcher);
expect(fetcher.fetch(SPEC_REQUEST))
- .andReturn(new RemoteContent(gadgetXml));
+ .andReturn(new HttpResponse(gadgetXml));
expect(fetcher.fetch(preloadRequest))
- .andReturn(new RemoteContent(preloadData));
+ .andReturn(new HttpResponse(preloadData));
replay();
GadgetContext context = new GadgetContext() {
@@ -226,8 +226,8 @@
public void testNoSignedPreloadWithoutToken() throws Exception {
String preloadUrl = "http://example.org/preload.txt";
String preloadData = "Preload Data";
- RemoteContentRequest preloadRequest
- = new RemoteContentRequest(URI.create(preloadUrl));
+ HttpRequest preloadRequest
+ = new HttpRequest(URI.create(preloadUrl));
String gadgetXml
= "<Module>" +
@@ -237,7 +237,7 @@
" <Content type=\"html\" view=\"v1,v2\">dummy</Content>" +
"</Module>";
expect(fetcher.fetch(SPEC_REQUEST))
- .andReturn(new RemoteContent(gadgetXml));
+ .andReturn(new HttpResponse(gadgetXml));
replay();
GadgetContext context = new GadgetContext() {
@@ -254,8 +254,8 @@
public void testSignedPreloadWithToken() throws Exception {
String preloadUrl = "http://example.org/preload.txt";
String preloadData = "Preload Data";
- RemoteContentRequest preloadRequest
- = new RemoteContentRequest(URI.create(preloadUrl));
+ HttpRequest preloadRequest
+ = new HttpRequest(URI.create(preloadUrl));
String gadgetXml
= "<Module>" +
@@ -265,11 +265,11 @@
" <Content type=\"html\" view=\"v1,v2\">dummy</Content>" +
"</Module>";
expect(fetcher.fetch(SPEC_REQUEST))
- .andReturn(new RemoteContent(gadgetXml));
+ .andReturn(new HttpResponse(gadgetXml));
expect(fetcherFactory.getSigningFetcher(BASIC_CONTEXT.getToken()))
.andReturn(fetcher);
expect(fetcher.fetch(preloadRequest))
- .andReturn(new RemoteContent(preloadData));
+ .andReturn(new HttpResponse(preloadData));
replay();
Gadget gadget = gadgetServer.processGadget(BASIC_CONTEXT);
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/GadgetTestFixture.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/GadgetTestFixture.java?rev=655788&r1=655787&r2=655788&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/GadgetTestFixture.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/GadgetTestFixture.java Tue May 13 02:19:01 2008
@@ -20,7 +20,7 @@
package org.apache.shindig.gadgets;
import org.apache.shindig.common.SecurityTokenDecoder;
-import org.apache.shindig.gadgets.http.ContentFetcher;
+import org.apache.shindig.gadgets.http.HttpFetcher;
import org.apache.shindig.gadgets.http.ContentFetcherFactory;
import java.util.concurrent.Executor;
@@ -36,7 +36,7 @@
public final GadgetServer gadgetServer;
public final ContentFetcherFactory fetcherFactory
= mock(ContentFetcherFactory.class);
- public final ContentFetcher fetcher = mock(ContentFetcher.class);
+ public final HttpFetcher fetcher = mock(HttpFetcher.class);
public final GadgetBlacklist blacklist = mock(GadgetBlacklist.class);
public GadgetFeatureRegistry registry;
public ContainerConfig containerConfig;
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/InterceptingContentFetcher.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/InterceptingContentFetcher.java?rev=655788&r1=655787&r2=655788&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/InterceptingContentFetcher.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/InterceptingContentFetcher.java Tue May 13 02:19:01 2008
@@ -14,8 +14,8 @@
package org.apache.shindig.gadgets;
-import org.apache.shindig.gadgets.http.RemoteContent;
-import org.apache.shindig.gadgets.http.RemoteContentRequest;
+import org.apache.shindig.gadgets.http.HttpResponse;
+import org.apache.shindig.gadgets.http.HttpRequest;
/**
* Test utility to intercept remote content requests for inspection.
@@ -26,9 +26,9 @@
super(null);
}
- public RemoteContentRequest interceptedRequest;
+ public HttpRequest interceptedRequest;
- public RemoteContent fetch(RemoteContentRequest request) {
+ public HttpResponse fetch(HttpRequest request) {
interceptedRequest = request;
return null;
}