Search in sources :

Example 6 with RMMessage

use of org.apache.cxf.ws.rm.persistence.RMMessage in project cxf by apache.

the class RMTxStoreTestBase method testCreateSequenceStoreOutboundMessage.

@Test
public void testCreateSequenceStoreOutboundMessage() throws SQLException, IOException {
    Identifier sid1 = null;
    try {
        SourceSequence seq = control.createMock(SourceSequence.class);
        sid1 = new Identifier();
        sid1.setValue("sequence1");
        EasyMock.expect(seq.getIdentifier()).andReturn(sid1);
        EasyMock.expect(seq.getExpires()).andReturn(null);
        EasyMock.expect(seq.getOfferingSequenceIdentifier()).andReturn(null);
        EasyMock.expect(seq.getEndpointIdentifier()).andReturn(CLIENT_ENDPOINT_ID);
        EasyMock.expect(seq.getProtocol()).andReturn(ProtocolVariation.RM10WSA200408);
        control.replay();
        store.createSourceSequence(seq);
        control.reset();
        Collection<SourceSequence> seqs = store.getSourceSequences(CLIENT_ENDPOINT_ID);
        assertEquals(1, seqs.size());
        SourceSequence rseq = seqs.iterator().next();
        assertFalse(rseq.isLastMessage());
        Collection<RMMessage> out = store.getMessages(sid1, true);
        assertEquals(0, out.size());
        // set the last message flag
        EasyMock.expect(seq.getIdentifier()).andReturn(sid1).anyTimes();
        EasyMock.expect(seq.isLastMessage()).andReturn(true);
        setupOutboundMessage(seq, 1L, null);
        out = store.getMessages(sid1, true);
        assertEquals(1, out.size());
        checkRecoveredMessages(out);
        // verify the updated sequence
        seqs = store.getSourceSequences(CLIENT_ENDPOINT_ID);
        assertEquals(1, seqs.size());
        rseq = seqs.iterator().next();
        assertTrue(rseq.isLastMessage());
        // set the last message flag
        EasyMock.expect(seq.getIdentifier()).andReturn(sid1).anyTimes();
        EasyMock.expect(seq.getCurrentMessageNr()).andReturn(2L);
        EasyMock.expect(seq.isLastMessage()).andReturn(true);
        control.replay();
        store.persistOutgoing(seq, null);
        control.reset();
        seqs = store.getSourceSequences(CLIENT_ENDPOINT_ID);
        assertEquals(1, seqs.size());
        rseq = seqs.iterator().next();
        assertEquals(2, rseq.getCurrentMessageNr());
    } finally {
        if (null != sid1) {
            store.removeSourceSequence(sid1);
        }
        Collection<Long> msgNrs = Arrays.asList(ONE);
        store.removeMessages(sid1, msgNrs, true);
    }
}
Also used : Identifier(org.apache.cxf.ws.rm.v200702.Identifier) RMMessage(org.apache.cxf.ws.rm.persistence.RMMessage) SourceSequence(org.apache.cxf.ws.rm.SourceSequence) Test(org.junit.Test)

Example 7 with RMMessage

use of org.apache.cxf.ws.rm.persistence.RMMessage in project cxf by apache.

the class RMTxStoreTestBase method setupMessage.

private void setupMessage(Identifier sid, Long mn, String to, boolean outbound) throws IOException, SQLException {
    RMMessage msg = createRMMessage(mn, to);
    control.replay();
    Connection con = getConnection();
    try {
        store.beginTransaction();
        store.storeMessage(con, sid, msg, outbound);
        store.commit(con);
    } finally {
        releaseConnection(con);
    }
    control.reset();
}
Also used : RMMessage(org.apache.cxf.ws.rm.persistence.RMMessage) Connection(java.sql.Connection)

Example 8 with RMMessage

use of org.apache.cxf.ws.rm.persistence.RMMessage in project cxf by apache.

the class RMTxStoreTestBase method testGetMessages.

