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);
}
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;
}
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);
}
}
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);
}
}
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);
}
}
Aggregations