|
From: <tre...@us...> - 2007-06-29 23:23:01
|
Revision: 203
http://ogoglio.svn.sourceforge.net/ogoglio/?rev=203&view=rev
Author: trevorolio
Date: 2007-06-29 16:23:02 -0700 (Fri, 29 Jun 2007)
Log Message:
-----------
Dropped S3 specific code since using S3 directly is a Bad Idea, learned painfully during this morning's outage.
Added WebStore and MediaServlet to replace S3. Together these allow multiple instances to use a single file store fronted by a simple servlet.
Added an ogoglio/mediaDirectory environment parameter to servlet.xml to indicate when the MediaServlet should serve (not a good idea unless firewalled).
Set more threads to daemon and cleaned up more Java3D state on renderer shutdown in hopes of alleviating cross space teleport leaks.
Safari seems happier when shutting down the viewer applet, but it's unclear that this will help in production.
Despite this, the sims still keep Tomcat alive past context cleanup.
Moved test account and template creation into the ClientTests instead of inflicting it on all installations.
Modified Paths:
--------------
spaces/trunk/.classpath
spaces/trunk/build.xml
spaces/trunk/docs/server.xml
spaces/trunk/src/com/ogoglio/client/ClientTests.java
spaces/trunk/src/com/ogoglio/client/SpaceDuplicatorTests.java
spaces/trunk/src/com/ogoglio/client/WebAPIClient.java
spaces/trunk/src/com/ogoglio/media/FileStore.java
spaces/trunk/src/com/ogoglio/media/MediaService.java
spaces/trunk/src/com/ogoglio/media/MediaStore.java
spaces/trunk/src/com/ogoglio/message/NetworkChannelServer.java
spaces/trunk/src/com/ogoglio/message/SenderQueue.java
spaces/trunk/src/com/ogoglio/persist/AccountPersistTasks.java
spaces/trunk/src/com/ogoglio/persist/PersistTests.java
spaces/trunk/src/com/ogoglio/persist/ServiceInitializationPersistTasks.java
spaces/trunk/src/com/ogoglio/sim/Sim.java
spaces/trunk/src/com/ogoglio/sim/SpaceSimulator.java
spaces/trunk/src/com/ogoglio/sim/script/ScriptHTTPRequest.java
spaces/trunk/src/com/ogoglio/sim/site/SimServlet.java
spaces/trunk/src/com/ogoglio/site/AbstractResourceServlet.java
spaces/trunk/src/com/ogoglio/site/AccountServlet.java
spaces/trunk/src/com/ogoglio/site/AuthenticatedSiteResource.java
spaces/trunk/src/com/ogoglio/site/MessageProxy.java
spaces/trunk/src/com/ogoglio/site/SiteInfo.java
spaces/trunk/src/com/ogoglio/site/SiteResource.java
spaces/trunk/src/com/ogoglio/viewer/j3d/J3DRenderer.java
spaces/trunk/src/com/ogoglio/viewer/j3d/PhysicsBehavior.java
spaces/trunk/src/hibernate.cfg.xml
spaces/trunk/war/WEB-INF/web.xml
Added Paths:
-----------
spaces/trunk/src/com/ogoglio/media/WebStore.java
spaces/trunk/src/com/ogoglio/media/site/
spaces/trunk/src/com/ogoglio/media/site/MediaServlet.java
Removed Paths:
-------------
spaces/trunk/src/com/ogoglio/media/MediaTests.java
spaces/trunk/src/com/ogoglio/media/S3Store.java
spaces/trunk/src/com/ogoglio/persist/TestPersistTasks.java
spaces/trunk/src/com/ogoglio/util/S3Utils.java
spaces/trunk/war/WEB-INF/lib/jets3t-0.5.0.jar
Modified: spaces/trunk/.classpath
===================================================================
--- spaces/trunk/.classpath 2007-06-28 23:14:43 UTC (rev 202)
+++ spaces/trunk/.classpath 2007-06-29 23:23:02 UTC (rev 203)
@@ -4,7 +4,7 @@
<classpathentry kind="var" path="TOMCAT_HOME/common/lib/servlet-api.jar"/>
<classpathentry kind="var" path="TOMCAT_HOME/common/lib/jasper-runtime.jar"/>
<classpathentry kind="var" path="TOMCAT_HOME/common/lib/jsp-api.jar"/>
- <classpathentry kind="src" output="work" path="work"/>
+ <classpathentry output="work" kind="src" path="work"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="war/WEB-INF/lib/junit.jar"/>
<classpathentry kind="lib" path="war/WEB-INF/lib/mysql-connector-java-3.1.11-bin.jar"/>
@@ -26,7 +26,6 @@
<classpathentry kind="lib" path="war/WEB-INF/lib/js.jar"/>
<classpathentry kind="lib" path="war/WEB-INF/lib/commons-httpclient-3.0.1.jar"/>
<classpathentry kind="lib" path="war/WEB-INF/lib/commons-codec-1.3.jar"/>
- <classpathentry kind="lib" path="war/WEB-INF/lib/jets3t-0.5.0.jar"/>
<classpathentry kind="var" path="BROWSER_PLUGIN"/>
<classpathentry kind="output" path="war/WEB-INF/classes"/>
</classpath>
Modified: spaces/trunk/build.xml
===================================================================
--- spaces/trunk/build.xml 2007-06-28 23:14:43 UTC (rev 202)
+++ spaces/trunk/build.xml 2007-06-29 23:23:02 UTC (rev 203)
@@ -2,7 +2,7 @@
<project default="war" basedir=".">
<property name="source" value="src" />
<property name="dest" value="war/WEB-INF/classes" />
- <property name="tomcatHome" value="/usr/share/tomcat5/" />
+ <property name="tomcatHome" value="../../tomcat/" />
<property name="webLibDir" value="./war/WEB-INF/lib/" />
<property name="warName" value="ogoglio.war" />
Modified: spaces/trunk/docs/server.xml
===================================================================
--- spaces/trunk/docs/server.xml 2007-06-28 23:14:43 UTC (rev 202)
+++ spaces/trunk/docs/server.xml 2007-06-29 23:23:02 UTC (rev 203)
@@ -16,22 +16,24 @@
<Context path="/og" reloadable="false" docBase="/Users/trevor/Code/EclipseWorkspace/spaces/war" workDir="/Users/trevor/Code/EclipseWorkspace/spaces/work" >
<Logger className="org.apache.catalina.logger.SystemOutLogger" verbosity="4" timestamp="true"/>
- <!-- THIS DEFINES THE DATABASE USED BY THE OGOGLIO SERVLETS -->
+ <!-- THIS DEFINES THE DATABASE USED BY THE OGOGLIO SERVLETS, SET THE HSQL PATH OR ANOTHER JDBC URL (e.g. MySQL) -->
<Resource name="jdbc/space" scope="Shareable" type="javax.sql.DataSource" factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory" url="jdbc:hsqldb:/Users/trevor/Code/EclipseWorkspace/spaces/db/ogoglio" driverClassName="org.hsqldb.jdbcDriver" username="sa" password="" maxIdle="5" maxActive="50" />
<!-- THE FOLLOWING VARIABLES ARE READ IN com.ogoglio.site.AbstractResourceServet.init -->
- <!-- CHANGE THIS TO POINT TO THE DIRECTORY WHERE YOU WANT THE MODELS, TEXTURES, SCRIPTS, and XML FILES TO BE STORED -->
+ <!-- CHANGE THIS TO POINT TO THE URL OF THE SERVER OR DIRECTORY WHERE YOU WANT THE MODELS, TEXTURES, SCRIPTS, and XML FILES TO BE STORED -->
+ <!-- IF YOU ARE RUNNING EVERYTHING ON ONE MACHINE, USE A FILE URL LIKE file:///home/username/mediaDir -->
+ <!-- IF YOU ARE RUNNING A REMOTE MEDIA SERVICE, USE A URL LIKE http://example.com:8080/og/media/ -->
<Environment name="ogoglio/mediaURL" value="file:///Users/trevor/Code/EclipseWorkspace/spaces/working/media" type="java.lang.String"/>
- <!-- OR, IF YOU HAVE AN AMAZON S3 ACCOUNT, YOU CAN USE THAT _INSTEAD_OF_ THE MEDIA URL ABOVE-->
- <!-- <Environment name="ogoglio/mediaURL" value="s3://YOUR_AWS_ACCESS_KEY:YOUR_AWS_SECRET_KEY@EXISTING_BUCKET_NAME" type="java.lang.String"/> -->
-
<!-- CHANGE THIS TO BE THE PUBLIC URL FOR YOUR SERVICE: http://YOUR_DOMAIN/og/ -->
- <Environment name="ogoglio/baseURL" value="http://127.0.0.1:8080/og/" type="java.lang.String"/>
+ <Environment name="ogoglio/baseURL" value="http://example.com:8080/og/" type="java.lang.String"/>
<!-- CHANGE THIS TO TRUE IF YOUR SIMS RUN ON SEPARATE MACHINES (UNSAFE UNLESS THE SIMS HAVE FIREWALLS WHICH REFUSE CONNECTIONS FROM ALL BUT KNOWN WEB APPS) -->
<Environment name="ogoglio/simsAllowRemoteAccess" value="false" type="java.lang.String" />
+
+ <!-- IF THIS CONFIG IS FOR A MEDIA SERVER, UNCOMMENT THESE, SET THE FULL PATH TO YOUR MEDIA DIR -->
+ <!-- <Environment name="ogoglio/mediaDirectory" value="/Users/trevor/Code/EclipseWorkspace/spaces/working/media" type="java.lang.String"/>
</Context>
</Host>
Modified: spaces/trunk/src/com/ogoglio/client/ClientTests.java
===================================================================
--- spaces/trunk/src/com/ogoglio/client/ClientTests.java 2007-06-28 23:14:43 UTC (rev 202)
+++ spaces/trunk/src/com/ogoglio/client/ClientTests.java 2007-06-29 23:23:02 UTC (rev 203)
@@ -13,6 +13,7 @@
limitations under the License. */
package com.ogoglio.client;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
@@ -34,7 +35,6 @@
import com.ogoglio.client.model.User;
import com.ogoglio.persist.AccountRecord;
import com.ogoglio.persist.ServiceInitializationPersistTasks;
-import com.ogoglio.persist.TestPersistTasks;
import com.ogoglio.util.StreamUtils;
import com.ogoglio.xml.AccountDocument;
import com.ogoglio.xml.AuthDocument;
@@ -51,12 +51,20 @@
public class ClientTests extends TestCase {
+ public static final String PASSWORD1 = "1234";
+
+ public static final String USERNAME1 = "susan";
+
+ public static final String USERNAME2 = "tina";
+
+ public static final String COOKIE1 = "tr5w95nxracntj";
+
+ public static final String COOKIE2 = "trMoonUnitZappa";
+
URI linkURI1 = null;
URI serviceURI1 = null;
- private String ownerUsername1;
-
private String spaceName1;
private long spaceID1;
@@ -65,7 +73,6 @@
public void setUp() {
try {
- ownerUsername1 = "susan";
spaceID1 = 1;
spaceName1 = "Angry Young Space";
serviceURI1 = new URI("http://127.0.0.1:8080/og/");
@@ -83,29 +90,36 @@
public void testWebAdmin() {
try {
- String basicAuthCookie = WebAPIClient.authenticate(serviceURI1, TestPersistTasks.USERNAME1, TestPersistTasks.PASSWORD1);
+ String adminAuthCookie = WebAPIClient.authenticate(serviceURI1, ServiceInitializationPersistTasks.LIBRARY_USERNAME, ServiceInitializationPersistTasks.DEFAULT_LIBRARY_PASSWORD);
+ assertNotNull("got null auth cookie", adminAuthCookie);
+
+ try {
+ WebAPIClient.createAccount(serviceURI1, adminAuthCookie, USERNAME1, AccountRecord.ACCOUNT_LEVEL_ADVANCED, "Susan", "Examplar", "http://example.com/susan/", "su...@ex...", PASSWORD1);
+ WebAPIClient.createAccount(serviceURI1, adminAuthCookie, USERNAME2, AccountRecord.ACCOUNT_LEVEL_ADVANCED, "Tina", "Examplar", "http://example.com/tina/", "ti...@ex...", PASSWORD1);
+ } catch (IOException e) {
+ //may already exist
+ }
+
+ String basicAuthCookie = WebAPIClient.authenticate(serviceURI1, USERNAME1, PASSWORD1);
assertNotNull("got null auth cookie", basicAuthCookie);
try {
String failedUsername = "Bogosity" + System.currentTimeMillis();
AccountDocument doc = WebAPIClient.createAccount(serviceURI1, basicAuthCookie, failedUsername, AccountRecord.ACCOUNT_LEVEL_BASIC, "Shouldnt", "Exist", null, failedUsername + "@example.com", "1234");
- if(doc != null) {
+ if (doc != null) {
fail();
}
} catch (Exception e) {
//this should happen, because basic accounts can't create new accounts
}
- String adminAuthCookie = WebAPIClient.authenticate(serviceURI1, ServiceInitializationPersistTasks.LIBRARY_USERNAME, ServiceInitializationPersistTasks.DEFAULT_LIBRARY_PASSWORD);
- assertNotNull("got null auth cookie", adminAuthCookie);
-
String username = "testuser" + Math.abs(new Random().nextLong());
WebAPIClient.createAccount(serviceURI1, adminAuthCookie, username, AccountRecord.ACCOUNT_LEVEL_BASIC, "Test", "Sims", null, username + "@example.com", "1234");
-
+
AccountDocument accountDoc = WebAPIClient.getAccountDocument(serviceURI1, adminAuthCookie, username);
assertNotNull(accountDoc);
assertEquals("Test", accountDoc.getFirstName());
assertEquals("Sims", accountDoc.getLastName());
-
+
Date frozenDate = new Date(System.currentTimeMillis() + 1000000);
accountDoc.setFrozenUntil(frozenDate);
accountDoc.setAccountLevel(AccountRecord.ACCOUNT_LEVEL_ADMIN);
@@ -131,7 +145,7 @@
SpaceClient guestSpaceClient1 = null;
try {
- String authCookie1 = WebAPIClient.authenticate(serviceURI1, TestPersistTasks.USERNAME1, TestPersistTasks.PASSWORD1);
+ String authCookie1 = WebAPIClient.authenticate(serviceURI1, USERNAME1, PASSWORD1);
assertNotNull("got null auth cookie", authCookie1);
SpaceDocument spaceDoc1 = WebAPIClient.createSpace(serviceURI1, authCookie1);
@@ -159,11 +173,11 @@
AuthDocument authDoc = webClient1.getAuthDocument(true);
assertNotNull(authDoc);
- assertEquals(TestPersistTasks.USERNAME1, authDoc.getUsername());
+ assertEquals(USERNAME1, authDoc.getUsername());
AccountDocument ownerDoc = webClient1.getAccountDocument(authDoc.getUsername());
assertNotNull(ownerDoc);
- assertEquals(TestPersistTasks.USERNAME1, ownerDoc.getUsername());
+ assertEquals(USERNAME1, ownerDoc.getUsername());
String key1 = "ogoglio.key.1";
String value1 = "This is a very fine value which is < 1";
@@ -208,14 +222,14 @@
assertNotNull(membershipDocs);
assertEquals(0, membershipDocs.length);
- webClient1.addSpaceMember(TestPersistTasks.USERNAME2, SpaceMemberDocument.MEMBER);
+ webClient1.addSpaceMember(USERNAME2, SpaceMemberDocument.MEMBER);
membershipDocs = webClient1.getSpaceMemberDocuments();
assertNotNull(membershipDocs);
assertEquals(1, membershipDocs.length);
- assertEquals(TestPersistTasks.USERNAME2, membershipDocs[0].getMemberUsername());
+ assertEquals(USERNAME2, membershipDocs[0].getMemberUsername());
assertEquals(SpaceMemberDocument.MEMBER, membershipDocs[0].getRole());
- String authCookie2 = WebAPIClient.authenticate(serviceURI1, TestPersistTasks.USERNAME2, TestPersistTasks.PASSWORD1);
+ String authCookie2 = WebAPIClient.authenticate(serviceURI1, USERNAME2, PASSWORD1);
assertNotNull("got null auth cookie", authCookie1);
WebAPIClient webClient2 = new WebAPIClient(spaceURI1, serviceURI1, authCookie2);
membershipDocs = webClient2.getUsersSpaceMemberships();
@@ -224,9 +238,9 @@
assertEquals(webClient2.getAuthDocument(true).getUsername(), membershipDocs[0].getMemberUsername());
SpaceMemberDocument[] spaceMemberDocs = webClient1.getSpaceMemberDocuments();
assertFalse("member doc length = " + spaceMemberDocs.length, spaceMemberDocs.length == 0);
- assertEquals(spaceMemberDocs[0].getMemberUsername(), TestPersistTasks.USERNAME2);
+ assertEquals(spaceMemberDocs[0].getMemberUsername(), USERNAME2);
- webClient1.removeSpaceMember(TestPersistTasks.USERNAME2);
+ webClient1.removeSpaceMember(USERNAME2);
membershipDocs = webClient2.getUsersSpaceMemberships();
assertEquals(0, membershipDocs.length);
@@ -237,7 +251,7 @@
TemplateDocument newTemplateDoc = webClient1.createTemplate(templateName);
assertEquals(templateName, newTemplateDoc.getDisplayName());
- templateName = "Cold Blue Shirt";
+ templateName = "Test Cube";
newTemplateDoc.setDisplayName(templateName);
newTemplateDoc = webClient1.updateTemplate(newTemplateDoc);
assertEquals(templateName, newTemplateDoc.getDisplayName());
@@ -248,25 +262,24 @@
webClient1.updateTemplateScript(newTemplateDoc.getTemplateID(), null);
assertEquals(null, webClient1.getTemplateScript(newTemplateDoc.getTemplateID()));
- PossessionDocument[] possDocs = webClient1.getPossessionDocuments(TestPersistTasks.USERNAME1);
+ URI templateURI = webClient1.getTemplateURI(newTemplateDoc.getOwnerUsername(), newTemplateDoc.getTemplateID());
+ FileInputStream objData = new FileInputStream("src/com/ogoglio/persist/resources/TestCube.obj");
+ webClient1.putGeometryStream(templateURI, objData, 0);
+ FileInputStream mtlData = new FileInputStream("src/com/ogoglio/persist/resources/TestCube.mtl");
+ webClient1.putGeometryStream(templateURI, mtlData, "TestCube.mtl");
+ FileInputStream textureData = new FileInputStream("src/com/ogoglio/persist/resources/TestCube.gif");
+ webClient1.putGeometryStream(templateURI, textureData, "TestCube.gif");
+ String cubeScript = StreamUtils.readInput(new FileInputStream("src/com/ogoglio/persist/resources/TestCube.js"));
+ webClient1.updateTemplateScript(newTemplateDoc.getTemplateID(), cubeScript);
+
+ PossessionDocument[] possDocs = webClient1.getPossessionDocuments(USERNAME1);
int numPossessions = possDocs.length;
- TemplateDocument[] templateDocs = webClient1.getTemplateDocuments(ServiceInitializationPersistTasks.LIBRARY_USERNAME);
- assertTrue(templateDocs.length > 0);
- assertEquals(templateDocs[0].getOwnerUsername(), ServiceInitializationPersistTasks.LIBRARY_USERNAME);
-
- TemplateDocument templateDoc = webClient1.getTemplateDocument(ServiceInitializationPersistTasks.LIBRARY_USERNAME, templateDocs[0].getTemplateID());
- assertNotNull(templateDoc);
- assertEquals(templateDocs[0].getTemplateID(), templateDoc.getTemplateID());
-
- webClient1.createPossession(templateDocs[0].getTemplateID());
- possDocs = webClient1.getPossessionDocuments(TestPersistTasks.USERNAME1);
+ webClient1.createPossession(newTemplateDoc.getTemplateID());
+ possDocs = webClient1.getPossessionDocuments(USERNAME1);
assertEquals(numPossessions + 1, possDocs.length);
- ThingDocument[] thingDocs = webClient1.getThingDocuments();
- if (thingDocs.length > 0) {
- System.out.println("Already have a " + thingDocs[0].getDisplayName());
- }
+ ThingDocument[] thingDocs = webClient1.getThingDocuments();
assertEquals(0, thingDocs.length);
PossessionDocument possDoc = webClient1.addPossessionToSpace(possDocs[numPossessions].getPossessionID(), spaceDocument.getSpaceID());
assertNotNull(possDoc);
@@ -283,7 +296,7 @@
ShapeDocument[] shapeDocs = thingDocs[0].getShapeDocuments();
assertEquals(1, shapeDocs.length);
- assertEquals("Grid_Grid_Green", shapeDocs[0].getShapeName());
+ assertEquals("Cube", shapeDocs[0].getShapeName());
PageDocument[] pages = webClient1.getPageDocuments(thingDocs[0].getThingID());
assertEquals(0, pages.length);
@@ -314,9 +327,10 @@
pages = webClient1.getPageDocuments(thingDocs[0].getThingID());
assertEquals(0, pages.length);
+ TemplateDocument[] templateDocs = webClient1.getTemplateDocuments(USERNAME1);
DoorDocument[] doorDocs = webClient1.getDoorDocuments();
assertEquals(0, doorDocs.length);
- DoorDocument doorDoc = webClient1.createDoor(spaceDocument.getSpaceID(), 2, ServiceInitializationPersistTasks.LIBRARY_USERNAME, "Test Door", linkURI1, new Transform3D());
+ DoorDocument doorDoc = webClient1.createDoor(spaceDocument.getSpaceID(), templateDocs[templateDocs.length - 1].getTemplateID(), USERNAME1, "Test Door", linkURI1, new Transform3D());
assertNotNull(doorDoc);
assertFalse(doorDoc.getDoorID() == -1);
assertEquals(linkURI1, doorDoc.getLink());
@@ -338,18 +352,18 @@
}
userDocs = webClient1.getUserDocuments();
assertEquals(1, userDocs.length);
- assertEquals(TestPersistTasks.USERNAME1, userDocs[0].getUsername());
+ assertEquals(USERNAME1, userDocs[0].getUsername());
spaceClient1.cleanup();
- InputStream stream = webClient1.getGeometryStream(webClient1.getTemplateURI(ServiceInitializationPersistTasks.LIBRARY_USERNAME, 1), 0);
+ InputStream stream = webClient1.getGeometryStream(webClient1.getTemplateURI(USERNAME1, templateDocs[templateDocs.length - 1].getTemplateID()), 0);
assertNotNull(stream);
consume(stream);
- stream = webClient1.getGeometryStream(webClient1.getTemplateURI(ServiceInitializationPersistTasks.LIBRARY_USERNAME, 1), "defaultLand.mtl");
+ stream = webClient1.getGeometryStream(webClient1.getTemplateURI(USERNAME1, templateDocs[templateDocs.length - 1].getTemplateID()), "TestCube.mtl");
assertNotNull(stream);
consume(stream);
- authCookie1 = WebAPIClient.authenticate(serviceURI1, TestPersistTasks.USERNAME1, TestPersistTasks.PASSWORD1);
+ authCookie1 = WebAPIClient.authenticate(serviceURI1, USERNAME1, PASSWORD1);
assertNotNull("got null auth cookie", authCookie1);
TestSpaceClientListener listener = new TestSpaceClientListener();
@@ -369,7 +383,7 @@
assertEquals(0, thingDocs.length);
webClient1.deletePossession(possDoc.getPossessionID());
- possDocs = webClient1.getPossessionDocuments(TestPersistTasks.USERNAME1);
+ possDocs = webClient1.getPossessionDocuments(USERNAME1);
assertEquals(numPossessions, possDocs.length);
String guestCookie1 = WebAPIClient.requestGuestCookie(serviceURI1);
Modified: spaces/trunk/src/com/ogoglio/client/SpaceDuplicatorTests.java
===================================================================
--- spaces/trunk/src/com/ogoglio/client/SpaceDuplicatorTests.java 2007-06-28 23:14:43 UTC (rev 202)
+++ spaces/trunk/src/com/ogoglio/client/SpaceDuplicatorTests.java 2007-06-29 23:23:02 UTC (rev 203)
@@ -8,7 +8,6 @@
import junit.framework.TestCase;
-import com.ogoglio.persist.TestPersistTasks;
import com.ogoglio.xml.DoorDocument;
import com.ogoglio.xml.PositionedDocument;
import com.ogoglio.xml.SpaceDocument;
@@ -27,18 +26,23 @@
WebAPIClient client2 = null;
String testSettingKey = "test.setting.key";
+
String testSettingValue = "A Value for the Test Setting";
-
+
+ String authCookie = null;
+
public void setUp() {
try {
spaceURI1 = new URI("http://127.0.0.1:8080/og/space/1/");
spaceURI2 = new URI("http://127.0.0.1:8080/og/space/2/");
serviceURI1 = new URI("http://127.0.0.1:8080/og/");
- client1 = new WebAPIClient(spaceURI1, serviceURI1, TestPersistTasks.COOKIE1);
+ authCookie = WebAPIClient.authenticate(serviceURI1, ClientTests.USERNAME1, ClientTests.PASSWORD1);
+ assertNotNull(authCookie);
+ client1 = new WebAPIClient(spaceURI1, serviceURI1, authCookie);
client1.putSetting(testSettingKey, testSettingValue);
-
- client2 = new WebAPIClient(spaceURI2, serviceURI1, TestPersistTasks.COOKIE1);
+
+ client2 = new WebAPIClient(spaceURI2, serviceURI1, authCookie);
} catch (Throwable e) {
e.printStackTrace();
fail(e.getMessage());
@@ -54,12 +58,12 @@
ThingDocument[] originalThingDocs = client1.getThingDocuments();
DoorDocument[] originalDoorDocs = client1.getDoorDocuments();
Map originalSettings = client1.getSettings();
-
+
//TODO settings transfer
-
- SpaceDuplicator duplicator = new SpaceDuplicator(spaceURI1, serviceURI1, TestPersistTasks.USERNAME1, TestPersistTasks.COOKIE1);
+
+ SpaceDuplicator duplicator = new SpaceDuplicator(spaceURI1, serviceURI1, ClientTests.USERNAME1, authCookie);
duplicator.duplicateSpace(spaceURI2, true);
-
+
SpaceDocument newSpaceDoc = client2.getSpaceDocument(false);
assertEquals(originalSpaceDoc.getDisplaySea(), newSpaceDoc.getDisplaySea());
assertEquals(originalSpaceDoc.getSeaLevel(), newSpaceDoc.getSeaLevel(), 0.001);
@@ -67,7 +71,7 @@
assertEquals(originalSpaceDoc.isPublished(), newSpaceDoc.isPublished());
assertEquals(originalSpaceDoc.getMaxGuests(), newSpaceDoc.getMaxGuests());
assertEquals(originalSpaceDoc.getOwnerUsername(), newSpaceDoc.getOwnerUsername());
-
+
ThingDocument[] newThingDocs = client2.getThingDocuments();
Arrays.sort(newThingDocs, new ThingDocComparator());
Arrays.sort(originalThingDocs, new ThingDocComparator());
@@ -83,7 +87,7 @@
assertEquals(originalDoorDocs[i].getLink(), newDoorDocs[i].getLink());
assertEqualPositions(originalDoorDocs[i], newDoorDocs[i]);
}
-
+
Map newSettings = client2.getSettings();
newSettings.equals(originalSettings);
} catch (IOException e) {
@@ -91,19 +95,19 @@
fail("" + e);
}
}
-
+
private static class ThingDocComparator implements Comparator {
public int compare(Object arg0, Object arg1) {
ThingDocument doc1 = (ThingDocument) arg0;
ThingDocument doc2 = (ThingDocument) arg1;
long idDiff = doc1.getTemplateID() - doc2.getTemplateID();
- if(idDiff != 0) {
+ if (idDiff != 0) {
return idDiff < 0 ? -1 : 1;
}
return doc1.getPossessionID() < doc1.getPossessionID() ? -1 : 1;
}
}
-
+
private static void assertEqualPositions(PositionedDocument doc1, PositionedDocument doc2) {
assertEquals(doc1.getX(), doc2.getX(), 0.001);
assertEquals(doc1.getY(), doc2.getY(), 0.001);
Modified: spaces/trunk/src/com/ogoglio/client/WebAPIClient.java
===================================================================
--- spaces/trunk/src/com/ogoglio/client/WebAPIClient.java 2007-06-28 23:14:43 UTC (rev 202)
+++ spaces/trunk/src/com/ogoglio/client/WebAPIClient.java 2007-06-29 23:23:02 UTC (rev 203)
@@ -520,13 +520,17 @@
}
public InputStream getGeometryStream(URI renderableRootURI, String name) throws IOException {
- return fetchAuthenticatedStream(appendToURI(renderableRootURI, "geometry/" + (name == null ? "data/" : name)), authCookie);
+ return fetchAuthenticatedStream(appendToURI(renderableRootURI, "geometry/" + name), authCookie);
}
public void putGeometryStream(URI rootURI, InputStream input, String name) throws IOException {
- performPOST(appendToURI(rootURI, "geometry/" + (name == null ? "data/" : name)), StreamUtils.readInput(input), "application/octet-stream", authCookie);
+ performPOST(appendToURI(rootURI, "geometry/" + name), StreamUtils.readInput(input), "application/octet-stream", authCookie);
}
+ public void putGeometryStream(URI rootURI, InputStream input, int lodIndex) throws IOException {
+ performPOST(appendToURI(rootURI, "geometry/data/" + lodIndex), StreamUtils.readInput(input), "application/octet-stream", authCookie);
+ }
+
public InputStream getGeometryStream(URI renderableRootURI, int lodIndex) throws IOException {
return fetchAuthenticatedStream(appendToURI(renderableRootURI, "geometry/data/" + lodIndex), authCookie);
}
@@ -554,6 +558,51 @@
return sendAuthenticatedXML(uri, body, "POST", authCookie);
}
+ public static long requestContentLength(URI uri, String authCookie) {
+ try {
+ HttpURLConnection connection = (HttpURLConnection) uri.toURL().openConnection();
+ connection.setRequestMethod("HEAD");
+ connection.setAllowUserInteraction(false);
+ if (authCookie != null) {
+ connection.setRequestProperty("Cookie", AuthServlet.AUTH_COOKIE + "=" + authCookie);
+ }
+
+ connection.setDoOutput(false);
+ if (connection.getResponseCode() != 200) {
+ return -1;
+ }
+ String lengthHeader = (String)connection.getRequestProperties().get("Content-Length");
+ if(lengthHeader == null) {
+ return -1;
+ }
+ return Integer.parseInt(lengthHeader);
+ } catch (IOException e) {
+ return -1;
+ }
+ }
+
+ public static InputStream performPUT(URI uri, InputStream input, String type, int length, String authCookie) throws IOException {
+ HttpURLConnection connection = (HttpURLConnection) uri.toURL().openConnection();
+ connection.setRequestMethod("PUT");
+ connection.setAllowUserInteraction(false);
+ if (authCookie != null) {
+ connection.setRequestProperty("Cookie", AuthServlet.AUTH_COOKIE + "=" + authCookie);
+ }
+
+ connection.setDoOutput(true);
+ connection.setRequestProperty("Content-type", type);
+ if (length >= 0) {
+ connection.setRequestProperty("Content-length", Integer.toString(length));
+ }
+ StreamUtils.write(input, connection.getOutputStream());
+
+ if (connection.getResponseCode() != 200) {
+ throw new IOException("Get status " + connection.getResponseCode() + " from " + uri);
+ }
+
+ return connection.getInputStream();
+ }
+
public static InputStream performPOST(URI uri, String body, String type, String authCookie) throws IOException {
HttpURLConnection connection = (HttpURLConnection) uri.toURL().openConnection();
connection.setRequestMethod("POST");
@@ -762,4 +811,5 @@
public URI getSettingURI(String key) {
return appendToURI(getSettingsURI(), key + "/");
}
+
}
Modified: spaces/trunk/src/com/ogoglio/media/FileStore.java
===================================================================
--- spaces/trunk/src/com/ogoglio/media/FileStore.java 2007-06-28 23:14:43 UTC (rev 202)
+++ spaces/trunk/src/com/ogoglio/media/FileStore.java 2007-06-29 23:23:02 UTC (rev 203)
@@ -43,6 +43,7 @@
ArgumentUtils.assertNoPaths(name);
File tempFile = new File(mediaDir, System.currentTimeMillis() + "_" + name);
StreamUtils.write(value, new FileOutputStream(tempFile));
+ new File(mediaDir, name).delete();
if (!tempFile.renameTo(new File(mediaDir, name))) {
System.err.println("Unable to rename the file:" + tempFile.getName() + " to: " + name);
tempFile.delete();
@@ -56,14 +57,16 @@
ArgumentUtils.assertNoPaths(name);
File tempFile = new File(mediaDir, System.currentTimeMillis() + "_" + name);
StreamUtils.write(input, new FileOutputStream(tempFile), maxSize);
+ new File(mediaDir, name).delete();
if (!tempFile.renameTo(new File(mediaDir, name))) {
+ System.err.println("Unable to rename the file:" + tempFile.getName() + " to: " + name);
tempFile.delete();
return false;
}
return true;
}
- public InputStream read(String name) {
+ public InputStream getData(String name) {
ArgumentUtils.assertNotEmpty(name);
ArgumentUtils.assertNoPaths(name);
try {
@@ -73,6 +76,11 @@
}
}
+ public boolean exists(String name) {
+ File file = new File(mediaDir, name);
+ return file.exists() && file.isFile();
+ }
+
public long getSize(String name) throws IOException {
ArgumentUtils.assertNotEmpty(name);
ArgumentUtils.assertNoPaths(name);
Modified: spaces/trunk/src/com/ogoglio/media/MediaService.java
===================================================================
--- spaces/trunk/src/com/ogoglio/media/MediaService.java 2007-06-28 23:14:43 UTC (rev 202)
+++ spaces/trunk/src/com/ogoglio/media/MediaService.java 2007-06-29 23:23:02 UTC (rev 203)
@@ -42,8 +42,8 @@
if(mediaURI.getScheme() == null || "file".equals(mediaURI.getScheme())){
store = new FileStore(mediaURI);
- } else if ("s3".equals(mediaURI.getScheme())){
- store = new S3Store(mediaURI);
+ } else if ("http".equals(mediaURI.getScheme())){
+ store = new WebStore(mediaURI);
} else {
throw new IllegalStateException("Could not create a store for " + mediaURI + " with scheme " + mediaURI.getScheme());
}
@@ -85,8 +85,8 @@
return store.write(name, input, maxSize);
}
- public InputStream read(String name) {
- return store.read(name);
+ public InputStream getData(String name) {
+ return store.getData(name);
}
public long getSize(String name) throws IOException {
Modified: spaces/trunk/src/com/ogoglio/media/MediaStore.java
===================================================================
--- spaces/trunk/src/com/ogoglio/media/MediaStore.java 2007-06-28 23:14:43 UTC (rev 202)
+++ spaces/trunk/src/com/ogoglio/media/MediaStore.java 2007-06-29 23:23:02 UTC (rev 203)
@@ -24,7 +24,7 @@
public long getSize(String name) throws IOException;
- public InputStream read(String name);
+ public InputStream getData(String name);
public boolean delete(String name);
Deleted: spaces/trunk/src/com/ogoglio/media/MediaTests.java
===================================================================
--- spaces/trunk/src/com/ogoglio/media/MediaTests.java 2007-06-28 23:14:43 UTC (rev 202)
+++ spaces/trunk/src/com/ogoglio/media/MediaTests.java 2007-06-29 23:23:02 UTC (rev 203)
@@ -1,33 +0,0 @@
-package com.ogoglio.media;
-
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-
-import junit.framework.TestCase;
-
-import com.ogoglio.util.StreamUtils;
-
-public class MediaTests extends TestCase {
-
- public void testS3() {
- String awsAccessKey = "Your AWS Access Key";
- String awsSecretKey = "Your AWS Secret Key";
-
- try {
- S3Store store = new S3Store(new URI("s3://" + awsAccessKey +":" + awsSecretKey + "@YOUR.BUCKET.NAME/"));
-
- String testValue = "The North Wind Doth Blow, and We Shall Have Snow, and What Will The Robin Do Then?";
- assertTrue(store.write("Test1", testValue));
- assertEquals(testValue, StreamUtils.readInput(store.read("Test1")));
- assertTrue(store.delete("Test1"));
- } catch (IOException e) {
- e.printStackTrace();
- fail();
- } catch (URISyntaxException e) {
- e.printStackTrace();
- fail();
- }
- }
-
-}
Deleted: spaces/trunk/src/com/ogoglio/media/S3Store.java
===================================================================
--- spaces/trunk/src/com/ogoglio/media/S3Store.java 2007-06-28 23:14:43 UTC (rev 202)
+++ spaces/trunk/src/com/ogoglio/media/S3Store.java 2007-06-29 23:23:02 UTC (rev 203)
@@ -1,134 +0,0 @@
-/* Copyright 2007 Transmutable (http://transmutable.com/)
-
- Licensed 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 com.ogoglio.media;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-
-import org.jets3t.service.S3ServiceException;
-import org.jets3t.service.impl.rest.httpclient.RestS3Service;
-import org.jets3t.service.model.S3Bucket;
-import org.jets3t.service.model.S3Object;
-import org.jets3t.service.security.AWSCredentials;
-
-import com.ogoglio.util.ArgumentUtils;
-
-/**
- * This utilizes Amazon's Simple Storage Service (S3) to persist and fetch media
- */
-public class S3Store implements MediaStore {
-
- private AWSCredentials awsCredentials = null;
-
- S3Bucket bucket = null;
-
- /**
- * @param mediaURI must be in the form s3://AWS_ACCESS_KEY:AWS_SECRET_KEY@EXISTING_BUCKET_NAME/
- * (as set in mediaURL var in server.xml)
- */
- public S3Store(URI mediaURI) throws IOException {
- ArgumentUtils.assertNotNull(mediaURI);
- String awsAccessKey = mediaURI.getUserInfo().split(":")[0];
- String awsSecretKey = mediaURI.getUserInfo().split(":")[1];;
- ArgumentUtils.assertNotEmpty(awsAccessKey);
- ArgumentUtils.assertNotEmpty(awsSecretKey);
-
- if (!"s3".equals(mediaURI.getScheme())) {
- throw new IllegalArgumentException("Tried to start S3Store with URI " + mediaURI);
- }
-
- try {
- awsCredentials = new AWSCredentials(awsAccessKey, awsSecretKey);
-
- RestS3Service service = new RestS3Service(awsCredentials);
-
- if (!service.isBucketAccessible(mediaURI.getHost())) {
- throw new IOException("Could not access S3 bucket " + mediaURI.getHost());
- }
-
- bucket = new S3Bucket(mediaURI.getHost());
- } catch (S3ServiceException e) {
- throw new IOException ("S3 IO Exception: " + e);
- }
- }
-
- public boolean delete(String name) {
- try {
- RestS3Service service = new RestS3Service(awsCredentials);
- service.deleteObject(bucket, name);
- return true;
- } catch (S3ServiceException e) {
- System.err.println("Error deleting: " + e.getMessage());
- return false;
- }
- }
-
- public long getSize(String name) throws IOException {
- try {
- RestS3Service service = new RestS3Service(awsCredentials);
- S3Object object = service.getObjectDetails(bucket, name);
- if(object == null) {
- return -1;
- }
- return object.getContentLength();
- } catch (S3ServiceException e) {
- return -1;
- }
- }
-
- public InputStream read(String name) {
- try {
- RestS3Service service = new RestS3Service(awsCredentials);
- S3Object object = service.getObject(bucket, name);
- if(object == null) {
- return null;
- }
- if(object.getContentLength() == 0){
- return null;
- }
- return object.getDataInputStream();
- } catch (S3ServiceException e) {
- return null;
- }
- }
-
- public boolean write(String name, String value) throws IOException {
- try {
- RestS3Service service = new RestS3Service(awsCredentials);
- S3Object object = new S3Object(bucket, name, value);
- service.putObject(bucket, object);
- return true;
- } catch (S3ServiceException e) {
- System.err.println("Error putting " + name + ": " + e.getMessage());
- return false;
- }
- }
-
- //TODO respect the maxSize
- public boolean write(String name, InputStream input, long maxSize) throws IOException {
- try {
- RestS3Service service = new RestS3Service(awsCredentials);
- S3Object object = new S3Object(name);
- object.setContentType("application/data");
- object.setDataInputStream(input);
- service.putObject(bucket, object);
- return true;
- } catch (S3ServiceException e) {
- System.err.println("Error putting " + name + ": " + e.getMessage());
- return false;
- }
- }
-
-}
Added: spaces/trunk/src/com/ogoglio/media/WebStore.java
===================================================================
--- spaces/trunk/src/com/ogoglio/media/WebStore.java (rev 0)
+++ spaces/trunk/src/com/ogoglio/media/WebStore.java 2007-06-29 23:23:02 UTC (rev 203)
@@ -0,0 +1,67 @@
+/* Copyright 2007 Transmutable (http://transmutable.com/)
+
+Licensed 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 com.ogoglio.media;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+
+import com.ogoglio.client.WebAPIClient;
+import com.ogoglio.util.ArgumentUtils;
+
+public class WebStore implements MediaStore {
+
+ URI mediaURI = null;
+
+ public WebStore(URI mediaURI) throws IOException {
+ ArgumentUtils.assertNotNull(mediaURI);
+ this.mediaURI = mediaURI;
+ }
+
+ public boolean write(String name, String value) throws IOException {
+ return write(name, new ByteArrayInputStream(value.getBytes()), -1);
+ }
+
+ public boolean write(String name, InputStream input, long maxSize) throws IOException {
+ InputStream responseInput = WebAPIClient.performPUT(WebAPIClient.appendToURI(mediaURI, name), input, "application/data", -1, null);
+ if(responseInput == null) {
+ return false;
+ }
+ responseInput.close();
+
+ return true;
+ }
+
+ public InputStream getData(String name) {
+ try {
+ return WebAPIClient.performGET(WebAPIClient.appendToURI(mediaURI, name), null);
+ } catch (IOException e) {
+ return null;
+ }
+ }
+
+ public long getSize(String name) {
+ return WebAPIClient.requestContentLength(WebAPIClient.appendToURI(mediaURI, name), null);
+ }
+
+ public boolean delete(String name) {
+ try {
+ return WebAPIClient.sendDelete(WebAPIClient.appendToURI(mediaURI, name), null);
+ } catch (IOException e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+}
Added: spaces/trunk/src/com/ogoglio/media/site/MediaServlet.java
===================================================================
--- spaces/trunk/src/com/ogoglio/media/site/MediaServlet.java (rev 0)
+++ spaces/trunk/src/com/ogoglio/media/site/MediaServlet.java 2007-06-29 23:23:02 UTC (rev 203)
@@ -0,0 +1,111 @@
+package com.ogoglio.media.site;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Date;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import com.ogoglio.media.FileStore;
+import com.ogoglio.site.AbstractResourceServlet;
+import com.ogoglio.site.SiteResource;
+import com.ogoglio.util.StreamUtils;
+
+public class MediaServlet extends AbstractResourceServlet {
+
+ private FileStore fileStore = null;
+
+ public void init(ServletConfig config) throws ServletException {
+ super.init(config);
+ File mediaDir = getSiteInfo().getMediaDirectory();
+ if (mediaDir == null) {
+ System.out.println(new Date() + ": NOTE: not running media service");
+ return;
+ }
+ fileStore = new FileStore(getSiteInfo().getMediaDirectory().toURI());
+ }
+
+ public void destroy() {
+ super.destroy();
+ }
+
+ public SiteResource createBaseResource(ServletConfig servletConfig) {
+ return new MediaResource();
+ }
+
+ private class MediaResource extends SiteResource {
+ public MediaResource() {
+ super("media");
+ if (fileStore != null) {
+ addSubResource(new DataResource());
+ }
+ }
+
+ public void doGet(HttpServletRequest request, HttpServletResponse response, String[] pathElements) throws ServletException, IOException {
+ sendStringResponse("I'm a media servlet (" + (fileStore == null ? "inactive" : "active") + ")", "text/plain", response);
+ }
+ }
+
+ private class DataResource extends SiteResource {
+ public DataResource() {
+ super(SiteResource.WILDCARD_ELEMENT);
+ }
+
+ public void doGet(HttpServletRequest request, HttpServletResponse response, String[] pathElements) throws ServletException, IOException {
+ String name = pathElements[pathElements.length - 1];
+ InputStream input = fileStore.getData(name);
+ if (input == null) {
+ response.setStatus(HttpServletResponse.SC_NOT_FOUND);
+ return;
+ }
+ response.setStatus(HttpServletResponse.SC_OK);
+ response.setContentLength((int) fileStore.getSize(name));
+ StreamUtils.write(input, response.getOutputStream());
+ }
+
+ public void doPut(HttpServletRequest request, HttpServletResponse response, String[] pathElements) throws ServletException, IOException {
+ String name = pathElements[pathElements.length - 1];
+ fileStore.write(name, request.getInputStream(), -1);
+ response.setStatus(HttpServletResponse.SC_OK);
+ response.setContentLength(0);
+ return;
+ }
+
+ public void doDelete(HttpServletRequest request, HttpServletResponse response, String[] pathElements) throws ServletException, IOException {
+ String name = pathElements[pathElements.length - 1];
+
+ if (!fileStore.exists(name)) {
+ response.setStatus(HttpServletResponse.SC_NOT_FOUND);
+ response.setContentLength(0);
+ return;
+ }
+
+ if (!fileStore.delete(name)) {
+ response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ response.setContentLength(0);
+ return;
+ }
+ response.setStatus(HttpServletResponse.SC_OK);
+ response.setContentLength(0);
+ return;
+ }
+
+ public void doHead(HttpServletRequest request, HttpServletResponse response, String[] pathElements) throws ServletException, IOException {
+ String name = pathElements[pathElements.length - 1];
+ if (!fileStore.exists(name)) {
+ response.setStatus(HttpServletResponse.SC_NOT_FOUND);
+ response.setContentLength(0);
+ return;
+ }
+
+ response.setStatus(HttpServletResponse.SC_OK);
+ response.setContentLength((int) fileStore.getSize(name));
+ return;
+ }
+ }
+
+}
Modified: spaces/trunk/src/com/ogoglio/message/NetworkChannelServer.java
===================================================================
--- spaces/trunk/src/com/ogoglio/message/NetworkChannelServer.java 2007-06-28 23:14:43 UTC (rev 202)
+++ spaces/trunk/src/com/ogoglio/message/NetworkChannelServer.java 2007-06-29 23:23:02 UTC (rev 203)
@@ -131,6 +131,12 @@
}
private class ChannelSocketListenerThread extends Thread {
+
+ public ChannelSocketListenerThread() {
+ super("NetworkChannelServer");
+ setDaemon(true);
+ }
+
public void run() {
while (!cleaned) {
try {
Modified: spaces/trunk/src/com/ogoglio/message/SenderQueue.java
===================================================================
--- spaces/trunk/src/com/ogoglio/message/SenderQueue.java 2007-06-28 23:14:43 UTC (rev 202)
+++ spaces/trunk/src/com/ogoglio/message/SenderQueue.java 2007-06-29 23:23:02 UTC (rev 203)
@@ -17,10 +17,8 @@
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
-import java.net.SocketException;
import com.ogoglio.util.BlockingQueue;
-import com.ogoglio.util.BlockingQueue.QueueClosedException;
public class SenderQueue {
private SenderThread senderThread = new SenderThread();
Modified: spaces/trunk/src/com/ogoglio/persist/AccountPersistTasks.java
===================================================================
--- spaces/trunk/src/com/ogoglio/persist/AccountPersistTasks.java 2007-06-28 23:14:43 UTC (rev 202)
+++ spaces/trunk/src/com/ogoglio/persist/AccountPersistTasks.java 2007-06-29 23:23:02 UTC (rev 203)
@@ -112,7 +112,16 @@
public static AccountRecord createAccount(final String username, final String accountlevel, final String email, SessionFactory sessionFactory) throws PersistException {
HibernateTask task = new HibernateTask() {
public Object run(Session hibernateSession) {
- AccountRecord record = new AccountRecord(username, accountlevel, email);
+ final String cleanedUsername = AccountRecord.cleanUsername(username);
+ Query query = hibernateSession.getNamedQuery(ACCOUNT_BY_USERNAME);
+ query.setParameter("username", cleanedUsername);
+
+ AccountRecord record = (AccountRecord)query.uniqueResult();
+ if(record != null) {
+ return null;
+ }
+
+ record = new AccountRecord(username, accountlevel, email);
hibernateSession.save(record);
BodyRecord bodyRec = new BodyRecord("Body", record.getUsername());
hibernateSession.save(bodyRec);
Modified: spaces/trunk/src/com/ogoglio/persist/PersistTests.java
===================================================================
--- spaces/trunk/src/com/ogoglio/persist/PersistTests.java 2007-06-28 23:14:43 UTC (rev 202)
+++ spaces/trunk/src/com/ogoglio/persist/PersistTests.java 2007-06-29 23:23:02 UTC (rev 203)
@@ -176,11 +176,9 @@
}
try {
- AccountRecord accRec3 = AccountPersistTasks.createAccount(username1, level1, email2, sessionFactory);
- fail("Shouldn't allow duplicate username records");
+ assertNull(AccountPersistTasks.createAccount(username1, level1, email2, sessionFactory));
} catch (PersistException e) {
- //this should happen
- System.err.println("Correctly generated PersistException for duplicate username record.");
+ fail("Should have just returned null instead of failed: " + e);
}
}
}
\ No newline at end of file
Modified: spaces/trunk/src/com/ogoglio/persist/ServiceInitializationPersistTasks.java
===================================================================
--- spaces/trunk/src/com/ogoglio/persist/ServiceInitializationPersistTasks.java 2007-06-28 23:14:43 UTC (rev 202)
+++ spaces/trunk/src/com/ogoglio/persist/ServiceInitializationPersistTasks.java 2007-06-29 23:23:02 UTC (rev 203)
@@ -62,6 +62,7 @@
accountRec.setPassword(DEFAULT_LIBRARY_PASSWORD);
AccountPersistTasks.update(accountRec, sessionFactory);
+ /*
TemplateRecord defaultLandTemplate = TemplatePersistTasks.createTemplate(DEFAULT_LAND_DISPLAY_NAME, accountRec.getUsername(), sessionFactory);
mediaService.write("templateGeometry-1-0", getResourceStream("com/ogoglio/persist/resources/defaultLand.obj"), -1);
mediaService.write("templateGeometry-1-defaultLand.mtl", getResourceStream("com/ogoglio/persist/resources/defaultLand.mtl"), -1);
@@ -79,6 +80,7 @@
TemplateRecord testCylinderTemplate = TemplatePersistTasks.createTemplate(TEST_CYLINDER_DISPLAY_NAME, accountRec.getUsername(), sessionFactory);
mediaService.write("templateGeometry-4-0", getResourceStream("com/ogoglio/persist/resources/TestCylinder.obj"), -1);
+ */
}
private static AccountRecord createUser(String username, String accountlevel, String email, String password, String cookie, SessionFactory sessionFactory) throws PersistException {
Deleted: spaces/trunk/src/com/ogoglio/persist/TestPersistTasks.java
===================================================================
--- spaces/trunk/src/com/ogoglio/persist/TestPersistTasks.java 2007-06-28 23:14:43 UTC (rev 202)
+++ spaces/trunk/src/com/ogoglio/persist/TestPersistTasks.java 2007-06-29 23:23:02 UTC (rev 203)
@@ -1,67 +0,0 @@
-/* Copyright 2007 Transmutable (http://transmutable.com/)
-
- Licensed 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 com.ogoglio.persist;
-
-import org.hibernate.SessionFactory;
-import org.hibernate.cfg.Configuration;
-
-public class TestPersistTasks {
-
- public static final String PASSWORD1 = "1234";
-
- public static final String USERNAME1 = "susan";
-
- public static final String USERNAME2 = "tina";
-
- public static final String USERNAME3 = "joe";
-
- public static final String USERNAME4 = "bob";
-
- public static final String COOKIE1 = "tr5w95nxracntj";
-
- public static final String COOKIE2 = "trMoonUnitZappa";
-
- private static AccountRecord createUser(String username, String accountlevel, String email, String password, String cookie, SessionFactory sessionFactory) throws PersistException {
- AccountRecord accountRec = AccountPersistTasks.findAccountByUsername(username, sessionFactory);
- if (accountRec == null) {
- accountRec = AccountPersistTasks.createAccount(username, accountlevel, email, sessionFactory);
- accountRec.setPassword(password);
- accountRec.setCookie(cookie);
- AccountPersistTasks.update(accountRec, sessionFactory);
- }
- return accountRec;
- }
-
- public static void initializeTestAccounts(SessionFactory sessionFactory) throws PersistException {
- createUser(USERNAME1, AccountRecord.ACCOUNT_LEVEL_BASIC, "su...@ex...", PASSWORD1, COOKIE1, sessionFactory);
- createUser(USERNAME2, AccountRecord.ACCOUNT_LEVEL_ADVANCED, "ti...@ex...", PASSWORD1, COOKIE2, sessionFactory);
- createUser(USERNAME3, AccountRecord.ACCOUNT_LEVEL_PRO, "jo...@ex...", PASSWORD1, "trTimequake", sessionFactory);
- createUser(USERNAME4, AccountRecord.ACCOUNT_LEVEL_BASIC, "bo...@ex...", PASSWORD1, "trCookiefoobar", sessionFactory);
-
- SpaceRecord[] spaces = SpacePersistTasks.findSpacesByOwnerUsername(USERNAME1, sessionFactory);
- if (spaces.length == 0) {
- SpacePersistTasks.createSpace("Test Space", USERNAME1, sessionFactory);
- PossessionPersistTasks.createPossession(USERNAME1, 1, sessionFactory);
- PossessionPersistTasks.createPossession(USERNAME1, 3, sessionFactory);
- }
- }
- public static void main(String argv[]) {
- try {
- initializeTestAccounts(new Configuration().configure().buildSessionFactory());
- } catch (PersistException e) {
- System.err.println("wow, we got an exception");
- e.printStackTrace();
- }
- }
-}
Modified: spaces/trunk/src/com/ogoglio/sim/Sim.java
===================================================================
--- spaces/trunk/src/com/ogoglio/sim/Sim.java 2007-06-28 23:14:43 UTC (rev 202)
+++ spaces/trunk/src/com/ogoglio/sim/Sim.java 2007-06-29 23:23:02 UTC (rev 203)
@@ -131,16 +131,16 @@
}
public InputStream getTemplateGeometryStream(long templateID, int lodIndex) {
- return mediaService.read(MediaService.getTemplateGeometryName(templateID, lodIndex));
+ return mediaService.getData(MediaService.getTemplateGeometryName(templateID, lodIndex));
}
public InputStream getTemplateResourceStream(long templateID, String name) {
- return mediaService.read(MediaService.getTemplateResourceName(templateID, name));
+ return mediaService.getData(MediaService.getTemplateResourceName(templateID, name));
}
public String getTemplateScript(long templateID) {
try {
- InputStream stream = mediaService.read(MediaService.getTemplateScriptName(templateID));
+ InputStream stream = mediaService.getData(MediaService.getTemplateScriptName(templateID));
if (stream == null) {
return null;
}
@@ -279,7 +279,7 @@
}
private SpaceDocument getSpaceDocument(long spaceID) throws IOException {
- InputStream stream = mediaService.read(MediaService.getSpaceDocumentName(spaceID));
+ InputStream stream = mediaService.getData(MediaService.getSpaceDocumentName(spaceID));
if (stream == null) {
return null;
}
Modified: spaces/trunk/src/com/ogoglio/sim/SpaceSimulator.java
===================================================================
--- spaces/trunk/src/com/ogoglio/sim/SpaceSimulator.java 2007-06-28 23:14:43 UTC (rev 202)
+++ spaces/trunk/src/com/ogoglio/sim/SpaceSimulator.java 2007-06-29 23:23:02 UTC (rev 203)
@@ -216,6 +216,11 @@
private class SimThread extends Thread {
BlockingQueue queue = new BlockingQueue();
+ public SimThread() {
+ super("SimThread");
+ setDaemon(true);
+ }
+
public void run() {
while (!cleaned) {
try {
Modified: spaces/trunk/src/com/ogoglio/sim/script/ScriptHTTPRequest.java
===================================================================
--- spaces/trunk/src/com/ogoglio/sim/script/ScriptHTTPRequest.java 2007-06-28 23:14:43 UTC (rev 202)
+++ spaces/trunk/src/com/ogoglio/sim/script/ScriptHTTPRequest.java 2007-06-29 23:23:02 UTC (rev 203)
@@ -191,6 +191,9 @@
HttpMethod method = null;
public HttpRequestThread(String methodType, String url, String content) {
+ super("ScriptHTTPRequest");
+ setDaemon(true);
+
this.methodType = methodType;
this.url = url;
this.content = content;
Modified: spaces/trunk/src/com/ogoglio/sim/site/SimServlet.java
===================================================================
--- spaces/trunk/src/com/ogoglio/sim/site/SimServlet.java 2007-06-28 23:14:43 UTC (rev 202)
+++ spaces/trunk/src/com/ogoglio/sim/site/SimServlet.java 2007-06-29 23:23:02 UTC (rev 203)
@@ -390,7 +390,7 @@
return;
}
- InputStream result = getMediaService().read(MediaService.getPageContentName(spaceID, thingID, pageID));
+ InputStream result = getMediaService().getData(MediaService.getPageContentName(spaceID, thingID, pageID));
if (result == null) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
return;
Modified: spaces/trunk/src/com/ogoglio/site/AbstractResourceServlet.java
===================================================================
--- spaces/trunk/src/com/ogoglio/site/AbstractResourceServlet.java 2007-06-28 23:14:43 UTC (rev 202)
+++ spaces/trunk/src/com/ogoglio/site/AbstractResourceServlet.java 2007-06-29 23:23:02 UTC (rev 203)
@@ -13,6 +13,7 @@
limitations under the License. */
package com.ogoglio.site;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -26,9 +27,10 @@
import javax.naming.Context;
import javax.naming.InitialContext;
-import javax.naming.NameNotFoundException;
import javax.naming.NamingException;
import javax.servlet.ServletConfig;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
@@ -68,15 +70,16 @@
try {
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
- siteInfo = new SiteInfo();
- siteInfo.setBaseUrl((String) envCtx.lookup("ogoglio/baseURL"));
- siteInfo.setMed...
[truncated message content] |