Search in sources :

Example 1 with RMMessage

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());
    }
}
Also used : Exchange(org.apache.cxf.message.Exchange) RMMessage(org.apache.cxf.ws.rm.persistence.RMMessage) Message(org.apache.cxf.message.Message) RMMessage(org.apache.cxf.ws.rm.persistence.RMMessage) CloseSequenceType(org.apache.cxf.ws.rm.v200702.CloseSequenceType) SequenceType(org.apache.cxf.ws.rm.v200702.SequenceType) IOException(java.io.IOException) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Example 2 with RMMessage

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());
}
Also used : RMMessage(org.apache.cxf.ws.rm.persistence.RMMessage) Message(org.apache.cxf.message.Message) RMMessage(org.apache.cxf.ws.rm.persistence.RMMessage) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Method(java.lang.reflect.Method) CachedOutputStream(org.apache.cxf.io.CachedOutputStream) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) Conduit(org.apache.cxf.transport.Conduit) BindingInfo(org.apache.cxf.service.model.BindingInfo) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo) Test(org.junit.Test)

Example 3 with RMMessage

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();
}
Also used : RMMessage(org.apache.cxf.ws.rm.persistence.RMMessage) Method(java.lang.reflect.Method) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) Conduit(org.apache.cxf.transport.Conduit) BindingInfo(org.apache.cxf.service.model.BindingInfo) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo) Test(org.junit.Test)

Example 4 with RMMessage

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();
}
Also used : Binding(org.apache.cxf.binding.Binding) SoapBinding(org.apache.cxf.binding.soap.SoapBinding) RMMessage(org.apache.cxf.ws.rm.persistence.RMMessage) ArrayList(java.util.ArrayList) Service(org.apache.cxf.service.Service) RMStore(org.apache.cxf.ws.rm.persistence.RMStore) Identifier(org.apache.cxf.ws.rm.v200702.Identifier)

Example 5 with RMMessage

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();
}
Also used : Binding(org.apache.cxf.binding.Binding) SoapBinding(org.apache.cxf.binding.soap.SoapBinding) RMMessage(org.apache.cxf.ws.rm.persistence.RMMessage) Message(org.apache.cxf.message.Message) RMMessage(org.apache.cxf.ws.rm.persistence.RMMessage) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Service(org.apache.cxf.service.Service) RMStore(org.apache.cxf.ws.rm.persistence.RMStore) CachedOutputStream(org.apache.cxf.io.CachedOutputStream) Identifier(org.apache.cxf.ws.rm.v200702.Identifier) ByteArrayInputStream(java.io.ByteArrayInputStream)

Aggregations

RMMessage (org.apache.cxf.ws.rm.persistence.RMMessage)18 CachedOutputStream (org.apache.cxf.io.CachedOutputStream)6 Identifier (org.apache.cxf.ws.rm.v200702.Identifier)6 Test (org.junit.Test)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 IOException (java.io.IOException)5 InputStream (java.io.InputStream)4 Message (org.apache.cxf.message.Message)4 RMStore (org.apache.cxf.ws.rm.persistence.RMStore)4 Connection (java.sql.Connection)3 ArrayList (java.util.ArrayList)3 SequenceType (org.apache.cxf.ws.rm.v200702.SequenceType)3 Method (java.lang.reflect.Method)2 SQLException (java.sql.SQLException)2 Binding (org.apache.cxf.binding.Binding)2 SoapBinding (org.apache.cxf.binding.soap.SoapBinding)2 Endpoint (org.apache.cxf.endpoint.Endpoint)2 Exchange (org.apache.cxf.message.Exchange)2 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)2 MessageImpl (org.apache.cxf.message.MessageImpl)2