Search in sources :

Example 16 with RMManager

use of org.apache.cxf.ws.rm.RMManager in project cxf by apache.

the class SequenceTest method testTerminateOnShutdown.

@Test
public void testTerminateOnShutdown() throws Exception {
    init("org/apache/cxf/systest/ws/rm/terminate-on-shutdown.xml", true);
    RMManager manager = greeterBus.getExtension(RMManager.class);
    // this test also verify the DB is correctly being updated during the shutdown
    RMMemoryStore store = new RMMemoryStore();
    manager.setStore(store);
    greeter.greetMeOneWay("neutrophil");
    greeter.greetMeOneWay("basophil");
    greeter.greetMeOneWay("eosinophil");
    stopGreeterButNotCloseConduit();
    awaitMessages(6, 2);
    MessageFlow mf = new MessageFlow(outRecorder.getOutboundMessages(), inRecorder.getInboundMessages(), Names200408.WSA_NAMESPACE_NAME, RM10Constants.NAMESPACE_URI);
    mf.verifyMessages(6, true);
    String[] expectedActions = new String[] { RM10Constants.CREATE_SEQUENCE_ACTION, GREETMEONEWAY_ACTION, GREETMEONEWAY_ACTION, GREETMEONEWAY_ACTION, RM10Constants.CLOSE_SEQUENCE_ACTION, RM10Constants.TERMINATE_SEQUENCE_ACTION };
    mf.verifyActions(expectedActions, true);
    mf.verifyMessageNumbers(new String[] { null, "1", "2", "3", "4", null }, true);
    // inbound: CreateSequenceResponse, out-of-band SequenceAcknowledgement
    // plus 6 partial responses
    mf.verifyMessages(2, false);
    mf.verifyMessageNumbers(new String[2], false);
    expectedActions = new String[] { RM10Constants.CREATE_SEQUENCE_RESPONSE_ACTION, RM10Constants.SEQUENCE_ACKNOWLEDGMENT_ACTION };
    mf.verifyActions(expectedActions, false);
    mf.verifyAcknowledgements(new boolean[] { false, true }, false);
    // additional check to verify the operations performed on DB
    assertEquals("sequences not released from DB", 0, store.ssmap.size());
    assertEquals("messages not released from DB", 0, store.ommap.size());
    assertEquals("sequence not closed in DB", 1, store.ssclosed.size());
}
Also used : RMManager(org.apache.cxf.ws.rm.RMManager) MessageFlow(org.apache.cxf.systest.ws.util.MessageFlow) Test(org.junit.Test)

Example 17 with RMManager

use of org.apache.cxf.ws.rm.RMManager 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)

Example 18 with RMManager

use of org.apache.cxf.ws.rm.RMManager in project cxf by apache.

the class SequenceTest method testTwowayMessageLoss.

private void testTwowayMessageLoss(Executor executor) throws Exception {
    init("org/apache/cxf/systest/ws/rm/message-loss.xml", true, executor);
    greeterBus.getOutInterceptors().add(new MessageLossSimulator());
    RMManager manager = greeterBus.getExtension(RMManager.class);
    manager.getConfiguration().setBaseRetransmissionInterval(new Long(2000));
    greeter.greetMe("one");
    greeter.greetMe("two");
    greeter.greetMe("three");
    greeter.greetMe("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
    // + 2 resends
    String[] expectedActions = new String[7];
    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", "2", "3", "4", "4" }, true);
    mf.verifyLastMessage(new boolean[7], true);
    boolean[] expectedAcks = new boolean[7];
    for (int i = 2; i < expectedAcks.length; i++) {
        expectedAcks[i] = true;
    }
    mf.verifyAcknowledgements(expectedAcks, true);
    // Expected inbound:
    // createSequenceResponse
    // + 4 greetMeResponse actions (to original or resent)
    // + 5 partial responses (to CSR & each of the initial greetMe messages)
    // + at least 2 further partial response (for each of the resends)
    expectedActions = new String[] { RM10Constants.CREATE_SEQUENCE_RESPONSE_ACTION, GREETME_RESPONSE_ACTION, GREETME_RESPONSE_ACTION, GREETME_RESPONSE_ACTION, GREETME_RESPONSE_ACTION };
    mf.verifyActions(expectedActions, false);
    mf.verifyMessageNumbers(new String[] { null, "1", "2", "3", "4" }, false);
    mf.verifyAcknowledgements(new boolean[] { false, true, true, true, true }, false);
}
Also used : RMManager(org.apache.cxf.ws.rm.RMManager) MessageFlow(org.apache.cxf.systest.ws.util.MessageFlow)

Example 19 with RMManager

use of org.apache.cxf.ws.rm.RMManager in project cxf by apache.

the class WSRMWithWSSecurityPolicyTest method testWithSecurityInPolicy.

@Test
public void testWithSecurityInPolicy() throws Exception {
    LOG.fine("Creating greeter client");
    try (ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("org/apache/cxf/systest/ws/rm/sec/client-policy.xml")) {
        Bus bus = (Bus) context.getBean("bus");
        BusFactory.setDefaultBus(bus);
        BusFactory.setThreadDefaultBus(bus);
        Greeter greeter = (Greeter) context.getBean("GreeterCombinedClient");
        RMManager manager = bus.getExtension(RMManager.class);
        boolean empty = manager.getRetransmissionQueue().isEmpty();
        assertTrue("RetransmissionQueue is not empty", empty);
        LOG.fine("Invoking greeter");
        greeter.greetMeOneWay("one");
        Thread.sleep(3000);
        empty = manager.getRetransmissionQueue().isEmpty();
        assertTrue("RetransmissionQueue not empty", empty);
    }
}
Also used : Bus(org.apache.cxf.Bus) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) RMManager(org.apache.cxf.ws.rm.RMManager) Greeter(org.apache.cxf.greeter_control.Greeter) Test(org.junit.Test)

