Search in sources :

Example 6 with DestinationPolicyType

use of org.apache.cxf.ws.rm.manager.DestinationPolicyType in project cxf by apache.

the class Servant method createSequence.

Object createSequence(Message message) {
    LOG.fine("Creating sequence");
    final ProtocolVariation protocol = RMContextUtils.getProtocolVariation(message);
    AddressingProperties maps = RMContextUtils.retrieveMAPs(message, false, false);
    Message outMessage = message.getExchange().getOutMessage();
    if (null != outMessage) {
        RMContextUtils.storeMAPs(maps, outMessage, false, false);
    }
    EncoderDecoder codec = protocol.getCodec();
    CreateSequenceType create = codec.convertReceivedCreateSequence(getParameter(message));
    Destination destination = reliableEndpoint.getDestination();
    CreateSequenceResponseType createResponse = new CreateSequenceResponseType();
    createResponse.setIdentifier(destination.generateSequenceIdentifier());
    DestinationPolicyType dp = reliableEndpoint.getManager().getDestinationPolicy();
    if (dp.getMaxSequences() > 0 && destination.getProcessingSequenceCount() >= dp.getMaxSequences()) {
        throw new RuntimeException("Sequence creation refused");
    }
    Duration supportedDuration = dp.getSequenceExpiration();
    if (null == supportedDuration) {
        supportedDuration = DatatypeFactory.PT0S;
    }
    Expires ex = create.getExpires();
    if (null != ex) {
        Duration effectiveDuration = ex.getValue();
        // PT0S represents 0 second and the shortest duration but in ws-rm, considered the longest
        if (DatatypeFactory.PT0S.equals(effectiveDuration) || (!DatatypeFactory.PT0S.equals(supportedDuration) && supportedDuration.isShorterThan(effectiveDuration))) {
            effectiveDuration = supportedDuration;
        }
        ex = new Expires();
        ex.setValue(effectiveDuration);
        createResponse.setExpires(ex);
    }
    OfferType offer = create.getOffer();
    if (null != offer) {
        AcceptType accept = new AcceptType();
        if (dp.isAcceptOffers()) {
            Source source = reliableEndpoint.getSource();
            LOG.fine("Accepting inbound sequence offer");
            // AddressingProperties maps = RMContextUtils.retrieveMAPs(message, false, false);
            accept.setAcksTo(RMUtils.createReference(maps.getTo().getValue()));
            SourceSequence seq = new SourceSequence(offer.getIdentifier(), null, createResponse.getIdentifier(), protocol);
            seq.setExpires(offer.getExpires());
            seq.setTarget(create.getAcksTo());
            source.addSequence(seq);
            source.setCurrent(createResponse.getIdentifier(), seq);
            if (LOG.isLoggable(Level.FINE)) {
                LOG.fine("Making offered sequence the current sequence for responses to " + createResponse.getIdentifier().getValue());
            }
        } else {
            if (LOG.isLoggable(Level.FINE)) {
                LOG.fine("Refusing inbound sequence offer");
            }
            accept.setAcksTo(RMUtils.createNoneReference());
        }
        createResponse.setAccept(accept);
    }
    DestinationSequence seq = new DestinationSequence(createResponse.getIdentifier(), create.getAcksTo(), destination, protocol);
    seq.setCorrelationID(maps.getMessageID().getValue());
    destination.addSequence(seq);
    LOG.fine("returning " + createResponse);
    return codec.convertToSend(createResponse);
}
Also used : Message(org.apache.cxf.message.Message) Duration(javax.xml.datatype.Duration) DestinationPolicyType(org.apache.cxf.ws.rm.manager.DestinationPolicyType) CreateSequenceResponseType(org.apache.cxf.ws.rm.v200702.CreateSequenceResponseType) AcceptType(org.apache.cxf.ws.rm.v200702.AcceptType) OfferType(org.apache.cxf.ws.rm.v200702.OfferType) CreateSequenceType(org.apache.cxf.ws.rm.v200702.CreateSequenceType) AddressingProperties(org.apache.cxf.ws.addressing.AddressingProperties) Expires(org.apache.cxf.ws.rm.v200702.Expires)

