|
From: <ian...@us...> - 2008-02-12 21:19:17
|
Revision: 741
http://ogoglio.svn.sourceforge.net/ogoglio/?rev=741&view=rev
Author: iansmith
Date: 2008-02-12 13:19:22 -0800 (Tue, 12 Feb 2008)
Log Message:
-----------
Fixed the redirect bug properly by changing the APIWire class to understand about GET without redirect. Only tests are likely to want this feature, but it's there.
Modified Paths:
--------------
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/WebAPIClient.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/WebAPIClientWire.java
maven/trunk/ogoglio-integration-test/src/test/java/com/ogoglio/client/test/ClientTest.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/media/WebStore.java
maven/trunk/ogoglio-server/src/main/resources/log4j/log4j.properties
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/WebAPIClient.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/WebAPIClient.java 2008-02-12 05:00:32 UTC (rev 740)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/WebAPIClient.java 2008-02-12 21:19:22 UTC (rev 741)
@@ -331,7 +331,7 @@
}
public InputStream getTemplateGeometryStream(String ownerUsername, long templateID, int lodIndex) throws IOException {
- return wire.performGET(descriptor.getTemplateGeometryURI(ownerUsername, templateID, lodIndex), authenticator.getAuthCookie(), true);
+ return wire.performGET(descriptor.getTemplateGeometryURI(ownerUsername, templateID, lodIndex), authenticator.getAuthCookie(), true, true);
}
public void uploadTemplateResourceStream(String ownerUsername, long templateID, String name, InputStream input) throws IOException {
@@ -339,7 +339,7 @@
}
public InputStream getTemplateResourceStream(String ownerUsername, long templateID, String name) throws IOException {
- return wire.performGET(descriptor.getTemplateResourceURI(ownerUsername, templateID, name), authenticator.getAuthCookie(), false);
+ return wire.performGET(descriptor.getTemplateResourceURI(ownerUsername, templateID, name), authenticator.getAuthCookie(), false, true);
}
public void updateTemplateScript(String ownerUsername, long templateID, String script) throws IOException {
@@ -396,7 +396,7 @@
public String getTemplateScript(String ownerUsername, long templateID) {
try {
- InputStream input = wire.performGET(descriptor.getTemplateScriptURI(ownerUsername, templateID), authenticator.getAuthCookie(), false);
+ InputStream input = wire.performGET(descriptor.getTemplateScriptURI(ownerUsername, templateID), authenticator.getAuthCookie(), false, true);
return StreamUtils.readInput(input);
} catch (IOException e) {
return null;
@@ -462,7 +462,7 @@
}
public InputStream getPageContents(long spaceID, long thingID, long pageID) throws IOException {
- return wire.performGET(descriptor.getPageContentsURI(spaceID, thingID, pageID), authenticator.getAuthCookie(), false);
+ return wire.performGET(descriptor.getPageContentsURI(spaceID, thingID, pageID), authenticator.getAuthCookie(), false, true);
}
public Map getSpaceSettings(long spaceID) throws IOException {
@@ -491,7 +491,7 @@
public String getSpaceSetting(long spaceID, String key) {
try {
- InputStream stream = wire.performGET(descriptor.getSettingURI(spaceID, key), authenticator.getAuthCookie(), false);
+ InputStream stream = wire.performGET(descriptor.getSettingURI(spaceID, key), authenticator.getAuthCookie(), false, true);
if (stream == null) {
return null;
}
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/WebAPIClientWire.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/WebAPIClientWire.java 2008-02-12 05:00:32 UTC (rev 740)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/WebAPIClientWire.java 2008-02-12 21:19:22 UTC (rev 741)
@@ -139,11 +139,26 @@
public XMLElement fetchAuthenticatedXML(URI uri, String authCookie) throws IOException {
XMLElement data = new XMLElement();
- data.parseFromReader(new InputStreamReader(performGET(uri, authCookie, false)));
+ data.parseFromReader(new InputStreamReader(performGET(uri, authCookie, false, true)));
return data;
}
- public DecoratedInputStream performGET(URI uri, String authCookie, boolean requestCompression) throws IOException {
+ /**
+ * This method does a get an returns an input stream connected to the supplied URI. The stream
+ * is decompressed, even if you request compression. The followRedirects switch is probably
+ * only useful to tests, as it returns null if a redirect was found (rather than the default
+ * behavior of following redirects) and the flag was false. The redirect URI cannot be
+ * recovered. There is no return path other than the redirection that returns null; other
+ * error cases cause an IOException to be thrown.
+ *
+ * @param uri URI to connect the stream to
+ * @param authCookie optional auth cookie for an authenticated URI (this can be null for no authentication)
+ * @param requestCompression pass true if you are expecting a really large object to be returned
+ * @param followRedirects pass false to cause this method to not follow redirects and return null if one is found
+ * @return a DecoratedInputStream that is connected to the URI
+ * @throws IOException thrown if an type of error is encountered trying to read the URI. Can happen due to HTTP error codes or connectivity problems.
+ */
+ public DecoratedInputStream performGET(URI uri, String authCookie, boolean requestCompression, boolean followRedirects) throws IOException {
String version = System.getProperty("java.version");
if ((version == null) || version.startsWith(BAD_SUN_VERSION)) {
//THIS IS TO WORK AROUND SUN'S ABSOLUTELY BROKEN APPLET CACHE IN JRE 1.6u1 & 2
@@ -172,15 +187,34 @@
if (requestCompression) {
connection.setRequestProperty("Accept-encoding", "gzip");
}
+ if (!followRedirects) { //switch it on, it's a static property? why?
+ HttpURLConnection.setFollowRedirects(false);
+ }
connection.setDoOutput(false);
- if (connection.getResponseCode() != 200) {
+ int code = connection.getResponseCode();
+ if (code != 200) {
+ if (!followRedirects) {
+ //we have to switch it back to prevent problems in the future
+ //XXX does this mean we can get concurrency problems in wire?
+ HttpURLConnection.setFollowRedirects(true);
+ if ((code>=300) && (code<400)) {
+ return null;
+ }
+ }
throw new IOException("Get status " + connection.getResponseCode() + " from " + uri);
}
+ DecoratedInputStream dis;
if ("gzip".equals(connection.getHeaderField("Content-encoding"))) {
- return new DecoratedInputStream(new GZIPInputStream(connection.getInputStream()), connection.getContentLength(), connection.getContentType(), connection.getLastModified());
+ dis=new DecoratedInputStream(new GZIPInputStream(connection.getInputStream()), connection.getContentLength(), connection.getContentType(), connection.getLastModified());
} else {
- return new DecoratedInputStream(connection.getInputStream(), connection.getContentLength(), connection.getContentType(), connection.getLastModified());
+ dis=new DecoratedInputStream(connection.getInputStream(), connection.getContentLength(), connection.getContentType(), connection.getLastModified());
}
+ if (!followRedirects) {
+ //we have to switch it back to prevent problems in the future
+ //XXX does this mean we can get concurrency problems in wire?
+ HttpURLConnection.setFollowRedirects(true);
+ }
+ return dis;
}
public XMLElement postAuthenticatedXML(URI uri, String body, String authCookie) throws IOException {
Modified: maven/trunk/ogoglio-integration-test/src/test/java/com/ogoglio/client/test/ClientTest.java
===================================================================
--- maven/trunk/ogoglio-integration-test/src/test/java/com/ogoglio/client/test/ClientTest.java 2008-02-12 05:00:32 UTC (rev 740)
+++ maven/trunk/ogoglio-integration-test/src/test/java/com/ogoglio/client/test/ClientTest.java 2008-02-12 21:19:22 UTC (rev 741)
@@ -223,13 +223,7 @@
assertFalse(accountDoc.isEmailValid());
String emailValidationURL = getLastEmailValidationURL(accountDoc.getEmail());
assertNotNull(emailValidationURL);
- try {
- StreamUtils.discardInput(wire1.performGET(URI.create(emailValidationURL), null));
- } catch (IOException e) {
- //this can have a few meanings, including that you haven't
- Log.info("TURNING OFF THIS TEST UNTIL TOMORROW BECAUSE IT BREAKS THE BUILD");
- //fail("You were unable to GET the URL for email validation: it may mean that you ROOT application's web page (/emailValidated.html) hasn't been built yet.");
- }
+ StreamUtils.discardInput(wire1.performGET(URI.create(emailValidationURL), null, false, false));
accountDoc = adminWebClient.getAccountDocument(username);
assertTrue(accountDoc.isEmailValid());
Modified: maven/trunk/ogoglio-server/src/main/java/com/ogoglio/media/WebStore.java
===================================================================
--- maven/trunk/ogoglio-server/src/main/java/com/ogoglio/media/WebStore.java 2008-02-12 05:00:32 UTC (rev 740)
+++ maven/trunk/ogoglio-server/src/main/java/com/ogoglio/media/WebStore.java 2008-02-12 21:19:22 UTC (rev 741)
@@ -52,7 +52,7 @@
public DecoratedInputStream getData(String name) {
try {
- return new WebAPIClientWire().performGET(WebAPIUtil.appendToURI(mediaURI, name), null, false);
+ return new WebAPIClientWire().performGET(WebAPIUtil.appendToURI(mediaURI, name), null, false, true);
} catch (IOException e) {
return null;
}
@@ -78,7 +78,7 @@
//This is really expensive and probably shouldn't be used except in the most rare of circumstances
public String[] getAllNames() {
try {
- DecoratedInputStream dis = new WebAPIClientWire().performGET(WebAPIUtil.appendToURI(mediaURI, "?list=true"), null, false);
+ DecoratedInputStream dis = new WebAPIClientWire().performGET(WebAPIUtil.appendToURI(mediaURI, "?list=true"), null, false, true);
InputStreamReader isr = new InputStreamReader(dis);
BufferedReader reader = new BufferedReader(isr);
List result = new ArrayList();
Modified: maven/trunk/ogoglio-server/src/main/resources/log4j/log4j.properties
===================================================================
--- maven/trunk/ogoglio-server/src/main/resources/log4j/log4j.properties 2008-02-12 05:00:32 UTC (rev 740)
+++ maven/trunk/ogoglio-server/src/main/resources/log4j/log4j.properties 2008-02-12 21:19:22 UTC (rev 741)
@@ -4,7 +4,7 @@
log4j.logger.org.apache=ERROR, R
log4j.logger.org.hibernate=ERROR, R
-log4j.logger.com.ogoglio=DEBUG, R
+log4j.logger.com.ogoglio=WARNING, R
log4j.logger.com.ogoglio.space=ERROR, R
#
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|