Search in sources :

Example 1 with RMConfiguration

use of org.apache.cxf.ws.rm.RMConfiguration in project cxf by apache.

the class RMPolicyUtilities method getRMConfiguration.

/**
 * Returns an RMAssertion that is compatible with the default value and all RMAssertions pertaining to the
 * message (can never be null).
 *
 * @param rma the default value (non-<code>null</code>)
 * @param message the message
 * @return the compatible RMAssertion
 */
public static RMConfiguration getRMConfiguration(RMConfiguration defaultValue, Message message) {
    RMConfiguration compatible = defaultValue;
    Collection<AssertionInfo> ais = collectRMAssertions(message.get(AssertionInfoMap.class));
    for (AssertionInfo ai : ais) {
        if (ai.getAssertion() instanceof JaxbAssertion<?>) {
            RMAssertion rma = (RMAssertion) ((JaxbAssertion<?>) ai.getAssertion()).getData();
            compatible = intersect(rma, compatible);
        } else if (ai.getAssertion() instanceof PrimitiveAssertion) {
            PrimitiveAssertion assertion = (PrimitiveAssertion) ai.getAssertion();
            if (RM11Constants.WSRMP_NAMESPACE_URI.equals(assertion.getName().getNamespaceURI())) {
                compatible = intersect(assertion, compatible);
            }
        }
    }
    return compatible;
}
Also used : AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) RMAssertion(org.apache.cxf.ws.rmp.v200502.RMAssertion) PrimitiveAssertion(org.apache.neethi.builders.PrimitiveAssertion) RMConfiguration(org.apache.cxf.ws.rm.RMConfiguration) JaxbAssertion(org.apache.cxf.ws.policy.builder.jaxb.JaxbAssertion) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap)

Example 2 with RMConfiguration

use of org.apache.cxf.ws.rm.RMConfiguration in project cxf by apache.

the class RMPolicyUtilities method intersect.

/**
 * Intersect a policy with a supplied configuration.
 *
 * @param rma
 * @param cfg
 * @return result configuration
 */
public static RMConfiguration intersect(RMAssertion rma, RMConfiguration cfg) {
    if (isCompatible(rma, cfg)) {
        return cfg;
    }
    RMConfiguration compatible = new RMConfiguration(cfg);
    // if supplied, policy value overrides default inactivity timeout
    Long aval = cfg.getInactivityTimeout();
    Long bval = null;
    if (null != rma.getInactivityTimeout()) {
        bval = rma.getInactivityTimeout().getMilliseconds();
    }
    if (null != aval || null != bval) {
        Long use;
        if (bval != null) {
            use = bval;
        } else {
            use = aval;
        }
        compatible.setInactivityTimeout(use);
    }
    // if supplied, policy value overrides base retransmission interval
    aval = cfg.getBaseRetransmissionInterval();
    bval = null;
    if (null != rma.getBaseRetransmissionInterval()) {
        bval = rma.getBaseRetransmissionInterval().getMilliseconds();
    }
    if (null != aval || null != bval) {
        Long use;
        if (bval != null) {
            use = bval;
        } else {
            use = aval;
        }
        compatible.setBaseRetransmissionInterval(use);
    }
    // if supplied, policy value overrides acknowledgement interval
    aval = cfg.getAcknowledgementInterval();
    bval = null;
    if (null != rma.getAcknowledgementInterval()) {
        bval = rma.getAcknowledgementInterval().getMilliseconds();
    }
    if (null != aval || null != bval) {
        Long use;
        if (bval != null) {
            use = bval;
        } else {
            use = aval;
        }
        compatible.setAcknowledgementInterval(use);
    }
    // backoff parameter
    if (cfg.isExponentialBackoff() || null != rma.getExponentialBackoff()) {
        compatible.setExponentialBackoff(true);
    }
    return compatible;
}
Also used : RMConfiguration(org.apache.cxf.ws.rm.RMConfiguration)

Example 3 with RMConfiguration

use of org.apache.cxf.ws.rm.RMConfiguration in project cxf by apache.

the class RMPolicyUtilities method intersect.

/**
 * Intersect a policy with a supplied configuration.
 *
 * @param rma
 * @param cfg
 * @return result configuration
 */
