Author: elvisisking
Date: 2009-09-10 17:16:23 -0400 (Thu, 10 Sep 2009)
New Revision: 1204
Added:
branches/eclipse/dna-web-jcr-rest-client/src/test/resources/myproject/My.Test -
Folder/
branches/eclipse/dna-web-jcr-rest-client/src/test/resources/myproject/My.Test -
Folder/Test File_.a-*().txt
Modified:
branches/eclipse/dna-web-jcr-rest-client/pom.xml
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/IJcrConstants.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/IRestClient.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/IServerRegistryListener.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/ServerAuthenticator.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/ServerManager.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/ServerRegistryEvent.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/Repository.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/Server.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/Workspace.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/FileNode.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/FolderNode.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonNode.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestClient.java
branches/eclipse/dna-web-jcr-rest-client/src/main/resources/org/jboss/dna/web/jcr/rest/client/RestClientI18n.properties
branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/MockRestClient.java
branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/RestIntegrationTest.java
branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestClientTest.java
Log:
Fixed problem with bad URLs for file names with non-letters and non-number characters.
Uploading of file content (binary and text) now works. Registry listeners now get events
after registering for all the registered servers. Added ServerManager to the registry
event as the event source. Now using DNA common to calculate hashcodes. Also now
calculating mimetype of files instead of defaulting to the same mimetype.
Modified: branches/eclipse/dna-web-jcr-rest-client/pom.xml
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/pom.xml 2009-09-10 18:53:32 UTC (rev 1203)
+++ branches/eclipse/dna-web-jcr-rest-client/pom.xml 2009-09-10 21:16:23 UTC (rev 1204)
@@ -96,103 +96,216 @@
</plugin>
</plugins>
</reporting>
- <build>
- <pluginManagement>
- <plugins>
- <plugin>
- <artifactId>maven-assembly-plugin</artifactId>
- <configuration>
- <descriptorRefs>
- <descriptorRef>jar-with-dependencies
- </descriptorRef>
- </descriptorRefs>
- </configuration>
- <executions>
- <execution>
- <id>create-project-bundle</id>
- <phase>package</phase>
- <goals>
- <goal>single</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </pluginManagement>
- <plugins>
- <plugin>
- <groupId>org.codehaus.cargo</groupId>
- <artifactId>cargo-maven2-plugin</artifactId>
- <!-- >version>1.0.1-SNAPSHOT</version -->
- <executions>
- <execution>
- <id>start-container</id>
- <phase>pre-integration-test</phase>
- <goals>
- <goal>start</goal>
- </goals>
- </execution>
- <execution>
- <id>stop-container</id>
- <phase>post-integration-test</phase>
- <goals>
- <goal>stop</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <container>
- <containerId>${cargo.container}</containerId>
- <home>${cargo.container.home}</home>
- </container>
- <configuration>
- <properties>
- <cargo.logging>high</cargo.logging>
- <cargo.servlet.users>
- dnauser:password:connect,readwrite|unauthorized:password:bogus
- </cargo.servlet.users>
- <cargo.servlet.port>8080</cargo.servlet.port>
- </properties>
+ <profiles>
+ <profile>
+ <id>cargo-1</id>
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <artifactId>maven-assembly-plugin
+ </artifactId>
+ <configuration>
+ <descriptorRefs>
+ <descriptorRef>jar-with-dependencies
+ </descriptorRef>
+ </descriptorRefs>
+ </configuration>
+ <executions>
+ <execution>
+ <id>create-project-bundle</id>
+ <phase>package</phase>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.cargo</groupId>
+ <artifactId>cargo-maven2-plugin</artifactId>
+ <!-- >version>1.0.1-SNAPSHOT</version -->
+ <executions>
+ <execution>
+ <id>start-container</id>
+ <phase>pre-integration-test</phase>
+ <goals>
+ <goal>start</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>stop-container</id>
+ <phase>post-integration-test</phase>
+ <goals>
+ <goal>stop</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <container>
+
<containerId>${cargo.container}</containerId>
+ <home>${cargo.container.home}</home>
+ </container>
+ <configuration>
+ <properties>
+ <cargo.logging>high</cargo.logging>
+ <cargo.servlet.users>
+
dnauser:password:connect,readwrite|unauthorized:password:bogus
+ </cargo.servlet.users>
+
<cargo.servlet.port>8080</cargo.servlet.port>
+ </properties>
- <deployables>
- <!-- application to deploy -->
- <deployable>
- <groupId>org.jboss.dna</groupId>
- <artifactId>dna-web-jcr-rest-war
- </artifactId>
- <type>war</type>
- <properties>
- <context>resources</context>
- </properties>
- </deployable>
- </deployables>
- </configuration>
- <wait>false</wait>
- </configuration>
- </plugin>
- <!--
- Override the default Surefire behavior to run during
- integration-test phase
- -->
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <skip>true</skip>
- </configuration>
- <executions>
- <execution>
- <id>surefire-it</id>
- <phase>integration-test</phase>
- <goals>
- <goal>test</goal>
- </goals>
- <configuration>
- <skip>false</skip>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
+ <deployables>
+ <!-- application to deploy -->
+ <deployable>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna-web-jcr-rest-war
+ </artifactId>
+ <type>war</type>
+ <properties>
+ <context>resources</context>
+ </properties>
+ </deployable>
+ </deployables>
+ </configuration>
+ <wait>false</wait>
+ </configuration>
+ </plugin>
+ <!--
+ Override the default Surefire behavior to run during
+ integration-test phase
+ -->
+ <plugin>
+ <groupId>org.apache.maven.plugins
+ </groupId>
+ <artifactId>maven-surefire-plugin
+ </artifactId>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ <executions>
+ <execution>
+ <id>surefire-it</id>
+ <phase>integration-test</phase>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ <configuration>
+ <skip>false</skip>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ <profile>
+ <id>cargo-2</id>
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <artifactId>maven-assembly-plugin
+ </artifactId>
+ <configuration>
+ <descriptorRefs>
+ <descriptorRef>jar-with-dependencies
+ </descriptorRef>
+ </descriptorRefs>
+ </configuration>
+ <executions>
+ <execution>
+ <id>create-project-bundle</id>
+ <phase>package</phase>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.cargo</groupId>
+ <artifactId>cargo-maven2-plugin</artifactId>
+ <!-- >version>1.0.1-SNAPSHOT</version -->
+ <executions>
+ <execution>
+ <id>start-container</id>
+ <phase>pre-integration-test</phase>
+ <goals>
+ <goal>start</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>stop-container</id>
+ <phase>post-integration-test</phase>
+ <goals>
+ <goal>stop</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <container>
+
<containerId>${cargo.container}</containerId>
+ <home>${cargo.container.home}</home>
+ </container>
+ <configuration>
+ <properties>
+ <cargo.logging>high</cargo.logging>
+ <cargo.servlet.users>
+
dnauser2:password2:connect,readwrite|unauthorized:password:bogus
+ </cargo.servlet.users>
+
<cargo.servlet.port>8180</cargo.servlet.port>
+ </properties>
+
+ <deployables>
+ <!-- application to deploy -->
+ <deployable>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna-web-jcr-rest-war
+ </artifactId>
+ <type>war</type>
+ <properties>
+ <context>resources</context>
+ </properties>
+ </deployable>
+ </deployables>
+ </configuration>
+ <wait>false</wait>
+ </configuration>
+ </plugin>
+ <!--
+ Override the default Surefire behavior to run during
+ integration-test phase
+ -->
+ <plugin>
+ <groupId>org.apache.maven.plugins
+ </groupId>
+ <artifactId>maven-surefire-plugin
+ </artifactId>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ <executions>
+ <execution>
+ <id>surefire-it</id>
+ <phase>integration-test</phase>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ <configuration>
+ <skip>false</skip>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
</project>
Modified:
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/IJcrConstants.java
===================================================================
---
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/IJcrConstants.java 2009-09-10
18:53:32 UTC (rev 1203)
+++
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/IJcrConstants.java 2009-09-10
21:16:23 UTC (rev 1204)
@@ -42,7 +42,7 @@
*
* @since 0.6
*/
- String DATA_PROPERTY = "jcr:data"; //$NON-NLS-1$
+ String DATA_PROPERTY = "jcr:data/base64/"; //$NON-NLS-1$
/**
* The JCR file node type (<code>nt:file</code>).
Modified:
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/IRestClient.java
===================================================================
---
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/IRestClient.java 2009-09-10
18:53:32 UTC (rev 1203)
+++
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/IRestClient.java 2009-09-10
21:16:23 UTC (rev 1204)
@@ -24,6 +24,7 @@
package org.jboss.dna.web.jcr.rest.client;
import java.io.File;
+import java.net.URL;
import java.util.Collection;
import org.jboss.dna.web.jcr.rest.client.Status.Severity;
import org.jboss.dna.web.jcr.rest.client.domain.Repository;
@@ -48,6 +49,18 @@
Collection<Repository> getRepositories( Server server ) throws Exception;
/**
+ * @param file the file whose URL is being requested (never
<code>null</code>)
+ * @param path the path in the DNA workspace where the file is/could be located
(never <code>null</code>)
+ * @param workspace the workspace where the file is/could be located (never
<code>null</code>)
+ * @return the workspace URL for the specified file (never
<code>null</code>)
+ * @throws Exception if there is a problem obtaining the URL or if the file is a
directory
+ * @since 0.6
+ */
+ URL getUrl( File file,
+ String path,
+ Workspace workspace ) throws Exception;
+
+ /**
* Obtains the workspaces defined within the specified DNA respository.
*
* @param repository the repository whose workspaces are being requested (never
<code>null</code>)
Modified:
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/IServerRegistryListener.java
===================================================================
---
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/IServerRegistryListener.java 2009-09-10
18:53:32 UTC (rev 1203)
+++
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/IServerRegistryListener.java 2009-09-10
21:16:23 UTC (rev 1204)
@@ -31,7 +31,7 @@
public interface IServerRegistryListener {
/**
- * @param event the event being processed
+ * @param event the event being processed (never <code>null</code>)
* @return any errors caught during the processing or <code>null</code>
* @since 0.6
*/
Modified:
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/ServerAuthenticator.java
===================================================================
---
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/ServerAuthenticator.java 2009-09-10
18:53:32 UTC (rev 1203)
+++
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/ServerAuthenticator.java 2009-09-10
21:16:23 UTC (rev 1204)
@@ -35,29 +35,6 @@
public class ServerAuthenticator extends Authenticator {
//
===========================================================================================================================
- // Fields
- //
===========================================================================================================================
-
- /**
- * The object managing the server registry.
- *
- * @since 0.6
- */
- private final ServerManager serverManager;
-
- //
===========================================================================================================================
- // Constructors
- //
===========================================================================================================================
-
- /**
- * @param serverManager the server manager manages the server registry
- * @since 0.6
- */
- public ServerAuthenticator( ServerManager serverManager ) {
- this.serverManager = serverManager;
- }
-
- //
===========================================================================================================================
// Methods
//
===========================================================================================================================
@@ -69,8 +46,9 @@
*/
@Override
protected PasswordAuthentication getPasswordAuthentication() {
- Server server = this.serverManager.getCurrentServer();
- return new PasswordAuthentication(server.getUser(),
server.getPassword().toCharArray());
+ Server server = ServerManager.getCurrentServer();
+ String password = ((server.getPassword() == null) ? "" :
server.getPassword()); //$NON-NLS-1$
+ return new PasswordAuthentication(server.getUser(), password.toCharArray());
}
}
Modified:
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/ServerManager.java
===================================================================
---
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/ServerManager.java 2009-09-10
18:53:32 UTC (rev 1203)
+++
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/ServerManager.java 2009-09-10
21:16:23 UTC (rev 1204)
@@ -26,6 +26,7 @@
import java.io.File;
import java.io.FileOutputStream;
import java.net.Authenticator;
+import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -202,7 +203,7 @@
this.listeners = new CopyOnWriteArrayList<IServerRegistryListener>();
// set our authenticator that uses the server registry
- Authenticator.setDefault(new ServerAuthenticator(this));
+ Authenticator.setDefault(new ServerAuthenticator());
}
/**
@@ -221,7 +222,7 @@
//
===========================================================================================================================
/**
- * Listeners already registered will not be added again.
+ * Listeners already registered will not be added again. The new listener will
receive events for all existing servers.
*
* @param listener the listener being register to receive events (never
<code>null</code>)
* @return <code>true</code> if listener was added
@@ -229,7 +230,14 @@
*/
public boolean addRegistryListener( IServerRegistryListener listener ) {
CheckArg.isNotNull(listener, "listener"); //$NON-NLS-1$
- return this.listeners.addIfAbsent(listener);
+ boolean result = this.listeners.addIfAbsent(listener);
+
+ // inform new listener of registered servers
+ for (Server server : getServers()) {
+ listener.serverRegistryChanged(ServerRegistryEvent.createNewEvent(this,
server));
+ }
+
+ return result;
}
/**
@@ -245,6 +253,25 @@
}
/**
+ * @param url the URL of the server being requested (never
<code>null</code>)
+ * @param user the user ID of the server being requested (never
<code>null</code>)
+ * @return the requested server or <code>null</code> if not found in the
registry
+ */
+ public Server findServer( String url,
+ String user ) {
+ CheckArg.isNotNull(url, "url"); //$NON-NLS-1$
+ CheckArg.isNotNull(user, "user"); //$NON-NLS-1$
+
+ for (Server server : getServers()) {
+ if (url.equals(server.getUrl()) && user.equals(server.getUser())) {
+ return server;
+ }
+ }
+
+ return null;
+ }
+
+ /**
* @return an unmodifiable collection of registered servers (never
<code>null</code>)
* @since 0.6
*/
@@ -301,6 +328,19 @@
/**
* {@inheritDoc}
*
+ * @see org.jboss.dna.web.jcr.rest.client.IRestClient#getUrl(java.io.File,
java.lang.String,
+ * org.jboss.dna.web.jcr.rest.client.domain.Workspace)
+ * @since 0.6
+ */
+ public URL getUrl( File file,
+ String path,
+ Workspace workspace ) throws Exception {
+ return this.delegate.getUrl(file, path, workspace);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see
org.jboss.dna.web.jcr.rest.client.IRestClient#getWorkspaces(org.jboss.dna.web.jcr.rest.client.domain.Repository)
* @throws RuntimeException if the server is not registered
* @see #isRegistered(Server)
@@ -350,7 +390,7 @@
if (added) {
if (notifyListeners) {
- Exception[] errors =
notifyRegistryListeners(ServerRegistryEvent.createNewEvent(server));
+ Exception[] errors =
notifyRegistryListeners(ServerRegistryEvent.createNewEvent(this, server));
return processRegistryListenerErrors(errors);
}
@@ -387,7 +427,7 @@
if (removed) {
if (notifyListeners) {
- Exception[] errors =
notifyRegistryListeners(ServerRegistryEvent.createRemoveEvent(server));
+ Exception[] errors =
notifyRegistryListeners(ServerRegistryEvent.createRemoveEvent(this, server));
return processRegistryListenerErrors(errors);
}
@@ -696,7 +736,8 @@
if (status.isOk()) {
// all good so notify listeners
- Exception[] errors =
notifyRegistryListeners(ServerRegistryEvent.createUpdateEvent(previousServerVersion,
+ Exception[] errors =
notifyRegistryListeners(ServerRegistryEvent.createUpdateEvent(this,
+
previousServerVersion,
newServerVersion));
return processRegistryListenerErrors(errors);
}
Modified:
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/ServerRegistryEvent.java
===================================================================
---
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/ServerRegistryEvent.java 2009-09-10
18:53:32 UTC (rev 1203)
+++
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/ServerRegistryEvent.java 2009-09-10
21:16:23 UTC (rev 1204)
@@ -71,40 +71,49 @@
//
===========================================================================================================================
/**
+ * @param serverManager the server manager sourcing this event (never
<code>null</code>)
* @param newServer the server that was added to the server registry (never
<code>null</code>)
* @return the event (never <code>null</code>)
* @see Type#NEW
* @since 0.6
*/
- public static ServerRegistryEvent createNewEvent( Server newServer ) {
+ public static ServerRegistryEvent createNewEvent( ServerManager serverManager,
+ Server newServer ) {
+ CheckArg.isNotNull(serverManager, "serverManager"); //$NON-NLS-1$
CheckArg.isNotNull(newServer, "newServer"); //$NON-NLS-1$
- return new ServerRegistryEvent(Type.NEW, newServer);
+ return new ServerRegistryEvent(serverManager, Type.NEW, newServer);
}
/**
+ * @param serverManager the server manager sourcing this event (never
<code>null</code>)
* @param removedServer the server removed from the server registry (never
<code>null</code>)
* @return the event (never <code>null</code>)
* @see Type#REMOVE
* @since 0.6
*/
- public static ServerRegistryEvent createRemoveEvent( Server removedServer ) {
+ public static ServerRegistryEvent createRemoveEvent( ServerManager serverManager,
+ Server removedServer ) {
+ CheckArg.isNotNull(serverManager, "serverManager"); //$NON-NLS-1$
CheckArg.isNotNull(removedServer, "removedServer"); //$NON-NLS-1$
- return new ServerRegistryEvent(Type.REMOVE, removedServer);
+ return new ServerRegistryEvent(serverManager, Type.REMOVE, removedServer);
}
/**
+ * @param serverManager the server manager sourcing this event (never
<code>null</code>)
* @param previousServerVersion the server being updated (never
<code>null</code>)
* @param newServerVersion the updated version of the server (never
<code>null</code>)
* @return the event (never <code>null</code>)
* @see Type#UPDATE
* @since 0.6
*/
- public static ServerRegistryEvent createUpdateEvent( Server previousServerVersion,
+ public static ServerRegistryEvent createUpdateEvent( ServerManager serverManager,
+ Server previousServerVersion,
Server newServerVersion ) {
+ CheckArg.isNotNull(serverManager, "serverManager"); //$NON-NLS-1$
CheckArg.isNotNull(previousServerVersion, "previousServerVersion");
//$NON-NLS-1$
CheckArg.isNotNull(newServerVersion, "newServerVersion");
//$NON-NLS-1$
- ServerRegistryEvent event = new ServerRegistryEvent(Type.UPDATE,
previousServerVersion);
+ ServerRegistryEvent event = new ServerRegistryEvent(serverManager, Type.UPDATE,
previousServerVersion);
event.updatedServer = newServerVersion;
return event;
}
@@ -121,6 +130,13 @@
private final Server server;
/**
+ * The server manager in charge of the server registry the event is associated with.
+ *
+ * @since 0.6
+ */
+ private final ServerManager serverManager;
+
+ /**
* The event type.
*
* @since 0.6
@@ -139,12 +155,15 @@
//
===========================================================================================================================
/**
+ * @param serverManager the server manager sourcing this event
* @param type the event type
* @param server the server being added, removed, or updated
* @since 0.6
*/
- private ServerRegistryEvent( Type type,
+ private ServerRegistryEvent( ServerManager serverManager,
+ Type type,
Server server ) {
+ this.serverManager = serverManager;
this.type = type;
this.server = server;
}
@@ -162,6 +181,14 @@
}
/**
+ * @return the server manager sourcing this event
+ * @since 0.6
+ */
+ public ServerManager getServerManager() {
+ return this.serverManager;
+ }
+
+ /**
* @return the new version of an existing server that has been updated
* @throws UnsupportedOperationException if method is called when the type is not an
update
* @see Type#UPDATE
Modified:
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/Repository.java
===================================================================
---
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/Repository.java 2009-09-10
18:53:32 UTC (rev 1203)
+++
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/Repository.java 2009-09-10
21:16:23 UTC (rev 1204)
@@ -25,6 +25,7 @@
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.util.CheckArg;
+import org.jboss.dna.common.util.HashCode;
import org.jboss.dna.web.jcr.rest.client.RestClientI18n;
import org.jboss.dna.web.jcr.rest.client.Status;
import org.jboss.dna.web.jcr.rest.client.domain.validation.RepositoryValidator;
@@ -143,10 +144,7 @@
*/
@Override
public int hashCode() {
- int hash = 7;
- hash = 31 * hash + this.name.hashCode();
- hash = 31 * hash + this.server.hashCode();
- return hash;
+ return HashCode.compute(this.name, this.server);
}
/**
Modified:
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/Server.java
===================================================================
---
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/Server.java 2009-09-10
18:53:32 UTC (rev 1203)
+++
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/Server.java 2009-09-10
21:16:23 UTC (rev 1204)
@@ -25,6 +25,7 @@
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.util.CheckArg;
+import org.jboss.dna.common.util.HashCode;
import org.jboss.dna.web.jcr.rest.client.RestClientI18n;
import org.jboss.dna.web.jcr.rest.client.Status;
import org.jboss.dna.web.jcr.rest.client.Utils;
@@ -180,20 +181,7 @@
*/
@Override
public int hashCode() {
- int hash = 7;
- hash = 31 * hash + this.url.hashCode();
-
- if (this.user != null) {
- hash = 31 * hash + this.user.hashCode();
- }
-
- if (this.password != null) {
- hash = 31 * hash + this.password.hashCode();
- }
-
- hash = 31 * hash + Boolean.valueOf(this.persistPassword).hashCode();
-
- return hash;
+ return HashCode.compute(this.url, this.user, this.password,
this.persistPassword);
}
/**
Modified:
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/Workspace.java
===================================================================
---
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/Workspace.java 2009-09-10
18:53:32 UTC (rev 1203)
+++
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/Workspace.java 2009-09-10
21:16:23 UTC (rev 1204)
@@ -25,6 +25,7 @@
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.util.CheckArg;
+import org.jboss.dna.common.util.HashCode;
import org.jboss.dna.web.jcr.rest.client.RestClientI18n;
import org.jboss.dna.web.jcr.rest.client.Status;
import org.jboss.dna.web.jcr.rest.client.domain.validation.WorkspaceValidator;
@@ -149,10 +150,7 @@
*/
@Override
public int hashCode() {
- int hash = 7;
- hash = 31 * hash + this.name.hashCode();
- hash = 31 * hash + this.repository.hashCode();
- return hash;
+ return HashCode.compute(this.name, this.repository);
}
/**
Modified:
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/FileNode.java
===================================================================
---
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/FileNode.java 2009-09-10
18:53:32 UTC (rev 1203)
+++
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/FileNode.java 2009-09-10
21:16:23 UTC (rev 1204)
@@ -23,21 +23,16 @@
*/
package org.jboss.dna.web.jcr.rest.client.json;
-import java.io.DataInputStream;
-import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
-import java.io.IOException;
import java.net.URL;
import java.text.SimpleDateFormat;
-import java.util.ArrayList;
import java.util.Calendar;
-import java.util.List;
import java.util.TimeZone;
import net.jcip.annotations.Immutable;
import org.codehaus.jettison.json.JSONObject;
+import org.jboss.dna.common.util.Base64;
import org.jboss.dna.common.util.CheckArg;
-import org.jboss.dna.common.util.Logger;
import org.jboss.dna.web.jcr.rest.client.IJcrConstants;
import org.jboss.dna.web.jcr.rest.client.Utils;
import org.jboss.dna.web.jcr.rest.client.domain.Workspace;
@@ -125,7 +120,7 @@
properties.put(IJcrConstants.LAST_MODIFIED,
formatter.format(lastModified.getTime()));
// add required jcr:mimeType property (just use a default value)
- properties.put(IJcrConstants.MIME_TYPE, "application/octet-stream");
//$NON-NLS-1$
+ properties.put(IJcrConstants.MIME_TYPE, Utils.getMimeType(file));
}
//
===========================================================================================================================
@@ -140,7 +135,6 @@
*/
@Override
public byte[] getContent() throws Exception {
- // TODO need to figure out how to write binary content to JSONObject
// add required jcr:data property (do this lazily only when the content is
requested)
JSONObject children = (JSONObject)get(IJsonConstants.CHILDREN_KEY);
JSONObject kid = (JSONObject)children.get(IJcrConstants.CONTENT_PROPERTY);
@@ -151,6 +145,36 @@
}
/**
+ * Note: Currently used for testing only.
+ *
+ * @param jsonResponse the JSON response obtained from performing a GET using the
file content URL
+ * @return the encoded file contents
+ * @throws Exception if there is a problem obtaining the contents
+ * @see #getFileContentsUrl()
+ * @since 0.6
+ */
+ String getFileContents( String jsonResponse ) throws Exception {
+ CheckArg.isNotNull(jsonResponse, "jsonResponse"); //$NON-NLS-1$
+ JSONObject contentNode = new JSONObject(jsonResponse);
+ JSONObject props = (JSONObject)contentNode.get(IJsonConstants.PROPERTIES_KEY);
+ String encodedContents = props.getString(IJcrConstants.DATA_PROPERTY);
+ return encodedContents;
+ }
+
+ /**
+ * Note: Currently used for testing only.
+ *
+ * @return the URL that can be used to obtain the encoded file contents from a
workspace
+ * @throws Exception if there is a problem constructing the URL
+ * @since 0.6
+ */
+ URL getFileContentsUrl() throws Exception {
+ StringBuilder url = new StringBuilder(getUrl().toString());
+ url.append('/').append(IJcrConstants.CONTENT_PROPERTY);
+ return new URL(url.toString());
+ }
+
+ /**
* @return the path where the file is or will be published or unpublished
* @since 0.6
*/
@@ -175,32 +199,12 @@
}
/**
- * @return the file content
+ * @return the base 64 encoded file content
* @throws Exception if there is a problem reading the file
* @since 0.6
*/
- private Byte[] readFile() throws Exception {
- DataInputStream is = null;
- List<Byte> bytes = new ArrayList<Byte>(1000);
-
- try {
- is = new DataInputStream(new FileInputStream(this.file.getAbsoluteFile()));
-
- while (true) {
- bytes.add(is.readByte());
- }
- } catch (EOFException e) {
- // nothing to do
- } finally {
- if (is != null) {
- try {
- is.close();
- } catch (IOException e) {
- }
- }
- }
-
- return bytes.toArray(new Byte[(bytes.size())]);
+ String readFile() throws Exception {
+ return Base64.encode(new FileInputStream(this.file.getAbsoluteFile()));
}
}
Modified:
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/FolderNode.java
===================================================================
---
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/FolderNode.java 2009-09-10
18:53:32 UTC (rev 1203)
+++
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/FolderNode.java 2009-09-10
21:16:23 UTC (rev 1204)
@@ -27,7 +27,6 @@
import net.jcip.annotations.Immutable;
import org.codehaus.jettison.json.JSONObject;
import org.jboss.dna.common.util.CheckArg;
-import org.jboss.dna.common.util.Logger;
import org.jboss.dna.web.jcr.rest.client.IJcrConstants;
import org.jboss.dna.web.jcr.rest.client.domain.Workspace;
@@ -107,12 +106,12 @@
if (!path.startsWith("/")) { //$NON-NLS-1$
path = '/' + path;
}
-
+
// make sure path does NOT end with a '/'
if (path.endsWith("/")) { //$NON-NLS-1$
path = path.substring(0, path.length() - 1);
}
-
+
// path needs to be encoded
url.append(JsonUtils.encode(path));
Modified:
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonNode.java
===================================================================
---
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonNode.java 2009-09-10
18:53:32 UTC (rev 1203)
+++
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonNode.java 2009-09-10
21:16:23 UTC (rev 1204)
@@ -69,7 +69,7 @@
* @since 0.6
*/
public byte[] getContent() throws Exception {
- return toString().getBytes();
+ return super.toString().getBytes();
}
/**
@@ -87,4 +87,26 @@
*/
public abstract URL getUrl() throws Exception;
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.codehaus.jettison.json.JSONObject#toString()
+ * @since 0.6
+ */
+ @Override
+ public String toString() {
+ StringBuilder txt = new StringBuilder();
+ txt.append("ID: ").append(getId()); //$NON-NLS-1$
+ txt.append(", URL: "); //$NON-NLS-1$
+
+ try {
+ txt.append(getUrl());
+ } catch (Exception e) {
+ txt.append("exception obtaining URL"); //$NON-NLS-1$
+ }
+
+ txt.append(", content: ").append(super.toString()); //$NON-NLS-1$
+ return txt.toString();
+ }
+
}
Modified:
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestClient.java
===================================================================
---
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestClient.java 2009-09-10
18:53:32 UTC (rev 1203)
+++
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestClient.java 2009-09-10
21:16:23 UTC (rev 1204)
@@ -209,6 +209,28 @@
/**
* {@inheritDoc}
*
+ * @see org.jboss.dna.web.jcr.rest.client.IRestClient#getUrl(java.io.File,
java.lang.String,
+ * org.jboss.dna.web.jcr.rest.client.domain.Workspace)
+ * @since 0.6
+ */
+ public URL getUrl( File file,
+ String path,
+ Workspace workspace ) throws Exception {
+ CheckArg.isNotNull(file, "file"); //$NON-NLS-1$
+ CheckArg.isNotNull(path, "path"); //$NON-NLS-1$
+ CheckArg.isNotNull(workspace, "workspace"); //$NON-NLS-1$
+
+ // can't be a directory
+ if (file.isDirectory()) {
+ throw new IllegalArgumentException();
+ }
+
+ return new FileNode(workspace, path, file).getUrl();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see
org.jboss.dna.web.jcr.rest.client.IRestClient#getWorkspaces(org.jboss.dna.web.jcr.rest.client.domain.Repository)
* @since 0.6
*/
@@ -250,30 +272,63 @@
URL url,
RequestMethod method ) throws Exception {
this.logger.trace("openConnection: url={0}, method={1}", url, method);
//$NON-NLS-1$
- HttpURLConnection connection = (HttpURLConnection)url.openConnection();
- connection.setDoOutput(true);
- String encoding = Base64.encodeBytes((server.getUser() + ':' +
server.getPassword()).getBytes());
- connection.setRequestProperty("Authorization", "Basic " +
encoding); //$NON-NLS-1$ //$NON-NLS-2$
- connection.setRequestMethod(method.toString());
- connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON); //$NON-NLS-1$
- connection.setUseCaches(false);
- return connection;
+
+ try {
+ HttpURLConnection connection = (HttpURLConnection)url.openConnection();
+ connection.setDoOutput(true);
+ String encoding = Base64.encodeBytes((server.getUser() + ':' +
server.getPassword()).getBytes());
+ connection.setRequestProperty("Authorization", "Basic " +
encoding); //$NON-NLS-1$ //$NON-NLS-2$
+ connection.setRequestMethod(method.toString());
+ connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON); //$NON-NLS-1$
+ connection.setUseCaches(false);
+ return connection;
+ } catch (Exception e) {
+ this.logger.trace("openConnection: exception:", e); //$NON-NLS-1$
+ throw e;
+ }
}
/**
+ * Note: Currently used for testing only.
+ *
+ * @param workspace the workspace where the file is published
+ * @param path the path in the workspace where the file is published
+ * @param file the file whose workspace contents are being requested
+ * @return the base 64 encoded file contents or <code>null</code> if file
is not found
+ * @throws Exception if there is a problem obtaining the contents
+ * @since 0.6
+ */
+ String getFileContents( Workspace workspace,
+ String path,
+ File file ) throws Exception {
+ FileNode fileNode = new FileNode(workspace, path, file);
+ HttpURLConnection connection = openConnection(workspace.getServer(),
fileNode.getFileContentsUrl(), RequestMethod.GET);
+ int responseCode = connection.getResponseCode();
+
+ if (responseCode == HttpURLConnection.HTTP_OK) {
+ String result = JsonUtils.readInputStream(connection);
+ return fileNode.getFileContents(result);
+ }
+
+ return null;
+ }
+
+ /**
* @param server the server where the URL will be used (never
<code>null</code>)
* @param url the path being checked (never <code>null</code>)
* @return <code>true</code> if the path exists
* @throws Exception if there is a problem checking the existence of the path
* @since 0.6
*/
- protected boolean pathExists( Server server,
- URL url ) throws Exception {
+ private boolean pathExists( Server server,
+ URL url ) throws Exception {
this.logger.trace("pathExists: url={0}", url); //$NON-NLS-1$
HttpURLConnection connection = openConnection(server, url, RequestMethod.GET);
try {
- return (connection.getResponseCode() == HttpURLConnection.HTTP_OK);
+ int responseCode = connection.getResponseCode();
+ this.logger.trace("pathExists: responseCode={0}", responseCode);
//$NON-NLS-1$
+ return (responseCode == HttpURLConnection.HTTP_OK);
} finally {
if (connection != null) {
this.logger.trace("pathExists: leaving"); //$NON-NLS-1$
@@ -294,7 +349,6 @@
String path,
File file ) throws Exception {
FileNode fileNode = new FileNode(workspace, path, file);
- this.logger.trace("pathExists: url={0}", fileNode.getUrl());
//$NON-NLS-1$
return pathExists(workspace.getServer(), fileNode.getUrl());
}
@@ -353,6 +407,7 @@
FileNode fileNode = new FileNode(workspace, path, file);
connection = openConnection(workspace.getServer(), fileNode.getUrl(),
RequestMethod.DELETE);
int responseCode = connection.getResponseCode();
+ this.logger.trace("responseCode={0}", responseCode); //$NON-NLS-1$
if (responseCode != HttpURLConnection.HTTP_NO_CONTENT) {
// check to see if the file was never published
@@ -363,13 +418,13 @@
// unexpected result
this.logger.error(RestClientI18n.connectionErrorMsg, responseCode,
"unpublish"); //$NON-NLS-1$
- String msg = RestClientI18n.unpublishFailedMsg.text(file.getName(),
workspace.getName(), path, responseCode);
+ String msg = RestClientI18n.unpublishFailedMsg.text(file.getName(),
workspace.getName(), path);
throw new RuntimeException(msg);
}
return Status.OK_STATUS;
} catch (Exception e) {
- String msg = RestClientI18n.publishFailedMsg.text(workspace.getName(), path,
file.getAbsolutePath());
+ String msg = RestClientI18n.unpublishFailedMsg.text(file.getAbsolutePath(),
workspace.getName(), path);
return new Status(Severity.ERROR, msg, e);
} finally {
if (connection != null) {
Modified:
branches/eclipse/dna-web-jcr-rest-client/src/main/resources/org/jboss/dna/web/jcr/rest/client/RestClientI18n.properties
===================================================================
---
branches/eclipse/dna-web-jcr-rest-client/src/main/resources/org/jboss/dna/web/jcr/rest/client/RestClientI18n.properties 2009-09-10
18:53:32 UTC (rev 1203)
+++
branches/eclipse/dna-web-jcr-rest-client/src/main/resources/org/jboss/dna/web/jcr/rest/client/RestClientI18n.properties 2009-09-10
21:16:23 UTC (rev 1204)
@@ -53,11 +53,11 @@
# JsonRestClient messages
-connectionErrorMsg = response code={0}: {1}
+connectionErrorMsg = response code={0} method={1}
createFileFailedMsg = Creating the "{0}" file node in folder "{1}" in
workspace "{2}" failed with HTTP response code of "{3}"
createFolderFailedMsg = Creating the "{0}" folder node in workspace
"{1}" failed with HTTP response code of "{2}"
getRepositoriesFailedMsg = Obtaining the repositories from server "{0}" failed
with HTTP response code of "{1}"
getWorkspacesFailedMsg = Obtaining the workspaces from repository "{0}" at
server "{1}" failed with HTTP response code of "{2}"
publishFailedMsg = Publishing file "{0}" to path "{1}" in workspace
"{2}" failed.
-unpublishFailedMsg = The file "{0}" could not be unpublished in workspace
"{1}" at path "{2}". The HTTP response code was "{3}".
+unpublishFailedMsg = The file "{0}" could not be unpublished in workspace
"{1}" at path "{2}".
unpublishNeverPublishedMsg = The file "{0}" could not be unpublished in
workspace "{1}" at path "{2}" because it could not be found.
Modified:
branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/MockRestClient.java
===================================================================
---
branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/MockRestClient.java 2009-09-10
18:53:32 UTC (rev 1203)
+++
branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/MockRestClient.java 2009-09-10
21:16:23 UTC (rev 1204)
@@ -24,6 +24,7 @@
package org.jboss.dna.web.jcr.rest.client;
import java.io.File;
+import java.net.URL;
import java.util.Collection;
import org.jboss.dna.web.jcr.rest.client.domain.Repository;
import org.jboss.dna.web.jcr.rest.client.domain.Server;
@@ -49,6 +50,18 @@
public Collection<Repository> getRepositories( Server server ) throws Exception
{
return null;
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.web.jcr.rest.client.IRestClient#getUrl(java.io.File,
java.lang.String, org.jboss.dna.web.jcr.rest.client.domain.Workspace)
+ * @since 0.6
+ */
+ public URL getUrl( File file,
+ String path,
+ Workspace workspace ) throws Exception {
+ return null;
+ }
/**
* {@inheritDoc}
Modified:
branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/RestIntegrationTest.java
===================================================================
---
branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/RestIntegrationTest.java 2009-09-10
18:53:32 UTC (rev 1203)
+++
branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/RestIntegrationTest.java 2009-09-10
21:16:23 UTC (rev 1204)
@@ -82,18 +82,23 @@
//
===========================================================================================================================
@Test
+ public void shouldAllowServerPropertiesToChange() {
+ // TODO implement shouldAllowServerPropertiesToChange()
+ }
+
+// @Test
public void shouldGetRepositories() throws Exception {
Collection<Repository> repositories =
this.serverManager.getRepositories(SERVER);
assertThat(repositories.size(), is(1));
}
- @Test
+// @Test
public void shouldGetWorkspaces() throws Exception {
Collection<Workspace> workspaces =
this.serverManager.getWorkspaces(REPOSITORY);
assertThat(workspaces.size(), is(1));
}
- @Test
+// @Test
public void shouldPublish() throws Exception {
URL textFile = getClass().getResource(FILE_PATH);
assertThat(textFile, is(notNullValue()));
Modified:
branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestClientTest.java
===================================================================
---
branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestClientTest.java 2009-09-10
18:53:32 UTC (rev 1203)
+++
branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestClientTest.java 2009-09-10
21:16:23 UTC (rev 1204)
@@ -42,6 +42,10 @@
/**
* The <code>JsonRestClientTest</code> class is a test class for the {@link
JsonRestClient JSON REST client} object.
+ * <p>
+ * One container: mvn -P cargo-1 clean install assembly:assembly
+ * <p>
+ * Two containers: mvn -P cargo-1,cargo-2 clean install assembly:assembly
*
* @since 0.6
*/
@@ -65,6 +69,9 @@
private static final String FILE_PATH = WORKSPACE_PATH + "document.txt";
//$NON-NLS-1$
private static final String BINARY_FILE_PATH = WORKSPACE_PATH +
"picture.jpg"; //$NON-NLS-1$
+ private static final String WORKSPACE_UNUSUALPATH = "/myproject/My.Test -
Folder/"; //$NON-NLS-1$
+ private static final String FILE_UNUSUALPATH = WORKSPACE_UNUSUALPATH + "Test
File_.a-*().txt"; //$NON-NLS-1$
+
//
===========================================================================================================================
// Fields
//
===========================================================================================================================
@@ -108,7 +115,14 @@
@Test
public void shouldNotUnpublishNonexistentFile() throws Exception {
File file = new File("bogusfile"); //$NON-NLS-1$
- assertThat(this.restClient.unpublish(WORKSPACE1, WORKSPACE_PATH, file).isInfo(),
is(true));
+ Status status = this.restClient.unpublish(WORKSPACE1, WORKSPACE_PATH, file);
+
+ if (status.isError()) {
+ System.err.println(status.getMessage());
+ status.getException().printStackTrace(System.err);
+ }
+
+ assertThat(status.getMessage(), status.isInfo(), is(true));
}
@Test
@@ -118,18 +132,23 @@
// publish
File file = new File(binaryFile.toURI());
- assertThat(this.restClient.publish(WORKSPACE1, WORKSPACE_PATH, file).isOk(),
is(true));
+ Status status = this.restClient.publish(WORKSPACE1, WORKSPACE_PATH, file);
+ if (status.isError()) {
+ System.err.println(status.getMessage());
+ status.getException().printStackTrace(System.err);
+ }
+
+ assertThat(status.isOk(), is(true));
+
// confirm it exists in repository
assertThat(((JsonRestClient)this.restClient).pathExists(WORKSPACE1,
WORKSPACE_PATH, file), is(true));
- // TODO: get jcr:data and compare
+ // compare file contents to the contents that have been published
+ String expected = new FileNode(WORKSPACE1, WORKSPACE_PATH, file).readFile();
+ String actual = ((JsonRestClient)this.restClient).getFileContents(WORKSPACE1,
WORKSPACE_PATH, file);
+ assertThat(actual, is(expected));
}
-
- @Test
- public void shouldPublishFilesHavingNonLettersNonNumbersInName() {
- // TODO implement shouldPublishFilesHavingNonLettersNonNumbersInName test
- }
@Test
public void shouldPublishTextResource() throws Exception {
@@ -139,15 +158,41 @@
// publish
File file = new File(textFile.toURI());
Status status = this.restClient.publish(WORKSPACE1, WORKSPACE_PATH, file);
+
+ if (status.isError()) {
+ System.err.println(status.getMessage());
+ status.getException().printStackTrace(System.err);
+ }
+
assertThat(status.getMessage(), status.isOk(), is(true));
// confirm it exists in repository
assertThat(((JsonRestClient)this.restClient).pathExists(WORKSPACE1,
WORKSPACE_PATH, file), is(true));
+
+ // compare file contents to the contents that have been published
+ String expected = new FileNode(WORKSPACE1, WORKSPACE_PATH, file).readFile();
+ String actual = ((JsonRestClient)this.restClient).getFileContents(WORKSPACE1,
WORKSPACE_PATH, file);
+ assertThat(actual, is(expected));
}
-
+
@Test
- public void shouldPublishToDirectoriesHavingNonLettersNonNumbersInName() {
- // TODO implement shouldPublishToDirectoriesHavingNonLettersNonNumbersInName
test
+ public void shouldPublishResourcesHavingNonLettersNonNumbersInName() throws Exception
{
+ URL textFile = getClass().getResource(FILE_UNUSUALPATH);
+ assertThat(textFile, is(notNullValue()));
+
+ // publish
+ File file = new File(textFile.toURI());
+ Status status = this.restClient.publish(WORKSPACE1, WORKSPACE_UNUSUALPATH,
file);
+
+ if (status.isError()) {
+ System.err.println(status.getMessage());
+ status.getException().printStackTrace(System.err);
+ }
+
+ assertThat(status.getMessage(), status.isOk(), is(true));
+
+ // confirm it exists in repository
+ assertThat(((JsonRestClient)this.restClient).pathExists(WORKSPACE1,
WORKSPACE_UNUSUALPATH, file), is(true));
}
@Test
@@ -157,8 +202,15 @@
URL textFile = getClass().getResource(FILE_PATH);
File file = new File(textFile.toURI());
- assertThat(this.restClient.unpublish(WORKSPACE1, WORKSPACE_PATH, file).isOk(),
is(true));
+ Status status = this.restClient.unpublish(WORKSPACE1, WORKSPACE_PATH, file);
+ if (status.isError()) {
+ System.err.println(status.getMessage());
+ status.getException().printStackTrace(System.err);
+ }
+
+ assertThat(status.isOk(), is(true));
+
// confirm it does not exist in repository
assertThat(((JsonRestClient)this.restClient).pathExists(WORKSPACE1,
WORKSPACE_PATH, file), is(false));
}
Added: branches/eclipse/dna-web-jcr-rest-client/src/test/resources/myproject/My.Test -
Folder/Test File_.a-*().txt
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/test/resources/myproject/My.Test -
Folder/Test File_.a-*().txt (rev 0)
+++ branches/eclipse/dna-web-jcr-rest-client/src/test/resources/myproject/My.Test -
Folder/Test File_.a-*().txt 2009-09-10 21:16:23 UTC (rev 1204)
@@ -0,0 +1,174 @@
+Help us improve Wikipedia by supporting it financially.
+Registration for Wikimania 2009 is now open. Learn more.
+
+[Hide] [Help us with translations!]
+Percent-encoding
+From Wikipedia, the free encyclopedia
+Jump to: navigation, search
+ This article includes a list of references, related reading or external links, but
its sources remain unclear because it lacks inline citations. Please improve this article
by introducing more precise citations where appropriate. (April 2008)
+
+ For the urlencode in mediawiki, see Help:Magic words
+
+Percent-encoding, also known as URL encoding, is a mechanism for encoding information in
a Uniform Resource Identifier (URI) under certain circumstances. Although it is known as
URL encoding it is, in fact, used more generally within the main Uniform Resource
Identifier (URI) set, which includes both Uniform Resource Locator (URL) and Uniform
Resource Name (URN). As such it is also used in the preparation of data of the
"application/x-www-form-urlencoded" media type, as is often used in email
messages and the submission of HTML form data in HTTP requests.
+Contents
+[hide]
+
+ * 1 Percent-encoding in a URI
+ o 1.1 Types of URI characters
+ o 1.2 Percent-encoding reserved characters
+ o 1.3 Percent-encoding unreserved characters
+ o 1.4 Percent-encoding arbitrary data
+ + 1.4.1 Binary data
+ + 1.4.2 Character data
+ o 1.5 Current standard
+ o 1.6 Non-standard implementations
+ * 2 The application/x-www-form-urlencoded type
+ * 3 See also
+ * 4 References
+ * 5 External links
+
+[edit] Percent-encoding in a URI
+
+[edit] Types of URI characters
+
+The characters allowed in a URI are either reserved or unreserved. Reserved characters
are those characters that sometimes have special meaning, while unreserved characters have
no such meaning. Using percent-encoding, characters which otherwise would not be allowed
are represented using allowed characters. The sets of reserved and unreserved characters
and the circumstances under which certain reserved characters have special meaning have
changed slightly with each revision of specifications that govern URIs and URI schemes.
+RFC 3986 section 2.2 Reserved Characters (January 2005) ! * ' ( ) ; : @
& = + $ , / ? % # [ ]
+RFC 3986 section 2.3 Unreserved Characters (January 2005) A B C D E F G H
I J K L M N O P Q R S T U V W X Y Z
+a b c d e f g h i j k l m n o p q r s t u v w
x y z
+0 1 2 3 4 5 6 7 8 9 - _ . ~
+
+No other characters are allowed in a URI.
+
+[edit] Percent-encoding reserved characters
+
+When a character from the reserved set (a "reserved character") has special
meaning (a "reserved purpose") in a certain context, and a URI scheme says that
it is necessary to use that character for some other purpose, then the character must be
percent-encoded. Percent-encoding a reserved character involves converting the character
to its corresponding byte value in ASCII and then representing that value as a pair of
hexadecimal digits. The digits, preceded by a percent sign ("%"), are then used
in the URI in place of the reserved character. (For a non-ASCII character, it is typically
converted to its byte sequence in UTF-8, and then each byte value is represented as
above.)
+
+The reserved character "/", for example, if used in the "path"
component of a URI, has the special meaning of being a delimiter between path segments.
If, according to a given URI scheme, "/" needs to be in a path segment, then the
three characters "%2F" or "%2f" must be used in the segment instead of
a raw "/".
+Reserved characters after percent-encoding ! * " ' ( ) ; : @
& = + $ , / ? % # [ ]
+%21 %2A %22 %27 %28 %29 %3B %3A %40 %26 %3D
%2B %24 %2C %2F %3F %25 %23 %5B %5D
+
+Reserved characters that have no reserved purpose in a particular context may also be
percent-encoded but are not semantically different from those that are not.
+
+In the "query" component of a URI, for example, "/" is still
considered a reserved character but it normally has no reserved purpose, unless a
particular URI scheme says otherwise. The character does not need to be percent-encoded
when it has no reserved purpose.
+
+URIs that differ only by whether a reserved character is percent-encoded or appears
literally are normally considered not equivalent (denoting the same resource) unless it
can be determined that the reserved characters in question have no reserved purpose. This
determination is dependent upon the rules established for reserved characters by
individual URI schemes.
+
+[edit] Percent-encoding unreserved characters
+
+Characters from the unreserved set can be percent-encoded in the same way as reserved
characters. That is, if a scheme calls for an unreserved character to be used in a URI,
either the raw character or its percent-encoded equivalent may be used interchangeably.
+
+URIs that differ only by whether an unreserved character is percent-encoded or appears
literally are equivalent by definition, but URI processors, in practice, may not always
recognize this equivalence. For example, URI consumers shouldn't treat "%41"
differently from "A" or "%7E" differently from "~", but some
do. For maximum interoperability, URI producers are discouraged from percent-encoding
unreserved characters.
+
+[edit] Percent-encoding arbitrary data
+
+Most URI schemes involve the representation of arbitrary data, such as an IP address or
file system path, as components of a URI. URI scheme specifications should, but often
don't, provide an explicit mapping between URI characters and all possible data values
being represented by those characters.
+
+[edit] Binary data
+
+Since the publication of RFC 1738 in 1994 it has been specified that schemes that provide
for the representation of binary data in a URI must divide the data into 8-bit bytes and
percent-encode each byte in the same manner as above. Byte value 0F (hexadecimal), for
example, should be represented by "%0F", but byte value 41 (hexadecimal) can be
represented by "A", or "%41". The use of unencoded characters for
alphanumeric and unreserved characters is typically preferred as it results in shorter
URLs.
+
+[edit] Character data
+
+The procedure for percent-encoding binary data has often been extrapolated, sometimes
inappropriately or without being fully specified, to apply to character-based data. In the
World Wide Web's formative years, when dealing with data characters in the ASCII
repertoire and using their corresponding bytes in ASCII as the basis for determining
percent-encoded sequences, this practice was relatively harmless; it was just assumed that
characters and bytes mapped one-to-one and were interchangeable. The need to represent
characters outside the ASCII range, however, grew quickly and URI schemes and protocols
often failed to provide standard rules for preparing character data for inclusion in a
URI. Web applications consequently began using different multi-byte, stateful, and other
non-ASCII-compatible encodings as the basis for percent-encoding, leading to ambiguities
and difficulty interpreting URIs reliably.
+
+For example, many URI schemes and protocols based on RFCs 1738 and 2396 presume that the
data characters will be converted to bytes according to some unspecified character
encoding before being represented in a URI by unreserved characters or percent-encoded
bytes. If the scheme does not allow the URI to provide a hint as to what encoding was
used, or if the encoding conflicts with the use of ASCII to percent-encode reserved and
unreserved characters, then the URI cannot be reliably interpreted. Some schemes fail to
account for encoding at all, and instead just suggest that data characters map directly to
URI characters, which leaves it up to implementations to decide whether and how to
percent-encode data characters that are in neither the reserved nor unreserved sets.
+
+[edit] Current standard
+
+The generic URI syntax mandates that new URI schemes that provide for the representation
of character data in a URI must, in effect, represent characters from the unreserved set
without translation, and should convert all other characters to bytes according to UTF-8,
and then percent-encode those values. This requirement was introduced in January 2005 with
the publication of RFC 3986. URI schemes introduced before this date are not affected.
+
+Not addressed by the current specification is what to do with encoded character data. For
example, in computers, character data manifests in encoded form, at some level, and thus
could be treated as either binary data or as character data when being mapped to URI
characters. Presumably, it is up to the URI scheme specifications to account for this
possibility and require one or the other, but in practice, few, if any, actually do.
+
+[edit] Non-standard implementations
+
+There exists a non-standard encoding for Unicode characters: %uxxxx, where xxxx is a
Unicode value represented as four hexadecimal digits. This behavior is not specified by
any RFC and has been rejected by the W3C. The third edition of ECMA-262 still includes an
escape(string) function that uses this syntax, but also an encodeURI(uri) function that
converts to UTF-8 and percent-encodes each octet.
+
+[edit] The application/x-www-form-urlencoded type
+
+When data that has been entered into HTML forms is submitted, the form field names and
values are encoded and sent to the server in an HTTP request message using method GET or
POST, or, historically, via email.[1] The encoding used by default is based on a very
early version of the general URI percent-encoding rules, with a number of modifications
such as newline normalization and replacing spaces with "+" instead of
"%20". The MIME type of data encoded this way is
application/x-www-form-urlencoded, and it is currently defined (still in a very outdated
manner) in the HTML and XForms specifications. In addition, the CGI specification contains
rules for how web servers decode data of this type and make it available to applications.
+
+When sent in an HTTP GET request, application/x-www-form-urlencoded data is included in
the query component of the request URI. When sent in an HTTP POST request or via email,
the data is placed in the body of the message, and the name of the media type is included
in the message's Content-Type header.
+
+[edit] See also
+
+ * Internationalized Resource Identifier
+ * Punycode
+
+[edit] References
+
+ 1. ^ User-agent support for email based HTML form submission, using a 'mailto'
URL as the form action, was proposed in RFC 1867 section 5.6, during the HTML 3.2 era.
Various web browsers implemented it by invoking a separate email program or using their
own rudimentary SMTP capabilities. Although sometimes unreliable, it was briefly popular
as a simple way to transmit form data without involving a web server or CGI scripts.
+
+[edit] External links
+
+The following specifications all discuss and define reserved characters, unreserved
characters, and percent-encoding, in some form or other:
+
+ * RFC 3986 / STD 66, the current generic URI syntax specification.
+ * RFC 2396 (obsolete) and RFC 2732 together comprised the previous version of the
generic URI syntax specification.
+ * RFC 1738 (mostly obsolete) and RFC 1808 (obsolete), which define URLs.
+ * RFC 1630 (obsolete), the first generic URI syntax specification.
+ * W3C Guidelines on Naming and Addressing: URIs, URLs, ...
+ * W3C explanation of UTF-8 in URIs
+ * W3C HTML form content types
+
+Retrieved from "http://en.wikipedia.org/wiki/Percent-encoding"
+Categories: URI scheme | Internet standards | Binary-to-text encoding formats
+Hidden categories: Articles lacking in-text citations from April 2008
+Views
+
+ * Article
+ * Discussion
+ * Edit this page
+ * History
+
+Personal tools
+
+ * Try Beta
+ * Log in / create account
+
+Navigation
+
+ * Main page
+ * Contents
+ * Featured content
+ * Current events
+ * Random article
+
+Search
+
+Interaction
+
+ * About Wikipedia
+ * Community portal
+ * Recent changes
+ * Contact Wikipedia
+ * Donate to Wikipedia
+ * Help
+
+Toolbox
+
+ * What links here
+ * Related changes
+ * Upload file
+ * Special pages
+ * Printable version
+ * Permanent link
+ * Cite this page
+
+Languages
+
+ * Česky
+ * Deutsch
+ * 한국어
+ * Magyar
+ * 日本語
+
+Powered by MediaWiki
+Wikimedia Foundation
+
+ * This page was last modified on 5 August 2009 at 16:59.
+ * Text is available under the Creative Commons Attribution-ShareAlike License;
additional terms may apply. See Terms of Use for details.
+ Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a
non-profit organization.
+ * Privacy policy
+ * About Wikipedia
+ * Disclaimers
+
Property changes on:
branches/eclipse/dna-web-jcr-rest-client/src/test/resources/myproject/My.Test -
Folder/Test File_.a-*().txt
___________________________________________________________________
Name: svn:mime-type
+ text/plain