Search in sources :

Example 1 with RMStore

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

the class DestinationSequence method terminate.

void terminate() {
    if (!terminated) {
        terminated = true;
        RMStore store = destination.getManager().getStore();
        if (null == store) {
            return;
        }
        // only updating the sequence
        store.persistIncoming(this, null);
    }
}
Also used : RMStore(org.apache.cxf.ws.rm.persistence.RMStore)

Example 2 with RMStore

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

the class DestinationSequence method acknowledge.

public void acknowledge(Message message) throws SequenceFault {
    RMProperties rmps = RMContextUtils.retrieveRMProperties(message, false);
    SequenceType st = rmps.getSequence();
    long messageNumber = st.getMessageNumber().longValue();
    LOG.fine("Acknowledging message: " + messageNumber);
    if (0 != lastMessageNumber && messageNumber > lastMessageNumber) {
        RMConstants consts = getProtocol().getConstants();
        SequenceFaultFactory sff = new SequenceFaultFactory(consts);
        throw sff.createSequenceTerminatedFault(st.getIdentifier(), false);
    }
    monitor.acknowledgeMessage();
    boolean updated = false;
    synchronized (this) {
        boolean done = false;
        int i = 0;
        for (; i < acknowledgement.getAcknowledgementRange().size(); i++) {
            AcknowledgementRange r = acknowledgement.getAcknowledgementRange().get(i);
            if (r.getLower().compareTo(messageNumber) <= 0 && r.getUpper().compareTo(messageNumber) >= 0) {
                done = true;
                break;
            }
            long diff = r.getLower() - messageNumber;
            if (diff == 1) {
                r.setLower(messageNumber);
                updated = true;
                done = true;
            } else if (diff > 0) {
                break;
            } else if (messageNumber - r.getUpper().longValue() == 1) {
                r.setUpper(messageNumber);
                updated = true;
                done = true;
                break;
            }
        }
        if (!done) {
            // need new acknowledgement range
            AcknowledgementRange range = new AcknowledgementRange();
            range.setLower(messageNumber);
            range.setUpper(messageNumber);
            updated = true;
            acknowledgement.getAcknowledgementRange().add(i, range);
            if (acknowledgement.getAcknowledgementRange().size() > 1) {
                // acknowledge out-of-order at first opportunity
                scheduleImmediateAcknowledgement();
            }
        }
        mergeRanges();
    }
    if (updated) {
        RMStore store = destination.getManager().getStore();
        if (null != store && !MessageUtils.getContextualBoolean(message, Message.ROBUST_ONEWAY)) {
            try {
                RMMessage msg = new RMMessage();
                CachedOutputStream cos = (CachedOutputStream) message.get(RMMessageConstants.SAVED_CONTENT);
                msg.setMessageNumber(st.getMessageNumber());
                msg.setCreatedTime(rmps.getCreatedTime());
                // in case no attachments are available, cos can be saved directly
                if (message.getAttachments() == null) {
                    msg.setContent(cos);
                    msg.setContentType((String) message.get(Message.CONTENT_TYPE));
                } else {
                    InputStream is = cos.getInputStream();
                    PersistenceUtils.encodeRMContent(msg, message, is);
                }
                store.persistIncoming(this, msg);
            } catch (IOException e) {
                throw new Fault(e);
            }
        }
    }
    deliveringMessageNumbers.add(messageNumber);
    RMEndpoint reliableEndpoint = destination.getReliableEndpoint();
    RMConfiguration cfg = reliableEndpoint.getConfiguration();
    if (null == rmps.getCloseSequence()) {
        scheduleAcknowledgement(cfg.getAcknowledgementIntervalTime());
    }
    long inactivityTimeout = cfg.getInactivityTimeoutTime();
    scheduleSequenceTermination(inactivityTimeout);
}
Also used : RMMessage(org.apache.cxf.ws.rm.persistence.RMMessage) InputStream(java.io.InputStream) RMStore(org.apache.cxf.ws.rm.persistence.RMStore) Fault(org.apache.cxf.interceptor.Fault) SequenceType(org.apache.cxf.ws.rm.v200702.SequenceType) IOException(java.io.IOException) CachedOutputStream(org.apache.cxf.io.CachedOutputStream) AcknowledgementRange(org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement.AcknowledgementRange)

Example 3 with RMStore

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

the class RMCaptureOutInterceptor method handle.