public static RMConfiguration intersect(PrimitiveAssertion rma, RMConfiguration cfg) {
    if (isCompatible(rma, cfg)) {
        return cfg;
    }
    RMConfiguration compatible = new RMConfiguration(cfg);
    String lname = rma.getName().getLocalPart();
    if (RMConstants.RMASSERTION_NAME.equals(lname)) {
        compatible.setRMNamespace(RM11Constants.NAMESPACE_URI);
    } else if (RM12AssertionBuilder.SEQUENCESTR_NAME.equals(lname)) {
        compatible.setSequenceSTRRequired(true);
    } else if (RM12AssertionBuilder.SEQUENCETRANSEC_NAME.equals(lname)) {
        compatible.setSequenceTransportSecurityRequired(true);
    } else if (RM12AssertionBuilder.EXACTLYONCE_NAME.equals(lname)) {
        compatible.setDeliveryAssurance(DeliveryAssurance.EXACTLY_ONCE);
    } else if (RM12AssertionBuilder.ATLEASTONCE_NAME.equals(lname)) {
        compatible.setDeliveryAssurance(DeliveryAssurance.AT_LEAST_ONCE);
    } else if (RM12AssertionBuilder.ATMOSTONCE_NAME.equals(lname)) {
        compatible.setDeliveryAssurance(DeliveryAssurance.AT_MOST_ONCE);
    } else if (RM12AssertionBuilder.INORDER_NAME.equals(lname)) {
        compatible.setInOrder(true);
    }
    return compatible;
}
Also used : RMConfiguration(org.apache.cxf.ws.rm.RMConfiguration)

Example 4 with RMConfiguration

use of org.apache.cxf.ws.rm.RMConfiguration in project cxf by apache.

the class PolicyUtilsTest method testIntersect.

@Test
public void testIntersect() {
    RMAssertion rma = new RMAssertion();
    RMConfiguration cfg0 = new RMConfiguration();
    assertTrue(RMPolicyUtilities.equals(cfg0, RMPolicyUtilities.intersect(rma, cfg0)));
    InactivityTimeout aiat = new RMAssertion.InactivityTimeout();
    aiat.setMilliseconds(new Long(7200000));
    rma.setInactivityTimeout(aiat);
    cfg0.setInactivityTimeout(new Long(3600000));
    RMConfiguration cfg1 = RMPolicyUtilities.intersect(rma, cfg0);
    assertEquals(7200000L, cfg1.getInactivityTimeout().longValue());
    assertNull(cfg1.getBaseRetransmissionInterval());
    assertNull(cfg1.getAcknowledgementInterval());
    assertFalse(cfg1.isExponentialBackoff());
    BaseRetransmissionInterval abri = new RMAssertion.BaseRetransmissionInterval();
    abri.setMilliseconds(new Long(20000));
    rma.setBaseRetransmissionInterval(abri);
    cfg0.setBaseRetransmissionInterval(new Long(10000));
    cfg1 = RMPolicyUtilities.intersect(rma, cfg0);
    assertEquals(7200000L, cfg1.getInactivityTimeout().longValue());
    assertEquals(20000L, cfg1.getBaseRetransmissionInterval().longValue());
    assertNull(cfg1.getAcknowledgementInterval());
    assertFalse(cfg1.isExponentialBackoff());
    AcknowledgementInterval aai = new RMAssertion.AcknowledgementInterval();
    aai.setMilliseconds(new Long(2000));
    rma.setAcknowledgementInterval(aai);
    cfg1 = RMPolicyUtilities.intersect(rma, cfg0);
    assertEquals(7200000L, cfg1.getInactivityTimeout().longValue());
    assertEquals(20000L, cfg1.getBaseRetransmissionInterval().longValue());
    assertEquals(2000L, cfg1.getAcknowledgementInterval().longValue());
    assertFalse(cfg1.isExponentialBackoff());
    cfg0.setExponentialBackoff(true);
    cfg1 = RMPolicyUtilities.intersect(rma, cfg0);
    assertEquals(7200000L, cfg1.getInactivityTimeout().longValue());
    assertEquals(20000L, cfg1.getBaseRetransmissionInterval().longValue());
    assertEquals(2000L, cfg1.getAcknowledgementInterval().longValue());
    assertTrue(cfg1.isExponentialBackoff());
}
Also used : RMAssertion(org.apache.cxf.ws.rmp.v200502.RMAssertion) AcknowledgementInterval(org.apache.cxf.ws.rmp.v200502.RMAssertion.AcknowledgementInterval) BaseRetransmissionInterval(org.apache.cxf.ws.rmp.v200502.RMAssertion.BaseRetransmissionInterval) RMConfiguration(org.apache.cxf.ws.rm.RMConfiguration) InactivityTimeout(org.apache.cxf.ws.rmp.v200502.RMAssertion.InactivityTimeout) Test(org.junit.Test)

