Search in sources :

Example 6 with DestinationSequence

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

the class RMTxStoreTestBase method testCreateSequenceStoreInboundMessage.

@Test
public void testCreateSequenceStoreInboundMessage() throws SQLException, IOException {
    Identifier sid1 = null;
    try {
        DestinationSequence seq = control.createMock(DestinationSequence.class);
        sid1 = new Identifier();
        sid1.setValue("sequence1");
        EndpointReferenceType epr = RMUtils.createAnonymousReference();
        EasyMock.expect(seq.getIdentifier()).andReturn(sid1);
        EasyMock.expect(seq.getAcksTo()).andReturn(epr);
        EasyMock.expect(seq.getEndpointIdentifier()).andReturn(SERVER_ENDPOINT_ID);
        EasyMock.expect(seq.getProtocol()).andReturn(ProtocolVariation.RM10WSA200408);
        control.replay();
        store.createDestinationSequence(seq);
        Collection<DestinationSequence> seqs = store.getDestinationSequences(SERVER_ENDPOINT_ID);
        assertEquals(1, seqs.size());
        DestinationSequence rseq = seqs.iterator().next();
        assertFalse(rseq.isAcknowledged(1));
        Collection<RMMessage> in = store.getMessages(sid1, false);
        assertEquals(0, in.size());
        control.reset();
        EasyMock.expect(seq.getIdentifier()).andReturn(sid1).anyTimes();
        EasyMock.expect(seq.getAcknowledgment()).andReturn(ack1);
        EasyMock.expect(seq.getAcksTo()).andReturn(epr);
        setupInboundMessage(seq, 1L, null);
        in = store.getMessages(sid1, false);
        assertEquals(1, in.size());
        checkRecoveredMessages(in);
        seqs = store.getDestinationSequences(SERVER_ENDPOINT_ID);
        assertEquals(1, seqs.size());
        rseq = seqs.iterator().next();
        assertTrue(rseq.isAcknowledged(1));
        assertFalse(rseq.isAcknowledged(10));
        EasyMock.expect(seq.getIdentifier()).andReturn(sid1).anyTimes();
        EasyMock.expect(seq.getAcknowledgment()).andReturn(ack2);
        EasyMock.expect(seq.getAcksTo()).andReturn(epr);
        control.replay();
        store.persistIncoming(seq, null);
        control.reset();
        seqs = store.getDestinationSequences(SERVER_ENDPOINT_ID);
        assertEquals(1, seqs.size());
        rseq = seqs.iterator().next();
        assertTrue(rseq.isAcknowledged(10));
    } finally {
        if (null != sid1) {
            store.removeDestinationSequence(sid1);
        }
        Collection<Long> msgNrs = new ArrayList<>();
        msgNrs.add(ONE);
        store.removeMessages(sid1, msgNrs, false);
    }
}
Also used : DestinationSequence(org.apache.cxf.ws.rm.DestinationSequence) Identifier(org.apache.cxf.ws.rm.v200702.Identifier) EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) RMMessage(org.apache.cxf.ws.rm.persistence.RMMessage) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 7 with DestinationSequence

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

the class RMTxStoreTestBase method testCreateDeleteDestSequences.

