[jboss-svn-commits] JBL Code SVN: r37368 - in labs/jbosstm/trunk/rest-tx/quickstarts: demo and 10 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Aug 8 10:26:22 EDT 2011


Author: mmusgrov
Date: 2011-08-08 10:26:21 -0400 (Mon, 08 Aug 2011)
New Revision: 37368

Added:
   labs/jbosstm/trunk/rest-tx/quickstarts/demo/
   labs/jbosstm/trunk/rest-tx/quickstarts/demo/client.rb
   labs/jbosstm/trunk/rest-tx/quickstarts/demo/demo.txt
   labs/jbosstm/trunk/rest-tx/quickstarts/demo/pom.xml
   labs/jbosstm/trunk/rest-tx/quickstarts/demo/readme.txt
   labs/jbosstm/trunk/rest-tx/quickstarts/demo/run.bat
   labs/jbosstm/trunk/rest-tx/quickstarts/demo/run.sh
   labs/jbosstm/trunk/rest-tx/quickstarts/demo/src/
   labs/jbosstm/trunk/rest-tx/quickstarts/demo/src/main/
   labs/jbosstm/trunk/rest-tx/quickstarts/demo/src/main/java/
   labs/jbosstm/trunk/rest-tx/quickstarts/demo/src/main/java/quickstart/
   labs/jbosstm/trunk/rest-tx/quickstarts/demo/src/main/java/quickstart/JaxrsServer.java
   labs/jbosstm/trunk/rest-tx/quickstarts/demo/src/main/java/quickstart/TransactionAwareResource.java
   labs/jbosstm/trunk/rest-tx/quickstarts/demo/src/main/java/quickstart/Work.java
   labs/jbosstm/trunk/rest-tx/quickstarts/demo/test.sh
   labs/jbosstm/trunk/rest-tx/quickstarts/demo/uiwar/
   labs/jbosstm/trunk/rest-tx/quickstarts/demo/uiwar/WEB-INF/
   labs/jbosstm/trunk/rest-tx/quickstarts/demo/uiwar/WEB-INF/web.xml
   labs/jbosstm/trunk/rest-tx/quickstarts/demo/uiwar/pom.xml
   labs/jbosstm/trunk/rest-tx/quickstarts/demo/uiwar/src/
   labs/jbosstm/trunk/rest-tx/quickstarts/demo/uiwar/src/main/
   labs/jbosstm/trunk/rest-tx/quickstarts/demo/uiwar/src/main/resources/
   labs/jbosstm/trunk/rest-tx/quickstarts/demo/uiwar/src/main/webapp/
   labs/jbosstm/trunk/rest-tx/quickstarts/demo/uiwar/src/main/webapp/WEB-INF/
   labs/jbosstm/trunk/rest-tx/quickstarts/demo/uiwar/src/main/webapp/WEB-INF/web.xml
   labs/jbosstm/trunk/rest-tx/quickstarts/demo/uiwar/src/main/webapp/index.html
Log:
[JBTM-856] Recovery Demonstration Quickstart

Added: labs/jbosstm/trunk/rest-tx/quickstarts/demo/client.rb
===================================================================
--- labs/jbosstm/trunk/rest-tx/quickstarts/demo/client.rb	                        (rev 0)
+++ labs/jbosstm/trunk/rest-tx/quickstarts/demo/client.rb	2011-08-08 14:26:21 UTC (rev 37368)
@@ -0,0 +1,95 @@
+require "net/http"
+require "uri"
+require 'optparse'
+
+def doRequest(http, requri, method, body)
+	request = nil
+
+	if method == "Head"
+		request = Net::HTTP::Head.new(requri)
+	elsif method == "Post"
+		request = Net::HTTP::Post.new(requri)
+		request["Content-Type"] = "application/x-www-form-urlencoded"
+	elsif method == "Put"
+		request = Net::HTTP::Put.new(requri)
+		request["Content-Type"] = "application/txstatus"
+	else
+		request = Net::HTTP::Get.new(requri)
+		request["Content-Type"] = "text/plain"
+	end
+
+	request["Content-Length"] = body.length 
+	request.body = body
+	response = http.request(request)
+
+	return response
+end
+
+def newRequest(url, method = 'Get', body = '', useproxy = 0)
+	uri = URI.parse(url)
+
+	if useproxy != "0"
+#		print "using proxies\n"
+		proxy = Net::HTTP::Proxy('file.rdu.redhat.com', 3128)
+		proxy.start(uri.host, uri.port)  do |http|
+			doRequest(http, uri.request_uri, method, body)
+		end
+	else
+#		print "no proxies\n"
+		http = Net::HTTP.new(uri.host, uri.port)
+		doRequest(http, uri.request_uri, method, body)
+	end
+end
+
+def parseLinkHeaders(response)
+	enlistUrl = endUrl = location = nil
+	location = response["Location"]
+	links = response["link"]
+	if (links != nil) then
+		links = links.delete " \"<>"
+		links.each_line(',') {
+  			|link|
+    		enlistUrl = link.split(';') [0] if link.include? "rel=durableparticipant"
+			endUrl = link.split(';') [0] if link.include? "rel=terminator"
+		}
+	end
+
+	if (location != nil) then
+		y=location[location.rindex('/') + 1 .. location.length]
+		File.open('tx', 'w') {|f| f.write(y) }
+	end
+
+	return enlistUrl, endUrl, location
+end
+
+OPTIONS = {
+  :verb  => 'Get',
+  :body  => '',
+  :proxy  => "0",
+}
+
+OptionParser.new do |o|
+	o.on('-a url') { |OPTIONS[:url]| }
+	o.on('-b body') { |OPTIONS[:body]| }
+	o.on('-p <true|false>') { |OPTIONS[:proxy]| }
+	o.on('-v method') { |OPTIONS[:verb]| }
+	o.on('-t <txn url>') { |OPTIONS[:txn]| }
+	o.on('-h') { puts o; exit }
+	o.parse!
+end
+
+url = OPTIONS[:url]
+verb = OPTIONS[:verb]
+body = OPTIONS[:body]
+txn = OPTIONS[:txn]
+proxy = OPTIONS[:proxy]
+
+response = newRequest(url, verb, body, proxy)
+if response.code != "200" && response.code != "201"
+	print "request error: ", response.code, " url=", url, " verb=", verb, "\n"
+else
+	print response.body, "\n"
+	enlistUrl, endUrl, location = parseLinkHeaders(response)
+	print "\nenlistUrl: ", enlistUrl, "\nendUrl: ", endUrl, "\n" if enlistUrl != nil
+	print "\nlocation: ", location, "\n" if location != nil
+end

