Search in sources :

Example 21 with SequenceType

use of org.apache.cxf.ws.rm.v200702.SequenceType in project midpoint by Evolveum.

the class SequenceHelper method advanceSequenceAttempt.

public long advanceSequenceAttempt(String oid, OperationResult result) throws ObjectNotFoundException, SchemaException, SerializationRelatedException {
    long returnValue;
    LOGGER.debug("Advancing sequence with oid '{}'.", oid);
    LOGGER_PERFORMANCE.debug("> advance sequence, oid={}", oid);
    Session session = null;
    try {
        session = baseHelper.beginTransaction();
        PrismObject<SequenceType> prismObject = objectRetriever.getObjectInternal(session, SequenceType.class, oid, null, true);
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("OBJECT before:\n{}", prismObject.debugDump());
        }
        SequenceType sequence = prismObject.asObjectable();
        if (!sequence.getUnusedValues().isEmpty()) {
            returnValue = sequence.getUnusedValues().remove(0);
        } else {
            long counter = sequence.getCounter() != null ? sequence.getCounter() : 0L;
            long maxCounter = sequence.getMaxCounter() != null ? sequence.getMaxCounter() : Long.MAX_VALUE;
            boolean allowRewind = Boolean.TRUE.equals(sequence.isAllowRewind());
            if (counter < maxCounter) {
                returnValue = counter;
                sequence.setCounter(counter + 1);
            } else if (counter == maxCounter) {
                returnValue = counter;
                if (allowRewind) {
                    sequence.setCounter(0L);
                } else {
                    // will produce exception during next run
                    sequence.setCounter(counter + 1);
                }
            } else {
                // i.e. counter > maxCounter
                if (allowRewind) {
                    // shouldn't occur but...
                    LOGGER.warn("Sequence {} overflown with allowRewind set to true. Rewinding.", oid);
                    returnValue = 0;
                    sequence.setCounter(1L);
                } else {
                    // TODO some better exception...
                    throw new SystemException("No (next) value available from sequence " + oid + ". Current counter = " + sequence.getCounter() + ", max value = " + sequence.getMaxCounter());
                }
            }
        }
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Return value = {}, OBJECT after:\n{}", returnValue, prismObject.debugDump());
        }
        // merge and update object
        LOGGER.trace("Translating JAXB to data type.");
        PrismIdentifierGenerator idGenerator = new PrismIdentifierGenerator(PrismIdentifierGenerator.Operation.MODIFY);
        RObject rObject = objectUpdater.createDataObjectFromJAXB(prismObject, idGenerator);
        rObject.setVersion(rObject.getVersion() + 1);
        objectUpdater.updateFullObject(rObject, prismObject);
        session.merge(rObject);
        LOGGER.trace("Before commit...");
        session.getTransaction().commit();
        LOGGER.trace("Committed!");
        return returnValue;
    } catch (ObjectNotFoundException | SchemaException ex) {
        baseHelper.rollbackTransaction(session, ex, result, true);
        throw ex;
    } catch (DtoTranslationException | RuntimeException ex) {
        // should always throw an exception
        baseHelper.handleGeneralException(ex, session, result);
        // ...so this shouldn't occur at all
        throw new SystemException("Exception " + ex + " was not handled correctly", ex);
    } finally {
        baseHelper.cleanupSessionAndResult(session, result);
        LOGGER.trace("Session cleaned up.");
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismIdentifierGenerator(com.evolveum.midpoint.repo.sql.util.PrismIdentifierGenerator) SequenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.SequenceType) DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException) SystemException(com.evolveum.midpoint.util.exception.SystemException) RObject(com.evolveum.midpoint.repo.sql.data.common.RObject) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) Session(org.hibernate.Session)

Example 22 with SequenceType

use of org.apache.cxf.ws.rm.v200702.SequenceType in project midpoint by Evolveum.

the class SequenceHelper method returnUnusedValuesToSequenceAttempt.