@Test
public void testCreateDeleteDestSequences() {
    DestinationSequence seq = control.createMock(DestinationSequence.class);
    Identifier sid1 = new Identifier();
    sid1.setValue("sequence1");
    EndpointReferenceType epr = RMUtils.createAnonymousReference();
    EasyMock.expect(seq.getIdentifier()).andReturn(sid1);
    EasyMock.expect(seq.getAcksTo()).andReturn(epr);
    EasyMock.expect(seq.getEndpointIdentifier()).andReturn(SERVER_ENDPOINT_ID);
    EasyMock.expect(seq.getProtocol()).andReturn(ProtocolVariation.RM10WSA200408);
    control.replay();
    store.createDestinationSequence(seq);
    control.verify();
    control.reset();
    EasyMock.expect(seq.getIdentifier()).andReturn(sid1);
    EasyMock.expect(seq.getAcksTo()).andReturn(epr);
    EasyMock.expect(seq.getEndpointIdentifier()).andReturn(SERVER_ENDPOINT_ID);
    EasyMock.expect(seq.getProtocol()).andReturn(ProtocolVariation.RM10WSA200408);
    control.replay();
    try {
        store.createDestinationSequence(seq);
        fail("Expected RMStoreException was not thrown.");
    } catch (RMStoreException ex) {
        SQLException se = (SQLException) ex.getCause();
        // duplicate key value
        assertEquals("23505", se.getSQLState());
    }
    control.verify();
    control.reset();
    Identifier sid2 = new Identifier();
    sid2.setValue("sequence2");
    EasyMock.expect(seq.getIdentifier()).andReturn(sid2);
    epr = RMUtils.createReference(NON_ANON_ACKS_TO);
    EasyMock.expect(seq.getAcksTo()).andReturn(epr);
    EasyMock.expect(seq.getEndpointIdentifier()).andReturn(CLIENT_ENDPOINT_ID);
    EasyMock.expect(seq.getProtocol()).andReturn(ProtocolVariation.RM10WSA200408);
    control.replay();
    store.createDestinationSequence(seq);
    control.verify();
    store.removeDestinationSequence(sid1);
    store.removeDestinationSequence(sid2);
    // deleting once again is a no-op
    store.removeDestinationSequence(sid2);
}
Also used : RMStoreException(org.apache.cxf.ws.rm.persistence.RMStoreException) DestinationSequence(org.apache.cxf.ws.rm.DestinationSequence) Identifier(org.apache.cxf.ws.rm.v200702.Identifier) EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 8 with DestinationSequence

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

the class RMTxStore method getDestinationSequence.

public DestinationSequence getDestinationSequence(Identifier sid) {
    if (LOG.isLoggable(Level.FINE)) {
        LOG.info("Getting destination sequence for id: " + sid);
    }
    Connection con = verifyConnection();
    PreparedStatement stmt = null;
    SQLException conex = null;
    ResultSet res = null;
    try {
        stmt = getStatement(con, SELECT_DEST_SEQUENCE_STMT_STR);
        stmt.setString(1, sid.getValue());
        res = stmt.executeQuery();
        if (res.next()) {
            EndpointReferenceType acksTo = RMUtils.createReference(res.getString(1));
            long lm = res.getLong(2);
            ProtocolVariation pv = decodeProtocolVersion(res.getString(3));
            boolean t = res.getBoolean(4);
            InputStream is = res.getBinaryStream(5);
            SequenceAcknowledgement ack = null;
            if (null != is) {
                ack = PersistenceUtils.getInstance().deserialiseAcknowledgment(is);
            }
            return new DestinationSequence(sid, acksTo, lm, t, ack, pv);
        }
    } catch (SQLException ex) {
        conex = ex;
        LOG.log(Level.WARNING, new Message("SELECT_DEST_SEQ_FAILED_MSG", LOG).toString(), ex);
    } finally {
        releaseResources(stmt, res);
        updateConnectionState(con, conex);
    }
    return null;
}
Also used : DestinationSequence(org.apache.cxf.ws.rm.DestinationSequence) EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) Message(org.apache.cxf.common.i18n.Message) RMMessage(org.apache.cxf.ws.rm.persistence.RMMessage) SQLException(java.sql.SQLException) InputStream(java.io.InputStream) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) SequenceAcknowledgement(org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement) ProtocolVariation(org.apache.cxf.ws.rm.ProtocolVariation)

Example 9 with DestinationSequence

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

the class RMTxStore method getDestinationSequences.