Added: labs/jbosstm/trunk/rest-tx/quickstarts/demo/demo.txt
===================================================================
--- labs/jbosstm/trunk/rest-tx/quickstarts/demo/demo.txt	                        (rev 0)
+++ labs/jbosstm/trunk/rest-tx/quickstarts/demo/demo.txt	2011-08-08 14:26:21 UTC (rev 37368)
@@ -0,0 +1,144 @@
+PART 1 Local Version
+
+1. start a transaction manager (on port 9090)
+
+	cd /home/mmusgrov/source/as/jboss-7.0.0.CR1
+	bin/standalone.sh -DRecoveryEnvironmentBean.periodicRecoveryPeriod=10
+
+2. deploy REST-AT war
+
+	cd /home/mmusgrov/source/jbosstm/trunk/rest-tx
+	cp webservice/target/rest-tx-web-5.0.0.M1-SNAPSHOT.war /home/mmusgrov/source/as/jboss-7.0.0.CR1/standalone/deployments
+
+3. deploy a simple javascript for monitoring REST-AT
+
+	cd quickstarts/demo
+	cp uiwar/target/uiwar-0.0.1-SNAPSHOT.war /home/mmusgrov/source/as/jboss-7.0.0.CR1/standalone/deployments
+
+	vi uiwar/src/main/webapp/index.html 
+
+4. test that these two services are installed. In a browser type:
+
+	http://127.0.0.1:9090/uiwar-0.0.1-SNAPSHOT/
+	and start a transaction
+
+5. start a web service (in another console window). Delete work.ser to clear out old work.
+
+	mvn compile exec:java -Dexec.mainClass=quickstart.TransactionAwareResource -Dexec.args="-a 127.0.0.1:8080" -Dhttp.proxyHost="file.rdu.redhat.com" -Dhttp.proxyPort=3128
+
+6. Check that the web service is running. In a browser type:
+
+	http://localhost:8080/service/query
+
+Explain what the web service is doing (use Intelij)
+
+7. In another browser tab show how to increment a counter:
+
+	http://localhost:8080/service?counter=0
+	http://localhost:8080/service?counter=1
+
+	and show both counters were incremented:
+
+	http://localhost:8080/service/query
+
+8. Now transactionally increment both counters failing the second request:
+
+	http://localhost:8080/service?counter=0&enlistURL=xxx
+	http://localhost:8080/service?counter=1&enlistURL=xxx
+
+9. Tell the service to halt the VM before committing the second work load:
+
+	http://localhost:8080/service?failWid=7
+
+10. Commit the transaction
+
+11. Pause the transaction recovey service ctrl Z in the AS7 console
+
+12. Restart the service
+	- point out that counter 0 has incremented but counter 1 has not;
+	- unpause AS, the recovery service will instruct the web service that it has an unfinished
+	  transaction branch to complete;
+	- reissue the query to get the counter values and point out that the 2nd counter has now
+	   been incremented:
+		http://localhost:9090/service/query
+
+Leave the service running for part 2 of the demo (note it runs for 1000 seconds and then exits
+so it may need restarting, or change main so that it runs forever ).
+
+PART 2 Deploy to Openshift
+==========================
+
+BEFORE STARTING change demo4 to rhcdemo
+
+Instead of starting a local application server and deploying various wars to it a similar result is achieved
+by using the RHC express tools to create a domain and application. The application war will then be
+deployed to a local git repo which will then be pushed to the cloud:
+
+	# skip create-domain
+	in the local as terminal ctrl C
+	cd ~/apps
+	rhc-create-domain -n mm2 -l mmusgrov+3 at redhat.com
+	rhc-create-app -a rhcdemo -t jbossas-7.0
+
+pulishes the app at http://rhcdemo-mm2.dev.rhcloud.com/
+
+	cd rhcdemo
+
+	cp /home/mmusgrov/source/as/jboss-7.0.0.CR1/standalone/deployments/rest-tx-web-5.0.0.M1-SNAPSHOT.war deployments/
+
+	git add deployments
+	git commit -m "rest war"
+	git push
+
+Now the application will be available at:
+
+TYPE into browser:
+	http://rhcdemo-mm2.dev.rhcloud.com
+	http://rhcdemo-mm2.dev.rhcloud.com/rest-tx/tx/transaction-manager
+
+Instead of using a browser/javascript to start and stop transactions we will employ a Ruby client:
+
+4. test that the REST-AT service is installed in openshift. Use a Ruby client to list transactions
+and then start a txn:
+
+cd /home/mmusgrov/source/jbosstm/trunk/rest-tx/quickstarts/demo
+# LIST TRANSACTIONS
+ruby client.rb -p 1 -v Get -a "http://rhcdemo-mm2.dev.rhcloud.com/rest-tx/tx/transaction-manager"
+# START TRANSACTION
+ruby client.rb -p 1 -v Post -a "http://rhcdemo-mm2.dev.rhcloud.com/rest-tx/tx/transaction-manager" -b "timeout=0"
+# COMMIT TRANSACTION
+ruby client.rb -p 1 -v Put -a "" -b "txStatus=TransactionCommitted"
+# LIST TRANSACTIONS
+ruby client.rb -p 1 -v Get -a "http://rhcdemo-mm2.dev.rhcloud.com/rest-tx/tx/transaction-manager"
+
+Repeat steps 7 to 10:
+ 7. (increment both counters),
+	http://localhost:8080/service?counter=0
+	http://localhost:8080/service?counter=1
+
+and show both counters were incremented:
+
+	http://localhost:8080/service/query
+
+ 8. Now transactionally increment both counters failing the second request:
+	# START TRANSACTION via the COMMAND LINE
+	ruby client.rb -p 1 -v Post -a "http://rhcdemo-mm2.dev.rhcloud.com/rest-tx/tx/transaction-manager" -b "timeout=0"
+
+	# enlist 2 participants via the BROWSER
+	# have to use the externally facing web address
+	http://gondolin.ncl.ac.uk:9188/service?counter=0&enlistURL=
+	http://gondolin.ncl.ac.uk:9188/service?counter=1&enlistURL=
+
+ 9. Tell tell the service to halt the VM before committing the second work load:
+
+	http://localhost:8080/service?failWid=9
+
+ 10. Commit the transaction
+
+	ruby client.rb -p 1 -v Put -a "" -b "txStatus=TransactionCommitted"
+
+ 11. Restart the service (it will have halted during commit of the 2nd work load) and quickly show tha
+	http://localhost:8080/service/query
+	shows counter 1 hasn't incremented yet.
+
+	wait for recovery to kick in and reissue the counter query

