use of org.jboss.jbossts.xts.servicetests.generated.ResultsType in project narayana by jbosstm.
the class XTSServiceTestPortTypeImpl method serve.
/**
* @param commands
* @return
* returns org.jboss.jbossts.xts.servicetests.generated.ResultsType
*/
@WebMethod
@WebResult(name = "results", targetNamespace = "http://jbossts.jboss.org/xts/servicetests/generated", partName = "results")
public ResultsType serve(@WebParam(name = "commands", targetNamespace = "http://jbossts.jboss.org/xts/servicetests/generated", partName = "commands") CommandsType commands) {
ResultsType results = new ResultsType();
List<String> resultsList = results.getResultList();
List<String> commandList = commands.getCommandList();
MessageContext messageContext = context.getMessageContext();
HttpServletRequest servletRequest = ((HttpServletRequest) messageContext.get(MessageContext.SERVLET_REQUEST));
String path = servletRequest.getServletPath();
System.out.println("service " + path);
for (String s : commandList) {
System.out.println(" command " + s);
}
XTSServiceTestInterpreter service = XTSServiceTestInterpreter.getService(path);
service.processCommands(commandList, resultsList);
return results;
}
use of org.jboss.jbossts.xts.servicetests.generated.ResultsType in project narayana by jbosstm.
the class XTSServiceTestInterpreter method processCommands.
// / implementation of the interpreter functionality
/**
* simple command interpreter which executes the commands in the command list, inserting the
* corresponding results in the results list and using the supplied bindings list
* to provide values for any parameters supplied in the commands and to bind any results
* obtained by executing the commands
*
* @param commandList a list of command strings
* @param resultsList a list into which results strings are to be inserted
* @param bindings a list of bound variables to be substituted into commands
* or updated with new bindings
*/
private void processCommands(List<String> commandList, List<String> resultsList, HashMap<String, String> bindings) throws WebServiceException {
int size = commandList.size();
if (size == 0) {
throw new WebServiceException("empty command list");
}
String command = commandList.remove(0);
size--;
if (command.equals("block")) {
// we don't bind the command block immediately since bindings may be produced
// by intermediate bind commands
processCommandBlock(commandList, resultsList, bindings);
} else {
int idx = 0;
if (command.equals("enlistDurable")) {
// enlistment commands
bindCommands(commandList, bindings);
String id = participantId("DurableTestParticipant");
DurableTestParticipant participant = new DurableTestParticipant(id);
TransactionManager txman = TransactionManagerFactory.transactionManager();
try {
txman.enlistForDurableTwoPhase(participant, id);
} catch (Exception e) {
throw new WebServiceException("enlistDurable failed ", e);
}
for (idx = 0; idx < size; idx++) {
participant.addCommand(commandList.get(idx));
}
participantMap.put(id, participant);
resultsList.add(id);
} else if (command.equals("enlistVolatile")) {
bindCommands(commandList, bindings);
String id = participantId("VolatileTestParticipant");
VolatileTestParticipant participant = new VolatileTestParticipant(id);
TransactionManager txman = TransactionManagerFactory.transactionManager();
try {
txman.enlistForVolatileTwoPhase(participant, id);
} catch (Exception e) {
throw new WebServiceException("enlistVolatile failed ", e);
}
for (idx = 0; idx < size; idx++) {
participant.addCommand(commandList.get(idx));
}
participantMap.put(id, participant);
resultsList.add(id);
} else if (command.equals("enlistCoordinatorCompletion")) {
bindCommands(commandList, bindings);
String id = participantId("CoordinatorCompletionParticipant");
CoordinatorCompletionTestParticipant participant = new CoordinatorCompletionTestParticipant(id);
BusinessActivityManager baman = BusinessActivityManagerFactory.businessActivityManager();
try {
BAParticipantManager partMan;
partMan = baman.enlistForBusinessAgreementWithCoordinatorCompletion(participant, id);
managerMap.put(id, partMan);
} catch (Exception e) {
throw new WebServiceException("enlistCoordinatorCompletion failed ", e);
}
for (idx = 0; idx < size; idx++) {
participant.addCommand(commandList.get(idx));
}
participantMap.put(id, participant);
resultsList.add(id);
} else if (command.equals("enlistParticipantCompletion")) {
bindCommands(commandList, bindings);
String id = participantId("ParticipantCompletionParticipant");
ParticipantCompletionTestParticipant participant = new ParticipantCompletionTestParticipant(id);
BusinessActivityManager baman = BusinessActivityManagerFactory.businessActivityManager();
try {
BAParticipantManager partMan;
partMan = baman.enlistForBusinessAgreementWithParticipantCompletion(participant, id);
managerMap.put(id, partMan);
} catch (Exception e) {
throw new WebServiceException("enlistParticipantCompletion failed ", e);
}
for (idx = 0; idx < size; idx++) {
participant.addCommand(commandList.get(idx));
}
participantMap.put(id, participant);
resultsList.add(id);
} else if (command.equals("addCommands")) {
// add extra commands to a participant script
bindCommands(commandList, bindings);
String id = commandList.remove(idx);
size--;
ScriptedTestParticipant participant = participantMap.get(id);
if (participant != null) {
for (idx = 0; idx < size; idx++) {
participant.addCommand(commandList.get(idx));
}
resultsList.add("ok");
} else {
throw new WebServiceException("addCommands failed to find participant " + id);
}
} else if (command.equals("exit")) {
// initiate BA manager activities
bindCommands(commandList, bindings);
String id = commandList.remove(idx);
size--;
ScriptedTestParticipant participant = participantMap.get(id);
if (participant != null) {
if (participant instanceof ParticipantCompletionTestParticipant) {
ParticipantCompletionTestParticipant baparticipant = (ParticipantCompletionTestParticipant) participant;
BAParticipantManager manager = managerMap.get(id);
try {
manager.exit();
} catch (Exception e) {
throw new WebServiceException("exit " + id + " failed with exception " + e);
}
resultsList.add("ok");
} else {
throw new WebServiceException("exit invalid participant type " + id);
}
} else {
throw new WebServiceException("exit unknown participant " + id);
}
} else if (command.equals("completed")) {
bindCommands(commandList, bindings);
String id = commandList.remove(idx);
size--;
ScriptedTestParticipant participant = participantMap.get(id);
if (participant != null) {
if (participant instanceof ParticipantCompletionTestParticipant) {
ParticipantCompletionTestParticipant baparticipant = (ParticipantCompletionTestParticipant) participant;
BAParticipantManager manager = managerMap.get(id);
try {
manager.completed();
resultsList.add("ok");
} catch (Exception e) {
throw new WebServiceException("completed " + id + " failed with exception " + e);
}
} else {
throw new WebServiceException("completed invalid participant type " + id);
}
} else {
throw new WebServiceException("completed unknown participant " + id);
}
} else if (command.equals("fail")) {
bindCommands(commandList, bindings);
String id = commandList.remove(idx);
size--;
ScriptedTestParticipant participant = participantMap.get(id);
if (participant != null) {
if (participant instanceof ParticipantCompletionTestParticipant) {
ParticipantCompletionTestParticipant baparticipant = (ParticipantCompletionTestParticipant) participant;
BAParticipantManager manager = managerMap.get(id);
QName qname = new QName("http://jbossts.jboss.org/xts/servicetests/", "fail");
try {
manager.fail(qname);
resultsList.add("ok");
} catch (Exception e) {
throw new WebServiceException("fail " + id + " failed with exception " + e);
}
} else {
throw new WebServiceException("fail invalid participant type " + id);
}
} else {
throw new WebServiceException("fail unknown participant " + id);
}
} else if (command.equals("cannotComplete")) {
bindCommands(commandList, bindings);
String id = commandList.remove(idx);
size--;
ScriptedTestParticipant participant = participantMap.get(id);
if (participant != null) {
if (participant instanceof ParticipantCompletionTestParticipant) {
ParticipantCompletionTestParticipant baparticipant = (ParticipantCompletionTestParticipant) participant;
BAParticipantManager manager = managerMap.get(id);
try {
manager.cannotComplete();
resultsList.add("ok");
} catch (Exception e) {
throw new WebServiceException("cannotComplete " + id + " failed with exception " + e);
}
} else {
throw new WebServiceException("cannotComplete invalid participant type " + id);
}
} else {
throw new WebServiceException("cannotComplete unknown participant " + id);
}
} else if (command.equals("serve")) {
// dispatch commands to a server for execution
// we should find a web service URL and a list of commands to dispatch to that service
String url = commandList.remove(idx);
size--;
// we throw an error if the server url is unbound but we allow
// unbound variables in the command list passed on to the server
// since they may be bound by bind commands in the command list
// being served.
url = bindCommand(url, bindings, true);
bindCommands(commandList, bindings, false);
CommandsType newCommands = new CommandsType();
List<String> newCommandList = newCommands.getCommandList();
for (int i = 0; i < size; i++) {
newCommandList.add(commandList.get(i));
}
ResultsType subResults = serveSubordinate(url, newCommands);
List<String> subResultsList = subResults.getResultList();
size = subResultsList.size();
for (idx = 0; idx < size; idx++) {
resultsList.add(subResultsList.get(idx));
}
} else if (command.equals("subtransaction")) {
// create subordinate AT transaction
// this is surplus to requirements since we should really be running against a service which uses
// the subordinate interposition JaxWS handler to install a subordinate transaction before
// entering the service method. we ought to test that handler rather than hand crank the
// interposition in the service
TxContext currentTx;
TxContext newTx;
try {
currentTx = TransactionManager.getTransactionManager().currentTransaction();
} catch (SystemException e) {
throw new WebServiceException("subtransaction currentTransaction() failed with exception " + e);
}
try {
UserTransaction userTransaction = UserTransactionFactory.userSubordinateTransaction();
userTransaction.begin();
newTx = TransactionManager.getTransactionManager().currentTransaction();
} catch (Exception e) {
throw new WebServiceException("subtransaction begin() failed with exception " + e);
}
String id = transactionId("at");
subordinateTransactionMap.put(id, newTx);
resultsList.add(id);
} else if (command.equals("subactivity")) {
// create subordinate BA transaction
// this is surplus ot requirements since we should really be running against a service which uses
// the subordinate interposition JaxWS handler to install a subordinate activity before
// entering the service method. we ought to test that handler rather than hand crank the
// interposition in the service
TxContext currentTx;
TxContext newTx;
try {
currentTx = BusinessActivityManagerFactory.businessActivityManager().currentTransaction();
} catch (SystemException e) {
throw new WebServiceException("subtransaction currentTransaction() failed with exception " + e);
}
try {
UserBusinessActivity userBusinessActivity = UserBusinessActivityFactory.userBusinessActivity();
// this is nto implemented yet!!!
// userBusinessActivity.beginSubordinate();
// and this will fail with a WrongStateException
userBusinessActivity.begin();
newTx = BusinessActivityManager.getBusinessActivityManager().currentTransaction();
} catch (Exception e) {
throw new WebServiceException("subtransaction begin() failed with exception " + e);
}
String id = transactionId("ba");
subordinateActivityMap.put(id, newTx);
resultsList.add(id);
} else if (command.equals("subtransactionserve")) {
// dispatch commands in a subordinate transaction or activity
// we should find the id of a subordinate transaction, a web service URL
// and a list of commands to dispatch to that transaction
// the txid and url must be resolved if supplied as bindings
String txId = bindCommand(commandList.remove(idx), bindings, true);
size--;
String url = bindCommand(commandList.remove(idx), bindings, true);
size--;
TxContext newTx = subordinateTransactionMap.get(txId);
if (newTx != null) {
try {
TransactionManager.getTransactionManager().resume(newTx);
} catch (Exception e) {
throw new WebServiceException("subtransactioncommands resume() failed with exception " + e);
}
} else {
throw new WebServiceException("subtransactioncommands unknown subordinate transaction id " + txId);
}
// ok, now we install the relevant transaction and then just pass the commands on to
// the web service
// we allow unresolved variable references in the rest of the command list as
// they may be satisfied by embedded bind commands
bindCommands(commandList, bindings, false);
CommandsType newCommands = new CommandsType();
List<String> newCommandList = newCommands.getCommandList();
for (int i = 0; i < size; i++) {
newCommandList.add(commandList.get(i));
}
ResultsType subResults = serveSubordinate(url, newCommands);
List<String> subResultsList = subResults.getResultList();
size = subResultsList.size();
for (idx = 0; idx < size; idx++) {
resultsList.add(subResultsList.get(idx));
}
} else if (command.equals("subactivityserve")) {
// dispatch commands in a subordinate transaction or activity
// we should find the id of a subordinate transaction, a web service URL
// and a list of commands to dispatch to that transaction
// the txid and url must be resolved if supplied as bindings
String txId = bindCommand(commandList.remove(idx), bindings, true);
size--;
String url = bindCommand(commandList.remove(idx), bindings, true);
size--;
TxContext newTx = subordinateActivityMap.get(txId);
if (newTx != null) {
try {
TransactionManager.getTransactionManager().resume(newTx);
} catch (Exception e) {
throw new WebServiceException("subactivitycommands resume() failed with exception " + e);
}
} else {
throw new WebServiceException("subactivitycommands unknown subordinate transaction id " + txId);
}
// ok, now we install the relevant transaction and then just pass the commands on to
// the web service
// we allow unresolved variable references in the rest of the command list as
// they may be satisfied by embedded bind commands
bindCommands(commandList, bindings, false);
CommandsType newCommands = new CommandsType();
List<String> newCommandList = newCommands.getCommandList();
for (int i = 0; i < size; i++) {
newCommandList.add(commandList.get(i));
}
ResultsType subResults = serveSubordinate(url, newCommands);
List<String> subResultsList = subResults.getResultList();
size = subResultsList.size();
for (idx = 0; idx < size; idx++) {
resultsList.add(subResultsList.get(idx));
}
}
}
}
use of org.jboss.jbossts.xts.servicetests.generated.ResultsType in project narayana by jbosstm.
the class XTSSubordinateServiceTestPortTypeImpl method serve.
/**
* @param commands
* @return
* returns org.jboss.jbossts.xts.servicetests.generated.ResultsType
*/
@WebMethod
@WebResult(name = "results", targetNamespace = "http://jbossts.jboss.org/xts/servicetests/generated", partName = "results")
public ResultsType serve(@WebParam(name = "commands", targetNamespace = "http://jbossts.jboss.org/xts/servicetests/generated", partName = "commands") CommandsType commands) {
ResultsType results = new ResultsType();
List<String> resultsList = results.getResultList();
List<String> commandList = commands.getCommandList();
MessageContext messageContext = context.getMessageContext();
HttpServletRequest servletRequest = ((HttpServletRequest) messageContext.get(MessageContext.SERVLET_REQUEST));
String path = servletRequest.getServletPath();
System.out.println("service " + path);
for (String s : commandList) {
System.out.println(" command " + s);
}
XTSServiceTestInterpreter service = XTSServiceTestInterpreter.getService(path);
service.processCommands(commandList, resultsList);
return results;
}
Aggregations