Search in sources :

Example 56 with Identifier

use of org.apache.cxf.ws.rm.v200502.Identifier in project cxf by apache.

the class RMOutInterceptor method handle.

protected void handle(Message msg) throws SequenceFault, RMException {
    AddressingProperties maps = ContextUtils.retrieveMAPs(msg, false, true, false);
    if (null == maps) {
        LogUtils.log(LOG, Level.WARNING, "MAPS_RETRIEVAL_FAILURE_MSG");
        return;
    }
    if (Boolean.TRUE.equals(msg.get(RMMessageConstants.RM_RETRANSMISSION))) {
        return;
    }
    if (isRuntimeFault(msg)) {
        return;
    }
    RMConfiguration config = getManager().getEffectiveConfiguration(msg);
    String wsaNamespace = config.getAddressingNamespace();
    String rmNamespace = config.getRMNamespace();
    ProtocolVariation protocol = ProtocolVariation.findVariant(rmNamespace, wsaNamespace);
    RMContextUtils.setProtocolVariation(msg, protocol);
    Destination destination = getManager().getDestination(msg);
    String action = null;
    if (null != maps.getAction()) {
        action = maps.getAction().getValue();
    }
    // make sure we use the appropriate namespace
    maps.exposeAs(wsaNamespace);
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Action: " + action);
    }
    boolean isApplicationMessage = !RMContextUtils.isRMProtocolMessage(action);
    boolean isPartialResponse = MessageUtils.isPartialResponse(msg);
    RMConstants constants = protocol.getConstants();
    RMProperties rmpsOut = RMContextUtils.retrieveRMProperties(msg, true);
    if (isApplicationMessage && !isPartialResponse) {
        addRetransmissionInterceptor(msg);
    }
    Identifier inSeqId = null;
    if (isApplicationMessage) {
        RMProperties rmpsIn = RMContextUtils.retrieveRMProperties(msg, false);
        if (null != rmpsIn && null != rmpsIn.getSequence()) {
            inSeqId = rmpsIn.getSequence().getIdentifier();
            SourceSequence seq = rmpsIn.getSourceSequence();
            SequenceType sequence = rmpsIn.getSequence();
            if (seq == null || sequence == null) {
                LOG.warning("sequence not set for outbound message, skipped acknowledgement request");
            } else {
                addAckRequest(msg, rmpsIn, seq, sequence);
            }
        }
    }
    // add Acknowledgements (to application messages or explicitly created Acknowledgement messages only)
    boolean isAck = constants.getSequenceAckAction().equals(action);
    boolean isClose = constants.getCloseSequenceAction().equals(action);
    boolean isTerminate = constants.getTerminateSequenceAction().equals(action);
    if (isApplicationMessage || isAck || isClose || isTerminate) {
        AttributedURIType to = maps.getTo();
        assert null != to;
        addAcknowledgements(destination, rmpsOut, inSeqId, to);
        if (isPartialResponse && rmpsOut.getAcks() != null && rmpsOut.getAcks().size() > 0) {
            setAction(maps, constants.getSequenceAckAction());
            msg.remove(Message.EMPTY_PARTIAL_RESPONSE_MESSAGE);
            isAck = true;
        }
    }
    if (isAck || (isTerminate && RM10Constants.NAMESPACE_URI.equals(rmNamespace))) {
        maps.setReplyTo(RMUtils.createNoneReference());
    }
    assertReliability(msg);
}
Also used : Identifier(org.apache.cxf.ws.rm.v200702.Identifier) AttributedURIType(org.apache.cxf.ws.addressing.AttributedURIType) AddressingProperties(org.apache.cxf.ws.addressing.AddressingProperties) SequenceType(org.apache.cxf.ws.rm.v200702.SequenceType)

Example 57 with Identifier

use of org.apache.cxf.ws.rm.v200502.Identifier in project cxf by apache.

the class Servant method createSequenceResponse.

