Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

JBTM-1092 TXFramework Quickstart: Bridging, JTA -> WS-AT -> JTA

  • Loading branch information...
commit f937ee30dceb81fbc81fe092e3c9ebf93ac18858 1 parent 3ed56bb
@paulrobinson paulrobinson authored
Showing with 1,119 additions and 2 deletions.
  1. +1 −0  TXFramework/pom.xml
  2. +169 −0 TXFramework/wsat-jta-bridge/README.md
  3. +262 −0 TXFramework/wsat-jta-bridge/pom.xml
  4. +41 −0 TXFramework/wsat-jta-bridge/src/main/java/org/jboss/as/quickstarts/wsat/jtabridge/BookingCountEntity.java
  5. +107 −0 TXFramework/wsat-jta-bridge/src/main/java/org/jboss/as/quickstarts/wsat/jtabridge/RestaurantServiceATImpl.java
  6. +65 −0 ...mework/wsat-jta-bridge/src/main/java/org/jboss/as/quickstarts/wsat/jtabridge/jaxws/RestaurantServiceAT.java
  7. +96 −0 ...wsat-jta-bridge/src/main/java/org/jboss/as/quickstarts/wsat/jtabridge/jaxws/RestaurantServiceATService.java
  8. +42 −0 TXFramework/wsat-jta-bridge/src/test/java/org/jboss/as/quickstarts/wsat/jtabridge/fromjta/ATBridgeClient.java
  9. +129 −0 ...mework/wsat-jta-bridge/src/test/java/org/jboss/as/quickstarts/wsat/jtabridge/fromjta/BridgeFromJTATest.java
  10. +40 −0 TXFramework/wsat-jta-bridge/src/test/java/org/jboss/as/quickstarts/wsat/jtabridge/tojta/ATBridgeClient.java
  11. +127 −0 TXFramework/wsat-jta-bridge/src/test/java/org/jboss/as/quickstarts/wsat/jtabridge/tojta/BridgeToJTATest.java
  12. +22 −0 TXFramework/wsat-jta-bridge/src/test/resources/arquillian.xml
  13. +14 −0 TXFramework/wsat-jta-bridge/src/test/resources/persistence.xml
  14. +3 −1 TXFramework/wsat-simple/src/test/java/org/jboss/as/quickstarts/wsat/simple/Client.java
  15. +1 −1  TXFramework/wsba-participant-completion-simple/README.md