public Collection<DestinationSequence> getDestinationSequences(String endpointIdentifier) {
    if (LOG.isLoggable(Level.FINE)) {
        LOG.info("Getting destination sequences for endpoint: " + endpointIdentifier);
    }
    Connection con = verifyConnection();
    PreparedStatement stmt = null;
    SQLException conex = null;
    Collection<DestinationSequence> seqs = new ArrayList<>();
    ResultSet res = null;
    try {
        stmt = getStatement(con, SELECT_DEST_SEQUENCES_STMT_STR);
        stmt.setString(1, endpointIdentifier);
        res = stmt.executeQuery();
        while (res.next()) {
            Identifier sid = new Identifier();
            sid.setValue(res.getString(1));
            EndpointReferenceType acksTo = RMUtils.createReference(res.getString(2));
            long lm = res.getLong(3);
            ProtocolVariation pv = decodeProtocolVersion(res.getString(4));
            boolean t = res.getBoolean(5);
            InputStream is = res.getBinaryStream(6);
            SequenceAcknowledgement ack = null;
            if (null != is) {
                ack = PersistenceUtils.getInstance().deserialiseAcknowledgment(is);
            }
            DestinationSequence seq = new DestinationSequence(sid, acksTo, lm, t, ack, pv);
            seqs.add(seq);
        }
    } catch (SQLException ex) {
        conex = ex;
        LOG.log(Level.WARNING, new Message("SELECT_DEST_SEQ_FAILED_MSG", LOG).toString(), ex);
    } finally {
        releaseResources(stmt, res);
        updateConnectionState(con, conex);
    }
    return seqs;
}
Also used : EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) Message(org.apache.cxf.common.i18n.Message) RMMessage(org.apache.cxf.ws.rm.persistence.RMMessage) SQLException(java.sql.SQLException) InputStream(java.io.InputStream) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) DestinationSequence(org.apache.cxf.ws.rm.DestinationSequence) Identifier(org.apache.cxf.ws.rm.v200702.Identifier) ResultSet(java.sql.ResultSet) SequenceAcknowledgement(org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement) ProtocolVariation(org.apache.cxf.ws.rm.ProtocolVariation)

Example 10 with DestinationSequence

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

the class AbstractClientPersistenceTest method verifyRecovery.

void verifyRecovery() throws Exception {
    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());
    int i = 0;
    while (store.getMessages(sss.iterator().next().getIdentifier(), true).size() > 0 && i < 10) {
        Thread.sleep(200);
        i++;
    }
    assertEquals(0, store.getMessages(sss.iterator().next().getIdentifier(), true).size());
    assertEquals(0, store.getMessages(sss.iterator().next().getIdentifier(), false).size());
}
Also used : DestinationSequence(org.apache.cxf.ws.rm.DestinationSequence) RMManager(org.apache.cxf.ws.rm.RMManager) RMStore(org.apache.cxf.ws.rm.persistence.RMStore) Client(org.apache.cxf.endpoint.Client) SourceSequence(org.apache.cxf.ws.rm.SourceSequence) Endpoint(javax.xml.ws.Endpoint)

Aggregations

DestinationSequence (org.apache.cxf.ws.rm.DestinationSequence)11 Identifier (org.apache.cxf.ws.rm.v200702.Identifier)7 EndpointReferenceType (org.apache.cxf.ws.addressing.EndpointReferenceType)6 Test (org.junit.Test)5 Connection (java.sql.Connection)4 RMMessage (org.apache.cxf.ws.rm.persistence.RMMessage)4 SequenceAcknowledgement (org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement)4 SQLException (java.sql.SQLException)3 ProtocolVariation (org.apache.cxf.ws.rm.ProtocolVariation)3 InputStream (java.io.InputStream)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 ArrayList (java.util.ArrayList)2 Message (org.apache.cxf.common.i18n.Message)2 Client (org.apache.cxf.endpoint.Client)2 RMManager (org.apache.cxf.ws.rm.RMManager)2 SourceSequence (org.apache.cxf.ws.rm.SourceSequence)2 RMStore (org.apache.cxf.ws.rm.persistence.RMStore)2 Endpoint (javax.xml.ws.Endpoint)1 RMStoreException (org.apache.cxf.ws.rm.persistence.RMStoreException)1