Added: labs/jbosstm/trunk/rest-tx/quickstarts/demo/pom.xml
===================================================================
--- labs/jbosstm/trunk/rest-tx/quickstarts/demo/pom.xml	                        (rev 0)
+++ labs/jbosstm/trunk/rest-tx/quickstarts/demo/pom.xml	2011-08-08 14:26:21 UTC (rev 37368)
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>quickstarts</artifactId>
+        <groupId>org.jboss.narayana.rts.quickstarts</groupId>
+        <version>5.0.0.M1-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>demo</artifactId>
+    <name>RESTful Atomic Transaction Quickstart: Demonstration of Participant Service with Recovery</name>
+    <description>Example of how a web service can recover from failures during transaction completion</description>
+
+    <repositories>
+        <!-- Jersey -->
+        <repository>
+            <id>maven2-repository.dev.java.net</id>
+            <name>Java.net Repository for Maven</name>
+            <url>http://download.java.net/maven/2/</url>
+            <layout>default</layout>
+        </repository>
+        <!-- end Jersey -->
+    </repositories>
+
+    <dependencies>
+
+        <!-- the implementation of REST Atomic Transactions -->
+        <dependency>
+            <groupId>org.jboss.narayana.rts</groupId>
+            <artifactId>rest-tx-api</artifactId>
+            <version>5.0.0.M1-SNAPSHOT</version>
+        </dependency>
+
+        <!-- Jersey container for running participant services -->
+        <dependency>
+            <groupId>com.sun.jersey</groupId>
+            <artifactId>jersey-server</artifactId>
+            <version>1.5-SNAPSHOT</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.sun.jersey</groupId>
+            <artifactId>jersey-client</artifactId>
+            <version>1.5-SNAPSHOT</version>
+        </dependency>
+
+
+        <dependency>
+            <groupId>com.sun.grizzly</groupId>
+            <artifactId>grizzly-servlet-webserver</artifactId>
+            <version>1.9.18-i</version>
+        </dependency>
+        <!-- end Jersey -->
+    </dependencies>
+
+</project>

Added: labs/jbosstm/trunk/rest-tx/quickstarts/demo/readme.txt
===================================================================
--- labs/jbosstm/trunk/rest-tx/quickstarts/demo/readme.txt	                        (rev 0)
+++ labs/jbosstm/trunk/rest-tx/quickstarts/demo/readme.txt	2011-08-08 14:26:21 UTC (rev 37368)
@@ -0,0 +1,72 @@
+OVERVIEW
+--------
+An example of how to start and end a transaction using REST style semantics and how services
+can recover from failures during the commitment protocol.
+
+The demo requires ruby.
+
+
+USAGE
+-----
+
+If you wish to run the demo interactively then use the notes in demo.txt. Ignore Part 2 of demo.txt
+unless you wish to migrate part of the demo to the OpenShift Express infrastructure.
+
+Alternatively:
+
+Install ruby (for example on centos type yum install ruby).
+
+Deploy the rest-tx war to an AS7 application server listening for http requests on
+localhost:8080 (if you use a different host/port change the relevant url in test.sh).
+
+Eg deploying to AS7:
+cp ../../webservice/target/rest-tx-web-<version>.war <AS7>/standalone/deployments/) into a running AS7
+
+and then execute the run script:
+
+./run.sh
+
+EXPECTED OUTPUT
+---------------
+The test generates a lot of output. The highligths are:
+
+Running recovery demo
+... lots of maven output
+JAX-RS container waiting for requests on 127.0.0.1:8081 (for 1000 seconds) ...
+... more output
+Service: PUT request to terminate url: wId=xx, status:=txStatus=TransactionCommitted
+Service: Halting VM during commit of work unit wId=xx
+Recovering failed service - this could take up to 2 minutes
+... more maven output
+Service: PUT request to terminate url: wId=xx, status:=txStatus=TransactionCommitted
+SUCCESS: Transaction was recovered
+
+
+WHAT JUST HAPPENED?
+-------------------
+
+1. run.sh starts an embedded JAX-RS web service using the mvn compile exec:java maven target.
+The web service listens for requests on localhost port 8081.
+
+2. A ruby client starts a transaction (using the REST-AT interface to JBoss Transactions). 
+
+3. The same client interacts with the web service (passing the 'transaction url')
+The web service enlists itself into the transaction so that it will be notified by the
+transaction coordinator (runing in the standalone JBoss AS container) when the transaction commits.
+
+4. Step 3 is repeated but on a different web service. This ensures that there are two
+services enlisted into the transaction (and therefore the transaction cooordinator will send
+both prepare and commit requests to each service).
+
+5. The client arranges things such that the second service will halt its JBM when asked to commit.
+(for details please refer to the script test.sh and the command:
+  ruby client.rb -p $proxies -v Get -a "$service?failWid=${wid2}"
+  this request is handled by the JAX-RS service quickstart.TransactionAwareResource in the method
+  incrementCounters)
+
+6. The client commits the transaction.
+
+7. The second web service halts its JVM when it receives the commit request.
+
+8. The controlling script run.sh restarts the web service and waits for the transaction
+coordinator to recover the transaction.