Example 7 with DestinationPolicyType

use of org.apache.cxf.ws.rm.manager.DestinationPolicyType in project cxf by apache.

the class RMManagerTest method testCustom.

@Test
public void testCustom() {
    Bus bus = new SpringBusFactory().createBus("org/apache/cxf/ws/rm/custom-rmmanager.xml", false);
    manager = bus.getExtension(RMManager.class);
    assertNotNull("sourcePolicy is not set.", manager.getSourcePolicy());
    assertNotNull("destinationPolicy is not set.", manager.getDestinationPolicy());
    manager.initialise();
    RMConfiguration cfg = manager.getConfiguration();
    assertNotNull("RMConfiguration is not set.", cfg);
    assertNotNull("deliveryAssurance is not set.", cfg.getDeliveryAssurance());
    assertFalse(cfg.isExponentialBackoff());
    assertEquals(10000L, cfg.getBaseRetransmissionInterval().longValue());
    assertEquals(10000L, cfg.getAcknowledgementIntervalTime());
    assertNull(cfg.getInactivityTimeout());
    SourcePolicyType sp = manager.getSourcePolicy();
    assertEquals(0L, sp.getSequenceExpiration().getTimeInMillis(new Date()));
    assertEquals(0L, sp.getOfferedSequenceExpiration().getTimeInMillis(new Date()));
    assertNull(sp.getAcksTo());
    assertTrue(sp.isIncludeOffer());
    SequenceTerminationPolicyType stp = sp.getSequenceTerminationPolicy();
    assertEquals(0, stp.getMaxRanges());
    assertEquals(0, stp.getMaxUnacknowledged());
    assertFalse(stp.isTerminateOnShutdown());
    assertEquals(0, stp.getMaxLength());
    DestinationPolicyType dp = manager.getDestinationPolicy();
    assertNotNull(dp.getAcksPolicy());
    assertEquals(dp.getAcksPolicy().getIntraMessageThreshold(), 0);
}
Also used : Bus(org.apache.cxf.Bus) SequenceTerminationPolicyType(org.apache.cxf.ws.rm.manager.SequenceTerminationPolicyType) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) SourcePolicyType(org.apache.cxf.ws.rm.manager.SourcePolicyType) DestinationPolicyType(org.apache.cxf.ws.rm.manager.DestinationPolicyType) Date(java.util.Date) Test(org.junit.Test)

Example 8 with DestinationPolicyType

use of org.apache.cxf.ws.rm.manager.DestinationPolicyType in project cxf by apache.

the class ServantTest method verifyCreateSequenceExpiresSetAtSource.

private void verifyCreateSequenceExpiresSetAtSource(Servant servant, RMManager manager) throws SequenceFault {
    DestinationPolicyType dp = RMMANGER_FACTORY.createDestinationPolicyType();
    AcksPolicyType ap = RMMANGER_FACTORY.createAcksPolicyType();
    dp.setAcksPolicy(ap);
    manager.setDestinationPolicy(dp);
    Expires expires = new Expires();
    expires.setValue(DURATION_SHORT);
    Message message = createTestCreateSequenceMessage(expires, null);
    CreateSequenceResponseType csr = (CreateSequenceResponseType) servant.createSequence(message);
    Expires expires2 = csr.getExpires();
    assertNotNull(expires2);
    assertEquals(DURATION_SHORT, expires2.getValue());
}
Also used : AcksPolicyType(org.apache.cxf.ws.rm.manager.AcksPolicyType) Message(org.apache.cxf.message.Message) DestinationPolicyType(org.apache.cxf.ws.rm.manager.DestinationPolicyType) Expires(org.apache.cxf.ws.rm.v200502.Expires) CreateSequenceResponseType(org.apache.cxf.ws.rm.v200502.CreateSequenceResponseType)

Example 9 with DestinationPolicyType

use of org.apache.cxf.ws.rm.manager.DestinationPolicyType in project cxf by apache.

the class ServantTest method verifyCreateSequenceExpiresSetAtBoth.

