Search in sources :

Example 6 with RMStoreException

use of org.apache.cxf.ws.rm.persistence.RMStoreException 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 7 with RMStoreException

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

the class RMTxStore method getMessages.

public Collection<RMMessage> getMessages(Identifier sid, boolean outbound) {
    Connection con = verifyConnection();
    PreparedStatement stmt = null;
    SQLException conex = null;
    Collection<RMMessage> msgs = new ArrayList<>();
    ResultSet res = null;
    try {
        stmt = getStatement(con, outbound ? SELECT_OUTBOUND_MESSAGES_STMT_STR : SELECT_INBOUND_MESSAGES_STMT_STR);
        stmt.setString(1, sid.getValue());
        res = stmt.executeQuery();
        while (res.next()) {
            long mn = res.getLong(1);
            String to = res.getString(2);
            long ct = res.getLong(3);
            Blob blob = res.getBlob(4);
            String contentType = res.getString(5);
            RMMessage msg = new RMMessage();
            msg.setMessageNumber(mn);
            msg.setTo(to);
            msg.setCreatedTime(ct);
            CachedOutputStream cos = new CachedOutputStream();
            IOUtils.copyAndCloseInput(blob.getBinaryStream(), cos);
            cos.flush();
            msg.setContent(cos);
            msg.setContentType(contentType);
            msgs.add(msg);
        }
    } catch (SQLException ex) {
        conex = ex;
        LOG.log(Level.WARNING, new Message(outbound ? "SELECT_OUTBOUND_MSGS_FAILED_MSG" : "SELECT_INBOUND_MSGS_FAILED_MSG", LOG).toString(), ex);
    } catch (IOException e) {
        abort(con);
        throw new RMStoreException(e);
    } finally {
        releaseResources(stmt, res);
        updateConnectionState(con, conex);
    }
    return msgs;
}
Also used : Blob(java.sql.Blob) Message(org.apache.cxf.common.i18n.Message) RMMessage(org.apache.cxf.ws.rm.persistence.RMMessage) SQLException(java.sql.SQLException) RMMessage(org.apache.cxf.ws.rm.persistence.RMMessage) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) IOException(java.io.IOException) CachedOutputStream(org.apache.cxf.io.CachedOutputStream) RMStoreException(org.apache.cxf.ws.rm.persistence.RMStoreException) ResultSet(java.sql.ResultSet)

Example 8 with RMStoreException

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

the class RMTxStore method createSourceSequence.

public void createSourceSequence(SourceSequence seq) {
    String sequenceIdentifier = seq.getIdentifier().getValue();
    String endpointIdentifier = seq.getEndpointIdentifier();
    String protocolVersion = encodeProtocolVersion(seq.getProtocol());
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Creating source sequence: " + sequenceIdentifier + ", (endpoint: " + endpointIdentifier + ")");
    }
    Connection con = verifyConnection();
    PreparedStatement stmt = null;
    SQLException conex = null;
    try {
        beginTransaction();
        stmt = getStatement(con, CREATE_SRC_SEQUENCE_STMT_STR);
        stmt.setString(1, sequenceIdentifier);
        Date expiry = seq.getExpires();
        stmt.setLong(2, expiry == null ? 0 : expiry.getTime());
        Identifier osid = seq.getOfferingSequenceIdentifier();
        stmt.setString(3, osid == null ? null : osid.getValue());
        stmt.setString(4, endpointIdentifier);
        stmt.setString(5, protocolVersion);
        stmt.execute();
        commit(con);
    } catch (SQLException ex) {
        conex = ex;
        abort(con);
        throw new RMStoreException(ex);
    } finally {
        releaseResources(stmt, null);
        updateConnectionState(con, conex);
    }
}
Also used : RMStoreException(org.apache.cxf.ws.rm.persistence.RMStoreException) Identifier(org.apache.cxf.ws.rm.v200702.Identifier) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Date(java.util.Date)

Example 9 with RMStoreException

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

the class RMTxStore method persistIncoming.

public void persistIncoming(DestinationSequence seq, RMMessage msg) {
    Connection con = verifyConnection();
    SQLException conex = null;
    try {
        beginTransaction();
        updateDestinationSequence(con, seq);
        if (msg != null && msg.getContent() != null) {
            storeMessage(con, seq.getIdentifier(), msg, false);
        }
        commit(con);
    } catch (SQLException ex) {
        conex = ex;
        abort(con);
        throw new RMStoreException(ex);
    } catch (IOException ex) {
        abort(con);
        throw new RMStoreException(ex);
    } finally {
        updateConnectionState(con, conex);
    }
}
Also used : RMStoreException(org.apache.cxf.ws.rm.persistence.RMStoreException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) IOException(java.io.IOException)

Example 10 with RMStoreException

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

the class RMTxStore method removeDestinationSequence.

public void removeDestinationSequence(Identifier sid) {
    Connection con = verifyConnection();
    PreparedStatement stmt = null;
    SQLException conex = null;
    try {
        beginTransaction();
        stmt = getStatement(con, DELETE_DEST_SEQUENCE_STMT_STR);
        stmt.setString(1, sid.getValue());
        stmt.execute();
        commit(con);
    } catch (SQLException ex) {
        conex = ex;
        abort(con);
        throw new RMStoreException(ex);
    } finally {
        releaseResources(stmt, null);
        updateConnectionState(con, conex);
    }
}
Also used : RMStoreException(org.apache.cxf.ws.rm.persistence.RMStoreException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Aggregations

SQLException (java.sql.SQLException)11 RMStoreException (org.apache.cxf.ws.rm.persistence.RMStoreException)11 Connection (java.sql.Connection)8 PreparedStatement (java.sql.PreparedStatement)6 Identifier (org.apache.cxf.ws.rm.v200702.Identifier)4 IOException (java.io.IOException)3 Test (org.junit.Test)3 Date (java.util.Date)2 SourceSequence (org.apache.cxf.ws.rm.SourceSequence)2 Blob (java.sql.Blob)1 ResultSet (java.sql.ResultSet)1 ArrayList (java.util.ArrayList)1 Message (org.apache.cxf.common.i18n.Message)1 CachedOutputStream (org.apache.cxf.io.CachedOutputStream)1 EndpointReferenceType (org.apache.cxf.ws.addressing.EndpointReferenceType)1 DestinationSequence (org.apache.cxf.ws.rm.DestinationSequence)1 RMMessage (org.apache.cxf.ws.rm.persistence.RMMessage)1