Added: labs/jbosstm/trunk/rest-tx/quickstarts/demo/run.bat
===================================================================
--- labs/jbosstm/trunk/rest-tx/quickstarts/demo/run.bat	                        (rev 0)
+++ labs/jbosstm/trunk/rest-tx/quickstarts/demo/run.bat	2011-08-08 14:26:21 UTC (rev 37368)
@@ -0,0 +1,4 @@
+ at echo off
+
+echo "Skipping recovery demo"
+


Property changes on: labs/jbosstm/trunk/rest-tx/quickstarts/demo/run.bat
___________________________________________________________________
Added: svn:executable
   + *

Added: labs/jbosstm/trunk/rest-tx/quickstarts/demo/run.sh
===================================================================
--- labs/jbosstm/trunk/rest-tx/quickstarts/demo/run.sh	                        (rev 0)
+++ labs/jbosstm/trunk/rest-tx/quickstarts/demo/run.sh	2011-08-08 14:26:21 UTC (rev 37368)
@@ -0,0 +1,44 @@
+# ALLOW JOBS TO BE BACKGROUNDED
+set -m
+
+x=`ruby -v`
+if [ $? != 0 ]; then
+	echo "Skipping recovery demo because it requires ruby to be installed"
+	exit 0
+else
+	echo "Running recovery demo"
+fi
+
+mvn compile exec:java -Dexec.mainClass=quickstart.TransactionAwareResource -Dexec.args="-a 127.0.0.1:8081" &
+
+sleep 5
+
+./test.sh demo
+
+echo "Recovering failed service - this could take up to 2 minutes"
+rm -f out.txt
+mvn compile exec:java -Dexec.mainClass=quickstart.TransactionAwareResource -Dexec.args="-a 127.0.0.1:8081" > out.txt &
+pid=$!
+
+# wait for message indicating that the transaction was recovered (should happen within 2 minutes)
+count=0
+res=0
+while true; do
+    grep "txStatus=TransactionCommitted" out.txt 
+    if [ $? == 0 ]; then
+        echo "SUCCESS: Transaction was recovered"
+        res=0
+		break
+    fi
+
+    sleep 6
+    count=`expr $count + 1`
+
+    if [ $count == 20 ]; then
+        echo "FAILURE: Transaction was not recovered"
+        break
+    fi
+done
+
+kill $pid
+exit $res


Property changes on: labs/jbosstm/trunk/rest-tx/quickstarts/demo/run.sh
___________________________________________________________________
Added: svn:executable
   + *

Added: labs/jbosstm/trunk/rest-tx/quickstarts/demo/src/main/java/quickstart/JaxrsServer.java
===================================================================
--- labs/jbosstm/trunk/rest-tx/quickstarts/demo/src/main/java/quickstart/JaxrsServer.java	                        (rev 0)
+++ labs/jbosstm/trunk/rest-tx/quickstarts/demo/src/main/java/quickstart/JaxrsServer.java	2011-08-08 14:26:21 UTC (rev 37368)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, Red Hat, Inc. and/or its affiliates,
+ * and individual contributors as indicated by the @author tags.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ *
+ * (C) 2011,
+ * @author JBoss, by Red Hat.
+ */
+package quickstart;
+
+import com.sun.grizzly.http.SelectorThread;
+import com.sun.jersey.api.container.grizzly.GrizzlyWebContainerFactory;
+
+import javax.ws.rs.core.UriBuilder;
+import java.io.IOException;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Start a simple embedded web server for hosting web services that will participate in
+ * REST Atomic transactions.
+ *
+ * We use Grizzly since it is the reference implementation and it supports JAX-RS.
+ * Using JAX-RS make our web service example is trivial to implement.
+ */
+public class JaxrsServer {
+   private static SelectorThread threadSelector = null;
+
+/*   public static void startTJWS(String host, int port) {
+        org.jboss.resteasy.plugins.server.tjws.TJWSEmbeddedJaxrsServer server;
+        server = new org.jboss.resteasy.plugins.server.tjws.TJWSEmbeddedJaxrsServer();
+        server.setPort(port);
+        server.start();
+
+        org.jboss.resteasy.spi.Registry registry = server.getDeployment().getRegistry();
+
+        registry.addPerRequestResource(TransactionAwareResource.class);
+    }*/
+
+    public static void startGrizzly(String host, int port) {
+        final URI baseUri= UriBuilder.fromUri("http://" + host + ':' + port + '/').build();
+        final Map<String, String> initParams = new HashMap<String, String>();
+        String packages = TransactionAwareResource.class.getPackage().getName();
+
+        initParams.put("com.sun.jersey.config.property.packages", packages);
+
+        try {
+            threadSelector = GrizzlyWebContainerFactory.create(baseUri, initParams);
+        } catch (IOException e) {
+            throw new RuntimeException("Error starting JAX-RS container: " + e.getMessage(), e);
+        }
+    }
+
+    public static void startServer(String host, int port) {
+         startGrizzly(host, port);
+    }
+
+    public static void stopServer() {
+        if (threadSelector != null)
+            threadSelector.stopEndpoint();
+
+        threadSelector = null;
+    }
+}