public void returnUnusedValuesToSequenceAttempt(String oid, Collection<Long> unusedValues, OperationResult result) throws ObjectNotFoundException, SchemaException, SerializationRelatedException {
    LOGGER.debug("Returning unused values of {} to a sequence with oid '{}'.", unusedValues, oid);
    LOGGER_PERFORMANCE.debug("> return unused values, oid={}, values={}", oid, unusedValues);
    Session session = null;
    try {
        session = baseHelper.beginTransaction();
        PrismObject<SequenceType> prismObject = objectRetriever.getObjectInternal(session, SequenceType.class, oid, null, true);
        LOGGER.trace("OBJECT before:\n{}", prismObject.debugDumpLazily());
        SequenceType sequence = prismObject.asObjectable();
        int maxUnusedValues = sequence.getMaxUnusedValues() != null ? sequence.getMaxUnusedValues() : 0;
        Iterator<Long> valuesToReturnIterator = unusedValues.iterator();
        while (valuesToReturnIterator.hasNext() && sequence.getUnusedValues().size() < maxUnusedValues) {
            Long valueToReturn = valuesToReturnIterator.next();
            if (valueToReturn == null) {
                // sanity check
                continue;
            }
            if (!sequence.getUnusedValues().contains(valueToReturn)) {
                sequence.getUnusedValues().add(valueToReturn);
            } else {
                LOGGER.warn("UnusedValues in sequence {} already contains value of {} - ignoring the return request", oid, valueToReturn);
            }
        }
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("OBJECT after:\n{}", prismObject.debugDump());
        }
        // merge and update object
        LOGGER.trace("Translating JAXB to data type.");
        PrismIdentifierGenerator idGenerator = new PrismIdentifierGenerator(PrismIdentifierGenerator.Operation.MODIFY);
        RObject rObject = objectUpdater.createDataObjectFromJAXB(prismObject, idGenerator);
        rObject.setVersion(rObject.getVersion() + 1);
        objectUpdater.updateFullObject(rObject, prismObject);
        session.merge(rObject);
        LOGGER.trace("Before commit...");
        session.getTransaction().commit();
        LOGGER.trace("Committed!");
    } catch (ObjectNotFoundException | SchemaException ex) {
        baseHelper.rollbackTransaction(session, ex, result, true);
        throw ex;
    } catch (DtoTranslationException | RuntimeException ex) {
        // should always throw an exception
        baseHelper.handleGeneralException(ex, session, result);
        // ...so this shouldn't occur at all
        throw new SystemException("Exception " + ex + " was not handled correctly", ex);
    } finally {
        baseHelper.cleanupSessionAndResult(session, result);
        LOGGER.trace("Session cleaned up.");
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismIdentifierGenerator(com.evolveum.midpoint.repo.sql.util.PrismIdentifierGenerator) SequenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.SequenceType) DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException) SystemException(com.evolveum.midpoint.util.exception.SystemException) RObject(com.evolveum.midpoint.repo.sql.data.common.RObject) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) Session(org.hibernate.Session)

Example 23 with SequenceType

use of org.apache.cxf.ws.rm.v200702.SequenceType in project cxf by apache.

the class RMSoapInInterceptorTest method testDecodeAcksRequested.

@Test
public void testDecodeAcksRequested() throws XMLStreamException {
    SoapMessage message = setUpInboundMessage("resources/Retransmission.xml");
    RMSoapInInterceptor codec = new RMSoapInInterceptor();
    codec.handleMessage(message);
    RMProperties rmps = RMContextUtils.retrieveRMProperties(message, false);
    Collection<AckRequestedType> requested = rmps.getAcksRequested();
    assertNotNull(requested);
    assertEquals(1, requested.size());
    AckRequestedType ar = requested.iterator().next();
    assertNotNull(ar);
    assertEquals(ar.getIdentifier().getValue(), SEQ_IDENTIFIER);
    SequenceType s = rmps.getSequence();
    assertNotNull(s);
    assertEquals(s.getIdentifier().getValue(), SEQ_IDENTIFIER);
    assertEquals(s.getMessageNumber(), MSG2_MESSAGE_NUMBER);
    assertNull(rmps.getAcks());
}
Also used : AckRequestedType(org.apache.cxf.ws.rm.v200702.AckRequestedType) SequenceType(org.apache.cxf.ws.rm.v200702.SequenceType) RMProperties(org.apache.cxf.ws.rm.RMProperties) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) Test(org.junit.Test)