View
1  TXFramework/pom.xml
@@ -21,6 +21,7 @@
</plugins>
</build>
<modules>
+ <module>wsat-jta-bridge</module>
<module>wsat-simple</module>
<module>wsba-participant-completion-simple</module>
</modules>
View
169 TXFramework/wsat-jta-bridge/README.md
@@ -0,0 +1,169 @@
+wsat-jta-bridge: WS-AT (WS-AtomicTransaction) - Simple, using the TXFramework
+========================================================================
+Author: Paul Robinson
+
+_NOTE: This quickstart utilises technology that is in status "Tech Preview". Although the quickstart is tested regularly,
+you may find issues when developing your own applications using the TXFramework. We are very keen to hear about your
+experiences with the TXFramework and of any bugs you may find. Please direct these to the JBossTS forum.
+
+What is it?
+-----------
+
+This example demonstrates the deployment of a WS-AT (WS-AtomicTransaction) enabled JAX-WS Web service bundled in a JAR archive for deployment to *JBoss AS 7* that bridges to and from a JTA transaction.
+
+The example uses the annotation support provided by the TXFramework. The TXFramwork provides annotation support for
+writing transactional applications. This particular example shows how it can be used to write a WS-AT application that bridges from and to a JTA transaction.
+However, the TXFramework provides support for other Transaction protocols, such as REST-AT and WS-BA.
+See the other TXFramework quickstarts for more examples and the README.md file in the directory above, for a more complete
+description of what the TXFramework provides.
+
+In particular this example showcases the following features of the TXFramework:
+
+1. Bridging a transaction from a JTA transaction to a WS-AT transaction. This bridging is not yet setup automatically by the TXFramework.
+2. Bridging a transaction from a WS-AT transaction to a JTA transaction. This bridging is setup automatically by the TXFramework.
+
+The quickstart comprises of a Web service that is offered by a Restaurant for making bookings. The Service allows bookings to be made within an Atomic Transaction.
+
+This example demonstrates the basics of implementing a WS-AT enabled Web service. It is beyond the scope of this quick start to demonstrate more advanced features. In particular:
+
+1. The Service does not implement the required hooks to support recovery in the presence of failures.
+2. Only one Web service participates in the protocol. As WS-AT is a 2PC coordination protocol, it is best suited to multi-participant scenarios.
+
+For a more complete example, please see the XTS demonstrator application that ships with the JBossTS project: http://www.jboss.org/jbosstm. However, this does not use the TXFramework.
+
+It is also assumed that you have an understanding of WS-AtomicTransaction and JTA. For more details, read the XTS and JTA documentation
+that ships with the Narayana project, which can be downloaded here: http://www.jboss.org/jbosstm/downloads/.
+Please note that this documentation focuses on developing applications *without* the TXFramework.
+
+The application consists of a single JAX-WS web service that is deployed within a JAR archive. It is tested with JBoss Arquillian enabled JUnit tests.
+
+The quickstart offers two tests; `org.jboss.as.quickstarts.wsat.jtabridge.tojta.BridgeToJTATest` and `org.jboss.as.quickstarts.wsat.jtabridge.fromjta.BridgeFromJTATest`. The first test (BridgeToJTATest)
+begins a WS-AT transaction on the client side and then bridges it on the server side to a JTA transaction. The second test (BridgeFromJTATest) begins a JTA transaction on the client side and then
+bridges it to a WS-AT transaction for the Web service call. The incoming WS-AT transaction is then bridged on the server side to another JTA transaction.
+
+When running the `org.jboss.as.quickstarts.wsat.jtabridge.tojta.BridgeToJTATest#testCommit()`, the following steps occur:
+
+1. A new Atomic Transaction (WS-AT) is created by the client.
+2. An operation on a WS-AT enabled Web service is invoked by the client.
+3. The JaxWSHeaderContextProcessor in the WS Client handler chain inserts the WS-AT context into the outgoing SOAP message
+4. When the service receives the SOAP request, the JaxWSHeaderContextProcessor in its handler chain inspects the WS-AT context and associates the request with this AT. This handler is automatically added by the TXFramework.
+5. Next, the JaxWSTxInboundBridgeHandler in its handler chain starts a new JTA transaction and bridges it onto the incoming WS-AT transaction. This handler is automatically added by the TXFramework.
+6. The Web service operation is invoked...
+7. The service invokes the business logic. In this case, a booking is made with the restaurant, by looking up a JPA entity and updating the booking count
+8. The client can then decide to commit or rollback the AT. If the client decides to commit, the coordinator will begin the 2PC protocol, which will be bridged onto the JTA transaction. If the participant decides to rollback, all participants will be told to rollback.
+
+There is another test that shows what happens if the client decides to rollback the AT.
+
+When running the `org.jboss.as.quickstarts.wsat.jtabridge.fromjta.BridgeFromJTATest#testCommit()`, the following steps occur:
+
+1. A new JTA Transaction is created by the client.
+2. An operation on a WS-AT enabled Web service is invoked by the client.
+3. The JaxWSTxOutboundBridgeHandler in the WS Client handler chain starts a new WS-AT transaction and bridges to it from the JTA transaction.
+3. The next handler, (JaxWSHeaderContextProcessor) in the WS Client handler chain inserts the WS-AT context into the outgoing SOAP message
+4. When the service receives the SOAP request, the JaxWSHeaderContextProcessor in its handler chain inspects the WS-AT context and associates the request with this AT. This handler is automatically added by the TXFramework.
+5. Next, the JaxWSTxInboundBridgeHandler in its handler chain starts a new JTA transaction and bridges it onto the incoming WS-AT transaction. This handler is automatically added by the TXFramework.
+6. The Web service operation is invoked...
+7. The service invokes the business logic. In this case, a booking is made with the restaurant, by looking up a JPA entity and updating the booking count
+8. The client can then decide to commit or rollback the JTA transaction. If the client decides to commit, the coordinator will begin the 2PC protocol, which will be bridged from the JTA transaction on the client, to the WS-AT transaction and then to the other JTA transaction on the server. If the participant decides to rollback, all participants will be told to rollback.
+
+There is another test that shows what happens if the client decides to rollback the JTA transaction.
+
+System requirements
+-------------------
+
+All you need to build this project is Java 6.0 (Java SDK 1.6) or better, Maven 3.0 or better.
+
+_NOTE: The TXFramework does not currently ship with JBossAS. This is because it is currently a tech preview.
+You will need to follow the instructions in the README.md file found in the parent directory to this quickstart.
+
+
+Start JBoss AS 7 with the Custom Options
+----------------------
+
+First, edit the log level to reduce the amount of log output. This should make it easier to read the logs produced by this example. To do this add the
+following logger block to the ./docs/examples/configs/standalone-xts.xml of your JBoss distribution. You should add it just bellow one of the other logger blocks.
+
+ <logger category="org.apache.cxf.service.factory.ReflectionServiceFactoryBean">
+ <level name="WARN"/>
+ </logger>
+
+Next you need to start the JBoss AS 7 server that you just built, with the XTS sub system enabled. This is enabled through the optional server configuration *standalone-xts.xml*. To do this, run the following commands from the top-level directory of JBossAS:
+
+ For Linux: ./bin/standalone.sh --server-config=../../docs/examples/configs/standalone-xts.xml | egrep "stdout|stderr|started"
+ For Windows: \bin\standalone.bat --server-config=..\..\docs\examples\configs\standalone-xts.xml
+
+Note the pipe to `egrep` on the linux command. this filters the output from the server and makes it easier to view the expected output.
+
+Run the Arquillian Tests
+-------------------------
+
+This quickstart provides Arquillian tests. By default, these tests are configured to be skipped as Arquillian tests require the use of a container.
+
+1. Make sure you have started the JBoss Server as described above.
+2. Open a command line and navigate to the root directory of this quickstart.
+3. Type the following command to run the test goal with the following profile activated:
+
+ mvn clean test -Parq-jbossas-remote
+
+
+Investigate the Console Output
+----------------------------
+
+The following expected output should appear. Note there will be some other log messages interlaced between these. The output explains what actually went on when these tests ran.
+
+BridgeToJTATest
+---------------
+
+Test commit:
+
+ 11:54:48,263 INFO [stdout] (http-localhost-127.0.0.1-8080-1) [CLIENT] Beginning the first WS-AT transaction
+ 11:54:49,361 INFO [stdout] (http-localhost-127.0.0.1-8080-1) [CLIENT] Calling makeBooking on the WS client stub.
+ 11:54:49,848 INFO [stdout] (http-localhost-127.0.0.1-8080-3) [SERVICE] Restaurant service invoked to make a booking for '1'
+ 11:54:49,849 INFO [stdout] (http-localhost-127.0.0.1-8080-3) [SERVICE] Using the JPA Entity Manager to update the BookingCountEntity within a JTA transaction
+ 11:54:49,957 INFO [stdout] (http-localhost-127.0.0.1-8080-1) [CLIENT] Booking successful, about to commit the WS-AT transaction.
+ 11:54:51,688 INFO [stdout] (http-localhost-127.0.0.1-8080-1) [CLIENT] Beginning the second WS-AT transaction
+ 11:54:51,765 INFO [stdout] (http-localhost-127.0.0.1-8080-1) [CLIENT] Calling getBookingCount on the WS client stub.
+ 11:54:51,880 INFO [stdout] (http-localhost-127.0.0.1-8080-3) [SERVICE] getBookingCount() invoked
+ 11:54:51,887 INFO [stdout] (http-localhost-127.0.0.1-8080-1) [CLIENT] Booking count obtained successfully, about to commit the WS-AT transaction.
+ 11:54:52,398 INFO [stdout] (http-localhost-127.0.0.1-8080-1) [CLIENT] Asserting that the booking was successful
+
+Test client driven rollback:
+
+ 11:54:53,001 INFO [stdout] (http-localhost-127.0.0.1-8080-2) [CLIENT] Beginning the first WS-AT transaction
+ 11:54:53,081 INFO [stdout] (http-localhost-127.0.0.1-8080-2) [CLIENT] Calling makeBooking on the WS client stub.
+ 11:54:53,296 INFO [stdout] (http-localhost-127.0.0.1-8080-3) [SERVICE] Restaurant service invoked to make a booking for '1'
+ 11:54:53,297 INFO [stdout] (http-localhost-127.0.0.1-8080-3) [SERVICE] Using the JPA Entity Manager to update the BookingCountEntity within a JTA transaction
+ 11:54:53,301 INFO [stdout] (http-localhost-127.0.0.1-8080-2) [CLIENT] Booking successful, about to rollback the WS-AT transaction
+ 11:54:54,189 INFO [stdout] (http-localhost-127.0.0.1-8080-2) [CLIENT] Beginning the second WS-AT transaction
+ 11:54:54,249 INFO [stdout] (http-localhost-127.0.0.1-8080-2) [CLIENT] Calling getBookingCount on the WS client stub.
+ 11:54:54,344 INFO [stdout] (http-localhost-127.0.0.1-8080-3) [SERVICE] getBookingCount() invoked
+ 11:54:54,350 INFO [stdout] (http-localhost-127.0.0.1-8080-2) [CLIENT] Booking count obtained successfully, about to commit the WS-AT transaction.
+ 11:54:54,690 INFO [stdout] (http-localhost-127.0.0.1-8080-2) [CLIENT] Asserting that the booking was *not* successful
+
+BridgeFromJTATest
+-----------------
+
+Test commit:
+
+ 11:54:56,868 INFO [stdout] (http-localhost-127.0.0.1-8080-1) [CLIENT] Beginning the first JTA transaction
+ 11:54:56,869 INFO [stdout] (http-localhost-127.0.0.1-8080-1) [CLIENT] Calling makeBooking on the WS client stub. The registered interceptor will bridge rom JTA to WS-AT
+ 11:54:57,103 INFO [stdout] (http-localhost-127.0.0.1-8080-3) [SERVICE] Restaurant service invoked to make a booking for '1'
+ 11:54:57,104 INFO [stdout] (http-localhost-127.0.0.1-8080-3) [SERVICE] Using the JPA Entity Manager to update the BookingCountEntity within a JTA transaction
+ 11:54:57,116 INFO [stdout] (http-localhost-127.0.0.1-8080-1) [CLIENT] Booking successful, about to commit the JTA transaction. This will also cause the bridged WS-AT transaction to commit
+ 11:54:57,933 INFO [stdout] (http-localhost-127.0.0.1-8080-1) [CLIENT] Beginning the second JTA transaction
+ 11:54:57,934 INFO [stdout] (http-localhost-127.0.0.1-8080-1) [CLIENT] Calling getBookingCount on the WS client stub. The registered interceptor will bridge rom JTA to WS-AT
+ 11:54:58,032 INFO [stdout] (http-localhost-127.0.0.1-8080-3) [SERVICE] getBookingCount() invoked
+ 11:54:58,037 INFO [stdout] (http-localhost-127.0.0.1-8080-1) [CLIENT] Booking count obtained successfully, about to commit the JTA transaction. This will also cause the bridged WS-AT transaction to commit
+ 11:54:58,309 INFO [stdout] (http-localhost-127.0.0.1-8080-1) [CLIENT] Asserting that the booking was successful
+
+Test client driven rollback:
+
+ 11:54:58,770 INFO [stdout] (http-localhost-127.0.0.1-8080-2) [CLIENT] Beginning the first JTA transaction
+ 11:54:58,770 INFO [stdout] (http-localhost-127.0.0.1-8080-2) [CLIENT] Calling makeBooking on the WS client stub. The registered interceptor will bridge rom JTA to WS-AT
+ 11:54:58,983 INFO [stdout] (http-localhost-127.0.0.1-8080-3) [SERVICE] Restaurant service invoked to make a booking for '1'
+ 11:54:58,983 INFO [stdout] (http-localhost-127.0.0.1-8080-3) [SERVICE] Using the JPA Entity Manager to update the BookingCountEntity within a JTA transaction
+ 11:54:58,988 INFO [stdout] (http-localhost-127.0.0.1-8080-2) [CLIENT] Booking successful, about to rollback the JTA transaction. This will also cause the bridged WS-AT transaction to rollback
+ 11:54:59,327 INFO [stdout] (http-localhost-127.0.0.1-8080-2) [CLIENT] Beginning the second JTA transaction
+ 11:54:59,328 INFO [stdout] (http-localhost-127.0.0.1-8080-2) [CLIENT] Calling getBookingCount on the WS client stub. The registered interceptor will bridge rom JTA to WS-AT
+ 11:54:59,431 INFO [stdout] (http-localhost-127.0.0.1-8080-3) [SERVICE] getBookingCount() invoked
+ 11:54:59,436 INFO [stdout] (http-localhost-127.0.0.1-8080-2) [CLIENT] Booking count obtained successfully, about to commit the JTA transaction. This will also cause the bridged WS-AT transaction to commit
View
262 TXFramework/wsat-jta-bridge/pom.xml
@@ -0,0 +1,262 @@
+<?xml version="1.0"?>
+<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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.jboss.narayana.quickstart.txframework.wsat-jta-bridge</groupId>
+ <artifactId>wsat-jta-bridge-all</artifactId>
+ <version>5.0.0.M2-SNAPSHOT</version>
+ <packaging>jar</packaging>
+ <name>JBoss Narayana Quickstarts: Simple WS-AT Web service, bridged to and from JTA, using the TXFramework</name>
+ <description>JBoss Narayana Quickstarts: Simple WS-AT Web service, bridged to and from JTA, using the TXFramework</description>
+
+ <properties>
+ <!-- Explicitly declaring the source encoding eliminates the following
+ message: -->
+ <!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered
+ resources, i.e. build is platform dependent! -->
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <jboss-as.version>7.1.2.Final-SNAPSHOT</jboss-as.version>
+ </properties>
+
+ <!-- We add the JBoss repository as we need the JBoss AS connectors
+ for Arquillian and also for the Narayana libraries-->
+ <repositories>
+ <!-- The JBoss Community public repository is a composite repository
+ of several major repositories -->
+ <!-- see http://community.jboss.org/wiki/MavenGettingStarted-Users -->
+ <repository>
+ <id>jboss-public-repository</id>
+ <name>JBoss Repository</name>
+ <url>http://repository.jboss.org/nexus/content/groups/public</url>
+ <!-- These optional flags are designed to speed up your builds
+ by reducing remote server calls -->
+ <releases>
+ </releases>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </repository>
+ </repositories>
+
+ <pluginRepositories>
+ <pluginRepository>
+ <id>jboss-public-repository</id>
+ <name>JBoss Repository</name>
+ <url>http://repository.jboss.org/nexus/content/groups/public</url>
+ <releases>
+ </releases>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </pluginRepository>
+ </pluginRepositories>
+
+ <dependencyManagement>
+ <dependencies>
+ <!-- Define the version of JBoss' Java EE 6 APIs and Tools we want to import. -->
+
+ <!-- JBoss distributes a complete set of Java EE 6 APIs including a Bill
+ of Materials (BOM). A BOM specifies the versions of a "stack" (or a collection)
+ of artifacts. We use this here so that we always get the correct versions
+ of artifacts.-->
+
+ <!-- This BOM provides the jboss-javaee-6.0 with tools stack (you can read this as
+ the JBoss stack of the Java EE 6 APIs, with some extras tools for your project, such
+ as Arquillian for testing) -->
+ <dependency>
+ <groupId>org.jboss.bom</groupId>
+ <artifactId>jboss-javaee-6.0-with-tools</artifactId>
+ <version>1.0.0.M7</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <!-- The XTS api needed to use WS-AT -->
+ <dependency>
+ <groupId>org.jboss.narayana.xts</groupId>
+ <artifactId>jbossxts</artifactId>
+ <classifier>api</classifier>
+ <version>5.0.0.M2-SNAPSHOT</version>
+ <scope>provided</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.jboss.logging</groupId>
+ <artifactId>jboss-logging-spi</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <!-- The TXFramework api needed to simplify usage of WS-AT -->
+ <dependency>
+ <groupId>org.jboss.narayana.txframework</groupId>
+ <artifactId>txframework</artifactId>
+ <version>5.0.0.M2-SNAPSHOT</version>
+ <scope>provided</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.jboss.logging</groupId>
+ <artifactId>jboss-logging-spi</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <!-- The TXBridge needed to bridge between WS-AT and JTA transactions -->
+ <dependency>
+ <groupId>org.jboss.narayana</groupId>
+ <artifactId>jbosstxbridge</artifactId>
+ <version>5.0.0.M2-SNAPSHOT</version>
+ <scope>provided</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.jboss.logging</groupId>
+ <artifactId>jboss-logging-spi</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.spec.javax.transaction</groupId>
+ <artifactId>jboss-transaction-api_1.1_spec</artifactId>
+ <version>1.0.0.Final</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- Import the CDI API, we use provided scope as the API is included
+ in JBoss AS 7 -->
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- Import the Common Annotations API (JSR-250), we use provided scope
+ as the API is included in JBoss AS 7 -->
+ <dependency>
+ <groupId>org.jboss.spec.javax.annotation</groupId>
+ <artifactId>jboss-annotations-api_1.1_spec</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.spec.javax.ejb</groupId>
+ <artifactId>jboss-ejb-api_3.1_spec</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- Test dependencies -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.arquillian.junit</groupId>
+ <artifactId>arquillian-junit-container</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.arquillian.protocol</groupId>
+ <artifactId>arquillian-protocol-servlet</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <!-- Set the name of the jar, used as the context root when the app is
+ deployed -->
+ <finalName>wsat-jta-bridge</finalName>
+ <plugins>
+ <plugin>
+ <groupId>org.jboss.as.plugins</groupId>
+ <artifactId>jboss-as-maven-plugin</artifactId>
+ <version>7.1.1.Final</version>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
+ <!-- Compiler plugin enforces Java 1.6 compatibility and activates
+ annotation processors -->
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.1</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.7.2</version>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <profiles>
+ <profile>
+ <!-- This profile will start a new JBoss AS instance, and execute
+ the test, shutting it down when done -->
+ <!-- Run with: mvn clean test -->
+ <id>arq-jbossas-managed</id>
+ <activation>
+ <activeByDefault>false</activeByDefault>
+ </activation>
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.as</groupId>
+ <artifactId>jboss-as-arquillian-container-managed</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <redirectTestOutputToFile>true</redirectTestOutputToFile>
+ <skip>false</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+
+ <profile>
+
+ <!-- An optional Arquillian testing profile that executes tests
+ in a remote JBoss AS instance -->
+ <!-- Run with: mvn clean test -Parq-jbossas-remote -->
+ <id>arq-jbossas-remote</id>
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.as</groupId>
+ <artifactId>jboss-as-arquillian-container-remote</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skip>false</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
+</project>
+
View
41 TXFramework/wsat-jta-bridge/src/main/java/org/jboss/as/quickstarts/wsat/jtabridge/BookingCountEntity.java
@@ -0,0 +1,41 @@
+package org.jboss.as.quickstarts.wsat.jtabridge;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import java.io.Serializable;
+
+/**
+ * @author paul.robinson@redhat.com, 2012-05-03
+ */
+@Entity
+public class BookingCountEntity implements Serializable {
+
+ private int id;
+ private int bookingCount;
+
+ public BookingCountEntity() {
+ }
+
+ @Id
+ @GeneratedValue
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public int getBookingCount() {
+ return bookingCount;
+ }
+
+ public void setBookingCount(int counter) {
+ this.bookingCount = counter;
+ }
+
+ public void addBookings(int howMany) {
+ setBookingCount(getBookingCount() + howMany);
+ }
+}
View
107 ...ework/wsat-jta-bridge/src/main/java/org/jboss/as/quickstarts/wsat/jtabridge/RestaurantServiceATImpl.java
@@ -0,0 +1,107 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, 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) 2005-2006,
+ * @author JBoss Inc.
+ */
+/*
+ * RestaurantServiceAT.java
+ *
+ * Copyright (c) 2003, 2004 Arjuna Technologies Ltd
+ *
+ * $Id: RestaurantServiceAT.java,v 1.3 2004/12/01 16:26:44 kconner Exp $
+ *
+ */
+package org.jboss.as.quickstarts.wsat.jtabridge;
+
+import org.jboss.as.quickstarts.wsat.jtabridge.jaxws.RestaurantServiceAT;
+import org.jboss.narayana.txframework.api.annotation.service.ServiceRequest;
+import org.jboss.narayana.txframework.api.annotation.transaction.AT;
+
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+import javax.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
+import javax.jws.WebMethod;
+import javax.jws.WebService;
+import javax.jws.soap.SOAPBinding;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+/**
+ * An adapter class that exposes the RestaurantManager business API as a transactional Web Service.
+ *
+ * @author paul.robinson@redhat.com, 2012-01-04
+ */
+@AT //By default bridge from WS-AT to JTA
+@Stateless
+@Remote(RestaurantServiceAT.class)
+@WebService(serviceName = "RestaurantServiceATService", portName = "RestaurantServiceAT", name = "RestaurantServiceAT", targetNamespace = "http://www.jboss.com/jbossas/quickstarts/wsat/simple/Restaurant")
+@SOAPBinding(style = SOAPBinding.Style.RPC)
+@TransactionAttribute(TransactionAttributeType.MANDATORY) // default is REQUIRED
+public class RestaurantServiceATImpl implements RestaurantServiceAT {
+
+ private static final int ENTITY_ID = 1;
+
+ @PersistenceContext
+ protected EntityManager em;
+
+ /**
+ * Book a number of seats in the restaurant. This is done by updating the BookingCountEntity within a JTA transaction. The JTA transaction
+ * was automatically bridged from the WS-AT transaction.
+ */
+ @WebMethod
+ @ServiceRequest
+ public void makeBooking(int numSeats) {
+
+ System.out.println("[SERVICE] Restaurant service invoked to make a booking for '" + numSeats + "'");
+
+ // invoke the backend business logic:
+ System.out.println("[SERVICE] Using the JPA Entity Manager to update the BookingCountEntity within a JTA transaction");
+
+ BookingCountEntity entity = lookupBookingCountEntity();
+ entity.addBookings(1);
+ em.merge(entity);
+ }
+
+ @WebMethod
+ public int getBookingCount() {
+ System.out.println("[SERVICE] getBookingCount() invoked");
+ BookingCountEntity bookingCountEntity = lookupBookingCountEntity();
+ if (bookingCountEntity == null) {
+ return -1;
+ }
+ return bookingCountEntity.getBookingCount();
+ }
+
+ @WebMethod
+ public void resetBookingCount() {
+ BookingCountEntity entity = lookupBookingCountEntity();
+ entity.setBookingCount(0);
+ em.merge(entity);
+ }
+
+ private BookingCountEntity lookupBookingCountEntity() {
+ BookingCountEntity entity = em.find(BookingCountEntity.class, ENTITY_ID);
+ if (entity == null) {
+ entity = new BookingCountEntity();
+ em.persist(entity);
+ }
+ return entity;
+ }
+
+}
View
65 ...ork/wsat-jta-bridge/src/main/java/org/jboss/as/quickstarts/wsat/jtabridge/jaxws/RestaurantServiceAT.java
@@ -0,0 +1,65 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2010, Red Hat, 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.
+ *
+ * @author JBoss Inc.
+ */
+/*
+ * RestaurantManager.java
+ *
+ * Copyright (c) 2003 Arjuna Technologies Ltd.
+ *
+ * $Id: RestaurantManager.java,v 1.3 2004/04/21 13:09:18 jhalliday Exp $
+ *
+ */
+package org.jboss.as.quickstarts.wsat.jtabridge.jaxws;
+
+import javax.ejb.Remote;
+import javax.jws.WebMethod;
+import javax.jws.WebService;
+import javax.jws.soap.SOAPBinding;
+
+/**
+ * Interface to a simple Restaurant. Provides simple methods to manipulate bookings.
+ *
+ * @author paul.robinson@redhat.com, 2012-01-04
+ */
+@WebService(name = "RestaurantServiceAT", targetNamespace = "http://www.jboss.com/jbossas/quickstarts/wsat/simple/Restaurant")
+@SOAPBinding(style = SOAPBinding.Style.RPC)
+@Remote
+public interface RestaurantServiceAT {
+
+ /**
+ * Create a new booking
+ */
+ @WebMethod
+ public void makeBooking(int numSeats);
+
+ /**
+ * obtain the number of existing bookings
+ *
+ * @return the number of current bookings
+ */
+ @WebMethod
+ public int getBookingCount();
+
+ /**
+ * Reset the booking count to zero
+ */
+ @WebMethod
+ public void resetBookingCount();
+
+}
View
96 ...t-jta-bridge/src/main/java/org/jboss/as/quickstarts/wsat/jtabridge/jaxws/RestaurantServiceATService.java
@@ -0,0 +1,96 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2010, Red Hat, 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.
+ *
+ * @author JBoss Inc.
+ */
+/*
+ * RestaurantManager.java
+ *
+ * Copyright (c) 2003 Arjuna Technologies Ltd.
+ *
+ * $Id: RestaurantManager.java,v 1.3 2004/04/21 13:09:18 jhalliday Exp $
+ *
+ */
+package org.jboss.as.quickstarts.wsat.jtabridge.jaxws;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.Service;
+import javax.xml.ws.WebEndpoint;
+import javax.xml.ws.WebServiceClient;
+import javax.xml.ws.WebServiceFeature;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.logging.Logger;
+
+/**
+ * This class was generated by the JAX-WS RI. JAX-WS RI 2.1.6 in JDK 6 Generated source version: 2.1
+ *
+ */
+@WebServiceClient(name = "RestaurantServiceATService", targetNamespace = "http://www.jboss.com/jbossas/quickstarts/wsat/simple/Restaurant")
+public class RestaurantServiceATService extends Service {
+
+ private final static URL RESTAURANTSERVICEATSERVICE_WSDL_LOCATION;
+ private final static Logger logger = Logger.getLogger(RestaurantServiceATService.class.getName());
+
+ static {
+ URL url = null;
+ try {
+ URL baseUrl;
+ baseUrl = RestaurantServiceATService.class.getResource(".");
+ url = new URL(baseUrl, "RestaurantServiceAT.wsdl");
+ } catch (MalformedURLException e) {
+ logger.warning("Failed to create URL for the wsdl Location: 'RestaurantServiceAT.wsdl', retrying as a local file");
+ logger.warning(e.getMessage());
+ }
+ RESTAURANTSERVICEATSERVICE_WSDL_LOCATION = url;
+ }
+
+ public RestaurantServiceATService(URL wsdlLocation, QName serviceName) {
+ super(wsdlLocation, serviceName);
+ }
+
+ public RestaurantServiceATService() {
+ super(RESTAURANTSERVICEATSERVICE_WSDL_LOCATION, new QName(
+ "http://www.jboss.com/jbossas/quickstarts/wsat/simple/Restaurant", "RestaurantServiceATService"));
+ }
+
+ /**
+ *
+ * @return returns RestaurantServiceAT
+ */
+ @WebEndpoint(name = "RestaurantServiceAT")
+ public RestaurantServiceAT getRestaurantServiceAT() {
+ return super.getPort(
+ new QName("http://www.jboss.com/jbossas/quickstarts/wsat/simple/Restaurant", "RestaurantServiceAT"),
+ RestaurantServiceAT.class);
+ }
+
+ /**
+ *
+ * @param features A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy. Supported features not in the
+ * <code>features</code> parameter will have their default values.
+ * @return returns RestaurantServiceAT
+ */
+ @WebEndpoint(name = "RestaurantServiceAT")
+ public RestaurantServiceAT getRestaurantServiceAT(WebServiceFeature... features) {
+ return super.getPort(
+ new QName("http://www.jboss.com/jbossas/quickstarts/wsat/simple/Restaurant", "RestaurantServiceAT"),
+ RestaurantServiceAT.class, features);
+ }
+
+}
View
42 ...mework/wsat-jta-bridge/src/test/java/org/jboss/as/quickstarts/wsat/jtabridge/fromjta/ATBridgeClient.java
@@ -0,0 +1,42 @@
+package org.jboss.as.quickstarts.wsat.jtabridge.fromjta;
+
+import com.arjuna.mw.wst11.client.JaxWSHeaderContextProcessor;
+import org.jboss.as.quickstarts.wsat.jtabridge.jaxws.RestaurantServiceAT;
+import org.jboss.jbossts.txbridge.outbound.JaxWSTxOutboundBridgeHandler;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.Service;
+import javax.xml.ws.handler.Handler;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author paul.robinson@redhat.com, 2012-05-03
+ */
+public class ATBridgeClient {
+
+ public static RestaurantServiceAT newInstance() throws Exception {
+ URL wsdlLocation = new URL("http://localhost:8080/test/RestaurantServiceATService/RestaurantServiceAT?wsdl");
+ QName serviceName = new QName("http://www.jboss.com/jbossas/quickstarts/wsat/simple/Restaurant", "RestaurantServiceATService");
+ QName portName = new QName("http://www.jboss.com/jbossas/quickstarts/wsat/simple/Restaurant", "RestaurantServiceAT");
+
+ Service service = Service.create(wsdlLocation, serviceName);
+ RestaurantServiceAT client = service.getPort(portName, RestaurantServiceAT.class);
+
+ /*
+ * Add client handler chain so that XTS can add the transaction context to the SOAP messages.
+ *
+ * This will be automatically added by the TXFramework in the future.
+ */
+ BindingProvider bindingProvider = (BindingProvider) client;
+ List<Handler> handlers = new ArrayList<Handler>();
+ handlers.add(new JaxWSTxOutboundBridgeHandler());
+ handlers.add(new JaxWSHeaderContextProcessor());
+ bindingProvider.getBinding().setHandlerChain(handlers);
+
+ return client;
+ }
+}
+
View
129 ...ork/wsat-jta-bridge/src/test/java/org/jboss/as/quickstarts/wsat/jtabridge/fromjta/BridgeFromJTATest.java
@@ -0,0 +1,129 @@
+package org.jboss.as.quickstarts.wsat.jtabridge.fromjta;
+
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.as.quickstarts.wsat.jtabridge.RestaurantServiceATImpl;
+import org.jboss.as.quickstarts.wsat.jtabridge.jaxws.RestaurantServiceAT;
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.ByteArrayAsset;
+import org.jboss.shrinkwrap.api.asset.StringAsset;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.transaction.UserTransaction;
+
+/**
+ * Simple set of tests for the RestaurantServiceAT
+ *
+ * @author paul.robinson@redhat.com, 2012-01-04
+ */
+@RunWith(Arquillian.class)
+public class BridgeFromJTATest {
+
+ private static final String ManifestMF = "Manifest-Version: 1.0\n"
+ + "Dependencies: org.jboss.narayana.txframework\n";
+
+ private UserTransaction ut;
+ private RestaurantServiceAT client;
+
+ /**
+ * Create the deployment archive to be deployed by Arquillian.
+ *
+ * @return a JavaArchive representing the required deployment
+ */
+ @Deployment
+ public static JavaArchive createTestArchive() {
+
+ //todo: Does the application developer have to specify the interceptor?
+ JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "bridge.jar")
+ .addPackages(true, RestaurantServiceATImpl.class.getPackage())
+ .addAsManifestResource("persistence.xml")
+ .addAsManifestResource(new ByteArrayAsset("<interceptors><class>org.jboss.narayana.txframework.impl.ServiceRequestInterceptor</class></interceptors>".getBytes()),
+ ArchivePaths.create("beans.xml"));
+
+ archive.delete(ArchivePaths.create("META-INF/MANIFEST.MF"));
+
+ archive.setManifest(new StringAsset(ManifestMF));
+
+ return archive;
+ }
+
+ @Before
+ public void setupTest() throws Exception {
+ Context initialContext = new InitialContext();
+ ut = (UserTransaction)initialContext.lookup("java:comp/UserTransaction");
+ client = ATBridgeClient.newInstance();
+ }
+
+ @After
+ public void teardownTest() throws Exception {
+ rollbackIfActive(ut);
+ try {
+ ut.begin();
+ client.resetBookingCount();
+ ut.commit();
+ } finally {
+ rollbackIfActive(ut);
+ }
+ }
+
+ @Test
+ public void testCommit() throws Exception {
+ System.out.println("[CLIENT] Beginning the first JTA transaction");
+ ut.begin();
+ System.out.println("[CLIENT] Calling makeBooking on the WS client stub. The registered interceptor will bridge rom JTA to WS-AT");
+ client.makeBooking(1);
+ System.out.println("[CLIENT] Booking successful, about to commit the JTA transaction. This will also cause the bridged WS-AT transaction to commit");
+ ut.commit();
+
+ System.out.println("[CLIENT] Beginning the second JTA transaction");
+ ut.begin();
+ System.out.println("[CLIENT] Calling getBookingCount on the WS client stub. The registered interceptor will bridge rom JTA to WS-AT");
+ int counter = client.getBookingCount();
+ System.out.println("[CLIENT] Booking count obtained successfully, about to commit the JTA transaction. This will also cause the bridged WS-AT transaction to commit");
+ ut.commit();
+
+ System.out.println("[CLIENT] Asserting that the booking was successful");
+ Assert.assertEquals(1, counter);
+ }
+
+ @Test
+ public void testClientDrivenRollback() throws Exception {
+ System.out.println("[CLIENT] Beginning the first JTA transaction");
+ ut.begin();
+ System.out.println("[CLIENT] Calling makeBooking on the WS client stub. The registered interceptor will bridge rom JTA to WS-AT");
+ client.makeBooking(1);
+ System.out.println("[CLIENT] Booking successful, about to rollback the JTA transaction. This will also cause the bridged WS-AT transaction to rollback");
+ ut.rollback();
+
+ System.out.println("[CLIENT] Beginning the second JTA transaction");
+ ut.begin();
+ System.out.println("[CLIENT] Calling getBookingCount on the WS client stub. The registered interceptor will bridge rom JTA to WS-AT");
+ int counter = client.getBookingCount();
+ System.out.println("[CLIENT] Booking count obtained successfully, about to commit the JTA transaction. This will also cause the bridged WS-AT transaction to commit");
+ ut.commit();
+
+ System.out.println("[CLIENT] Asserting that the booking was *not* successful");
+ Assert.assertEquals(0, counter);
+ }
+
+ /**
+ * Utility method for rolling back a transaction if it is currently active.
+ *
+ * @param ut The User Business Activity to cancel.
+ */
+ private void rollbackIfActive(UserTransaction ut) {
+ try {
+ ut.rollback();
+ } catch (Throwable th2) {
+ // do nothing, not active
+ }
+ }
+}
View
40 TXFramework/wsat-jta-bridge/src/test/java/org/jboss/as/quickstarts/wsat/jtabridge/tojta/ATBridgeClient.java
@@ -0,0 +1,40 @@
+package org.jboss.as.quickstarts.wsat.jtabridge.tojta;
+
+import com.arjuna.mw.wst11.client.JaxWSHeaderContextProcessor;
+import org.jboss.as.quickstarts.wsat.jtabridge.jaxws.RestaurantServiceAT;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.Service;
+import javax.xml.ws.handler.Handler;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author paul.robinson@redhat.com, 2012-05-03
+ */
+public class ATBridgeClient {
+
+ public static RestaurantServiceAT newInstance() throws Exception {
+ URL wsdlLocation = new URL("http://localhost:8080/test/RestaurantServiceATService/RestaurantServiceAT?wsdl");
+ QName serviceName = new QName("http://www.jboss.com/jbossas/quickstarts/wsat/simple/Restaurant", "RestaurantServiceATService");
+ QName portName = new QName("http://www.jboss.com/jbossas/quickstarts/wsat/simple/Restaurant", "RestaurantServiceAT");
+
+ Service service = Service.create(wsdlLocation, serviceName);
+ RestaurantServiceAT client = service.getPort(portName, RestaurantServiceAT.class);
+
+ /*
+ * Add client handler chain so that XTS can add the transaction context to the SOAP messages.
+ *
+ * This will be automatically added by the TXFramework in the future.
+ */
+ BindingProvider bindingProvider = (BindingProvider) client;
+ List<Handler> handlers = new ArrayList<Handler>();
+ handlers.add(new JaxWSHeaderContextProcessor());
+ bindingProvider.getBinding().setHandlerChain(handlers);
+
+ return client;
+ }
+}
+
View
127 ...amework/wsat-jta-bridge/src/test/java/org/jboss/as/quickstarts/wsat/jtabridge/tojta/BridgeToJTATest.java
@@ -0,0 +1,127 @@
+package org.jboss.as.quickstarts.wsat.jtabridge.tojta;
+
+import com.arjuna.mw.wst11.UserTransaction;
+import com.arjuna.mw.wst11.UserTransactionFactory;
+
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.as.quickstarts.wsat.jtabridge.RestaurantServiceATImpl;
+import org.jboss.as.quickstarts.wsat.jtabridge.jaxws.RestaurantServiceAT;
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.ByteArrayAsset;
+import org.jboss.shrinkwrap.api.asset.StringAsset;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * Simple set of tests for the RestaurantServiceAT
+ *
+ * @author paul.robinson@redhat.com, 2012-01-04
+ */
+@RunWith(Arquillian.class)
+public class BridgeToJTATest {
+
+ private static final String ManifestMF = "Manifest-Version: 1.0\n"
+ + "Dependencies: org.jboss.narayana.txframework\n";
+
+ private UserTransaction ut;
+ private RestaurantServiceAT client;
+
+ /**
+ * Create the deployment archive to be deployed by Arquillian.
+ *
+ * @return a JavaArchive representing the required deployment
+ */
+ @Deployment
+ public static JavaArchive createTestArchive() {
+
+ //todo: Does the application developer have to specify the interceptor?
+ JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "bridge.jar")
+ .addPackages(true, RestaurantServiceATImpl.class.getPackage())
+ .addAsManifestResource("persistence.xml")
+ .addAsManifestResource(new ByteArrayAsset("<interceptors><class>org.jboss.narayana.txframework.impl.ServiceRequestInterceptor</class></interceptors>".getBytes()),
+ ArchivePaths.create("beans.xml"));
+
+ archive.delete(ArchivePaths.create("META-INF/MANIFEST.MF"));
+
+ archive.setManifest(new StringAsset(ManifestMF));
+
+ return archive;
+ }
+
+ @Before
+ public void setupTest() throws Exception {
+ ut = UserTransactionFactory.userTransaction();
+ client = ATBridgeClient.newInstance();
+ }
+
+ @After
+ public void teardownTest() throws Exception {
+ rollbackIfActive(ut);
+ try {
+ ut.begin();
+ client.resetBookingCount();
+ ut.commit();
+ } finally {
+ rollbackIfActive(ut);
+ }
+ }
+
+ @Test
+ public void testCommit() throws Exception {
+ System.out.println("[CLIENT] Beginning the first WS-AT transaction");
+ ut.begin();
+ System.out.println("[CLIENT] Calling makeBooking on the WS client stub.");
+ client.makeBooking(1);
+ System.out.println("[CLIENT] Booking successful, about to commit the WS-AT transaction.");
+ ut.commit();
+
+ System.out.println("[CLIENT] Beginning the second WS-AT transaction");
+ ut.begin();
+ System.out.println("[CLIENT] Calling getBookingCount on the WS client stub.");
+ int counter = client.getBookingCount();
+ System.out.println("[CLIENT] Booking count obtained successfully, about to commit the WS-AT transaction.");
+ ut.commit();
+
+ System.out.println("[CLIENT] Asserting that the booking was successful");
+ Assert.assertEquals(1, counter);
+ }
+
+ @Test
+ public void testClientDrivenRollback() throws Exception {
+ System.out.println("[CLIENT] Beginning the first WS-AT transaction");
+ ut.begin();
+ System.out.println("[CLIENT] Calling makeBooking on the WS client stub.");
+ client.makeBooking(1);
+ System.out.println("[CLIENT] Booking successful, about to rollback the WS-AT transaction");
+ ut.rollback();
+
+ System.out.println("[CLIENT] Beginning the second WS-AT transaction");
+ ut.begin();
+ System.out.println("[CLIENT] Calling getBookingCount on the WS client stub.");
+ int counter = client.getBookingCount();
+ System.out.println("[CLIENT] Booking count obtained successfully, about to commit the WS-AT transaction.");
+ ut.commit();
+
+ System.out.println("[CLIENT] Asserting that the booking was *not* successful");
+ Assert.assertEquals(0, counter);
+ }
+
+ /**
+ * Utility method for rolling back a transaction if it is currently active.
+ *
+ * @param ut The User Business Activity to cancel.
+ */
+ private void rollbackIfActive(UserTransaction ut) {
+ try {
+ ut.rollback();
+ } catch (Throwable th2) {
+ // do nothing, not active
+ }
+ }
+}
View
22 TXFramework/wsat-jta-bridge/src/test/resources/arquillian.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<arquillian xmlns="http://jboss.org/schema/arquillian"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://jboss.org/schema/arquillian
+ http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
+
+ <!-- Uncomment to have test archives exported to the file system for inspection -->
+ <engine>
+ <property name="deploymentExportPath">target/</property>
+ </engine>
+
+ <!-- Force the use of the Servlet 3.0 protocol with all containers, as it is the most mature -->
+ <defaultProtocol type="Servlet 3.0" />
+
+ <!-- Example configuration for a remote JBoss AS 7 instance -->
+ <container qualifier="jboss" default="true">
+ <configuration>
+ <property name="serverConfig">../../docs/examples/configs/standalone-xts.xml</property>
+ </configuration>
+ </container>
+
+</arquillian>
View
14 TXFramework/wsat-jta-bridge/src/test/resources/persistence.xml
@@ -0,0 +1,14 @@
+<persistence xmlns="http://java.sun.com/xml/ns/persistence"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
+ version="1.0">
+
+ <persistence-unit name="restaurant">
+ <jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>
+ <properties>
+ <property name="hibernate.hbm2ddl.auto"
+ value="create-drop"/>
+ </properties>
+ </persistence-unit>
+
+</persistence>
View
4 TXFramework/wsat-simple/src/test/java/org/jboss/as/quickstarts/wsat/simple/Client.java
@@ -59,7 +59,9 @@ public Client() throws MalformedURLException {
restaurant = service.getPort(portName, RestaurantServiceAT.class);
/*
- * Add client handler chain
+ * Add client handler chain so that XTS can add the transaction context to the SOAP messages.
+ *
+ * This will be automatically added by the TXFramework in the future.
*/
BindingProvider bindingProvider = (BindingProvider) restaurant;
List<Handler> handlers = new ArrayList<Handler>(1);
View
2  TXFramework/wsba-participant-completion-simple/README.md
@@ -13,7 +13,7 @@ This example demonstrates the deployment of a WS-BA (WS Business Activity) enabl
The example uses the annotation support provided by the TXFramework. The TXFramwork provides annotation support for
writing transactional applications. This particular example shows how it can be used to write a WS-BA application.
-However, the TXFramework provides support for other Transaction protocols, such as REST-AT and WS-BA.
+However, the TXFramework provides support for other Transaction protocols, such as REST-AT and WS-AT.
See the other TXFramework quickstarts for more examples and the README.md file in the directory above, for a more complete
description of what the TXFramework provides.
Please sign in to comment.
Something went wrong with that request. Please try again.