Added: labs/jbosstm/trunk/rest-tx/quickstarts/demo/src/main/java/quickstart/TransactionAwareResource.java
===================================================================
--- labs/jbosstm/trunk/rest-tx/quickstarts/demo/src/main/java/quickstart/TransactionAwareResource.java	                        (rev 0)
+++ labs/jbosstm/trunk/rest-tx/quickstarts/demo/src/main/java/quickstart/TransactionAwareResource.java	2011-08-08 14:26:21 UTC (rev 37368)
@@ -0,0 +1,235 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, Red Hat, Inc. and/or its affiliates,
+ * and individual contributors as indicated by the @author tags.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ *
+ * (C) 2011,
+ * @author JBoss, by Red Hat.
+ */
+package quickstart;
+
+import org.jboss.jbossts.star.provider.HttpResponseException;
+import org.jboss.jbossts.star.util.TxSupport;
+
+import java.io.*;
+
+import javax.ws.rs.*;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import java.net.HttpURLConnection;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * An example of how a REST resource can act as a participant in a REST Atomic transaction.
+ * For a complete implementation of a participant please refer to the test suite, in particular
+ * the inner class: org.jboss.jbossts.star.test.BaseTest$TransactionalResource which implements
+ * all the responsibilities of a participant
+ *
+ * The example sends a service request which is handled by the method incrementCounters.
+ * The request includes the URL for registering durable participants within the transaction.
+ * This naive implementation assumes every request with a valid enlistment URL is a request
+ * a new unit of transactional work and enlists a new URL into the transaction.
+ * Thus if a client makes two http requests to the method incrementCounters then the participant
+ * is enlisted twice into the transaction but with different completion URLs. This facilitates
+ * the demonstration of 2 phase commit processing.
+ */
+ at Path(TransactionAwareResource.PSEGMENT)
+public class TransactionAwareResource {
+    public static final String PSEGMENT = "service";
+    public static String FAIL_COMMIT;
+    private static AtomicInteger workId = new AtomicInteger(1);
+    private static AtomicInteger[] counters = {new AtomicInteger(0), new AtomicInteger(0)};
+
+    private static Work getWork(String enlistUrl, int index) {
+        for (Work w : Work.work.values())
+            if (w.index == index && w.enlistUrl.equals(enlistUrl))
+                return w;
+
+        return null;
+    }
+
+    @GET
+    public Response incrementCounters(@Context UriInfo info,
+                                      @QueryParam("enlistURL") @DefaultValue("")String enlistUrl,
+                                      @QueryParam("counter") @DefaultValue("0") int index,
+                                      @QueryParam("failWid") @DefaultValue("")String failWid) {
+        System.out.println("Service:incrementCounters request, enlistUrl=" + enlistUrl);
+        Response response = null;
+
+        if (failWid.length() != 0) {
+            FAIL_COMMIT = failWid;
+            return Response.ok("will fail wid " + failWid).build();
+        }
+
+        if (index != 0 && index != 1)
+            return Response.status(400).entity("Counter not supported").build();
+
+        Work w = getWork(enlistUrl, index);
+        if (w != null) {
+            response = Response.ok("" + ++w.counter).build();
+        } else if (enlistUrl.length() == 0) {
+            response = Response.ok("non transactional request. Value=" +
+				counters[index].incrementAndGet()).build();
+        } else {
+            int wid = workId.incrementAndGet();
+            String serviceURL = info.getBaseUri() + info.getPath();
+            String workURL = serviceURL + '/' + workId;
+
+            String terminator = workURL + "/terminate";
+            String participant = workURL + "/terminator";
+
+            String pUrls = TxSupport.getParticipantUrls(terminator, participant);
+            System.out.println("Service: Enlisting " + pUrls + "\non endpoint: " + enlistUrl);
+            System.out.println("proxies: " +  System.getProperty("http.proxyHost") +
+				':' + System.getProperty("http.proxyPort"));
+
+            try {
+                new TxSupport().httpRequest(new int[]{HttpURLConnection.HTTP_CREATED}, enlistUrl,
+                        "POST", TxSupport.POST_MEDIA_TYPE, pUrls, null);
+            } catch (HttpResponseException e) {
+                System.out.println("Enlist error: " + e);
+                if (e.getActualResponse() == 404)
+                    return Response.status(e.getActualResponse()).entity("No such url").build();
+                else
+                    return Response.status(e.getActualResponse()).
+						entity("Transaction Manager service is unavailable").build();
+            }
+
+            w = new Work(enlistUrl, wid, index, counters[index].get() + 1);
+            Work.work.put(Integer.toString(wid), w);
+
+            serializeWork();
+
+            response = Response.ok(Integer.toString(wid)).build();
+        }
+
+        serializeWork();
+
+        return response;
+    }
+
+    @GET
+    @Path("query")
+    public Response readCounters(@QueryParam("wId") @DefaultValue("0") String wid) {
+        Work w = Work.work.get(wid);
+
+        if (w == null)
+            return Response.ok("counter[0]=" + counters[0].get() + "<br/>counter[1]=" +
+				counters[1].get()).build();
+        else
+            return Response.ok("counter[" + w.index + "]=" + w.counter).build();
+    }
+
+    /*
+     * this method handles PUT requests to the url that the participant gave to the
+     * REST Atomic Transactions implementation (in the someServiceRequest method).
+     * This is the endpoint that the transaction manager interacts with when it needs
+     * participants to prepare/commit/rollback their transactional work.
+     */
+    @PUT
+    @Path("{wId}/terminate")
+    public Response terminate(@PathParam("wId") @DefaultValue("")String wId, String content) {
+        System.out.println("Service: PUT request to terminate url: wId=" + wId + ", status:=" + content);
+        String status = TxSupport.getStatus(content);
+        Work w = Work.work.get(wId);
+
+        if (TxSupport.isPrepare(status)) {
+            return Response.ok(TxSupport.toStatusContent(TxSupport.PREPARED)).build();
+        } else if (TxSupport.isCommit(status)) {
+            if (!serializeWork()) {
+                Work.work.remove(wId);
+                return Response.ok(TxSupport.toStatusContent(TxSupport.ABORTED)).build();
+            }
+
+            if (wId.equals(FAIL_COMMIT)) {
+                System.out.println("Service: Halting VM during commit of work unit wId=" + wId);
+                Runtime.getRuntime().halt(1);
+            }
+
+            counters[w.index].set(w.counter);
+            Work.work.remove(wId);
+            return Response.ok(TxSupport.toStatusContent(TxSupport.COMMITTED)).build();
+        } else if (TxSupport.isAbort(status)) {
+            Work.work.remove(wId);
+            serializeWork();
+            return Response.ok(TxSupport.toStatusContent(TxSupport.ABORTED)).build();
+        } else {
+            return Response.status(HttpURLConnection.HTTP_BAD_REQUEST).build();
+        }
+    }
+
+    static boolean serializeWork() {
+        try {
+            FileOutputStream fos = new FileOutputStream("work.ser");
+            ObjectOutputStream oos = new ObjectOutputStream(fos);
+            oos.writeObject(Work.work);
+            oos.writeObject(workId);
+            oos.writeObject(counters);
+            oos.close();
+            return true;
+        } catch (IOException e) {
+            return false;
+        }
+
+    }
+
+    static boolean deserializeWork() {
+        FileInputStream fis = null;
+        try {
+            fis = new FileInputStream("work.ser");
+            ObjectInputStream ois = null;
+            ois = new ObjectInputStream(fis);
+
+            Work.work = (Map<String, Work>) ois.readObject();
+            workId = (AtomicInteger) ois.readObject();
+            counters = (AtomicInteger[]) ois.readObject();
+            ois.close();
+            return true;
+        } catch (Exception e) {
+            return false;
+        }
+    }
+
+    public static void main(String[] args) throws InterruptedException {
+        int PORT = 8081;
+        String HOST = "localhost";
+
+        System.out.println("ARGS " + args.length);
+        for (int i = 0; i + 1 < args.length; i++)
+            if ("-h".equals(args[i])) {
+                HOST = args[++i];
+            } else if ("-p".equals(args[i])) {
+                PORT = Integer.valueOf(args[++i]);
+            } else if ("-a".equals(args[i])) {
+                String[] addr = args[++i].split(":");
+                HOST = addr[0];
+                PORT = Integer.valueOf(addr[1]);
+            }
+
+        deserializeWork();
+
+        // start an embedded JAX-RS server
+        JaxrsServer.startServer(HOST, PORT);
+
+        System.out.println("JAX-RS container waiting for requests on " + HOST + ":" +
+			PORT + " (for 1000 seconds) ...");
+        Thread.sleep(1000000);
+
+        // shutdown the embedded JAX-RS server
+        JaxrsServer.stopServer();
+    }
+}