private void verifyCreateSequenceExpiresSetAtBoth(Servant servant, RMManager manager) throws SequenceFault {
    DestinationPolicyType dp = RMMANGER_FACTORY.createDestinationPolicyType();
    AcksPolicyType ap = RMMANGER_FACTORY.createAcksPolicyType();
    dp.setAcksPolicy(ap);
    dp.setSequenceExpiration(DURATION_SHORT);
    manager.setDestinationPolicy(dp);
    Expires expires = new Expires();
    expires.setValue(DURATION_VERY_SHORT);
    Message message = createTestCreateSequenceMessage(expires, null);
    CreateSequenceResponseType csr = (CreateSequenceResponseType) servant.createSequence(message);
    Expires expires2 = csr.getExpires();
    assertNotNull(expires2);
    assertEquals(DURATION_VERY_SHORT, expires2.getValue());
}
Also used : AcksPolicyType(org.apache.cxf.ws.rm.manager.AcksPolicyType) Message(org.apache.cxf.message.Message) DestinationPolicyType(org.apache.cxf.ws.rm.manager.DestinationPolicyType) Expires(org.apache.cxf.ws.rm.v200502.Expires) CreateSequenceResponseType(org.apache.cxf.ws.rm.v200502.CreateSequenceResponseType)

Example 10 with DestinationPolicyType

use of org.apache.cxf.ws.rm.manager.DestinationPolicyType in project cxf by apache.

the class ServantTest method verifyTerminateSequenceDefault.

private void verifyTerminateSequenceDefault(Servant servant, RMManager manager, String sidstr, ProtocolVariation protocol) throws SequenceFault {
    DestinationPolicyType dp = RMMANGER_FACTORY.createDestinationPolicyType();
    AcksPolicyType ap = RMMANGER_FACTORY.createAcksPolicyType();
    dp.setAcksPolicy(ap);
    manager.setDestinationPolicy(dp);
    Message message = createTestTerminateSequenceMessage(sidstr, protocol);
    Object tsr = servant.terminateSequence(message);
    if (ProtocolVariation.RM10WSA200408.getWSRMNamespace().equals(protocol.getWSRMNamespace())) {
        // rm 1.0
        assertNull(tsr);
    } else {
        // rm 1.1
        assertTrue(tsr instanceof TerminateSequenceResponseType);
        org.apache.cxf.ws.rm.v200702.Identifier sid = ((TerminateSequenceResponseType) tsr).getIdentifier();
        assertNotNull(sid);
        assertEquals(sidstr, sid.getValue());
    }
}
Also used : TerminateSequenceResponseType(org.apache.cxf.ws.rm.v200702.TerminateSequenceResponseType) AcksPolicyType(org.apache.cxf.ws.rm.manager.AcksPolicyType) Message(org.apache.cxf.message.Message) DestinationPolicyType(org.apache.cxf.ws.rm.manager.DestinationPolicyType)

Aggregations

DestinationPolicyType (org.apache.cxf.ws.rm.manager.DestinationPolicyType)11 Message (org.apache.cxf.message.Message)7 AcksPolicyType (org.apache.cxf.ws.rm.manager.AcksPolicyType)7 CreateSequenceResponseType (org.apache.cxf.ws.rm.v200502.CreateSequenceResponseType)4 Expires (org.apache.cxf.ws.rm.v200502.Expires)4 Test (org.junit.Test)3 Date (java.util.Date)2 SequenceTerminationPolicyType (org.apache.cxf.ws.rm.manager.SequenceTerminationPolicyType)2 SourcePolicyType (org.apache.cxf.ws.rm.manager.SourcePolicyType)2 PostConstruct (javax.annotation.PostConstruct)1 JMException (javax.management.JMException)1 Duration (javax.xml.datatype.Duration)1 Bus (org.apache.cxf.Bus)1 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)1 InstrumentationManager (org.apache.cxf.management.InstrumentationManager)1 Exchange (org.apache.cxf.message.Exchange)1 AddressingProperties (org.apache.cxf.ws.addressing.AddressingProperties)1 DeliveryAssurance (org.apache.cxf.ws.rm.RMConfiguration.DeliveryAssurance)1 RMFeature (org.apache.cxf.ws.rm.feature.RMFeature)1 RetryPolicyType (org.apache.cxf.ws.rm.manager.RetryPolicyType)1