Example 24 with SequenceType

use of org.apache.cxf.ws.rm.v200702.SequenceType in project cxf by apache.

the class RMSoapInInterceptorTest method testDecodeSequence.

@Test
public void testDecodeSequence() throws XMLStreamException {
    SoapMessage message = setUpInboundMessage("resources/Message1.xml");
    RMSoapInInterceptor codec = new RMSoapInInterceptor();
    codec.handleMessage(message);
    RMProperties rmps = RMContextUtils.retrieveRMProperties(message, false);
    SequenceType st = rmps.getSequence();
    assertNotNull(st);
    assertEquals(st.getIdentifier().getValue(), SEQ_IDENTIFIER);
    assertEquals(st.getMessageNumber(), MSG1_MESSAGE_NUMBER);
    assertNull(rmps.getAcks());
    assertNull(rmps.getAcksRequested());
}
Also used : SequenceType(org.apache.cxf.ws.rm.v200702.SequenceType) RMProperties(org.apache.cxf.ws.rm.RMProperties) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) Test(org.junit.Test)

Example 25 with SequenceType

use of org.apache.cxf.ws.rm.v200702.SequenceType in project cxf by apache.

the class Destination method processingComplete.

void processingComplete(Message message) {
    SequenceType sequenceType = RMContextUtils.retrieveRMProperties(message, false).getSequence();
    if (null == sequenceType) {
        return;
    }
    DestinationSequence seq = getSequence(sequenceType.getIdentifier());
    if (null != seq) {
        long mn = sequenceType.getMessageNumber().longValue();
        seq.processingComplete(mn);
        seq.purgeAcknowledged(mn);
        // remove acknowledged undelivered message
        seq.removeDeliveringMessageNumber(mn);
        if (seq.isTerminated() && seq.allAcknowledgedMessagesDelivered()) {
            removeSequence(seq);
        }
    }
    CachedOutputStream saved = (CachedOutputStream) message.remove(RMMessageConstants.SAVED_CONTENT);
    if (saved != null) {
        saved.releaseTempFileHold();
        try {
            saved.close();
        } catch (IOException e) {
        // ignore
        }
    }
}
Also used : SequenceType(org.apache.cxf.ws.rm.v200702.SequenceType) IOException(java.io.IOException) CachedOutputStream(org.apache.cxf.io.CachedOutputStream)

Aggregations

SequenceType (org.apache.cxf.ws.rm.v200702.SequenceType)33 CloseSequenceType (org.apache.cxf.ws.rm.v200702.CloseSequenceType)12 RMProperties (org.apache.cxf.ws.rm.RMProperties)11 CreateSequenceType (org.apache.cxf.ws.rm.v200702.CreateSequenceType)11 TerminateSequenceType (org.apache.cxf.ws.rm.v200702.TerminateSequenceType)11 SequenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.SequenceType)9 Message (org.apache.cxf.message.Message)8 Identifier (org.apache.cxf.ws.rm.v200702.Identifier)8 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)6 IOException (java.io.IOException)6 Unmarshaller (javax.xml.bind.Unmarshaller)5 AckRequestedType (org.apache.cxf.ws.rm.v200702.AckRequestedType)5 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)4 Endpoint (org.apache.cxf.endpoint.Endpoint)4 Exchange (org.apache.cxf.message.Exchange)4 AddressingProperties (org.apache.cxf.ws.addressing.AddressingProperties)4 SequenceAcknowledgement (org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement)4 Test (org.junit.Test)4 Test (org.testng.annotations.Test)4 SystemException (com.evolveum.midpoint.util.exception.SystemException)3