use of org.apache.cxf.ws.rm.RMManager in project cxf by apache.
the class RobustServiceAtMostOnceTest method testRobustAtMostOnceWithSlowProcessing.
@Test
public void testRobustAtMostOnceWithSlowProcessing() throws Exception {
LOG.fine("Creating greeter client");
SpringBusFactory bf = new SpringBusFactory();
bus = bf.createBus("/org/apache/cxf/systest/ws/rm/seqlength1.xml");
// set the client retry interval much shorter than the slow processing delay
RMManager manager = bus.getExtension(RMManager.class);
manager.getConfiguration().setBaseRetransmissionInterval(new Long(3000));
BusFactory.setDefaultBus(bus);
GreeterService gs = new GreeterService();
greeter = gs.getGreeterPort();
updateAddressPort(greeter, PORT);
LOG.fine("Invoking greeter");
greeter.greetMeOneWay("one");
Thread.sleep(10000);
assertEquals("invoked too many times", 1, serverGreeter.getCount());
assertTrue("still in retransmission", manager.getRetransmissionQueue().isEmpty());
}
use of org.apache.cxf.ws.rm.RMManager 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.ws.rm.RMManager 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.ws.rm.RMManager 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.ws.rm.RMManager in project cxf by apache.
the class SequenceTest method testOnewayMessageLoss.
private void testOnewayMessageLoss(Executor executor) throws Exception {
init("org/apache/cxf/systest/ws/rm/message-loss.xml", false, executor);
greeterBus.getOutInterceptors().add(new MessageLossSimulator());
RMManager manager = greeterBus.getExtension(RMManager.class);
manager.getConfiguration().setBaseRetransmissionInterval(new Long(2000));
greeter.greetMeOneWay("one");
greeter.greetMeOneWay("two");
greeter.greetMeOneWay("three");
greeter.greetMeOneWay("four");
awaitMessages(7, 5, 10000);
MessageFlow mf = new MessageFlow(outRecorder.getOutboundMessages(), inRecorder.getInboundMessages(), Names200408.WSA_NAMESPACE_NAME, RM10Constants.NAMESPACE_URI);
// Expected outbound:
// CreateSequence
// + 4 greetMe messages
// + at least 2 resends (message may be resent multiple times depending
// on the timing of the ACKs)
String[] expectedActions = new String[7];
expectedActions[0] = RM10Constants.CREATE_SEQUENCE_ACTION;
for (int i = 1; i < expectedActions.length; i++) {
expectedActions[i] = GREETMEONEWAY_ACTION;
}
mf.verifyActions(expectedActions, true);
mf.verifyMessageNumbers(new String[] { null, "1", "2", "3", "4", "2", "4" }, true, false);
mf.verifyLastMessage(new boolean[7], true);
mf.verifyAcknowledgements(new boolean[7], true);
// Expected inbound:
// createSequenceResponse
// + 2 partial responses to successfully transmitted messages
// + 2 partial responses to resent messages
mf.verifyMessages(5, false);
expectedActions = new String[] { RM10Constants.CREATE_SEQUENCE_RESPONSE_ACTION, RM10Constants.SEQUENCE_ACKNOWLEDGMENT_ACTION, RM10Constants.SEQUENCE_ACKNOWLEDGMENT_ACTION, RM10Constants.SEQUENCE_ACKNOWLEDGMENT_ACTION, RM10Constants.SEQUENCE_ACKNOWLEDGMENT_ACTION };
mf.verifyActions(expectedActions, false);
mf.verifyMessageNumbers(new String[] { null, null, null, null, null }, false);
mf.verifyAcknowledgements(new boolean[] { false, true, true, true, true }, false);
}
Aggregations