@Test public void testSubTransactionCommitRollbackInPrepare() throws Exception { final UserTransaction ut = UserTransactionFactory.userTransaction(); final UserTransaction ust = UserTransactionFactory.userSubordinateTransaction(); final TransactionManager tm = TransactionManager.getTransactionManager(); final DemoDurableParticipant p1 = new DemoDurableParticipant(); final DemoVolatileParticipant p2 = new DemoVolatileParticipant(); final FailureParticipant p3 = new FailureParticipant(FailureParticipant.FAIL_IN_PREPARE, FailureParticipant.NONE); final DemoVolatileParticipant p4 = new DemoVolatileParticipant(); ut.begin(); final TxContext tx = tm.suspend(); tm.resume(tx); tm.enlistForDurableTwoPhase(p1, p1.identifier()); tm.enlistForVolatileTwoPhase(p2, p2.identifier()); ust.begin(); final TxContext stx = tm.suspend(); tm.resume(stx); tm.enlistForDurableTwoPhase(p3, "failure in prepare"); tm.enlistForVolatileTwoPhase(p4, p4.identifier()); tm.resume(tx); try { ut.commit(); fail("expecting TransactionRolledBackException"); } catch (TransactionRolledBackException trbe) { // expect this } assertTrue(p1.prepared() && p1.resolved() && !p1.passed()); assertTrue(p2.prepared() && p2.resolved() && !p2.passed()); assertTrue(!p3.passed()); assertTrue(p4.prepared() && p4.resolved() && !p4.passed()); }
/** * Test the simple scenario where a booking is made and then committed. * * @throws Exception if something goes wrong. */ @Test public void testCommit() throws Exception { System.out.println( "\n\nStarting 'testCommit'. This test invokes a WS within an AT. The AT is later committed, which causes the back-end resource(s) to be committed."); System.out.println("[CLIENT] Creating a new WS-AT User Transaction"); UserTransaction ut = UserTransactionFactory.userTransaction(); try { System.out.println( "[CLIENT] Beginning Atomic Transaction (All calls to Web services that support WS-AT wil be included in this transaction)"); ut.begin(); System.out.println("[CLIENT] invoking makeBooking() on WS"); client.makeBooking(); System.out.println( "[CLIENT] committing Atomic Transaction (This will cause the AT to complete successfully)"); ut.commit(); // Check the booking is visible after the transaction has committed. Assert.assertEquals(1, client.getBookingCount()); } finally { rollbackIfActive(ut); client.reset(); } }
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { /* * Add client handler chain */ BindingProvider bindingProvider = (BindingProvider) client; List<Handler> handlers = new ArrayList<Handler>(1); handlers.add(new JaxWSHeaderContextProcessor()); bindingProvider.getBinding().setHandlerChain(handlers); /* * Lookup the DNS name of the server from the environment and set the endpoint address on the client. */ String openshift = System.getenv("OPENSHIFT_APP_DNS"); if (openshift != null) { bindingProvider .getRequestContext() .put( BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://" + openshift + "/RestaurantServiceAT"); } resp.setContentType("text/html"); PrintWriter out = resp.getWriter(); out.write( "<h1>Quickstart: This example demonstrates the deployment of a WS-AT (WS-AtomicTransaction) enabled JAX-WS Web service bundled in a war archive for deployment to *JBoss Enterprise Application Platform 6*.</h1>"); System.out.println("[CLIENT] Creating a new WS-AT User Transaction"); UserTransaction ut = UserTransactionFactory.userTransaction(); try { System.out.println( "[CLIENT] Beginning Atomic Transaction (All calls to Web services that support WS-AT wil be included in this transaction)"); ut.begin(); System.out.println("[CLIENT] invoking makeBooking() on WS"); client.makeBooking(); System.out.println( "[CLIENT] committing Atomic Transaction (This will cause the AT to complete successfully)"); ut.commit(); out.write("<p><b>Transaction succeeded!</b></p>"); } catch (Exception e) { e.printStackTrace(); out.write("<p><b>Transaction failed with the following error:</b></p>"); out.write("<p><blockquote>"); out.write(e.toString()); out.write("</blockquote></p>"); } finally { rollbackIfActive(ut); client.reset(); out.write( "<p><i>Go to your JBoss Application Server console or Server log to see the detailed result of the transaction.</i></p>"); } }
@Before public void setupTest() throws Exception { ut = UserTransactionFactory.userTransaction(); client = ATStatefullClient.newInstance(); }