Search in sources :

Example 1 with OfferType

use of org.apache.cxf.ws.rm.v200702.OfferType 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 2 with OfferType

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

the class Proxy method createSequence.

public CreateSequenceResponseType createSequence(EndpointReferenceType defaultAcksTo, RelatesToType relatesTo, boolean isServer, final ProtocolVariation protocol, final Exchange exchange, Map<String, Object> context) throws RMException {
    this.sequenceContext = context;
    SourcePolicyType sp = reliableEndpoint.getManager().getSourcePolicy();
    CreateSequenceType create = new CreateSequenceType();
    String address = sp.getAcksTo();
    EndpointReferenceType acksTo = null;
    if (null != address) {
        acksTo = RMUtils.createReference(address);
    } else {
        acksTo = defaultAcksTo;
    }
    create.setAcksTo(acksTo);
    Duration d = sp.getSequenceExpiration();
    if (null != d) {
        Expires expires = new Expires();
        expires.setValue(d);
        create.setExpires(expires);
    }
    if (sp.isIncludeOffer()) {
        OfferType offer = new OfferType();
        d = sp.getOfferedSequenceExpiration();
        if (null != d) {
            Expires expires = new Expires();
            expires.setValue(d);
            offer.setExpires(expires);
        }
        offer.setIdentifier(reliableEndpoint.getSource().generateSequenceIdentifier());
        offer.setEndpoint(acksTo);
        create.setOffer(offer);
        setOfferedIdentifier(offer);
    }
    InterfaceInfo ii = reliableEndpoint.getEndpoint(protocol).getEndpointInfo().getService().getInterface();
    EncoderDecoder codec = protocol.getCodec();
    RMConstants constants = codec.getConstants();
    final OperationInfo oi = isServer ? ii.getOperation(constants.getCreateSequenceOnewayOperationName()) : ii.getOperation(constants.getCreateSequenceOperationName());
    final Object send = codec.convertToSend(create);
    if (isServer) {
        LOG.fine("sending CreateSequenceRequest from server side");
        Runnable r = new Runnable() {

            public void run() {
                try {
                    invoke(oi, protocol, new Object[] { send }, null, exchange);
                } catch (RMException ex) {
                // already logged
                }
            }
        };
        Executor ex = reliableEndpoint.getApplicationEndpoint().getExecutor();
        if (ex == null) {
            ex = SynchronousExecutor.getInstance();
        }
        ex.execute(r);
        return null;
    }
    Object resp = invoke(oi, protocol, new Object[] { send }, context, exchange);
    return codec.convertReceivedCreateSequenceResponse(resp);
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) Duration(javax.xml.datatype.Duration) OfferType(org.apache.cxf.ws.rm.v200702.OfferType) Executor(java.util.concurrent.Executor) SynchronousExecutor(org.apache.cxf.workqueue.SynchronousExecutor) CreateSequenceType(org.apache.cxf.ws.rm.v200702.CreateSequenceType) SourcePolicyType(org.apache.cxf.ws.rm.manager.SourcePolicyType) Expires(org.apache.cxf.ws.rm.v200702.Expires) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo)

Example 3 with OfferType

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

the class VersionTransformer method convert.

/**
 * Convert 200502 OfferType with 200508 WS-Addressing namespace to internal form.
 *
 * @param exposed (may be <code>null</code>)
 * @return converted (<code>null</code> if internal is <code>null</code>)
 */
public static OfferType convert(org.apache.cxf.ws.rm.v200502wsa15.OfferType exposed) {
    if (exposed == null) {
        return null;
    }
    OfferType internal = new OfferType();
    internal.setExpires(convert(exposed.getExpires()));
    internal.setIdentifier(convert(exposed.getIdentifier()));
    return internal;
}
Also used : OfferType(org.apache.cxf.ws.rm.v200702.OfferType)

Example 4 with OfferType

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

the class VersionTransformer method convert.

/**
 * Convert 200502 OfferType with 200408 WS-Addressing namespace to internal form.
 *
 * @param exposed (may be <code>null</code>)
 * @return converted (<code>null</code> if internal is <code>null</code>)
 */
public static OfferType convert(org.apache.cxf.ws.rm.v200502.OfferType exposed) {
    if (exposed == null) {
        return null;
    }
    OfferType internal = new OfferType();
    internal.setExpires(convert(exposed.getExpires()));
    internal.setIdentifier(convert(exposed.getIdentifier()));
    return internal;
}
Also used : OfferType(org.apache.cxf.ws.rm.v200702.OfferType)

Example 5 with OfferType

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

the class ProxyTest method testOfferedIdentifier.

@Test
public void testOfferedIdentifier() {
    OfferType offer = control.createMock(OfferType.class);
    Identifier id = control.createMock(Identifier.class);
    EasyMock.expect(offer.getIdentifier()).andReturn(id).anyTimes();
    control.replay();
    Proxy proxy = new Proxy(rme);
    assertNull(proxy.getOfferedIdentifier());
    proxy.setOfferedIdentifier(offer);
    assertSame(id, proxy.getOfferedIdentifier());
}
Also used : Identifier(org.apache.cxf.ws.rm.v200702.Identifier) OfferType(org.apache.cxf.ws.rm.v200702.OfferType) Test(org.junit.Test)

Aggregations

OfferType (org.apache.cxf.ws.rm.v200702.OfferType)5 Duration (javax.xml.datatype.Duration)2 CreateSequenceType (org.apache.cxf.ws.rm.v200702.CreateSequenceType)2 Expires (org.apache.cxf.ws.rm.v200702.Expires)2 Executor (java.util.concurrent.Executor)1 Message (org.apache.cxf.message.Message)1 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)1 InterfaceInfo (org.apache.cxf.service.model.InterfaceInfo)1 OperationInfo (org.apache.cxf.service.model.OperationInfo)1 SynchronousExecutor (org.apache.cxf.workqueue.SynchronousExecutor)1 AddressingProperties (org.apache.cxf.ws.addressing.AddressingProperties)1 EndpointReferenceType (org.apache.cxf.ws.addressing.EndpointReferenceType)1 DestinationPolicyType (org.apache.cxf.ws.rm.manager.DestinationPolicyType)1 SourcePolicyType (org.apache.cxf.ws.rm.manager.SourcePolicyType)1 AcceptType (org.apache.cxf.ws.rm.v200702.AcceptType)1 CreateSequenceResponseType (org.apache.cxf.ws.rm.v200702.CreateSequenceResponseType)1 Identifier (org.apache.cxf.ws.rm.v200702.Identifier)1 Test (org.junit.Test)1