Author: elvisisking
Date: 2009-09-30 11:32:21 -0400 (Wed, 30 Sep 2009)
New Revision: 1278
Added:
trunk/web/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/http/
trunk/web/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/http/HttpClientConnection.java
trunk/web/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/http/HttpUrlConnection.java
trunk/web/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/http/IHttpConnection.java
Modified:
trunk/tools/org.jboss.dna.eclipse.jcr.rest.client.feature/feature.xml
trunk/tools/org.jboss.dna.eclipse.jcr.rest.client.updatesite/
trunk/tools/org.jboss.dna.eclipse.jcr.rest.client.updatesite/site.xml
trunk/tools/org.jboss.dna.eclipse.jcr.rest.client/.settings/org.eclipse.jdt.core.prefs
trunk/tools/org.jboss.dna.eclipse.jcr.rest.client/dna-web-jcr-rest-client-0.7-SNAPSHOT-jar-with-dependencies.jar
trunk/tools/org.jboss.dna.eclipse.jcr.rest.client/dna-web-jcr-rest-client-0.7-SNAPSHOT-sources.jar
trunk/tools/org.jboss.dna.eclipse.jcr.rest.client/src/org/jboss/dna/eclipse/jcr/rest/client/RestClientI18n.properties
trunk/tools/org.jboss.dna.eclipse.jcr.rest.client/src/org/jboss/dna/eclipse/jcr/rest/client/jobs/PublishJob.java
trunk/web/dna-web-jcr-rest-client/pom.xml
trunk/web/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/ServerManager.java
trunk/web/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestClient.java
trunk/web/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestClientTest.java
Log:
Changed from using java.net.Authenticator (HTTP authentication) to Apache's
HttpClient. The
java.net framework allows only one Authenticator at a time (a static
instance) and our authenticator was being removed by an Eclipse plugin who was also using
java.net.Authenticator. Also changed the publishing job numbers to start with 1 not 2. And
changed the way error, info, and warning messages appear in the DNA message console.
Modified:
trunk/tools/org.jboss.dna.eclipse.jcr.rest.client/.settings/org.eclipse.jdt.core.prefs
===================================================================
---
trunk/tools/org.jboss.dna.eclipse.jcr.rest.client/.settings/org.eclipse.jdt.core.prefs 2009-09-30
13:10:56 UTC (rev 1277)
+++
trunk/tools/org.jboss.dna.eclipse.jcr.rest.client/.settings/org.eclipse.jdt.core.prefs 2009-09-30
15:32:21 UTC (rev 1278)
@@ -1,7 +1,12 @@
-#Wed Jul 01 08:14:43 CDT 2009
+#Wed Sep 30 07:56:02 CDT 2009
eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.doc.comment.support=enabled
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
Modified:
trunk/tools/org.jboss.dna.eclipse.jcr.rest.client/dna-web-jcr-rest-client-0.7-SNAPSHOT-jar-with-dependencies.jar
===================================================================
(Binary files differ)
Modified:
trunk/tools/org.jboss.dna.eclipse.jcr.rest.client/dna-web-jcr-rest-client-0.7-SNAPSHOT-sources.jar
===================================================================
(Binary files differ)
Modified:
trunk/tools/org.jboss.dna.eclipse.jcr.rest.client/src/org/jboss/dna/eclipse/jcr/rest/client/RestClientI18n.properties
===================================================================
---
trunk/tools/org.jboss.dna.eclipse.jcr.rest.client/src/org/jboss/dna/eclipse/jcr/rest/client/RestClientI18n.properties 2009-09-30
13:10:56 UTC (rev 1277)
+++
trunk/tools/org.jboss.dna.eclipse.jcr.rest.client/src/org/jboss/dna/eclipse/jcr/rest/client/RestClientI18n.properties 2009-09-30
15:32:21 UTC (rev 1278)
@@ -84,9 +84,9 @@
publishJobPublish = [{0}] Publishing {4} file(s) to server "{1}" (repository
"{2}", workspace "{3}") ...
publishJobPublishCanceledMsg = [{0}] Publishing was canceled after {1} file(s) out of {2}
were processed. Elapsed time: {3}.\n
publishJobPublishFile = [{0}] + Published file "{1}" to URL
"<em>{2}</em>"
-publishJobPublishFileFailed = [{0}] -- ERROR -- Publishing file "{1}" generated
an ERROR message. See log.
-publishJobPublishFileInfo = [{0}] -- INFO -- Publishing file "{1}" generated an
INFO message. See log.
-publishJobPublishFileWarning = [{0}] -- WARNING -- Publishing file "{1}"
generated a WARNING message. See log.
+publishJobPublishFileFailed = [{0}] << ERROR >> Publishing file
"{1}" generated an ERROR message. See log.
+publishJobPublishFileInfo = [{0}] << INFO >> Publishing file "{1}"
generated an INFO message. See log.
+publishJobPublishFileWarning = [{0}] << WARNING >> Publishing file
"{1}" generated a WARNING message. See log.
publishJobPublishFinishedMsg = [{0}] Done publishing. Elapsed time: {1}.\n
publishJobPublishName = DNA Publish [{0}]
publishJobPublishTaskName = Publishing resources [{0}]
@@ -94,9 +94,9 @@
publishJobUnpublish = [{0}] Unpublishing {4} file(s) from server "{1}"
(repository "{2}", workspace "{3}") ...
publishJobUnpublishCanceledMsg = [{0}] Unublishing was canceled after {1} file(s) out of
{2} were processed. Elapsed time: {3}.\n
publishJobUnpublishFile = [{0}] - Unpublished file "{1}"
-publishJobUnpublishFileFailed = [{0}] -- ERROR -- Unpublishing file "{0}"
generated an ERROR message. See log.
-publishJobUnpublishFileInfo = [{0}] -- INFO -- Unpublishing file "{1}"
generated an INFO message. See log.
-publishJobUnpublishFileWarning = [{0}] -- WARN -- Unpublishing file "{1}"
generated a WARNING message. See log.
+publishJobUnpublishFileFailed = [{0}] << ERROR >> Unpublishing file
"{0}" generated an ERROR message. See log.
+publishJobUnpublishFileInfo = [{0}] << INFO >> Unpublishing file
"{1}" generated an INFO message. See log.
+publishJobUnpublishFileWarning = [{0}] << WARN >> Unpublishing file
"{1}" generated a WARNING message. See log.
publishJobUnpublishFinishedMsg = [{0}] Done unpublishing. Elapsed time: {1}. \n
publishJobUnpublishName = DNA Unpublish [{0}]
publishJobUnpublishTaskName = Unpublishing resources [{0}]
Modified:
trunk/tools/org.jboss.dna.eclipse.jcr.rest.client/src/org/jboss/dna/eclipse/jcr/rest/client/jobs/PublishJob.java
===================================================================
---
trunk/tools/org.jboss.dna.eclipse.jcr.rest.client/src/org/jboss/dna/eclipse/jcr/rest/client/jobs/PublishJob.java 2009-09-30
13:10:56 UTC (rev 1277)
+++
trunk/tools/org.jboss.dna.eclipse.jcr.rest.client/src/org/jboss/dna/eclipse/jcr/rest/client/jobs/PublishJob.java 2009-09-30
15:32:21 UTC (rev 1278)
@@ -70,7 +70,7 @@
/**
* A unique job identifier given to each publishing/unpublishing job.
*/
- private static final AtomicInteger JOB_ID = new AtomicInteger(1);
+ private static final AtomicInteger JOB_ID = new AtomicInteger();
//
===========================================================================================================================
// Class Methods
Modified: trunk/tools/org.jboss.dna.eclipse.jcr.rest.client.feature/feature.xml
===================================================================
--- trunk/tools/org.jboss.dna.eclipse.jcr.rest.client.feature/feature.xml 2009-09-30
13:10:56 UTC (rev 1277)
+++ trunk/tools/org.jboss.dna.eclipse.jcr.rest.client.feature/feature.xml 2009-09-30
15:32:21 UTC (rev 1278)
@@ -2,13 +2,11 @@
<feature
id="org.jboss.dna.eclipse.jcr.rest.client.feature"
label="%featureName"
- version="1.0.0.v20090819"
- image="feature.png"
+ version="1.0.0.v20090930"
provider-name="%featureProvider"
- plugin="org.jboss.dna.eclipse.jcr.rest.client">
+ plugin="org.jboss.dna.eclipse.jcr.rest.client"
+ image="feature.png">
-<!-- NOTE: above image is found in the branding plugin -->
-
<description
url="http://www.jboss.org/dna/">
%description
</description>
@@ -31,7 +29,6 @@
id="org.jboss.dna.eclipse.jcr.rest.client"
download-size="0"
install-size="0"
- version="0.0.0"
- unpack="true"/>
+ version="0.0.0"/>
</feature>
Property changes on: trunk/tools/org.jboss.dna.eclipse.jcr.rest.client.updatesite
___________________________________________________________________
Name: svn:ignore
+ features
plugins
artifacts.xml
content.xml
Modified: trunk/tools/org.jboss.dna.eclipse.jcr.rest.client.updatesite/site.xml
===================================================================
--- trunk/tools/org.jboss.dna.eclipse.jcr.rest.client.updatesite/site.xml 2009-09-30
13:10:56 UTC (rev 1277)
+++ trunk/tools/org.jboss.dna.eclipse.jcr.rest.client.updatesite/site.xml 2009-09-30
15:32:21 UTC (rev 1278)
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<site>
- <feature
url="features/org.jboss.dna.eclipse.jcr.rest.client.feature_1.0.0.v20090922.jar"
id="org.jboss.dna.eclipse.jcr.rest.client.feature"
version="1.0.0.v20090922"/>
+ <feature
url="features/org.jboss.dna.eclipse.jcr.rest.client.feature_1.0.0.v20090930.jar"
id="org.jboss.dna.eclipse.jcr.rest.client.feature"
version="1.0.0.v20090930"/>
</site>
Modified: trunk/web/dna-web-jcr-rest-client/pom.xml
===================================================================
--- trunk/web/dna-web-jcr-rest-client/pom.xml 2009-09-30 13:10:56 UTC (rev 1277)
+++ trunk/web/dna-web-jcr-rest-client/pom.xml 2009-09-30 15:32:21 UTC (rev 1278)
@@ -5,7 +5,7 @@
<groupId>org.jboss.dna</groupId>
<artifactId>dna</artifactId>
<version>0.7-SNAPSHOT</version>
- <relativePath>../..</relativePath>
+ <relativePath>../..</relativePath>
</parent>
<!-- The groupId and version values are inherited from parent -->
<artifactId>dna-web-jcr-rest-client</artifactId>
@@ -38,6 +38,12 @@
<scope>integration-test</scope>
</dependency>
<dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ <version>4.0</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>integration-test</scope>
@@ -98,218 +104,218 @@
</plugins>
</reporting>
<profiles>
- <profile>
- <id>cargo-1</id>
- <activation>
- <activeByDefault>true</activeByDefault>
- </activation>
- <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>
+ <profile>
+ <id>cargo-1</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <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>
- </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>
+ <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>
+ <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:
trunk/web/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/ServerManager.java
===================================================================
---
trunk/web/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/ServerManager.java 2009-09-30
13:10:56 UTC (rev 1277)
+++
trunk/web/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/ServerManager.java 2009-09-30
15:32:21 UTC (rev 1278)
@@ -25,7 +25,6 @@
import java.io.File;
import java.io.FileOutputStream;
-import java.net.Authenticator;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
@@ -173,9 +172,6 @@
this.stateLocationPath = stateLocationPath;
this.delegate = restClient;
this.listeners = new CopyOnWriteArrayList<IServerRegistryListener>();
-
- // set our authenticator that uses the server registry
- Authenticator.setDefault(new ServerAuthenticator());
}
/**
Added:
trunk/web/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/http/HttpClientConnection.java
===================================================================
---
trunk/web/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/http/HttpClientConnection.java
(rev 0)
+++
trunk/web/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/http/HttpClientConnection.java 2009-09-30
15:32:21 UTC (rev 1278)
@@ -0,0 +1,160 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.web.jcr.rest.client.http;
+
+import java.net.URL;
+import javax.ws.rs.core.MediaType;
+import org.apache.http.HttpResponse;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.UsernamePasswordCredentials;
+import org.apache.http.client.methods.HttpDelete;
+import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpPut;
+import org.apache.http.client.methods.HttpRequestBase;
+import org.apache.http.entity.ByteArrayEntity;
+import org.apache.http.impl.client.AbstractHttpClient;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.util.EntityUtils;
+import org.jboss.dna.web.jcr.rest.client.domain.Server;
+import org.jboss.dna.web.jcr.rest.client.json.IJsonConstants.RequestMethod;
+
+/**
+ * <code>HttpClientConnection</code> is an <code>Apache
HttpClient</code> implementation of <code>IHttpConnection</code>.
+ */
+public final class HttpClientConnection implements IHttpConnection {
+
+ //
===========================================================================================================================
+ // Fields
+ //
===========================================================================================================================
+
+ /**
+ * The HTTP client that opens the connection, executes the request, and closes the
connection.
+ */
+ private final AbstractHttpClient httpClient;
+
+ /**
+ * The HTTP request.
+ */
+ private final HttpRequestBase request;
+
+ /**
+ * The HTTP response.
+ */
+ private HttpResponse response;
+
+ //
===========================================================================================================================
+ // Constructors
+ //
===========================================================================================================================
+
+ /**
+ * @param server the server with the host and port information
+ * @param url the URL that will be used in the request
+ * @param method the HTTP request method
+ * @throws Exception if there is a problem establishing the connection
+ */
+ public HttpClientConnection( Server server,
+ URL url,
+ RequestMethod method ) throws Exception {
+ this.httpClient = new DefaultHttpClient();
+ this.httpClient.getCredentialsProvider().setCredentials(new
AuthScope(url.getHost(), url.getPort()),
+ new
UsernamePasswordCredentials(server.getUser(),
+
server.getPassword()));
+ // determine the request type
+ if (RequestMethod.GET == method) {
+ this.request = new HttpGet();
+ } else if (RequestMethod.DELETE == method) {
+ this.request = new HttpDelete();
+ } else if (RequestMethod.POST == method) {
+ this.request = new HttpPost();
+ } else if (RequestMethod.PUT == method) {
+ this.request = new HttpPut();
+ } else {
+ // TODO need exception message
+ throw new RuntimeException();
+ }
+
+ // set request URI
+ this.request.setURI(url.toURI());
+ }
+
+ //
===========================================================================================================================
+ // Methods
+ //
===========================================================================================================================
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.web.jcr.rest.client.http.IHttpConnection#disconnect()
+ */
+ public void disconnect() {
+ this.httpClient.getConnectionManager().shutdown();
+ }
+
+ /**
+ * @return the HTTP response
+ * @throws Exception if there is a problem obtaining the response
+ */
+ private HttpResponse getResponse() throws Exception {
+ if (this.response == null) {
+ this.response = this.httpClient.execute(request);
+ }
+
+ return this.response;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.web.jcr.rest.client.http.IHttpConnection#getResponseCode()
+ */
+ public int getResponseCode() throws Exception {
+ return getResponse().getStatusLine().getStatusCode();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.web.jcr.rest.client.http.IHttpConnection#read()
+ */
+ public String read() throws Exception {
+ return EntityUtils.toString(getResponse().getEntity());
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.web.jcr.rest.client.http.IHttpConnection#write(byte[])
+ */
+ public void write( byte[] bytes ) throws Exception {
+ ByteArrayEntity entity = new ByteArrayEntity(bytes);
+ entity.setContentType(MediaType.APPLICATION_JSON);
+
+ if (this.request instanceof HttpEntityEnclosingRequestBase) {
+ ((HttpEntityEnclosingRequestBase)this.request).setEntity(entity);
+ }
+ }
+
+}
Property changes on:
trunk/web/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/http/HttpClientConnection.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/web/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/http/HttpUrlConnection.java
===================================================================
---
trunk/web/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/http/HttpUrlConnection.java
(rev 0)
+++
trunk/web/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/http/HttpUrlConnection.java 2009-09-30
15:32:21 UTC (rev 1278)
@@ -0,0 +1,124 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.web.jcr.rest.client.http;
+
+import java.net.Authenticator;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import javax.ws.rs.core.MediaType;
+import org.jboss.dna.common.util.Base64;
+import org.jboss.dna.web.jcr.rest.client.ServerAuthenticator;
+import org.jboss.dna.web.jcr.rest.client.domain.Server;
+import org.jboss.dna.web.jcr.rest.client.json.JsonUtils;
+import org.jboss.dna.web.jcr.rest.client.json.IJsonConstants.RequestMethod;
+
+/**
+ * <code>HttpUrlConnection</code> is a <code>java.net</code>
implementation of <code>IHttpConnection</code>.
+ */
+public final class HttpUrlConnection implements IHttpConnection {
+
+ //
===========================================================================================================================
+ // Class Initializer
+ //
===========================================================================================================================
+
+ static {
+ // must be set when using
java.net framework but a problem occurs when other
subsytems have their own Authenticator and
+ // also call this method
+ Authenticator.setDefault(new ServerAuthenticator());
+ }
+
+ //
===========================================================================================================================
+ // Fields
+ //
===========================================================================================================================
+
+ /**
+ * The HTTP connection that executes the request and obtains the response.
+ */
+ private final HttpURLConnection connection;
+
+ //
===========================================================================================================================
+ // Constructors
+ //
===========================================================================================================================
+
+ /**
+ * @param server the server with the host and port information
+ * @param url the URL that will be used in the request
+ * @param method the HTTP request method
+ * @throws Exception if there is a problem establishing the connection
+ */
+ public HttpUrlConnection( Server server,
+ URL url,
+ RequestMethod method ) throws Exception {
+ this.connection = (HttpURLConnection)url.openConnection();
+ this.connection.setDoOutput(true);
+
+ String encoding = Base64.encodeBytes((server.getUser() + ':' +
server.getPassword()).getBytes());
+ this.connection.setRequestProperty("Authorization", "Basic "
+ encoding); //$NON-NLS-1$ //$NON-NLS-2$
+
+ this.connection.setRequestMethod(method.toString());
+ this.connection.setRequestProperty("Content-Type",
MediaType.APPLICATION_JSON); //$NON-NLS-1$
+ this.connection.setUseCaches(false);
+ }
+
+ //
===========================================================================================================================
+ // Methods
+ //
===========================================================================================================================
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.web.jcr.rest.client.http.IHttpConnection#disconnect()
+ */
+ public void disconnect() {
+ this.connection.disconnect();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.web.jcr.rest.client.http.IHttpConnection#getResponseCode()
+ */
+ public int getResponseCode() throws Exception {
+ return this.connection.getResponseCode();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.web.jcr.rest.client.http.IHttpConnection#read()
+ */
+ public String read() throws Exception {
+ return JsonUtils.readInputStream(this.connection);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.web.jcr.rest.client.http.IHttpConnection#write(byte[])
+ */
+ public void write( byte[] bytes ) throws Exception {
+ connection.getOutputStream().write(bytes);
+ }
+
+}
Property changes on:
trunk/web/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/http/HttpUrlConnection.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/web/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/http/IHttpConnection.java
===================================================================
---
trunk/web/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/http/IHttpConnection.java
(rev 0)
+++
trunk/web/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/http/IHttpConnection.java 2009-09-30
15:32:21 UTC (rev 1278)
@@ -0,0 +1,55 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.web.jcr.rest.client.http;
+
+/**
+ * The <code>IHttpConnection</code> is the contract for all HTTP connection
frameworks must implement to work with the DNA REST
+ * server.
+ */
+public interface IHttpConnection {
+
+ /**
+ * Disconnects this connection.
+ */
+ void disconnect();
+
+ /**
+ * @return the HTTP response code
+ * @throws Exception if there is a problem getting the response code
+ */
+ int getResponseCode() throws Exception;
+
+ /**
+ * @return the HTTP response body as a string
+ * @throws Exception if there is a problem reading from the connection
+ */
+ String read() throws Exception;
+
+ /**
+ * @param bytes the bytes being posted to the HTTP connection
+ * @throws Exception if there is a problem writing to the connection
+ */
+ void write( byte[] bytes ) throws Exception;
+
+}
Property changes on:
trunk/web/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/http/IHttpConnection.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/web/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestClient.java
===================================================================
---
trunk/web/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestClient.java 2009-09-30
13:10:56 UTC (rev 1277)
+++
trunk/web/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestClient.java 2009-09-30
15:32:21 UTC (rev 1278)
@@ -27,8 +27,6 @@
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Collection;
-import javax.ws.rs.core.MediaType;
-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.IRestClient;
@@ -38,6 +36,8 @@
import org.jboss.dna.web.jcr.rest.client.domain.Repository;
import org.jboss.dna.web.jcr.rest.client.domain.Server;
import org.jboss.dna.web.jcr.rest.client.domain.Workspace;
+import org.jboss.dna.web.jcr.rest.client.http.HttpClientConnection;
+import org.jboss.dna.web.jcr.rest.client.http.IHttpConnection;
import org.jboss.dna.web.jcr.rest.client.json.IJsonConstants.RequestMethod;
/**
@@ -60,6 +60,21 @@
//
===========================================================================================================================
/**
+ * @param server the server where the connection will be established
+ * @param url the URL where the connection will be established
+ * @param method the request method
+ * @return the connection which <strong>MUST</strong> be disconnected
+ * @throws Exception if there is a problem establishing the connection
+ */
+ private IHttpConnection connect( Server server,
+ URL url,
+ RequestMethod method ) throws Exception {
+ this.logger.trace("connect: url={0}, method={1}", url, method);
//$NON-NLS-1$
+ // return new HttpUrlConnection(server, url, method);
+ return new HttpClientConnection(server, url, method);
+ }
+
+ /**
* Creates a file node in the specified repository. Note: All parent folders are
assumed to already exist.
*
* @param workspace the workspace where the file node is being created
@@ -72,11 +87,11 @@
File file ) throws Exception {
this.logger.trace("createFileNode: workspace={0}, path={1}, file={2}",
workspace.getName(), path, file.getAbsolutePath()); //$NON-NLS-1$
FileNode fileNode = new FileNode(workspace, path, file);
- HttpURLConnection connection = openConnection(workspace.getServer(),
fileNode.getUrl(), RequestMethod.POST);
+ IHttpConnection connection = connect(workspace.getServer(), fileNode.getUrl(),
RequestMethod.POST);
try {
this.logger.trace("createFileNode: create node={0}", fileNode);
//$NON-NLS-1$
- connection.getOutputStream().write(fileNode.getContent());
+ connection.write(fileNode.getContent());
// make sure node was created
if (connection.getResponseCode() != HttpURLConnection.HTTP_CREATED) {
@@ -107,11 +122,11 @@
String path ) throws Exception {
this.logger.trace("createFolderNode: workspace={0}, path={1}",
workspace.getName(), path); //$NON-NLS-1$
FolderNode folderNode = new FolderNode(workspace, path);
- HttpURLConnection connection = openConnection(workspace.getServer(),
folderNode.getUrl(), RequestMethod.POST);
+ IHttpConnection connection = connect(workspace.getServer(), folderNode.getUrl(),
RequestMethod.POST);
try {
this.logger.trace("createFolderNode: create node={0}", folderNode);
//$NON-NLS-1$
- connection.getOutputStream().write(folderNode.getContent());
+ connection.write(folderNode.getContent());
// make sure node was created
if (connection.getResponseCode() != HttpURLConnection.HTTP_CREATED) {
@@ -179,11 +194,11 @@
this.logger.trace("getRepositories: server={0}", server);
//$NON-NLS-1$
ServerNode serverNode = new ServerNode(server);
- HttpURLConnection connection = openConnection(server,
serverNode.getFindRepositoriesUrl(), RequestMethod.GET);
+ IHttpConnection connection = connect(server, serverNode.getFindRepositoriesUrl(),
RequestMethod.GET);
try {
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
- return
serverNode.getRepositories(JsonUtils.readInputStream(connection));
+ return serverNode.getRepositories(connection.read());
}
// not a good response code
@@ -229,11 +244,11 @@
this.logger.trace("getWorkspaces: repository={0}", repository);
//$NON-NLS-1$
RepositoryNode repositoryNode = new RepositoryNode(repository);
- HttpURLConnection connection = openConnection(repository.getServer(),
repositoryNode.getUrl(), RequestMethod.GET);
+ IHttpConnection connection = connect(repository.getServer(),
repositoryNode.getUrl(), RequestMethod.GET);
try {
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
- return
repositoryNode.getWorkspaces(JsonUtils.readInputStream(connection));
+ return repositoryNode.getWorkspaces(connection.read());
}
// not a good response code
@@ -251,33 +266,6 @@
}
/**
- * @param server the server where the connection will be established
- * @param url the URL where the connection will be established
- * @param method the request method
- * @return the open connection which <strong>MUST</strong> be
disconnected
- * @throws Exception if there is a problem establishing the connection
- */
- private HttpURLConnection openConnection( Server server,
- URL url,
- RequestMethod method ) throws Exception {
- this.logger.trace("openConnection: url={0}, method={1}", url, method);
//$NON-NLS-1$
-
- 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
@@ -290,11 +278,11 @@
String path,
File file ) throws Exception {
FileNode fileNode = new FileNode(workspace, path, file);
- HttpURLConnection connection = openConnection(workspace.getServer(),
fileNode.getFileContentsUrl(), RequestMethod.GET);
+ IHttpConnection connection = connect(workspace.getServer(),
fileNode.getFileContentsUrl(), RequestMethod.GET);
int responseCode = connection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
- String result = JsonUtils.readInputStream(connection);
+ String result = connection.read();
return fileNode.getFileContents(result);
}
@@ -310,7 +298,7 @@
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);
+ IHttpConnection connection = connect(server, url, RequestMethod.GET);
try {
int responseCode = connection.getResponseCode();
@@ -385,11 +373,11 @@
CheckArg.isNotNull(file, "file"); //$NON-NLS-1$
this.logger.trace("unpublish: workspace={0}, path={1}, file={2}",
workspace.getName(), path, file.getAbsolutePath()); //$NON-NLS-1$
- HttpURLConnection connection = null;
+ IHttpConnection connection = null;
try {
FileNode fileNode = new FileNode(workspace, path, file);
- connection = openConnection(workspace.getServer(), fileNode.getUrl(),
RequestMethod.DELETE);
+ connection = connect(workspace.getServer(), fileNode.getUrl(),
RequestMethod.DELETE);
int responseCode = connection.getResponseCode();
this.logger.trace("responseCode={0}", responseCode); //$NON-NLS-1$
Modified:
trunk/web/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestClientTest.java
===================================================================
---
trunk/web/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestClientTest.java 2009-09-30
13:10:56 UTC (rev 1277)
+++
trunk/web/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestClientTest.java 2009-09-30
15:32:21 UTC (rev 1278)
@@ -28,8 +28,6 @@
import static org.hamcrest.core.IsNull.notNullValue;
import static org.junit.Assert.assertThat;
import java.io.File;
-import java.net.Authenticator;
-import java.net.PasswordAuthentication;
import java.net.URL;
import java.util.Collection;
import org.jboss.dna.web.jcr.rest.client.IRestClient;
@@ -83,13 +81,6 @@
@Before
public void beforeEach() {
this.restClient = new JsonRestClient();
-
- Authenticator.setDefault(new Authenticator() {
- @Override
- protected PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication(USER, PSWD.toCharArray());
- }
- });
}
//
===========================================================================================================================