Esempio n. 1
0
  private void recoverSourceSequence(
      Endpoint endpoint, Conduit conduit, Source s, SourceSequence ss) {
    Collection<RMMessage> ms = store.getMessages(ss.getIdentifier(), true);
    if (null == ms || 0 == ms.size()) {
      store.removeSourceSequence(ss.getIdentifier());
      return;
    }
    LOG.log(Level.FINE, "Number of messages in sequence: {0}", ms.size());

    s.addSequence(ss, false);
    // choosing an arbitrary valid source sequence as the current source sequence
    if (s.getAssociatedSequence(null) == null && !ss.isExpired() && !ss.isLastMessage()) {
      s.setCurrent(ss);
    }
    for (RMMessage m : ms) {

      Message message = new MessageImpl();
      Exchange exchange = new ExchangeImpl();
      message.setExchange(exchange);
      exchange.setOutMessage(message);
      if (null != conduit) {
        exchange.setConduit(conduit);
        message.put(Message.REQUESTOR_ROLE, Boolean.TRUE);
      }
      exchange.put(Endpoint.class, endpoint);
      exchange.put(Service.class, endpoint.getService());
      exchange.put(Binding.class, endpoint.getBinding());
      exchange.put(Bus.class, bus);

      SequenceType st = new SequenceType();
      st.setIdentifier(ss.getIdentifier());
      st.setMessageNumber(m.getMessageNumber());
      RMProperties rmps = new RMProperties();
      rmps.setSequence(st);
      rmps.exposeAs(ss.getProtocol().getWSRMNamespace());
      if (ss.isLastMessage() && ss.getCurrentMessageNr() == m.getMessageNumber()) {
        CloseSequenceType close = new CloseSequenceType();
        close.setIdentifier(ss.getIdentifier());
        rmps.setCloseSequence(close);
      }
      RMContextUtils.storeRMProperties(message, rmps, true);
      if (null == conduit) {
        String to = m.getTo();
        AddressingProperties maps = new AddressingProperties();
        maps.setTo(RMUtils.createReference(to));
        RMContextUtils.storeMAPs(maps, message, true, false);
      }

      try {
        // RMMessage is stored in a serialized way, therefore
        // RMMessage content must be splitted into soap root message
        // and attachments
        PersistenceUtils.decodeRMContent(m, message);
        RMContextUtils.setProtocolVariation(message, ss.getProtocol());
        retransmissionQueue.addUnacknowledged(message);
      } catch (IOException e) {
        LOG.log(Level.SEVERE, "Error reading persisted message data", e);
      }
    }
  }
Esempio n. 2
0
 public Identifier generateSequenceIdentifier() {
   String sequenceID = RMContextUtils.generateUUID();
   Identifier sid = new Identifier();
   sid.setValue(sequenceID);
   return sid;
 }
Esempio n. 3
0
  public SourceSequence getSequence(Identifier inSeqId, Message message, AddressingProperties maps)
      throws RMException {

    Source source = getSource(message);
    SourceSequence seq = source.getCurrent(inSeqId);
    RMConfiguration config = getEffectiveConfiguration(message);
    if (null == seq || seq.isExpired()) {
      // TODO: better error handling
      EndpointReferenceType to = null;
      boolean isServer = RMContextUtils.isServerSide(message);
      EndpointReferenceType acksTo = null;
      RelatesToType relatesTo = null;
      if (isServer) {
        AddressingProperties inMaps = RMContextUtils.retrieveMAPs(message, false, false);
        inMaps.exposeAs(config.getAddressingNamespace());
        acksTo = RMUtils.createReference(inMaps.getTo().getValue());
        to = inMaps.getReplyTo();
        source.getReliableEndpoint().getServant().setUnattachedIdentifier(inSeqId);
        relatesTo = (new org.apache.cxf.ws.addressing.ObjectFactory()).createRelatesToType();
        Destination destination = getDestination(message);
        DestinationSequence inSeq = inSeqId == null ? null : destination.getSequence(inSeqId);
        relatesTo.setValue(inSeq != null ? inSeq.getCorrelationID() : null);

      } else {
        to = RMUtils.createReference(maps.getTo().getValue());
        acksTo = maps.getReplyTo();
        if (RMUtils.getAddressingConstants().getNoneURI().equals(acksTo.getAddress().getValue())) {
          Endpoint ei = message.getExchange().getEndpoint();
          org.apache.cxf.transport.Destination dest =
              ei == null
                  ? null
                  : ei.getEndpointInfo()
                      .getProperty(
                          MAPAggregator.DECOUPLED_DESTINATION,
                          org.apache.cxf.transport.Destination.class);
          if (null == dest) {
            acksTo = RMUtils.createAnonymousReference();
          } else {
            acksTo = dest.getAddress();
          }
        }
      }

      if (ContextUtils.isGenericAddress(to)) {
        org.apache.cxf.common.i18n.Message msg =
            new org.apache.cxf.common.i18n.Message(
                "CREATE_SEQ_ANON_TARGET",
                LOG,
                to != null && to.getAddress() != null ? to.getAddress().getValue() : null);
        LOG.log(Level.INFO, msg.toString());
        throw new RMException(msg);
      }
      Proxy proxy = source.getReliableEndpoint().getProxy();
      ProtocolVariation protocol = config.getProtocolVariation();
      Exchange exchange = new ExchangeImpl();
      Map<String, Object> context = new HashMap<String, Object>(16);
      for (String key : message.getContextualPropertyKeys()) {
        // copy other properties?
        if (key.startsWith("ws-security")) {
          context.put(key, message.getContextualProperty(key));
        }
      }

      CreateSequenceResponseType createResponse =
          proxy.createSequence(acksTo, relatesTo, isServer, protocol, exchange, context);
      if (!isServer) {
        Servant servant = source.getReliableEndpoint().getServant();
        servant.createSequenceResponse(createResponse, protocol);

        // propagate security properties to application endpoint, in case we're using
        // WS-SecureConversation
        Exchange appex = message.getExchange();
        if (appex.get(SecurityConstants.TOKEN) == null) {
          appex.put(SecurityConstants.TOKEN, exchange.get(SecurityConstants.TOKEN));
          appex.put(SecurityConstants.TOKEN_ID, exchange.get(SecurityConstants.TOKEN_ID));
        }
      }

      seq = source.awaitCurrent(inSeqId);
      seq.setTarget(to);
    }

    return seq;
  }
