[jboss-svn-commits] JBL Code SVN: r26292 - in labs/jbosstm/workspace/resttx: src/main/java/org/jboss/jbossts/rts/client and 5 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Apr 28 15:01:45 EDT 2009
Author: mmusgrov
Date: 2009-04-28 15:01:45 -0400 (Tue, 28 Apr 2009)
New Revision: 26292
Modified:
labs/jbosstm/workspace/resttx/build.xml
labs/jbosstm/workspace/resttx/pom.xml
labs/jbosstm/workspace/resttx/src/main/java/org/jboss/jbossts/rts/client/TxTest.java
labs/jbosstm/workspace/resttx/src/main/java/org/jboss/jbossts/rts/example/Participant.java
labs/jbosstm/workspace/resttx/src/main/java/org/jboss/jbossts/rts/resource/RESTRecord.java
labs/jbosstm/workspace/resttx/src/main/java/org/jboss/jbossts/rts/service/Coordinator.java
labs/jbosstm/workspace/resttx/src/main/java/org/jboss/jbossts/rts/util/TxUtil.java
labs/jbosstm/workspace/resttx/src/test/java/org/jboss/jbossts/rts/test/AppTest.java
Log:
Added Consumes mime-type on PUT requests.
Added an ant target for running an external recovery manager
Modified: labs/jbosstm/workspace/resttx/build.xml
===================================================================
--- labs/jbosstm/workspace/resttx/build.xml 2009-04-28 13:10:33 UTC (rev 26291)
+++ labs/jbosstm/workspace/resttx/build.xml 2009-04-28 19:01:45 UTC (rev 26292)
@@ -20,9 +20,26 @@
<include name="commons-httpclient-3.1.jar"/>
<include name="commons-logging-1.0.4.jar"/>
<include name="commons-codec-1.2.jar"/>
+ <!-- jar for running an external recovery manager -->
+ <include name="jbossjta-4.4.0.GA.jar"/>
+ <include name="jbossts-common-4.4.0.GA.jar"/>
+ <include name="log4j-1.2.12.jar"/>
+ <include name="logkit-1.0.1.jar"/>
</fileset>
+ <pathelement location="${basedir}/target/classes"/>
+ <pathelement location="${basedir}/src/test/resources"/>
</path>
+ <target name="rm">
+ <java classname="com.arjuna.ats.arjuna.recovery.RecoveryManager" fork="yes" dir=".">
+ <classpath refid="classpath"/>
+ <!--
+ <sysproperty key="com.arjuna.ats.arjuna.common.propertiesFile" value="${basedir}/src/test/resources"/>
+ -->
+ <sysproperty key="com.arjuna.ats.arjuna.recovery.periodicRecoveryPeriod" value="30"/>
+ </java>
+ </target>
+
<target name="compile">
<javac srcdir="${src.dir}"
destdir="${build.classes.dir}"
Modified: labs/jbosstm/workspace/resttx/pom.xml
===================================================================
--- labs/jbosstm/workspace/resttx/pom.xml 2009-04-28 13:10:33 UTC (rev 26291)
+++ labs/jbosstm/workspace/resttx/pom.xml 2009-04-28 19:01:45 UTC (rev 26292)
@@ -35,7 +35,7 @@
<dependencies>
<dependency>
<groupId>jboss.jbossts</groupId>
- <artifactId>jbossjts</artifactId>
+ <artifactId>jbossjta</artifactId>
<version>4.4.0.GA</version>
</dependency>
<dependency>
Modified: labs/jbosstm/workspace/resttx/src/main/java/org/jboss/jbossts/rts/client/TxTest.java
===================================================================
--- labs/jbosstm/workspace/resttx/src/main/java/org/jboss/jbossts/rts/client/TxTest.java 2009-04-28 13:10:33 UTC (rev 26291)
+++ labs/jbosstm/workspace/resttx/src/main/java/org/jboss/jbossts/rts/client/TxTest.java 2009-04-28 19:01:45 UTC (rev 26292)
@@ -46,6 +46,6 @@
"name=p1", "value=v1", "context=" + tx);
// commit the changes
- TxUtil.doPut(new int[] {HttpResponseCodes.SC_OK}, tx + "/commit", "fault=none");
+ TxUtil.doPut(new int[] {HttpResponseCodes.SC_OK}, tx + "/commit", "", "fault=none");
}
}
Modified: labs/jbosstm/workspace/resttx/src/main/java/org/jboss/jbossts/rts/example/Participant.java
===================================================================
--- labs/jbosstm/workspace/resttx/src/main/java/org/jboss/jbossts/rts/example/Participant.java 2009-04-28 13:10:33 UTC (rev 26291)
+++ labs/jbosstm/workspace/resttx/src/main/java/org/jboss/jbossts/rts/example/Participant.java 2009-04-28 19:01:45 UTC (rev 26292)
@@ -270,7 +270,7 @@
try
{
- TxUtil.doPut(new int[] {HttpResponseCodes.SC_OK}, TxUtil.rcURI + "/" + w.recCoordId, "URL=" + url);
+ TxUtil.doPut(new int[] {HttpResponseCodes.SC_OK}, TxUtil.rcURI + "/" + w.recCoordId, url, "URL=" + url);
}
catch (HttpResponseException e)
{
@@ -318,7 +318,7 @@
{
// enlist as a participant in this transaction context
String pUrl = makeParticipantUrl(w);
- w.recCoordId = TxUtil.doPut(new int[] {HttpResponseCodes.SC_OK}, TxUtil.txURI + ctx, "URL=" + pUrl);
+ w.recCoordId = TxUtil.doPut(new int[] {HttpResponseCodes.SC_OK}, TxUtil.txURI + ctx, pUrl, "URL=" + pUrl);
}
catch (HttpResponseException e)
{
Modified: labs/jbosstm/workspace/resttx/src/main/java/org/jboss/jbossts/rts/resource/RESTRecord.java
===================================================================
--- labs/jbosstm/workspace/resttx/src/main/java/org/jboss/jbossts/rts/resource/RESTRecord.java 2009-04-28 13:10:33 UTC (rev 26291)
+++ labs/jbosstm/workspace/resttx/src/main/java/org/jboss/jbossts/rts/resource/RESTRecord.java 2009-04-28 19:01:45 UTC (rev 26292)
@@ -196,7 +196,18 @@
log.info("commit: halt VM");
Runtime.getRuntime().halt(1);
}
-
+
+ if (fault.equals(Fault.commit_suspend)) {
+ try
+ {
+ Thread.sleep(10000);
+ }
+ catch (InterruptedException e)
+ {
+ e.printStackTrace();
+ }
+ }
+
if (txId == null)
return TwoPhaseOutcome.FINISH_ERROR;
@@ -354,7 +365,7 @@
return false;
}
- enum Fault {abort_halt, prepare_halt, commit_halt, h_commit, h_rollback, h_hazard, h_mixed, none}
+ enum Fault {abort_halt, prepare_halt, commit_halt, commit_suspend, h_commit, h_rollback, h_hazard, h_mixed, none}
Fault fault = Fault.none;
public void setFault(String name)
Modified: labs/jbosstm/workspace/resttx/src/main/java/org/jboss/jbossts/rts/service/Coordinator.java
===================================================================
--- labs/jbosstm/workspace/resttx/src/main/java/org/jboss/jbossts/rts/service/Coordinator.java 2009-04-28 13:10:33 UTC (rev 26291)
+++ labs/jbosstm/workspace/resttx/src/main/java/org/jboss/jbossts/rts/service/Coordinator.java 2009-04-28 19:01:45 UTC (rev 26292)
@@ -143,7 +143,7 @@
*/
@POST
@Path("transaction-coordinator/begin/")
- public Response beginTransaction(@QueryParam("clientId")String clientId, @QueryParam("timeout") @DefaultValue("0")int timeout)
+ public Response beginTransaction(@QueryParam("clientId")String clientId, @QueryParam("timeout") @DefaultValue("-1")int timeout)
// @Path("transaction-coordinator/begin/{clientId}")
// public Response beginTransaction(@PathParam("clientId")String clientId, @QueryParam("timeout") @DefaultValue("0")int timeout)
{
@@ -231,15 +231,21 @@
*/
@PUT
@Path("transaction-coordinator/{TxId}")
- public Response enlistParticipant(@PathParam("TxId")String txId, @QueryParam("URL")String url)
+ @Consumes("text/html")
+ public Response enlistParticipant(@PathParam("TxId")String txId, @QueryParam("URL")String url, String content)
{
Transaction tx = getTransaction(txId);
+
+ if (url == null)
+ url = content.trim();
+
String coordinatorId = tx.enlistParticipant(url);
if (coordinatorId == null)
return TxUtil.response(HttpResponseCodes.SC_NOT_ACCEPTABLE);
- log.debug("enlisting participant " + url + " in tx " + txId + " Coordinator url: " + TxUtil.rcURI + '/' + coordinatorId);
+ log.debug("enlisting participant: content=" + content +
+ " URL=" + url + " in tx " + txId + " Coordinator url: " + TxUtil.rcURI + '/' + coordinatorId);
// TODO would be nice if there was something in the spec for telling the participant it
// has been enlisted
participants.put(coordinatorId, url);
Modified: labs/jbosstm/workspace/resttx/src/main/java/org/jboss/jbossts/rts/util/TxUtil.java
===================================================================
--- labs/jbosstm/workspace/resttx/src/main/java/org/jboss/jbossts/rts/util/TxUtil.java 2009-04-28 13:10:33 UTC (rev 26291)
+++ labs/jbosstm/workspace/resttx/src/main/java/org/jboss/jbossts/rts/util/TxUtil.java 2009-04-28 19:01:45 UTC (rev 26292)
@@ -20,10 +20,7 @@
*/
package org.jboss.jbossts.rts.util;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.commons.httpclient.methods.PostMethod;
-import org.apache.commons.httpclient.methods.PutMethod;
-import org.apache.commons.httpclient.methods.DeleteMethod;
+import org.apache.commons.httpclient.methods.*;
import org.apache.commons.httpclient.*;
import org.apache.log4j.Logger;
import org.jboss.jbossts.rts.provider.HttpResponseException;
@@ -33,6 +30,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
@@ -209,9 +207,23 @@
return header != null ? header.getValue() : res;
}
- public static String doPut(int[] expect, String url, String... nvParams) throws HttpResponseException
+ public static String doPut(int[] expect, String url, String request, String... nvParams) throws HttpResponseException
{
- return doMethod(expect, new PutMethod(url), nvParams);
+ PutMethod pm = new PutMethod(url);
+
+ if (request != null) {
+ try
+ {
+ pm.setRequestEntity(new StringRequestEntity(request, "text/html", null));
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ log.debug("put request entity create error");
+ e.printStackTrace();
+ }
+ }
+
+ return doMethod(expect, pm, nvParams);
}
public static String doDelete(int[] expect, String url, String... nvParams) throws HttpResponseException
Modified: labs/jbosstm/workspace/resttx/src/test/java/org/jboss/jbossts/rts/test/AppTest.java
===================================================================
--- labs/jbosstm/workspace/resttx/src/test/java/org/jboss/jbossts/rts/test/AppTest.java 2009-04-28 13:10:33 UTC (rev 26291)
+++ labs/jbosstm/workspace/resttx/src/test/java/org/jboss/jbossts/rts/test/AppTest.java 2009-04-28 19:01:45 UTC (rev 26292)
@@ -108,7 +108,7 @@
private void terminateTx(String tx, String how, boolean fail, String ... args)
{
try {
- TxUtil.doPut(new int[] {HttpResponseCodes.SC_OK}, tx + "/" + how, args);
+ TxUtil.doPut(new int[] {HttpResponseCodes.SC_OK}, tx + "/" + how, "", args);
if (fail)
assertTrue("commit should not have succeeded", false);
} catch (HttpResponseException e) {
@@ -165,7 +165,7 @@
String v4 = modifyResource(tx, "pid2", "p1", "txv1");
rollbackTx(tx, false);
- rollbackTx(tx, true); // should be able to rollback a completed transaction
+ rollbackTx(tx, true); // should not be able to rollback a completed transaction
// make sure the changes were rolled back
String v5 = getResource(null, "pid1", "p1");
@@ -184,7 +184,7 @@
String pUrl = TxUtil.getBaseURI() + "particpant/123"; // participant url
// Registering a participant with the transaction returns a recovery url
- String recCoordId = TxUtil.doPut(new int[] {HttpResponseCodes.SC_OK}, tx, "URL=" + pUrl);
+ String recCoordId = TxUtil.doPut(new int[] {HttpResponseCodes.SC_OK}, tx, pUrl, "URL=" + pUrl);
// doing a GET on recCoordId should return the original url
String origUrl = TxUtil.doGet(new int[] {HttpResponseCodes.SC_OK}, recCoordId);
@@ -194,7 +194,7 @@
// participants to tell the recovery coordinator that they have moved
pUrl = TxUtil.getBaseURI() + "particpant/123"; // the new participant URL
// replace the url with a new one
- TxUtil.doPut(new int[] {HttpResponseCodes.SC_OK}, recCoordId, "URL=" + pUrl);
+ TxUtil.doPut(new int[] {HttpResponseCodes.SC_OK}, recCoordId, pUrl, "URL=" + pUrl);
// check that the url was replaced by doing another GET on the recovery URL
origUrl = TxUtil.doGet(new int[] {HttpResponseCodes.SC_OK}, recCoordId);
More information about the jboss-svn-commits
mailing list