public void createSequenceResponse(CreateSequenceResponseType createResponse, ProtocolVariation protocol) {
    LOG.fine("Creating sequence response");
    SourceSequence seq = new SourceSequence(createResponse.getIdentifier(), protocol);
    seq.setExpires(createResponse.getExpires());
    Source source = reliableEndpoint.getSource();
    source.addSequence(seq);
    // the incoming sequence ID is either used as the requestor sequence
    // (signalled by null) or associated with a corresponding sequence
    // identifier
    source.setCurrent(clearUnattachedIdentifier(), seq);
    // if a sequence was offered and accepted, then we can add this to
    // to the local destination sequence list, otherwise we have to wait for
    // and incoming CreateSequence request
    Identifier offeredId = reliableEndpoint.getProxy().getOfferedIdentifier();
    if (null != offeredId) {
        AcceptType accept = createResponse.getAccept();
        if (accept != null) {
            Destination dest = reliableEndpoint.getDestination();
            String address = accept.getAcksTo().getAddress().getValue();
            if (!RMUtils.getAddressingConstants().getNoneURI().equals(address)) {
                DestinationSequence ds = new DestinationSequence(offeredId, accept.getAcksTo(), dest, protocol);
                dest.addSequence(ds);
            }
        }
    }
}
Also used : Identifier(org.apache.cxf.ws.rm.v200702.Identifier) AcceptType(org.apache.cxf.ws.rm.v200702.AcceptType)

Example 58 with Identifier

use of org.apache.cxf.ws.rm.v200502.Identifier in project cxf by apache.

the class Servant method closeSequence.

public Object closeSequence(Message message) {
    LOG.fine("Closing sequence");
    CloseSequenceType close = (CloseSequenceType) getParameter(message);
    // check if the terminated sequence was created in response to a a createSequence
    // request
    Destination destination = reliableEndpoint.getDestination();
    Identifier sid = close.getIdentifier();
    DestinationSequence closedSeq = destination.getSequence(sid);
    if (null == closedSeq) {
        // TODO
        LOG.severe("No such sequence.");
        return null;
    }
    closedSeq.scheduleImmediateAcknowledgement();
    closedSeq.setLastMessageNumber(close.getLastMsgNumber());
    CloseSequenceResponseType closeResponse = new CloseSequenceResponseType();
    closeResponse.setIdentifier(close.getIdentifier());
    AddressingProperties maps = RMContextUtils.retrieveMAPs(message, false, false);
    Message outMessage = message.getExchange().getOutMessage();
    if (null == outMessage) {
        // outMessage may be null e.g. if ReplyTo is not set for TS
        outMessage = ContextUtils.createMessage(message.getExchange());
        message.getExchange().setOutMessage(outMessage);
    }
    if (null != outMessage) {
        RMContextUtils.storeMAPs(maps, outMessage, false, false);
    }
    return closeResponse;
}
Also used : Identifier(org.apache.cxf.ws.rm.v200702.Identifier) Message(org.apache.cxf.message.Message) CloseSequenceResponseType(org.apache.cxf.ws.rm.v200702.CloseSequenceResponseType) CloseSequenceType(org.apache.cxf.ws.rm.v200702.CloseSequenceType) AddressingProperties(org.apache.cxf.ws.addressing.AddressingProperties)

Example 59 with Identifier

use of org.apache.cxf.ws.rm.v200502.Identifier in project cxf by apache.

the class Servant method terminateSequence.

public Object terminateSequence(Message message) {
    LOG.fine("Terminating sequence");
    final ProtocolVariation protocol = RMContextUtils.getProtocolVariation(message);
    EncoderDecoder codec = protocol.getCodec();
    TerminateSequenceType terminate = codec.convertReceivedTerminateSequence(getParameter(message));
    // check if the terminated sequence was created in response to a a createSequence
    // request
    Destination destination = reliableEndpoint.getDestination();
    Identifier sid = terminate.getIdentifier();
    DestinationSequence terminatedSeq = destination.getSequence(sid);
    if (null != terminatedSeq) {
        destination.terminateSequence(terminatedSeq);
    }
    // the following may be necessary if the last message for this sequence was a oneway
    // request and hence there was no response to which a last message could have been added
    // REVISIT: A last message for the correlated sequence should have been sent by the time
    // the last message for the underlying sequence was received.
    Source source = reliableEndpoint.getSource();
    for (SourceSequence outboundSeq : source.getAllSequences()) {
        if (outboundSeq.offeredBy(sid) && !outboundSeq.isLastMessage()) {
            if (outboundSeq.getCurrentMessageNr() == 0) {
                source.removeSequence(outboundSeq);
            }
            break;
        }
    }
    TerminateSequenceResponseType terminateResponse = null;
    if (RM11Constants.NAMESPACE_URI.equals(protocol.getWSRMNamespace())) {
        AddressingProperties maps = RMContextUtils.retrieveMAPs(message, false, false);
        Message outMessage = message.getExchange().getOutMessage();
        if (null == outMessage) {
            // outMessage may be null e.g. if ReplyTo is not set for TS
            outMessage = ContextUtils.createMessage(message.getExchange());
            message.getExchange().setOutMessage(outMessage);
        }
        if (null != outMessage) {
            RMContextUtils.storeMAPs(maps, outMessage, false, false);
        }
        terminateResponse = new TerminateSequenceResponseType();
        terminateResponse.setIdentifier(sid);
    }
    return terminateResponse;
}
Also used : TerminateSequenceResponseType(org.apache.cxf.ws.rm.v200702.TerminateSequenceResponseType) Identifier(org.apache.cxf.ws.rm.v200702.Identifier) Message(org.apache.cxf.message.Message) TerminateSequenceType(org.apache.cxf.ws.rm.v200702.TerminateSequenceType) AddressingProperties(org.apache.cxf.ws.addressing.AddressingProperties)

