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