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;
}
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;
}
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;
}
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());
}
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());
}
Aggregations