Search in sources :

Example 6 with MessageFlow

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;
    }
}
Also used : Bus(org.apache.cxf.Bus) InMessageRecorder(org.apache.cxf.testutil.recorders.InMessageRecorder) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) OutMessageRecorder(org.apache.cxf.testutil.recorders.OutMessageRecorder) Greeter(org.apache.cxf.greeter_control.Greeter) MessageFlow(org.apache.cxf.systest.ws.util.MessageFlow) Test(org.junit.Test)

Example 7 with MessageFlow

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

Example 8 with MessageFlow

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

Example 9 with MessageFlow

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

Example 10 with MessageFlow

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

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