Added: labs/jbosstm/trunk/rest-tx/quickstarts/demo/src/main/java/quickstart/Work.java
===================================================================
--- labs/jbosstm/trunk/rest-tx/quickstarts/demo/src/main/java/quickstart/Work.java	                        (rev 0)
+++ labs/jbosstm/trunk/rest-tx/quickstarts/demo/src/main/java/quickstart/Work.java	2011-08-08 14:26:21 UTC (rev 37368)
@@ -0,0 +1,21 @@
+package quickstart;
+
+import java.io.*;
+import java.util.HashMap;
+import java.util.Map;
+
+class Work implements java.io.Serializable {
+    static Map<String, Work> work = new HashMap<String, Work>();
+
+    String enlistUrl;
+    int wid;
+    int index;
+    int counter;
+
+    public Work(String enlistUrl, int wid, int index, int counter) {
+        this.enlistUrl = enlistUrl;
+        this.wid = wid;
+        this.index = index;
+        this.counter = counter;
+    }
+}

Added: labs/jbosstm/trunk/rest-tx/quickstarts/demo/test.sh
===================================================================
--- labs/jbosstm/trunk/rest-tx/quickstarts/demo/test.sh	                        (rev 0)
+++ labs/jbosstm/trunk/rest-tx/quickstarts/demo/test.sh	2011-08-08 14:26:21 UTC (rev 37368)
@@ -0,0 +1,77 @@
+#!/bin/sh
+
+# start txm
+# bin/standalone.sh
+# start participant
+# mvn compile exec:java -Dexec.mainClass=quickstart.TransactionAwareResource -Dexec.arg"-a 172.17.130.188:8081"
+#./test start
+#./test service 0_ffff7f000001_1831c3b0_4e2ed0f3_141
+#./test commit 0_ffff7f000001_1831c3b0_4e2ed0f3_141
+
+
+function fatal {
+	echo "syntax: start | abort txid | commit txid | status txid | service txid | fail wid"
+	exit 1
+}
+
+aws=0
+
+if [ $aws != 0 ]; then
+	ep="gondolin.ncl.ac.uk:9188"
+	auth="demo4-mm2.dev.rhcloud.com"
+	proxies=1
+
+#mvn compile exec:java -Dexec.mainClass=quickstart.TransactionAwareResource -Dexec.args="-a 127.0.0.1:8080" -Dhttp.proxyHost="file.rdu.redhat.com" -Dhttp.proxyPort=3128
+else
+#cd /home/mmusgrov/source/as/jboss-7.0.0.CR1
+#bin/standalone.sh -DRecoveryEnvironmentBean.periodicRecoveryPeriod=10 &
+#mvn compile exec:java -Dexec.mainClass=quickstart.TransactionAwareResource -Dexec.args="-a 127.0.0.1:8081"
+	ep="172.17.130.188:8081"
+	ep="127.0.0.1:8081"
+	auth="127.0.0.1:8080"
+	proxies=0
+fi
+
+service="http://$ep/service"
+tm="http://${auth}/rest-tx/tx/transaction-manager"
+
+if [ $# == 0 ]; then
+	ruby client.rb -p $proxies -a "${tm}"
+	exit 0
+fi
+
+case "$1" in
+"status")
+	[[ $# == 1 ]] && fatal
+	ruby client.rb -p $proxies -v Get -a "${tm}/${2}";;
+"start")
+	ruby client.rb -p $proxies -v Post -a "$tm" -b "timeout=0";;
+"commit")
+	[[ $# == 1 ]] && fatal
+	ruby client.rb -p $proxies -v Put -a "${tm}/${2}/terminate" -b "txStatus=TransactionCommitted";;
+"abort")
+	[[ $# == 1 ]] && fatal
+	ruby client.rb -p $proxies -v Put -a "${tm}/${2}/terminate" -b "txStatus=TransactionRolledBack";;
+"service")
+	if [ $# == 1 ]; then
+		ruby client.rb -p $proxies -v Get -a "$service/query"
+	else
+		ruby client.rb -p $proxies -v Get -a "$service?counter=0&enlistURL=${tm}/${2}"
+	fi;;
+"fail")
+	[[ $# == 1 ]] && fatal
+	ruby client.rb -p $proxies -v Get -a "$service?failWid=$2";;
+"demo")
+	ruby client.rb -p $proxies -v Post -a "$tm" -b "timeout=0"
+	txn=`cat tx`
+	echo "service url for counter 0: $service?counter=0&enlistURL=${tm}/${txn}"
+
+	wid1=`ruby client.rb -p $proxies -v Get -a "$service?counter=0&enlistURL=${tm}/${txn}"`
+	wid2=`ruby client.rb -p $proxies -v Get -a "$service?counter=1&enlistURL=${tm}/${txn}"`
+#echo "WORK ids: $wid1 and $wid2"
+	ruby client.rb -p $proxies -v Get -a "$service?failWid=${wid2}"
+	ruby client.rb -p $proxies -v Put -a "${tm}/${txn}/terminate" -b "txStatus=TransactionCommitted"
+	;;
+*)
+	fatal;;
+esac


Property changes on: labs/jbosstm/trunk/rest-tx/quickstarts/demo/test.sh
___________________________________________________________________
Added: svn:executable
   + *

Added: labs/jbosstm/trunk/rest-tx/quickstarts/demo/uiwar/WEB-INF/web.xml
===================================================================
--- labs/jbosstm/trunk/rest-tx/quickstarts/demo/uiwar/WEB-INF/web.xml	                        (rev 0)
+++ labs/jbosstm/trunk/rest-tx/quickstarts/demo/uiwar/WEB-INF/web.xml	2011-08-08 14:26:21 UTC (rev 37368)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+	metadata-complete="false">
+
+	<servlet>
+		<servlet-name>hello</servlet-name>
+		<servlet-class>HelloOpenshift</servlet-class>
+	</servlet>
+	<servlet-mapping>
+		<servlet-name>hello</servlet-name>
+		<url-pattern>/hello</url-pattern>
+	</servlet-mapping>
+
+</web-app>

Added: labs/jbosstm/trunk/rest-tx/quickstarts/demo/uiwar/pom.xml
===================================================================
--- labs/jbosstm/trunk/rest-tx/quickstarts/demo/uiwar/pom.xml	                        (rev 0)
+++ labs/jbosstm/trunk/rest-tx/quickstarts/demo/uiwar/pom.xml	2011-08-08 14:26:21 UTC (rev 37368)
@@ -0,0 +1,8 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<groupId>org.jboss.narayana.examples</groupId>
+	<artifactId>uiwar</artifactId>
+	<version>0.0.1-SNAPSHOT</version>
+	<packaging>war</packaging>
+</project>

Added: labs/jbosstm/trunk/rest-tx/quickstarts/demo/uiwar/src/main/webapp/WEB-INF/web.xml
===================================================================
--- labs/jbosstm/trunk/rest-tx/quickstarts/demo/uiwar/src/main/webapp/WEB-INF/web.xml	                        (rev 0)
+++ labs/jbosstm/trunk/rest-tx/quickstarts/demo/uiwar/src/main/webapp/WEB-INF/web.xml	2011-08-08 14:26:21 UTC (rev 37368)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+	metadata-complete="false">
+</web-app>

Added: labs/jbosstm/trunk/rest-tx/quickstarts/demo/uiwar/src/main/webapp/index.html
===================================================================
--- labs/jbosstm/trunk/rest-tx/quickstarts/demo/uiwar/src/main/webapp/index.html	                        (rev 0)
+++ labs/jbosstm/trunk/rest-tx/quickstarts/demo/uiwar/src/main/webapp/index.html	2011-08-08 14:26:21 UTC (rev 37368)
@@ -0,0 +1,238 @@
+<!-- JBoss, Home of Professional Open Source Copyright 2011, Red Hat Middleware 
+        LLC, and individual contributors as indicated by the @author tags. See the 
+        copyright.txt in the distribution for a full listing of individual contributors. 
+        This copyrighted material is made available to anyone wishing to use, modify, 
+        copy, or redistribute it subject to the terms and conditions of the GNU Lesser 
+        General Public License, v. 2.1. This program is distributed in the hope that 
+        it will be useful, but WITHOUT A 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, v.2.1 along with this distribution; 
+        if not, write to the Free Software Foundation, Inc., 51 Franklin Street, 
+        Fifth Floor, Boston, MA 02110-1301, USA. (C) 2011 -->
+
+<!-- javascript client for starting and stopping REST-AT transactions -->
+
+<html>
+    <head> 
+
+<script>
+function ajaxPost(url,stream,callback) {
+	ajaxRequest(url,stream,callback,'POST', null);
+}
+
+function ajaxPut(url,stream,callback) {
+	ajaxRequest(url,stream,callback,'PUT', null);
+}
+
+function ajaxGet(url,callback, accept) {
+	ajaxRequest(url, '' ,callback, 'GET', accept);
+}
+
+function ajaxHead(url,callback, accept) {
+	ajaxRequest(url, '' ,callback, 'Head', accept);
+}
+
+function ajaxRequest(url,stream,callback,method, accept) {
+//alert(method + ' ' + url);
+	if( ! method ) method = 'POST';
+	var xmlhttp = new XMLHttpRequest();
+	xmlhttp.open(method, url, true);
+	if (method == 'POST')
+		xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
+	else if (method == 'PUT')
+		xmlhttp.setRequestHeader('Content-Type','application/txstatus');
+	else
+		xmlhttp.setRequestHeader('Content-Type','text/plain');
+
+	xmlhttp.setRequestHeader('Accept',accept ? accept : 'text/plain');
+	xmlhttp.onreadystatechange=function() {
+		if(xmlhttp.readyState==4) {
+			if (xmlhttp.status != 200 && xmlhttp.status != 201)
+				info(xmlhttp.status + ' - HTTP status text: ' + xmlhttp.statusText);
+			else
+				callback(xmlhttp);
+		}
+	};
+	xmlhttp.send(stream);
+}
+
+function currentTxn() {
+	var lb = document.f1.txnList;
+	if (lb.selectedIndex != -1)
+		return lb.options[lb.selectedIndex].value;
+	else
+		throw 'No transaction selected';
+}
+
+function endTx(commit) {
+	var txn = currentTxn() + '/terminate';
+	var body = commit ? 'txStatus=TransactionCommitted' : 'txStatus=TransactionRolledBack';
+
+	info("PUTing " + body + ' to ' + txn);
+	ajaxPut( txn, body, requestResponseHandler );
+	ajaxGet( window.txMgr, txnListHandler, null );
+}
+
+function callRequest(c)
+{
+	try {
+
+		var uri = window.txMgr;
+
+		if (c == 's') {
+			ajaxGet(currentTxn(), txnStatusHandler, 'application/txstatus' );
+		} else if (c == 'h') {
+			ajaxHead( currentTxn(), parseLinkHeaders );
+		} else {
+			if (c == 'l') {
+			} else if (c == 'b') {
+				ajaxPost( uri, document.f1.timeout.value, requestResponseHandler );
+			} else if (c == 'c') {
+				endTx(true);
+			} else if (c == 'a') {
+				endTx(false);
+			}
+			ajaxGet( uri, txnListHandler, null);
+		}
+	} catch (e) {
+  		info(e);
+	}
+}
+
+function requestResponseHandler( response ) {
+	info(response.responseText);
+}
+
+function txnStatusHandler( response ) {
+	var value = document.f1.txnList.value;
+
+	info(
+		'Status: ' + response.responseText +
+		'<br/>Durable Participant: ' + value +
+		'<br/>Completion: ' + value + '/terminate');
+}
+
+function parseLinkHeaders(response) {
+    var enlistUrl, endUrl, loc;
+
+//	loc = response.getResponseHeader("Location");
+	links = response.getResponseHeader("Link");
+
+	info(links);
+
+/*
+    if (links != nil) {
+        links = links.delete " \"<>"
+        links.each_line(',') {
+            |link|
+            enlistUrl = link.split(';') [0] if link.include? "rel=durableparticipant"
+            endUrl = link.split(';') [0] if link.include? "rel=terminator"
+        }
+    }
+
+    return enlistUrl, endUrl, location
+*/
+}
+
+function addOption(selectbox,text,value ) {
+	var optn = document.createElement("option");
+	optn.text = text;
+	optn.value = value;
+	selectbox.options.add(optn);
+
+	var xmlhttp = new XMLHttpRequest();
+	xmlhttp.open('GET', value, false);
+	xmlhttp.onreadystatechange=function() {
+		if(xmlhttp.readyState==4) {
+			//optn.style.backgroundColor= "red";
+			if (xmlhttp.responseText == 'txStatus=TransactionRolledBack')
+				optn.style.color= "red";
+			else if (xmlhttp.responseText == 'txStatus=TransactionActive')
+				optn.style.color= "green";
+		}
+	}
+	xmlhttp.send('');
+}
+
+function xxaddOption(selectbox,text,value ) {
+	var optn = document.createElement("option");
+	optn.text = text;
+	optn.value = value;
+	selectbox.options.add(optn);
+
+	callback=function(xmlhttp, optn) {
+		if(xmlhttp.readyState==4) {
+			//optn.style.backgroundColor= "red";
+			if (xmlhttp.responseText == 'txStatus=TransactionRolledBack')
+				optn.style.color= "red";
+			else if (xmlhttp.responseText == 'txStatus=TransactionActive')
+				optn.style.color= "green";
+		}
+	};
+
+	ajaxGet(value,callback);
+}
+
+function txnListHandler( response ) {
+	var txns = response.responseText.split(";");
+	var lb = document.f1.txnList;
+	lb.options.length = 0;
+	for (var i=0; i < txns.length; ++i)
+		addOption(lb, txns[i], txns[i]);
+}
+
+function info(str) {
+	document.getElementById("consoleOutput").innerHTML = str;
+}
+
+function load() {
+	// split into 'url', 'scheme', 'slash', 'host', 'port', 'path', 'query', 'hash'
+	var parse_url = /^(?:([A-Za-z]+):)?(\/{0,3})([0-9.\-A-Za-z]+)(?::(\d+))?(?:\/([^?#]*))?(?:\?([^#]*))?(?:#(.*))?$/;
+	var parts = parse_url.exec(window.location.href);
+	var context = '/rest-tx/tx/transaction-manager/';
+	window.txMgr = parts[1] + ':' +  parts[2] + parts[3] + ':' + parts[4] + context;
+
+    document.f1.txMgr.value = window.txMgr;
+}
+
+function setTxMgr() {
+	window.txMgr = document.f1.txMgr.value;
+	document.f1.txnList.options.length = 0;
+	info('using uri: ' + window.txMgr);
+}
+
+function getUrl() {
+	//alert("ajaxGet " + document.f1.reqUrl.value);
+	ajaxGet(document.f1.reqUrl.value, requestResponseHandler, null );
+}
+
+window.onload = load;
+
+</script>
+    </head>
+    <body>
+        <div class="content">
+        <form name="f1">
+			<p>Transaction URI:<input name="txMgr" type="text" size="60" onload="getTxMgr()", value="">
+			<a href="#" onclick="setTxMgr()">Update</a>
+			<!--<p>Transaction timeout:--> <input name="timeout" type="hidden" value="0">
+			<p>
+			<a href="#" onclick="callRequest('b')">start</a>
+			<a href="#" onclick="callRequest('c')">commit</a>
+			<a href="#" onclick="callRequest('a')">rollback</a>
+			<a href="#" onclick="callRequest('l')">list</a>
+
+			<p>
+			<select NAME="txnList" SIZE=10 onchange="callRequest('s');"> 
+			</select>
+<!--
+			<p><a href="#" onclick="getUrl()">Get URL:</a>
+			<input name="reqUrl" type="text" size="100" onclick="getUrl()">
+-->
+			<p>
+			<div id="consoleOutput"></div>
+		</form>
+		</div>
+	</body>
+</html>



More information about the jboss-svn-commits mailing list