@Test
public void testGetMessages() throws SQLException, IOException {
    Identifier sid1 = new Identifier();
    sid1.setValue("sequence1");
    Identifier sid2 = new Identifier();
    sid2.setValue("sequence2");
    Collection<RMMessage> out = store.getMessages(sid1, true);
    assertEquals(0, out.size());
    Collection<RMMessage> in = store.getMessages(sid1, false);
    assertEquals(0, in.size());
    try {
        setupMessage(sid1, ONE, null, true);
        setupMessage(sid1, ONE, null, false);
        out = store.getMessages(sid1, true);
        assertEquals(1, out.size());
        checkRecoveredMessages(out);
        in = store.getMessages(sid1, false);
        assertEquals(1, in.size());
        checkRecoveredMessages(in);
        setupMessage(sid1, TEN, NON_ANON_ACKS_TO, true);
        setupMessage(sid1, TEN, NON_ANON_ACKS_TO, false);
        out = store.getMessages(sid1, true);
        assertEquals(2, out.size());
        checkRecoveredMessages(out);
        in = store.getMessages(sid1, false);
        assertEquals(2, in.size());
        checkRecoveredMessages(in);
    } finally {
        Collection<Long> msgNrs = Arrays.asList(ONE, TEN);
        store.removeMessages(sid1, msgNrs, true);
        store.removeMessages(sid1, msgNrs, false);
    }
}
Also used : Identifier(org.apache.cxf.ws.rm.v200702.Identifier) RMMessage(org.apache.cxf.ws.rm.persistence.RMMessage) Test(org.junit.Test)

Example 9 with RMMessage

use of org.apache.cxf.ws.rm.persistence.RMMessage in project cxf by apache.

the class DestinationSequence method acknowledge.

public void acknowledge(Message message) throws SequenceFault {
    RMProperties rmps = RMContextUtils.retrieveRMProperties(message, false);
    SequenceType st = rmps.getSequence();
    long messageNumber = st.getMessageNumber();
    LOG.fine("Acknowledging message: " + messageNumber);
    if (0L != lastMessageNumber && messageNumber > lastMessageNumber) {
        RMConstants consts = getProtocol().getConstants();
        SequenceFaultFactory sff = new SequenceFaultFactory(consts);
        throw sff.createSequenceTerminatedFault(st.getIdentifier(), false);
    }
    monitor.acknowledgeMessage();
    boolean updated = false;
    synchronized (this) {
        boolean done = false;
        int i = 0;
        for (; i < acknowledgement.getAcknowledgementRange().size(); i++) {
            AcknowledgementRange r = acknowledgement.getAcknowledgementRange().get(i);
            if (r.getLower().compareTo(messageNumber) <= 0 && r.getUpper().compareTo(messageNumber) >= 0) {
                done = true;
                break;
            }
            long diff = r.getLower() - messageNumber;
            if (diff == 1L) {
                r.setLower(messageNumber);
                updated = true;
                done = true;
            } else if (diff > 0L) {
                break;
            } else if (messageNumber - r.getUpper() == 1L) {
                r.setUpper(messageNumber);
                updated = true;
                done = true;
                break;
            }
        }
        if (!done) {
            // need new acknowledgement range
            AcknowledgementRange range = new AcknowledgementRange();
            range.setLower(messageNumber);
            range.setUpper(messageNumber);
            updated = true;
            acknowledgement.getAcknowledgementRange().add(i, range);
            if (acknowledgement.getAcknowledgementRange().size() > 1) {
                // acknowledge out-of-order at first opportunity
                scheduleImmediateAcknowledgement();
            }
        }
        mergeRanges();
    }
    if (updated) {
        RMStore store = destination.getManager().getStore();
        if (null != store && !MessageUtils.getContextualBoolean(message, Message.ROBUST_ONEWAY)) {
            try {
                RMMessage msg = new RMMessage();
                CachedOutputStream cos = (CachedOutputStream) message.get(RMMessageConstants.SAVED_CONTENT);
                msg.setMessageNumber(st.getMessageNumber());
                msg.setCreatedTime(rmps.getCreatedTime());
                // in case no attachments are available, cos can be saved directly
                if (message.getAttachments() == null) {
                    msg.setContent(cos);
                    msg.setContentType((String) message.get(Message.CONTENT_TYPE));
                } else {
                    InputStream is = cos.getInputStream();
                    PersistenceUtils.encodeRMContent(msg, message, is);
                }
                store.persistIncoming(this, msg);
            } catch (IOException e) {
                throw new Fault(e);
            }
        }
    }
    deliveringMessageNumbers.add(messageNumber);
    RMEndpoint reliableEndpoint = destination.getReliableEndpoint();
    RMConfiguration cfg = reliableEndpoint.getConfiguration();
    if (null == rmps.getCloseSequence()) {
        scheduleAcknowledgement(cfg.getAcknowledgementIntervalTime());
    }
    long inactivityTimeout = cfg.getInactivityTimeoutTime();
    scheduleSequenceTermination(inactivityTimeout);
}
Also used : RMMessage(org.apache.cxf.ws.rm.persistence.RMMessage) InputStream(java.io.InputStream) RMStore(org.apache.cxf.ws.rm.persistence.RMStore) Fault(org.apache.cxf.interceptor.Fault) SequenceType(org.apache.cxf.ws.rm.v200702.SequenceType) IOException(java.io.IOException) CachedOutputStream(org.apache.cxf.io.CachedOutputStream) AcknowledgementRange(org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement.AcknowledgementRange)