Example 20 with RMManager

use of org.apache.cxf.ws.rm.RMManager in project cxf by apache.

the class WSRMWithWSSecurityPolicyTest method testContextProperty.

@Test
public void testContextProperty() throws Exception {
    try (ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("org/apache/cxf/systest/ws/rm/sec/client-policy.xml")) {
        Bus bus = (Bus) context.getBean("bus");
        BusFactory.setDefaultBus(bus);
        BusFactory.setThreadDefaultBus(bus);
        Greeter greeter = (Greeter) context.getBean("GreeterCombinedClientNoProperty");
        Client client = ClientProxy.getClient(greeter);
        QName operationQName = new QName("http://cxf.apache.org/greeter_control", "greetMe");
        BindingOperationInfo boi = client.getEndpoint().getBinding().getBindingInfo().getOperation(operationQName);
        Map<String, Object> invocationContext = new HashMap<>();
        Map<String, Object> requestContext = new HashMap<>();
        Map<String, Object> responseContext = new HashMap<>();
        invocationContext.put(Client.REQUEST_CONTEXT, requestContext);
        invocationContext.put(Client.RESPONSE_CONTEXT, responseContext);
        requestContext.put(SecurityConstants.USERNAME, "Alice");
        requestContext.put(SecurityConstants.CALLBACK_HANDLER, "org.apache.cxf.systest.ws.rm.sec.UTPasswordCallback");
        requestContext.put(SecurityConstants.ENCRYPT_PROPERTIES, "bob.properties");
        requestContext.put(SecurityConstants.ENCRYPT_USERNAME, "bob");
        requestContext.put(SecurityConstants.SIGNATURE_PROPERTIES, "alice.properties");
        requestContext.put(SecurityConstants.SIGNATURE_USERNAME, "alice");
        RMManager manager = bus.getExtension(RMManager.class);
        boolean empty = manager.getRetransmissionQueue().isEmpty();
        assertTrue("RetransmissionQueue is not empty", empty);
        GreetMe param = new GreetMe();
        param.setRequestType("testContextProperty");
        Object[] answer = client.invoke(boi, new Object[] { param }, invocationContext);
        Assert.assertEquals("TESTCONTEXTPROPERTY", answer[0].toString());
        Thread.sleep(5000);
        empty = manager.getRetransmissionQueue().isEmpty();
        assertTrue("RetransmissionQueue not empty", empty);
    }
}
Also used : GreetMe(org.apache.cxf.greeter_control.types.GreetMe) Bus(org.apache.cxf.Bus) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) RMManager(org.apache.cxf.ws.rm.RMManager) Greeter(org.apache.cxf.greeter_control.Greeter) Client(org.apache.cxf.endpoint.Client) Test(org.junit.Test)

Aggregations

RMManager (org.apache.cxf.ws.rm.RMManager)43 Test (org.junit.Test)26 Endpoint (javax.xml.ws.Endpoint)12 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)12 GreeterService (org.apache.cxf.greeter_control.GreeterService)10 Greeter (org.apache.cxf.greeter_control.Greeter)9 MessageFlow (org.apache.cxf.systest.ws.util.MessageFlow)8 Bus (org.apache.cxf.Bus)7 Client (org.apache.cxf.endpoint.Client)4 LoggingInInterceptor (org.apache.cxf.ext.logging.LoggingInInterceptor)4 LoggingOutInterceptor (org.apache.cxf.ext.logging.LoggingOutInterceptor)4 MBeanServer (javax.management.MBeanServer)3 ObjectName (javax.management.ObjectName)3 WebServiceException (javax.xml.ws.WebServiceException)3 InstrumentationManager (org.apache.cxf.management.InstrumentationManager)3 Message (org.apache.cxf.message.Message)3 RMProperties (org.apache.cxf.ws.rm.RMProperties)3 RMMessage (org.apache.cxf.ws.rm.persistence.RMMessage)3 SQLException (java.sql.SQLException)2 SoapFault (org.apache.cxf.binding.soap.SoapFault)2