protected void handle(Message msg) throws SequenceFault, RMException {
    AddressingProperties maps = ContextUtils.retrieveMAPs(msg, false, true, false);
    if (null == maps) {
        LogUtils.log(LOG, Level.WARNING, "MAPS_RETRIEVAL_FAILURE_MSG");
        return;
    }
    if (Boolean.TRUE.equals(msg.get(RMMessageConstants.RM_RETRANSMISSION))) {
        return;
    }
    if (isRuntimeFault(msg)) {
        LogUtils.log(LOG, Level.WARNING, "RUNTIME_FAULT_MSG");
        // in case of a SequenceFault or other WS-RM related fault, set action appropriately.
        // the received inbound maps is available to extract some values in case if needed.
        Throwable cause = msg.getContent(Exception.class).getCause();
        if (cause instanceof SequenceFault || cause instanceof RMException) {
            maps.getAction().setValue(getAddressingNamespace(maps) + "/fault");
        }
        return;
    }
    Source source = getManager().getSource(msg);
    RMConfiguration config = getManager().getEffectiveConfiguration(msg);
    String wsaNamespace = config.getAddressingNamespace();
    String rmNamespace = config.getRMNamespace();
    ProtocolVariation protocol = ProtocolVariation.findVariant(rmNamespace, wsaNamespace);
    RMContextUtils.setProtocolVariation(msg, protocol);
    maps.exposeAs(wsaNamespace);
    String action = null;
    if (null != maps.getAction()) {
        action = maps.getAction().getValue();
    }
    // make sure we use the appropriate namespace
    maps.exposeAs(wsaNamespace);
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Action: " + action);
    }
    boolean isApplicationMessage = !RMContextUtils.isRMProtocolMessage(action);
    boolean isPartialResponse = MessageUtils.isPartialResponse(msg);
    RMConstants constants = protocol.getConstants();
    boolean isLastMessage = RM10Constants.CLOSE_SEQUENCE_ACTION.equals(action);
    RMProperties rmpsOut = RMContextUtils.retrieveRMProperties(msg, true);
    if (null == rmpsOut) {
        rmpsOut = new RMProperties();
        rmpsOut.exposeAs(protocol.getWSRMNamespace());
        RMContextUtils.storeRMProperties(msg, rmpsOut, true);
    }
    // Activate process response for oneWay
    if (msg.getExchange().isOneWay()) {
        msg.getExchange().put(Message.PROCESS_ONEWAY_RESPONSE, true);
    }
    RMProperties rmpsIn = null;
    Identifier inSeqId = null;
    long inMessageNumber = 0;
    if (isApplicationMessage) {
        rmpsIn = RMContextUtils.retrieveRMProperties(msg, false);
        if (null != rmpsIn && null != rmpsIn.getSequence()) {
            inSeqId = rmpsIn.getSequence().getIdentifier();
            inMessageNumber = rmpsIn.getSequence().getMessageNumber();
        }
        ContextUtils.storeDeferUncorrelatedMessageAbort(msg);
    }
    Map<?, ?> invocationContext = (Map<?, ?>) msg.get(Message.INVOCATION_CONTEXT);
    if ((isApplicationMessage || (isLastMessage && invocationContext != null)) && !isPartialResponse) {
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("inbound sequence: " + (null == inSeqId ? "null" : inSeqId.getValue()));
        }
        // get the current sequence, requesting the creation of a new one if necessary
        synchronized (source) {
            SourceSequence seq = null;
            if (isLastMessage) {
                seq = (SourceSequence) invocationContext.get(SourceSequence.class.getName());
            } else {
                seq = getManager().getSequence(inSeqId, msg, maps);
            }
            assert null != seq;
            // increase message number and store a sequence type object in
            // context
            seq.nextMessageNumber(inSeqId, inMessageNumber, isLastMessage);
            if (Boolean.TRUE.equals(msg.getContextualProperty(RMManager.WSRM_LAST_MESSAGE_PROPERTY))) {
                // mark the message as the last one
                seq.setLastMessage(true);
            }
            rmpsOut.setSequence(seq);
            if (seq.isLastMessage()) {
                source.setCurrent(null);
            }
        }
    } else if (!MessageUtils.isRequestor(msg) && constants.getCreateSequenceAction().equals(action)) {
        maps.getAction().setValue(constants.getCreateSequenceResponseAction());
    } else if (isPartialResponse && action == null && isResponseToAction(msg, constants.getSequenceAckAction())) {
        Collection<SequenceAcknowledgement> acks = rmpsIn != null ? rmpsIn.getAcks() : null;
        if (acks != null && acks.size() == 1) {
            SourceSequence ss = source.getSequence(acks.iterator().next().getIdentifier());
            if (ss != null && ss.allAcknowledged()) {
                setAction(maps, constants.getTerminateSequenceAction());
                setTerminateSequence(msg, ss.getIdentifier(), protocol);
                msg.remove(Message.EMPTY_PARTIAL_RESPONSE_MESSAGE);
                // removing this sequence now. See the comment in SourceSequence.setAcknowledged()
                source.removeSequence(ss);
            }
        }
    }
    // capture message if retransmission possible
    if (isApplicationMessage && !isPartialResponse) {
        OutputStream os = msg.getContent(OutputStream.class);
        // message until connection is setup
        if (!(os instanceof WriteOnCloseOutputStream)) {
            WriteOnCloseOutputStream cached = new WriteOnCloseOutputStream(os);
            msg.setContent(OutputStream.class, cached);
            os = cached;
        }
        getManager().initializeInterceptorChain(msg);
        // doneCaptureMessage(msg);
        captureMessage(msg);
    } else if (isLastMessage) {
        // got either the rm11 CS or the rm10 empty LM
        RMStore store = getManager().getStore();
        if (null != store) {
            store.persistOutgoing(rmpsOut.getSourceSequence(), null);
        }
    }
}
Also used : WriteOnCloseOutputStream(org.apache.cxf.io.WriteOnCloseOutputStream) WriteOnCloseOutputStream(org.apache.cxf.io.WriteOnCloseOutputStream) OutputStream(java.io.OutputStream) CachedOutputStream(org.apache.cxf.io.CachedOutputStream) RMStore(org.apache.cxf.ws.rm.persistence.RMStore) XMLStreamException(javax.xml.stream.XMLStreamException) IOException(java.io.IOException) Identifier(org.apache.cxf.ws.rm.v200702.Identifier) AddressingProperties(org.apache.cxf.ws.addressing.AddressingProperties) SequenceAcknowledgement(org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement) Map(java.util.Map)