Esempio n. 4
0
  public RMEndpoint getReliableEndpoint(Message message) throws RMException {
    Endpoint endpoint = message.getExchange().getEndpoint();
    QName name = endpoint.getEndpointInfo().getName();
    if (LOG.isLoggable(Level.FINE)) {
      LOG.fine("Getting RMEndpoint for endpoint with info: " + name);
    }
    if (name.equals(RM10Constants.PORT_NAME) || name.equals(RM11Constants.PORT_NAME)) {
      WrappedEndpoint wrappedEndpoint = (WrappedEndpoint) endpoint;
      endpoint = wrappedEndpoint.getWrappedEndpoint();
    }
    String rmUri = (String) message.getContextualProperty(WSRM_VERSION_PROPERTY);
    if (rmUri == null) {
      RMProperties rmps = RMContextUtils.retrieveRMProperties(message, false);
      if (rmps != null) {
        rmUri = rmps.getNamespaceURI();
      }
    }
    String addrUri = (String) message.getContextualProperty(WSRM_WSA_VERSION_PROPERTY);
    if (addrUri == null) {
      AddressingProperties maps = ContextUtils.retrieveMAPs(message, false, false, false);
      if (maps != null) {
        addrUri = maps.getNamespaceURI();
      }
    }

    RMConfiguration config = getConfiguration();
    if (rmUri != null) {
      config.setRMNamespace(rmUri);
      ProtocolVariation protocol = ProtocolVariation.findVariant(rmUri, addrUri);
      if (protocol == null) {
        org.apache.cxf.common.i18n.Message msg =
            new org.apache.cxf.common.i18n.Message("UNSUPPORTED_NAMESPACE", LOG, addrUri, rmUri);
        LOG.log(Level.INFO, msg.toString());
        throw new RMException(msg);
      }
    }
    if (addrUri != null) {
      config.setRM10AddressingNamespace(addrUri);
    }
    Long timeout = (Long) message.getContextualProperty(WSRM_INACTIVITY_TIMEOUT_PROPERTY);
    if (timeout != null) {
      config.setInactivityTimeout(timeout);
    }
    Long interval = (Long) message.getContextualProperty(WSRM_RETRANSMISSION_INTERVAL_PROPERTY);
    if (interval != null) {
      config.setBaseRetransmissionInterval(interval);
    }
    Boolean exponential =
        (Boolean) message.getContextualProperty(WSRM_EXPONENTIAL_BACKOFF_PROPERTY);
    if (exponential != null) {
      config.setExponentialBackoff(exponential);
    }
    interval = (Long) message.getContextualProperty(WSRM_ACKNOWLEDGEMENT_INTERVAL_PROPERTY);
    if (interval != null) {
      config.setAcknowledgementInterval(interval);
    }
    RMEndpoint rme = reliableEndpoints.get(endpoint);
    if (null == rme) {
      synchronized (endpoint) {
        rme = reliableEndpoints.get(endpoint);
        if (rme != null) {
          return rme;
        }
        rme = createReliableEndpoint(endpoint);
        org.apache.cxf.transport.Destination destination = message.getExchange().getDestination();
        EndpointReferenceType replyTo = null;
        if (null != destination) {
          AddressingProperties maps = RMContextUtils.retrieveMAPs(message, false, false);
          replyTo = maps.getReplyTo();
        }
        Endpoint ei = message.getExchange().getEndpoint();
        org.apache.cxf.transport.Destination dest =
            ei == null
                ? null
                : ei.getEndpointInfo()
                    .getProperty(
                        MAPAggregator.DECOUPLED_DESTINATION,
                        org.apache.cxf.transport.Destination.class);
        config = RMPolicyUtilities.getRMConfiguration(config, message);
        rme.initialise(config, message.getExchange().getConduit(message), replyTo, dest, message);
        reliableEndpoints.put(endpoint, rme);
        LOG.fine("Created new RMEndpoint.");
      }
    }
    return rme;
  }