Example 5 with RMConfiguration

use of org.apache.cxf.ws.rm.RMConfiguration in project cxf by apache.

the class RedeliveryTest method testAutomaticRedeliveryAfterError.

@Test
public void testAutomaticRedeliveryAfterError() throws Exception {
    LOG.fine("Creating greeter client");
    SpringBusFactory bf = new SpringBusFactory();
    bus = bf.createBus("/org/apache/cxf/systest/ws/rm/rminterceptors.xml");
    // set the client retry interval much shorter than the slow processing delay
    RMManager manager = bus.getExtension(RMManager.class);
    RMConfiguration cfg = manager.getConfiguration();
    cfg.setBaseRetransmissionInterval(3000L);
    BusFactory.setDefaultBus(bus);
    GreeterService gs = new GreeterService();
    greeter = gs.getGreeterPort();
    updateAddressPort(greeter, PORT);
    assertNull("last greeted by none", serverGreeter.getValue());
    LOG.fine("Invoking greeter for one");
    greeter.greetMeOneWay("one");
    LOG.fine("Wait for 4 secs ...");
    Thread.sleep(4000);
    assertEquals("last greeted by one", "one", serverGreeter.getValue());
    assertTrue("retransmission running", manager.getRetransmissionQueue().isEmpty());
    LOG.fine("Activating the error trigger and invoking greeter for two");
    serverGreeter.setThrowAlways(true);
    greeter.greetMeOneWay("two");
    LOG.fine("Wait for 4 secs ...");
    Thread.sleep(4000);
    RMManager serverManager = serverBus.getExtension(RMManager.class);
    assertEquals("last greeted by one", "one", serverGreeter.getValue());
    assertTrue("retransmission running", manager.getRetransmissionQueue().isEmpty());
    assertFalse("redelivery not running", serverManager.getRedeliveryQueue().isEmpty());
    LOG.fine("Deactivating the error trigger and wait for 9 secs ...");
    serverGreeter.setThrowAlways(false);
    Thread.sleep(9000);
    assertEquals("last greeted by two", "two", serverGreeter.getValue());
    assertTrue("redelivery running", serverManager.getRedeliveryQueue().isEmpty());
}
Also used : SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) RMManager(org.apache.cxf.ws.rm.RMManager) GreeterService(org.apache.cxf.greeter_control.GreeterService) RMConfiguration(org.apache.cxf.ws.rm.RMConfiguration) Test(org.junit.Test)

Aggregations

RMConfiguration (org.apache.cxf.ws.rm.RMConfiguration)8 RMAssertion (org.apache.cxf.ws.rmp.v200502.RMAssertion)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 AssertionInfo (org.apache.cxf.ws.policy.AssertionInfo)2 AssertionInfoMap (org.apache.cxf.ws.policy.AssertionInfoMap)2 JaxbAssertion (org.apache.cxf.ws.policy.builder.jaxb.JaxbAssertion)2 BaseRetransmissionInterval (org.apache.cxf.ws.rmp.v200502.RMAssertion.BaseRetransmissionInterval)2 JAXBException (javax.xml.bind.JAXBException)1 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)1 GreeterService (org.apache.cxf.greeter_control.GreeterService)1 Header (org.apache.cxf.headers.Header)1 Message (org.apache.cxf.message.Message)1 AddressingProperties (org.apache.cxf.ws.addressing.AddressingProperties)1 EncoderDecoder (org.apache.cxf.ws.rm.EncoderDecoder)1 ProtocolVariation (org.apache.cxf.ws.rm.ProtocolVariation)1 RMManager (org.apache.cxf.ws.rm.RMManager)1 AckRequestedType (org.apache.cxf.ws.rm.v200702.AckRequestedType)1 SequenceAcknowledgement (org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement)1 AcknowledgementInterval (org.apache.cxf.ws.rmp.v200502.RMAssertion.AcknowledgementInterval)1