use of org.apache.cxf.ws.rm.persistence.RMMessage 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.RMMessage in project cxf by apache.
the class RMManager method recoverSourceSequence.
private void recoverSourceSequence(Endpoint endpoint, Conduit conduit, Source s, SourceSequence ss) {
Collection<RMMessage> ms = store.getMessages(ss.getIdentifier(), true);
if (null == ms || ms.isEmpty()) {
store.removeSourceSequence(ss.getIdentifier());
return;
}
LOG.log(Level.FINE, "Number of messages in sequence: {0}", ms.size());
// only recover the sequence if there are pending messages
s.addSequence(ss, false);
// choosing an arbitrary valid source sequence as the current source sequence
if (s.getAssociatedSequence(null) == null && !ss.isExpired() && !ss.isLastMessage()) {
s.setCurrent(ss);
}
// make sure this is associated with the offering id
s.setCurrent(ss.getOfferingSequenceIdentifier(), ss);
for (RMMessage m : ms) {
Message message = new MessageImpl();
Exchange exchange = new ExchangeImpl();
message.setExchange(exchange);
exchange.setOutMessage(message);
if (null != conduit) {
exchange.setConduit(conduit);
message.put(Message.REQUESTOR_ROLE, Boolean.TRUE);
}
exchange.put(Endpoint.class, endpoint);
exchange.put(Service.class, endpoint.getService());
exchange.put(Binding.class, endpoint.getBinding());
exchange.put(Bus.class, bus);
SequenceType st = new SequenceType();
st.setIdentifier(ss.getIdentifier());
st.setMessageNumber(m.getMessageNumber());
RMProperties rmps = new RMProperties();
rmps.setSequence(st);
rmps.setCreatedTime(m.getCreatedTime());
rmps.exposeAs(ss.getProtocol().getWSRMNamespace());
if (ss.isLastMessage() && ss.getCurrentMessageNr() == m.getMessageNumber()) {
CloseSequenceType close = new CloseSequenceType();
close.setIdentifier(ss.getIdentifier());
rmps.setCloseSequence(close);
}
RMContextUtils.storeRMProperties(message, rmps, true);
if (null == conduit) {
String to = m.getTo();
AddressingProperties maps = new AddressingProperties();
maps.setTo(RMUtils.createReference(to));
RMContextUtils.storeMAPs(maps, message, true, false);
}
try {
// RMMessage is stored in a serialized way, therefore
// RMMessage content must be splitted into soap root message
// and attachments
PersistenceUtils.decodeRMContent(m, message);
RMContextUtils.setProtocolVariation(message, ss.getProtocol());
retransmissionQueue.addUnacknowledged(message);
} catch (IOException e) {
LOG.log(Level.SEVERE, "Error reading persisted message data", e);
}
}
}
use of org.apache.cxf.ws.rm.persistence.RMMessage in project cxf by apache.
the class RMTxStoreTestBase method testCreateDeleteMessages.
@Test
public void testCreateDeleteMessages() throws IOException, SQLException {
RMMessage msg1 = control.createMock(RMMessage.class);
RMMessage msg2 = control.createMock(RMMessage.class);
Identifier sid1 = new Identifier();
sid1.setValue("sequence1");
EasyMock.expect(msg1.getMessageNumber()).andReturn(ONE).anyTimes();
EasyMock.expect(msg2.getMessageNumber()).andReturn(ONE).anyTimes();
byte[] bytes = new byte[89];
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
CachedOutputStream cos = new CachedOutputStream();
IOUtils.copy(bais, cos);
cos.flush();
bais.close();
EasyMock.expect(msg1.getContent()).andReturn(cos).anyTimes();
EasyMock.expect(msg2.getContent()).andReturn(cos).anyTimes();
EasyMock.expect(msg1.getContentType()).andReturn("text/xml").times(1);
control.replay();
Connection con = getConnection();
try {
store.beginTransaction();
store.storeMessage(con, sid1, msg1, true);
store.storeMessage(con, sid1, msg2, false);
store.commit(con);
} finally {
releaseConnection(con);
}
control.verify();
control.reset();
EasyMock.expect(msg1.getMessageNumber()).andReturn(ONE);
EasyMock.expect(msg1.getContent()).andReturn(cos);
control.replay();
con = getConnection();
try {
store.beginTransaction();
store.storeMessage(con, sid1, msg1, true);
} catch (SQLException ex) {
assertEquals("23505", ex.getSQLState());
store.abort(con);
} finally {
releaseConnection(con);
}
control.verify();
control.reset();
EasyMock.expect(msg1.getMessageNumber()).andReturn(TEN).anyTimes();
EasyMock.expect(msg2.getMessageNumber()).andReturn(TEN).anyTimes();
EasyMock.expect(msg1.getContent()).andReturn(cos).anyTimes();
EasyMock.expect(msg2.getContent()).andReturn(cos).anyTimes();
control.replay();
con = getConnection();
try {
store.beginTransaction();
store.storeMessage(con, sid1, msg1, true);
store.storeMessage(con, sid1, msg2, false);
store.commit(con);
} finally {
releaseConnection(con);
}
control.verify();
Collection<Long> messageNrs = Arrays.asList(ZERO, TEN, ONE, TEN);
store.removeMessages(sid1, messageNrs, true);
store.removeMessages(sid1, messageNrs, false);
Identifier sid2 = new Identifier();
sid1.setValue("sequence2");
store.removeMessages(sid2, messageNrs, true);
}
use of org.apache.cxf.ws.rm.persistence.RMMessage in project cxf by apache.
the class RMTxStoreTestBase method setupInboundMessage.
private void setupInboundMessage(DestinationSequence seq, long mn, String to) throws IOException, SQLException {
RMMessage msg = createRMMessage(ONE, to);
control.replay();
store.persistIncoming(seq, msg);
control.reset();
}
use of org.apache.cxf.ws.rm.persistence.RMMessage in project cxf by apache.
the class RMTxStoreTestBase method checkRecoveredMessages.
private void checkRecoveredMessages(Collection<RMMessage> msgs) {
for (RMMessage msg : msgs) {
long mn = msg.getMessageNumber();
assertTrue(mn == 1 || mn == 10);
if (mn == 10) {
assertEquals(NON_ANON_ACKS_TO, msg.getTo());
} else {
assertNull(msg.getTo());
}
assertEquals(TIME, msg.getCreatedTime());
try {
InputStream actual = msg.getContent().getInputStream();
assertEquals(new String("Message " + mn), IOUtils.readStringFromStream(actual));
} catch (IOException e) {
fail("failed to get the input stream");
}
}
}
Aggregations