use of org.apache.cxf.ws.rm.persistence.RMMessage in project cxf by apache.
the class RMManager method recoverDestinationSequence.
private void recoverDestinationSequence(Endpoint endpoint, Conduit conduit, Destination d, DestinationSequence ds) {
// always recover the sequence
d.addSequence(ds, false);
Collection<RMMessage> ms = store.getMessages(ds.getIdentifier(), false);
if (null == ms || ms.isEmpty()) {
return;
}
LOG.log(Level.FINE, "Number of messages in sequence: {0}", ms.size());
for (RMMessage m : ms) {
Message message = new MessageImpl();
Exchange exchange = new ExchangeImpl();
message.setExchange(exchange);
if (null != conduit) {
exchange.setConduit(conduit);
}
exchange.put(Endpoint.class, endpoint);
exchange.put(Service.class, endpoint.getService());
if (endpoint.getEndpointInfo().getService() != null) {
exchange.put(ServiceInfo.class, endpoint.getEndpointInfo().getService());
exchange.put(InterfaceInfo.class, endpoint.getEndpointInfo().getService().getInterface());
}
exchange.put(Binding.class, endpoint.getBinding());
exchange.put(BindingInfo.class, endpoint.getEndpointInfo().getBinding());
exchange.put(Bus.class, bus);
SequenceType st = new SequenceType();
st.setIdentifier(ds.getIdentifier());
st.setMessageNumber(m.getMessageNumber());
RMProperties rmps = new RMProperties();
rmps.setSequence(st);
rmps.setCreatedTime(m.getCreatedTime());
RMContextUtils.storeRMProperties(message, rmps, 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);
redeliveryQueue.addUndelivered(message);
// add acknowledged undelivered message
ds.addDeliveringMessageNumber(m.getMessageNumber());
} catch (IOException e) {
LOG.log(Level.SEVERE, "Error reading persisted message data", e);
}
}
// if no messages are recovered and the sequence has been already terminated, remove the sequence
if (ds.isTerminated() && ds.allAcknowledgedMessagesDelivered()) {
d.removeSequence(ds);
store.removeDestinationSequence(ds.getIdentifier());
}
}
use of org.apache.cxf.ws.rm.persistence.RMMessage in project cxf by apache.
the class RMManagerTest method testRecoverReliableClientEndpointWithAttachment.
@Test
public void testRecoverReliableClientEndpointWithAttachment() throws NoSuchMethodException, IOException {
Method method = RMManager.class.getDeclaredMethod("createReliableEndpoint", new Class[] { Endpoint.class });
manager = control.createMock(RMManager.class, new Method[] { method });
manager.setReliableEndpointsMap(new HashMap<Endpoint, RMEndpoint>());
Endpoint endpoint = control.createMock(Endpoint.class);
EndpointInfo ei = control.createMock(EndpointInfo.class);
ServiceInfo si = control.createMock(ServiceInfo.class);
BindingInfo bi = control.createMock(BindingInfo.class);
InterfaceInfo ii = control.createMock(InterfaceInfo.class);
setUpEndpointForRecovery(endpoint, ei, si, bi, ii);
Conduit conduit = control.createMock(Conduit.class);
SourceSequence ss = control.createMock(SourceSequence.class);
DestinationSequence ds = control.createMock(DestinationSequence.class);
RMMessage m1 = new RMMessage();
InputStream fis = getClass().getResourceAsStream("persistence/SerializedRMMessage.txt");
CachedOutputStream cos = new CachedOutputStream();
IOUtils.copyAndCloseInput(fis, cos);
cos.flush();
m1.setContent(cos);
m1.setTo("toAddress");
m1.setMessageNumber(Long.valueOf(10));
m1.setContentType(MULTIPART_TYPE);
Capture<Message> mc = Capture.newInstance();
setUpRecoverReliableEndpointWithAttachment(endpoint, conduit, ss, ds, m1, mc);
control.replay();
manager.recoverReliableEndpoint(endpoint, conduit);
control.verify();
Message msg = mc.getValue();
assertNotNull(msg);
assertNotNull(msg.getExchange());
assertSame(msg, msg.getExchange().getOutMessage());
CachedOutputStream cos1 = (CachedOutputStream) msg.get(RMMessageConstants.SAVED_CONTENT);
assertStartsWith(cos1.getInputStream(), "<soap:Envelope");
assertEquals(1, msg.getAttachments().size());
}
use of org.apache.cxf.ws.rm.persistence.RMMessage in project cxf by apache.
the class RMManagerTest method testRecoverReliableClientEndpoint.
@Test
public void testRecoverReliableClientEndpoint() throws NoSuchMethodException, IOException {
Method method = RMManager.class.getDeclaredMethod("createReliableEndpoint", new Class[] { Endpoint.class });
manager = control.createMock(RMManager.class, new Method[] { method });
manager.setReliableEndpointsMap(new HashMap<Endpoint, RMEndpoint>());
Endpoint endpoint = control.createMock(Endpoint.class);
EndpointInfo ei = control.createMock(EndpointInfo.class);
ServiceInfo si = control.createMock(ServiceInfo.class);
BindingInfo bi = control.createMock(BindingInfo.class);
InterfaceInfo ii = control.createMock(InterfaceInfo.class);
setUpEndpointForRecovery(endpoint, ei, si, bi, ii);
Conduit conduit = control.createMock(Conduit.class);
setUpRecoverReliableEndpoint(endpoint, conduit, null, null, null);
control.replay();
manager.recoverReliableEndpoint(endpoint, conduit);
control.verify();
control.reset();
setUpEndpointForRecovery(endpoint, ei, si, bi, ii);
SourceSequence ss = control.createMock(SourceSequence.class);
DestinationSequence ds = control.createMock(DestinationSequence.class);
setUpRecoverReliableEndpoint(endpoint, conduit, ss, ds, null);
control.replay();
manager.recoverReliableEndpoint(endpoint, conduit);
control.verify();
control.reset();
setUpEndpointForRecovery(endpoint, ei, si, bi, ii);
RMMessage m = control.createMock(RMMessage.class);
setUpRecoverReliableEndpoint(endpoint, conduit, ss, ds, m);
control.replay();
manager.recoverReliableEndpoint(endpoint, conduit);
control.verify();
}
use of org.apache.cxf.ws.rm.persistence.RMMessage in project cxf by apache.
the class RMManagerTest method setUpRecoverReliableEndpointWithAttachment.
void setUpRecoverReliableEndpointWithAttachment(Endpoint endpoint, Conduit conduit, SourceSequence ss, DestinationSequence ds, RMMessage m, Capture<Message> mc) throws IOException {
RMStore store = control.createMock(RMStore.class);
RetransmissionQueue oqueue = control.createMock(RetransmissionQueue.class);
RedeliveryQueue iqueue = control.createMock(RedeliveryQueue.class);
manager.setStore(store);
manager.setRetransmissionQueue(oqueue);
manager.setRedeliveryQueue(iqueue);
Collection<SourceSequence> sss = new ArrayList<>();
if (null != ss) {
sss.add(ss);
}
EasyMock.expect(store.getSourceSequences("{S}s.{P}p@cxf")).andReturn(sss);
if (null == ss) {
return;
}
Collection<DestinationSequence> dss = new ArrayList<>();
if (null != ds) {
dss.add(ds);
}
EasyMock.expect(store.getDestinationSequences("{S}s.{P}p@cxf")).andReturn(dss);
if (null == ds) {
return;
}
Collection<RMMessage> ms = new ArrayList<>();
if (null != m) {
ms.add(m);
}
Identifier id = new Identifier();
id.setValue("S1");
EasyMock.expect(ss.getIdentifier()).andReturn(id).times(null == m ? 1 : 2);
EasyMock.expect(ss.getProtocol()).andReturn(ProtocolVariation.RM10WSA200408).anyTimes();
EasyMock.expect(store.getMessages(id, true)).andReturn(ms);
RMEndpoint rme = control.createMock(RMEndpoint.class);
EasyMock.expect(manager.createReliableEndpoint(endpoint)).andReturn(rme);
Source source = control.createMock(Source.class);
EasyMock.expect(rme.getSource()).andReturn(source).anyTimes();
Destination destination = control.createMock(Destination.class);
EasyMock.expect(rme.getDestination()).andReturn(destination);
destination.addSequence(ds, false);
EasyMock.expectLastCall();
Service service = control.createMock(Service.class);
EasyMock.expect(endpoint.getService()).andReturn(service).anyTimes();
Binding binding = control.createMock(Binding.class);
EasyMock.expect(endpoint.getBinding()).andReturn(binding).anyTimes();
EasyMock.expect(ss.isLastMessage()).andReturn(true).anyTimes();
EasyMock.expect(ss.getCurrentMessageNr()).andReturn(Long.valueOf(10)).anyTimes();
if (null == m) {
return;
}
oqueue.addUnacknowledged(EasyMock.capture(mc));
EasyMock.expectLastCall();
oqueue.start();
EasyMock.expectLastCall();
iqueue.start();
EasyMock.expectLastCall();
}
use of org.apache.cxf.ws.rm.persistence.RMMessage in project cxf by apache.
the class RMManagerTest method setUpRecoverReliableEndpoint.
void setUpRecoverReliableEndpoint(Endpoint endpoint, Conduit conduit, SourceSequence ss, DestinationSequence ds, RMMessage m) throws IOException {
RMStore store = control.createMock(RMStore.class);
RetransmissionQueue oqueue = control.createMock(RetransmissionQueue.class);
RedeliveryQueue iqueue = control.createMock(RedeliveryQueue.class);
manager.setStore(store);
manager.setRetransmissionQueue(oqueue);
manager.setRedeliveryQueue(iqueue);
Collection<SourceSequence> sss = new ArrayList<>();
if (null != ss) {
sss.add(ss);
}
EasyMock.expect(store.getSourceSequences("{S}s.{P}p@cxf")).andReturn(sss);
if (null == ss) {
return;
}
Collection<DestinationSequence> dss = new ArrayList<>();
if (null != ds) {
dss.add(ds);
}
EasyMock.expect(store.getDestinationSequences("{S}s.{P}p@cxf")).andReturn(dss);
if (null == ds) {
return;
}
Collection<RMMessage> ms = new ArrayList<>();
if (null != m) {
ms.add(m);
}
Identifier id = new Identifier();
id.setValue("S1");
EasyMock.expect(ss.getIdentifier()).andReturn(id).times(null == m ? 1 : 2);
EasyMock.expect(ss.getProtocol()).andReturn(ProtocolVariation.RM10WSA200408).anyTimes();
EasyMock.expect(store.getMessages(id, true)).andReturn(ms);
RMEndpoint rme = control.createMock(RMEndpoint.class);
EasyMock.expect(manager.createReliableEndpoint(endpoint)).andReturn(rme);
Source source = control.createMock(Source.class);
EasyMock.expect(rme.getSource()).andReturn(source).anyTimes();
Destination destination = control.createMock(Destination.class);
EasyMock.expect(rme.getDestination()).andReturn(destination);
destination.addSequence(ds, false);
EasyMock.expectLastCall();
Service service = control.createMock(Service.class);
EasyMock.expect(endpoint.getService()).andReturn(service).anyTimes();
Binding binding = control.createMock(Binding.class);
EasyMock.expect(endpoint.getBinding()).andReturn(binding).anyTimes();
EasyMock.expect(ss.isLastMessage()).andReturn(true).anyTimes();
EasyMock.expect(ss.getCurrentMessageNr()).andReturn(Long.valueOf(10)).anyTimes();
if (null == m) {
return;
}
EasyMock.expect(m.getMessageNumber()).andReturn(Long.valueOf(10)).times(2);
if (null == conduit) {
EasyMock.expect(m.getTo()).andReturn("toAddress");
}
InputStream is = new ByteArrayInputStream(new byte[0]);
CachedOutputStream cos = new CachedOutputStream();
IOUtils.copy(is, cos);
cos.flush();
is.close();
EasyMock.expect(m.getContent()).andReturn(cos).anyTimes();
oqueue.addUnacknowledged(EasyMock.isA(Message.class));
EasyMock.expectLastCall();
oqueue.start();
EasyMock.expectLastCall();
iqueue.start();
EasyMock.expectLastCall();
}
Aggregations