Example 4 with RMStore

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

the class DestinationSequenceTest method testPurgeAcknowledged.

@Test
public void testPurgeAcknowledged() {
    destination = control.createMock(Destination.class);
    DestinationSequence seq = new DestinationSequence(id, ref, destination, ProtocolVariation.RM10WSA200408);
    manager = control.createMock(RMManager.class);
    EasyMock.expect(destination.getManager()).andReturn(manager);
    RMStore store = control.createMock(RMStore.class);
    EasyMock.expect(manager.getStore()).andReturn(store);
    store.removeMessages(EasyMock.eq(id), CastUtils.cast(EasyMock.isA(Collection.class), Long.class), EasyMock.eq(false));
    EasyMock.expectLastCall();
    control.replay();
    seq.purgeAcknowledged(1);
    control.verify();
}
Also used : RMStore(org.apache.cxf.ws.rm.persistence.RMStore) Test(org.junit.Test)

Example 5 with RMStore

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

the class RMManagerTest method testAccessors.

@Test
public void testAccessors() {
    manager = new RMManager();
    assertNull(manager.getBus());
    assertNull(manager.getStore());
    assertNull(manager.getRetransmissionQueue());
    assertNotNull(manager.getTimer());
    Bus bus = control.createMock(Bus.class);
    RMStore store = control.createMock(RMStore.class);
    RetransmissionQueue queue = control.createMock(RetransmissionQueue.class);
    manager.setBus(bus);
    manager.setStore(store);
    manager.setRetransmissionQueue(queue);
    assertSame(bus, manager.getBus());
    assertSame(store, manager.getStore());
    assertSame(queue, manager.getRetransmissionQueue());
    control.replay();
    control.reset();
}
Also used : Bus(org.apache.cxf.Bus) RMStore(org.apache.cxf.ws.rm.persistence.RMStore) Test(org.junit.Test)

Aggregations

RMStore (org.apache.cxf.ws.rm.persistence.RMStore)19 Identifier (org.apache.cxf.ws.rm.v200702.Identifier)6 ArrayList (java.util.ArrayList)4 RMMessage (org.apache.cxf.ws.rm.persistence.RMMessage)4 Test (org.junit.Test)4 Endpoint (org.apache.cxf.endpoint.Endpoint)3 CachedOutputStream (org.apache.cxf.io.CachedOutputStream)3 SourceSequence (org.apache.cxf.ws.rm.SourceSequence)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Binding (org.apache.cxf.binding.Binding)2 SoapBinding (org.apache.cxf.binding.soap.SoapBinding)2 Client (org.apache.cxf.endpoint.Client)2 Service (org.apache.cxf.service.Service)2 DestinationSequence (org.apache.cxf.ws.rm.DestinationSequence)2 RMEndpoint (org.apache.cxf.ws.rm.RMEndpoint)2 RMManager (org.apache.cxf.ws.rm.RMManager)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 OutputStream (java.io.OutputStream)1 Map (java.util.Map)1