Search in sources :

Example 26 with MessageFlow

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);
}
Also used : RMMessage(org.apache.cxf.ws.rm.persistence.RMMessage) Message(org.apache.cxf.message.Message) WebServiceException(javax.xml.ws.WebServiceException) RMManager(org.apache.cxf.ws.rm.RMManager) AbstractPhaseInterceptor(org.apache.cxf.phase.AbstractPhaseInterceptor) IOException(java.io.IOException) MessageFlow(org.apache.cxf.systest.ws.util.MessageFlow) RMProperties(org.apache.cxf.ws.rm.RMProperties)

Example 27 with MessageFlow

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);
}
Also used : MessageFlow(org.apache.cxf.systest.ws.util.MessageFlow) Test(org.junit.Test)

Example 28 with MessageFlow

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());
}
Also used : RMManager(org.apache.cxf.ws.rm.RMManager) MessageFlow(org.apache.cxf.systest.ws.util.MessageFlow) Test(org.junit.Test)

Example 29 with MessageFlow

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);
}
Also used : SoapFault(org.apache.cxf.binding.soap.SoapFault) RMMessage(org.apache.cxf.ws.rm.persistence.RMMessage) Message(org.apache.cxf.message.Message) WebServiceException(javax.xml.ws.WebServiceException) RMManager(org.apache.cxf.ws.rm.RMManager) AbstractPhaseInterceptor(org.apache.cxf.phase.AbstractPhaseInterceptor) MessageFlow(org.apache.cxf.systest.ws.util.MessageFlow) RMProperties(org.apache.cxf.ws.rm.RMProperties) Test(org.junit.Test)

Example 30 with MessageFlow

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);
}
Also used : MessageFlow(org.apache.cxf.systest.ws.util.MessageFlow)

Aggregations

MessageFlow (org.apache.cxf.systest.ws.util.MessageFlow)36 Test (org.junit.Test)23 RMManager (org.apache.cxf.ws.rm.RMManager)8 Greeter (org.apache.cxf.greeter_control.Greeter)7 Closeable (java.io.Closeable)6 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)5 PingMeFault (org.apache.cxf.greeter_control.PingMeFault)5 InMessageRecorder (org.apache.cxf.testutil.recorders.InMessageRecorder)5 OutMessageRecorder (org.apache.cxf.testutil.recorders.OutMessageRecorder)5 Endpoint (javax.xml.ws.Endpoint)4 WebServiceException (javax.xml.ws.WebServiceException)4 BasicGreeterService (org.apache.cxf.greeter_control.BasicGreeterService)3 Message (org.apache.cxf.message.Message)3 AbstractPhaseInterceptor (org.apache.cxf.phase.AbstractPhaseInterceptor)3 MessageRecorder (org.apache.cxf.testutil.recorders.MessageRecorder)3 RMMessage (org.apache.cxf.ws.rm.persistence.RMMessage)3 Bus (org.apache.cxf.Bus)2 SoapFault (org.apache.cxf.binding.soap.SoapFault)2 RMProperties (org.apache.cxf.ws.rm.RMProperties)2 IOException (java.io.IOException)1