use of org.apache.cxf.systest.ws.util.MessageFlow in project cxf by apache.
the class SequenceTest method doTestTwowayNoDuplicates.
private void doTestTwowayNoDuplicates(String cfg) throws Exception {
init(cfg);
class MessageNumberInterceptor extends AbstractPhaseInterceptor<Message> {
MessageNumberInterceptor() {
super(Phase.PRE_STREAM);
}
public void handleMessage(Message m) {
RMProperties rmps = RMContextUtils.retrieveRMProperties(m, true);
if (null != rmps && null != rmps.getSequence()) {
rmps.getSequence().setMessageNumber(new Long(1));
}
}
}
greeterBus.getOutInterceptors().add(new MessageNumberInterceptor());
RMManager manager = greeterBus.getExtension(RMManager.class);
manager.getConfiguration().setBaseRetransmissionInterval(new Long(2000));
greeter.greetMe("one");
try {
((BindingProvider) greeter).getRequestContext().put("cxf.synchronous.timeout", 5000);
String s = greeter.greetMe("two");
fail("Expected timeout. Received response: " + s);
} catch (WebServiceException ex) {
assertTrue("Unexpected exception cause", ex.getCause() instanceof IOException);
IOException ie = (IOException) ex.getCause();
assertTrue("Unexpected IOException message", ie.getMessage().startsWith("Timed out"));
}
// wait for resend to occur
awaitMessages(4, 3, 5000);
MessageFlow mf = new MessageFlow(outRecorder.getOutboundMessages(), inRecorder.getInboundMessages(), Names200408.WSA_NAMESPACE_NAME, RM10Constants.NAMESPACE_URI);
// Expected outbound:
// CreateSequence
// + two requests
// + acknowledgement
String[] expectedActions = new String[4];
expectedActions[0] = RM10Constants.CREATE_SEQUENCE_ACTION;
expectedActions[1] = GREETME_ACTION;
expectedActions[2] = GREETME_ACTION;
expectedActions[3] = RM10Constants.SEQUENCE_ACKNOWLEDGMENT_ACTION;
mf.verifyActions(expectedActions, true);
mf.verifyMessageNumbers(new String[] { null, "1", "1", null }, true);
mf.verifyLastMessage(new boolean[expectedActions.length], true);
mf.verifyAcknowledgements(new boolean[] { false, false, false, true }, true);
// Expected inbound:
// createSequenceResponse
// + 1 response without acknowledgement
// + 1 acknowledgement/last message
mf.verifyMessages(3, false);
expectedActions = new String[] { RM10Constants.CREATE_SEQUENCE_RESPONSE_ACTION, GREETME_RESPONSE_ACTION, RM10Constants.SEQUENCE_ACKNOWLEDGMENT_ACTION };
mf.verifyActions(expectedActions, false);
mf.verifyMessageNumbers(new String[] { null, "1", null }, false);
mf.verifyAcknowledgements(new boolean[] { false, false, true }, false);
}
use of org.apache.cxf.systest.ws.util.MessageFlow in project cxf by apache.
the class SequenceTest method testTwowayAnonymousSequenceLength1.
@Test
public void testTwowayAnonymousSequenceLength1() throws Exception {
init("org/apache/cxf/systest/ws/rm/seqlength1.xml");
String v = greeter.greetMe("once");
assertEquals("Unexpected response", "ONCE", v);
// outbound: CS, greetReq, TS, SA
// inbound: CSR, greetResp+SA, , TS
awaitMessages(4, 3);
MessageFlow mf = new MessageFlow(outRecorder.getOutboundMessages(), inRecorder.getInboundMessages(), Names200408.WSA_NAMESPACE_NAME, RM10Constants.NAMESPACE_URI);
mf.verifyMessages(4, true);
String[] expectedActions = new String[] { RM10Constants.CREATE_SEQUENCE_ACTION, GREETME_ACTION, RM10Constants.TERMINATE_SEQUENCE_ACTION, RM10Constants.SEQUENCE_ACKNOWLEDGMENT_ACTION };
mf.verifyActions(expectedActions, true);
mf.verifyMessageNumbers(new String[] { null, "1", null, null }, true);
mf.verifyLastMessage(new boolean[] { false, true, false, false }, true);
mf.verifyAcknowledgements(new boolean[] { false, false, false, true }, true);
mf.verifyMessages(3, false);
expectedActions = new String[] { RM10Constants.CREATE_SEQUENCE_RESPONSE_ACTION, GREETME_RESPONSE_ACTION, RM10Constants.TERMINATE_SEQUENCE_ACTION };
mf.verifyActions(expectedActions, false);
mf.verifyMessageNumbers(new String[] { null, "1", null }, false);
mf.verifyLastMessage(new boolean[] { false, true, false }, false);
mf.verifyAcknowledgements(new boolean[] { false, true, false }, false);
}
use of org.apache.cxf.systest.ws.util.MessageFlow in project cxf by apache.
the class SequenceTest method testCreateSequenceAfterSequenceExpiration.
@Test
public void testCreateSequenceAfterSequenceExpiration() throws Exception {
init("org/apache/cxf/systest/ws/rm/expire-fast-seq.xml", true);
RMManager manager = greeterBus.getExtension(RMManager.class);
assertEquals("Unexpected expiration", DatatypeFactory.createDuration("PT5S"), manager.getSourcePolicy().getSequenceExpiration());
// phase one
greeter.greetMeOneWay("one");
greeter.greetMeOneWay("two");
// let the first sequence expire
Thread.sleep(8000);
// expecting 3 outbounds and 2 inbounds
awaitMessages(3, 2, 5000);
MessageFlow mf = new MessageFlow(outRecorder.getOutboundMessages(), inRecorder.getInboundMessages(), Names200408.WSA_NAMESPACE_NAME, RM10Constants.NAMESPACE_URI);
// CS, GA, GA
mf.verifyMessages(3, true);
verifyCreateSequenceAction(0, "PT5S", mf, true);
String[] expectedActions = new String[] { RM10Constants.INSTANCE.getCreateSequenceAction(), GREETMEONEWAY_ACTION, GREETMEONEWAY_ACTION };
mf.verifyActions(expectedActions, true);
mf.verifyMessageNumbers(new String[] { null, "1", "2" }, true);
mf.verifyAcknowledgementRange(1, 2);
// phase two
outRecorder.getOutboundMessages().clear();
inRecorder.getInboundMessages().clear();
greeter.greetMeOneWay("three");
// expecting 2 outbounds and 2 inbounds
awaitMessages(2, 2, 5000);
mf = new MessageFlow(outRecorder.getOutboundMessages(), inRecorder.getInboundMessages(), Names200408.WSA_NAMESPACE_NAME, RM10Constants.NAMESPACE_URI);
// CS, GA
mf.verifyMessages(2, true);
verifyCreateSequenceAction(0, "PT5S", mf, true);
expectedActions = new String[] { RM10Constants.INSTANCE.getCreateSequenceAction(), GREETMEONEWAY_ACTION };
mf.verifyActions(expectedActions, true);
mf.verifyMessageNumbers(new String[] { null, "1" }, true);
// PR, CSR, PR, ACK
mf.verifyMessages(2, false);
expectedActions = new String[] { RM10Constants.INSTANCE.getCreateSequenceResponseAction(), RM10Constants.INSTANCE.getSequenceAckAction() };
mf.verifyActions(expectedActions, false);
mf.purge();
assertEquals(0, outRecorder.getOutboundMessages().size());
assertEquals(0, inRecorder.getInboundMessages().size());
}
use of org.apache.cxf.systest.ws.util.MessageFlow in project cxf by apache.
the class SequenceTest method testUnknownSequence.
@Test
public void testUnknownSequence() throws Exception {
init("org/apache/cxf/systest/ws/rm/rminterceptors.xml");
class SequenceIdInterceptor extends AbstractPhaseInterceptor<Message> {
SequenceIdInterceptor() {
super(Phase.PRE_STREAM);
}
public void handleMessage(Message m) {
RMProperties rmps = RMContextUtils.retrieveRMProperties(m, true);
if (null != rmps && null != rmps.getSequence()) {
rmps.getSequence().getIdentifier().setValue("UNKNOWN");
}
}
}
greeterBus.getOutInterceptors().add(new SequenceIdInterceptor());
RMManager manager = greeterBus.getExtension(RMManager.class);
manager.getConfiguration().setBaseRetransmissionInterval(new Long(2000));
try {
greeter.greetMe("one");
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."));
}
// 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.UNKNOWN_SEQUENCE_FAULT_QNAME, false, 1);
String[] expectedActions = new String[3];
expectedActions = new String[] { RM10Constants.CREATE_SEQUENCE_RESPONSE_ACTION, RM10_GENERIC_FAULT_ACTION };
mf.verifyActions(expectedActions, false);
}
use of org.apache.cxf.systest.ws.util.MessageFlow in project cxf by apache.
the class SequenceTest method testOnewayAnonymousAcksSuppressed.
private void testOnewayAnonymousAcksSuppressed(Executor executor) throws Exception {
init("org/apache/cxf/systest/ws/rm/suppressed.xml", false, executor);
greeter.greetMeOneWay("once");
greeter.greetMeOneWay("twice");
greeter.greetMeOneWay("thrice");
// three application messages plus createSequence
awaitMessages(4, 1, 2000);
MessageFlow mf = new MessageFlow(outRecorder.getOutboundMessages(), inRecorder.getInboundMessages(), Names200408.WSA_NAMESPACE_NAME, RM10Constants.NAMESPACE_URI);
mf.verifyMessages(4, true);
String[] expectedActions = new String[] { RM10Constants.CREATE_SEQUENCE_ACTION, GREETMEONEWAY_ACTION, GREETMEONEWAY_ACTION, GREETMEONEWAY_ACTION };
mf.verifyActions(expectedActions, true);
mf.verifyMessageNumbers(new String[] { null, "1", "2", "3" }, true);
// createSequenceResponse plus 3 partial responses, none of which
// contain an acknowledgment
mf.verifyMessages(1, false);
expectedActions = new String[] { RM10Constants.CREATE_SEQUENCE_RESPONSE_ACTION };
mf.verifyActions(expectedActions, false);
mf.purge();
assertEquals(0, outRecorder.getOutboundMessages().size());
assertEquals(0, inRecorder.getInboundMessages().size());
// allow resends to kick in
// first duplicate received will trigger acknowledgement
awaitMessages(1, 1, 3000);
mf.reset(outRecorder.getOutboundMessages(), inRecorder.getInboundMessages());
mf.verifyMessages(1, true);
mf.verifyMessages(1, false);
mf.verifyAcknowledgements(new boolean[] { true }, false);
}
Aggregations