Example 10 with RMMessage

use of org.apache.cxf.ws.rm.persistence.RMMessage in project cxf by apache.

the class AbstractClientPersistenceTest method verifyStorePopulation.

protected void verifyStorePopulation() {
    RMManager manager = bus.getExtension(RMManager.class);
    assertNotNull(manager);
    RMStore store = manager.getStore();
    assertNotNull(store);
    Client client = ClientProxy.getClient(greeter);
    String id = RMUtils.getEndpointIdentifier(client.getEndpoint());
    Collection<DestinationSequence> dss = store.getDestinationSequences(id);
    assertEquals(1, dss.size());
    Collection<SourceSequence> sss = store.getSourceSequences(id);
    assertEquals(1, sss.size());
    Collection<RMMessage> msgs = store.getMessages(sss.iterator().next().getIdentifier(), true);
    assertEquals(2, msgs.size());
    msgs = store.getMessages(sss.iterator().next().getIdentifier(), false);
    assertEquals(0, msgs.size());
}
Also used : DestinationSequence(org.apache.cxf.ws.rm.DestinationSequence) RMManager(org.apache.cxf.ws.rm.RMManager) RMMessage(org.apache.cxf.ws.rm.persistence.RMMessage) RMStore(org.apache.cxf.ws.rm.persistence.RMStore) Client(org.apache.cxf.endpoint.Client) SourceSequence(org.apache.cxf.ws.rm.SourceSequence)

Aggregations

RMMessage (org.apache.cxf.ws.rm.persistence.RMMessage)18 CachedOutputStream (org.apache.cxf.io.CachedOutputStream)6 Identifier (org.apache.cxf.ws.rm.v200702.Identifier)6 Test (org.junit.Test)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 IOException (java.io.IOException)5 InputStream (java.io.InputStream)4 Message (org.apache.cxf.message.Message)4 RMStore (org.apache.cxf.ws.rm.persistence.RMStore)4 Connection (java.sql.Connection)3 ArrayList (java.util.ArrayList)3 SequenceType (org.apache.cxf.ws.rm.v200702.SequenceType)3 Method (java.lang.reflect.Method)2 SQLException (java.sql.SQLException)2 Binding (org.apache.cxf.binding.Binding)2 SoapBinding (org.apache.cxf.binding.soap.SoapBinding)2 Endpoint (org.apache.cxf.endpoint.Endpoint)2 Exchange (org.apache.cxf.message.Exchange)2 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)2 MessageImpl (org.apache.cxf.message.MessageImpl)2