use of org.apache.cxf.systest.ws.util.MessageFlow in project cxf by apache.
the class SequenceTest method testMultiClientTwoway.
@Test
public void testMultiClientTwoway() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
String cfgResource = "org/apache/cxf/systest/ws/rm/rminterceptors.xml";
initControl(bf, cfgResource);
class ClientThread extends Thread {
Greeter greeter;
Bus greeterBus;
InMessageRecorder inRecorder;
OutMessageRecorder outRecorder;
String id;
ClientThread(SpringBusFactory bf, String cfgResource, int n) {
super("client " + n);
SequenceTest.this.initGreeter(bf, cfgResource, true, null);
greeter = SequenceTest.this.greeter;
greeterBus = SequenceTest.this.greeterBus;
inRecorder = SequenceTest.this.inRecorder;
outRecorder = SequenceTest.this.outRecorder;
id = "client " + n;
}
public void run() {
String s = greeter.greetMe(id + ": a").toLowerCase();
if (!s.contains(id)) {
System.out.println("Correlation problem <" + s + "> <" + id + ">");
}
s = greeter.greetMe(id + ": b").toLowerCase();
if (!s.contains(id)) {
System.out.println("Correlation problem <" + s + "> <" + id + ">");
}
s = greeter.greetMe(id + ": c").toLowerCase();
if (!s.contains(id)) {
System.out.println("Correlation problem <" + s + "> <" + id + ">");
}
// three application messages plus createSequence
awaitMessages(5, 4);
}
}
ClientThread[] clients = new ClientThread[2];
try {
for (int i = 0; i < clients.length; i++) {
clients[i] = new ClientThread(bf, cfgResource, i);
}
for (int i = 0; i < clients.length; i++) {
clients[i].start();
}
for (int i = 0; i < clients.length; i++) {
clients[i].join();
}
for (int i = 0; i < clients.length; i++) {
MessageFlow mf = new MessageFlow(clients[i].outRecorder.getOutboundMessages(), clients[i].inRecorder.getInboundMessages(), Names200408.WSA_NAMESPACE_NAME, RM10Constants.NAMESPACE_URI);
mf.verifyMessages(5, true);
String[] expectedActions = new String[] { RM10Constants.CREATE_SEQUENCE_ACTION, GREETME_ACTION, GREETME_ACTION, GREETME_ACTION, RM10Constants.SEQUENCE_ACKNOWLEDGMENT_ACTION };
mf.verifyActions(expectedActions, true);
mf.verifyMessageNumbers(new String[] { null, "1", "2", "3", null }, true);
mf.verifyLastMessage(new boolean[] { false, false, false, false, false }, true);
mf.verifyAcknowledgements(new boolean[] { false, false, true, true, true }, true);
// createSequenceResponse plus 3 greetMeResponse messages plus
// one sequence ack response.
mf.verifyMessages(4, false);
expectedActions = new String[] { RM10Constants.CREATE_SEQUENCE_RESPONSE_ACTION, GREETME_RESPONSE_ACTION, GREETME_RESPONSE_ACTION, GREETME_RESPONSE_ACTION };
mf.verifyActions(expectedActions, false);
mf.verifyMessageNumbers(new String[] { null, "1", "2", "3" }, false);
mf.verifyLastMessage(new boolean[4], false);
mf.verifyAcknowledgements(new boolean[] { false, true, true, true }, false);
}
} finally {
for (int i = 0; i < clients.length; i++) {
greeter = clients[i].greeter;
greeterBus = clients[i].greeterBus;
stopClient();
}
greeter = null;
}
}
use of org.apache.cxf.systest.ws.util.MessageFlow in project cxf by apache.
the class SequenceTest method testInactivityTimeout.
@Test
public void testInactivityTimeout() throws Exception {
init("org/apache/cxf/systest/ws/rm/inactivity-timeout.xml");
greeter.greetMe("one");
try {
Thread.sleep(500);
} catch (InterruptedException ex) {
// ignore
}
try {
greeter.greetMe("two");
fail("Expected fault.");
} catch (WebServiceException ex) {
SoapFault sf = (SoapFault) ex.getCause();
assertEquals("Unexpected fault code.", Soap11.getInstance().getSender(), sf.getFaultCode());
assertNull("Unexpected sub code.", sf.getSubCode());
assertTrue("Unexpected reason.", sf.getReason().endsWith("is not a known Sequence identifier."));
}
awaitMessages(3, 3, 5000);
MessageFlow mf = new MessageFlow(outRecorder.getOutboundMessages(), inRecorder.getInboundMessages(), Names200408.WSA_NAMESPACE_NAME, RM10Constants.NAMESPACE_URI);
// Expected outbound:
// CreateSequence
// + two requests (second request does not include acknowledgement for first response as
// in the meantime the client has terminated the sequence
String[] expectedActions = new String[3];
expectedActions[0] = RM10Constants.CREATE_SEQUENCE_ACTION;
for (int i = 1; i < expectedActions.length; i++) {
expectedActions[i] = GREETME_ACTION;
}
mf.verifyActions(expectedActions, true);
mf.verifyMessageNumbers(new String[] { null, "1", "2" }, true);
mf.verifyLastMessage(new boolean[3], true);
mf.verifyAcknowledgements(new boolean[] { false, false, false }, true);
// Expected inbound:
// createSequenceResponse
// + 1 response with acknowledgement
// + 1 fault without acknowledgement
mf.verifyMessages(3, false);
expectedActions = new String[] { RM10Constants.CREATE_SEQUENCE_RESPONSE_ACTION, GREETME_RESPONSE_ACTION, RM10_GENERIC_FAULT_ACTION };
mf.verifyActions(expectedActions, false);
mf.verifyMessageNumbers(new String[] { null, "1", null }, false);
mf.verifyAcknowledgements(new boolean[] { false, true, false }, false);
// the third inbound message has a SequenceFault header
mf.verifySequenceFault(RM10Constants.UNKNOWN_SEQUENCE_FAULT_QNAME, false, 2);
}
use of org.apache.cxf.systest.ws.util.MessageFlow in project cxf by apache.
the class SequenceTest method testOnewayDeferredNonAnonymousAcks.
@Test
public void testOnewayDeferredNonAnonymousAcks() throws Exception {
init("org/apache/cxf/systest/ws/rm/deferred.xml", true);
greeter.greetMeOneWay("once");
greeter.greetMeOneWay("twice");
// CreateSequence plus two greetMeOneWay requests
awaitMessages(3, 1);
MessageFlow mf = new MessageFlow(outRecorder.getOutboundMessages(), inRecorder.getInboundMessages(), Names200408.WSA_NAMESPACE_NAME, RM10Constants.NAMESPACE_URI);
mf.verifyMessages(3, true);
String[] expectedActions = new String[] { RM10Constants.CREATE_SEQUENCE_ACTION, GREETMEONEWAY_ACTION, GREETMEONEWAY_ACTION };
mf.verifyActions(expectedActions, true);
mf.verifyMessageNumbers(new String[] { null, "1", "2" }, true);
// CreateSequenceResponse plus three partial responses, no
// acknowledgments included
mf.verifyMessages(1, false);
mf.verifyMessageNumbers(new String[1], false);
mf.verifyAcknowledgements(new boolean[1], false);
expectedActions = new String[] { RM10Constants.CREATE_SEQUENCE_RESPONSE_ACTION };
mf.verifyActionsIgnoringPartialResponses(expectedActions);
mf.purge();
try {
Thread.sleep(3 * 1000);
} catch (InterruptedException ex) {
// ignore
}
// a standalone acknowledgement should have been sent from the server
// side by now
awaitMessages(0, 1);
mf.reset(outRecorder.getOutboundMessages(), inRecorder.getInboundMessages());
mf.verifyMessages(0, true);
mf.verifyMessages(1, false);
mf.verifyAcknowledgements(new boolean[] { true }, false);
}
use of org.apache.cxf.systest.ws.util.MessageFlow in project cxf by apache.
the class SequenceTest method testTwowayNonAnonymousDeferred.
@Test
public void testTwowayNonAnonymousDeferred() throws Exception {
init("org/apache/cxf/systest/ws/rm/deferred.xml", true);
greeter.greetMe("one");
greeter.greetMe("two");
// CreateSequence and three greetMe messages, no acknowledgments
// included
awaitMessages(3, 3);
MessageFlow mf = new MessageFlow(outRecorder.getOutboundMessages(), inRecorder.getInboundMessages(), Names200408.WSA_NAMESPACE_NAME, RM10Constants.NAMESPACE_URI);
mf.verifyMessages(3, true);
String[] expectedActions = new String[] { RM10Constants.CREATE_SEQUENCE_ACTION, GREETME_ACTION, GREETME_ACTION };
mf.verifyActions(expectedActions, true);
mf.verifyMessageNumbers(new String[] { null, "1", "2" }, true);
mf.verifyLastMessage(new boolean[3], true);
mf.verifyAcknowledgements(new boolean[3], true);
// CreateSequenceResponse plus 2 greetMeResponse messages plus
// one partial response for each of the three messages no acknowledgments
// included
mf.verifyMessages(3, false);
mf.verifyLastMessage(new boolean[3], false);
mf.verifyAcknowledgements(new boolean[3], false);
expectedActions = new String[] { RM10Constants.CREATE_SEQUENCE_RESPONSE_ACTION, GREETME_RESPONSE_ACTION, GREETME_RESPONSE_ACTION };
mf.verifyActions(expectedActions, false);
mf.verifyMessageNumbers(new String[] { null, "1", "2" }, false);
mf.purge();
// one standalone acknowledgement should have been sent from the client and one
// should have been received from the server
awaitMessages(1, 0);
mf.reset(outRecorder.getOutboundMessages(), inRecorder.getInboundMessages());
mf.verifyMessageNumbers(new String[1], true);
mf.verifyLastMessage(new boolean[1], true);
mf.verifyAcknowledgements(new boolean[] { true }, true);
}
use of org.apache.cxf.systest.ws.util.MessageFlow in project cxf by apache.
the class SequenceTest method testCreateSequenceRefused.
@Test
public void testCreateSequenceRefused() throws Exception {
init("org/apache/cxf/systest/ws/rm/limit-seqs.xml");
RMManager manager = greeterBus.getExtension(RMManager.class);
assertEquals("Unexpected maximum sequence count.", 1, manager.getDestinationPolicy().getMaxSequences());
greeter.greetMe("one");
// hold onto the greeter to keep the sequence open
Closeable oldGreeter = (Closeable) greeter;
// force greeter to be re-initialized so that a new sequence is created
initProxy(false, null);
try {
greeter.greetMe("two");
fail("Expected fault.");
} catch (WebServiceException ex) {
// sequence creation refused
}
// the third inbound message has a SequenceFault header
MessageFlow mf = new MessageFlow(outRecorder.getOutboundMessages(), inRecorder.getInboundMessages(), Names200408.WSA_NAMESPACE_NAME, RM10Constants.NAMESPACE_URI);
mf.verifySequenceFault(RM10Constants.CREATE_SEQUENCE_REFUSED_FAULT_QNAME, false, 2);
String[] expectedActions = new String[3];
expectedActions = new String[] { RM10Constants.CREATE_SEQUENCE_RESPONSE_ACTION, GREETME_RESPONSE_ACTION, RM10_GENERIC_FAULT_ACTION };
mf.verifyActions(expectedActions, false);
// now close the old greeter to cleanup the sequence
oldGreeter.close();
}
Aggregations