Example 60 with Identifier

use of org.apache.cxf.ws.rm.v200502.Identifier in project cxf by apache.

the class RMTxStore method getSourceSequence.

public SourceSequence getSourceSequence(Identifier sid) {
    if (LOG.isLoggable(Level.FINE)) {
        LOG.info("Getting source sequences for id: " + sid);
    }
    Connection con = verifyConnection();
    PreparedStatement stmt = null;
    SQLException conex = null;
    ResultSet res = null;
    try {
        stmt = getStatement(con, SELECT_SRC_SEQUENCE_STMT_STR);
        stmt.setString(1, sid.getValue());
        res = stmt.executeQuery();
        if (res.next()) {
            long cmn = res.getLong(1);
            boolean lm = res.getBoolean(2);
            long lval = res.getLong(3);
            Date expiry = 0 == lval ? null : new Date(lval);
            String oidValue = res.getString(4);
            Identifier oi = null;
            if (null != oidValue) {
                oi = RMUtils.getWSRMFactory().createIdentifier();
                oi.setValue(oidValue);
            }
            ProtocolVariation pv = decodeProtocolVersion(res.getString(5));
            return new SourceSequence(sid, expiry, oi, cmn, lm, pv);
        }
    } catch (SQLException ex) {
        conex = ex;
        // ignore
        LOG.log(Level.WARNING, new Message("SELECT_SRC_SEQ_FAILED_MSG", LOG).toString(), ex);
    } finally {
        releaseResources(stmt, res);
        updateConnectionState(con, conex);
    }
    return null;
}
Also used : Identifier(org.apache.cxf.ws.rm.v200702.Identifier) Message(org.apache.cxf.common.i18n.Message) RMMessage(org.apache.cxf.ws.rm.persistence.RMMessage) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) SourceSequence(org.apache.cxf.ws.rm.SourceSequence) Date(java.util.Date) ProtocolVariation(org.apache.cxf.ws.rm.ProtocolVariation)

Aggregations

Identifier (org.apache.cxf.ws.rm.v200702.Identifier)72 Test (org.junit.Test)40 ArrayList (java.util.ArrayList)11 Message (org.apache.cxf.message.Message)11 SourceSequence (org.apache.cxf.ws.rm.SourceSequence)11 RMMessage (org.apache.cxf.ws.rm.persistence.RMMessage)11 SequenceAcknowledgement (org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement)11 Connection (java.sql.Connection)9 AddressingProperties (org.apache.cxf.ws.addressing.AddressingProperties)8 SQLException (java.sql.SQLException)7 Date (java.util.Date)7 EndpointReferenceType (org.apache.cxf.ws.addressing.EndpointReferenceType)7 DestinationSequence (org.apache.cxf.ws.rm.DestinationSequence)7 Method (java.lang.reflect.Method)6 AttributedURIType (org.apache.cxf.ws.addressing.AttributedURIType)6 RMStore (org.apache.cxf.ws.rm.persistence.RMStore)6 SequenceType (org.apache.cxf.ws.rm.v200702.SequenceType)6 SoapBinding (org.apache.cxf.binding.soap.SoapBinding)5 ProtocolVariation (org.apache.cxf.ws.rm.ProtocolVariation)5 PreparedStatement (java.sql.PreparedStatement)4