示例#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);
      }
    }
  }
示例#2
0
  /**
   * Add MAPs which are specific to the requestor or responder role.
   *
   * @param maps the MAPs being assembled
   * @param message the current message
   * @param isRequestor true iff the current messaging role is that of requestor
   * @param isFault true if a fault is being mediated
   */
  private void addRoleSpecific(
      AddressingProperties maps, Message message, boolean isRequestor, boolean isFault) {
    if (isRequestor) {
      Exchange exchange = message.getExchange();

      // add request-specific MAPs
      boolean isOneway = exchange.isOneWay();
      boolean isOutbound = ContextUtils.isOutbound(message);

      // To
      if (maps.getTo() == null) {
        Conduit conduit = null;
        if (isOutbound) {
          conduit = ContextUtils.getConduit(null, message);
        }
        String s = (String) message.get(Message.ENDPOINT_ADDRESS);
        EndpointReferenceType reference =
            conduit != null ? conduit.getTarget() : ContextUtils.getNoneEndpointReference();
        if (conduit != null
            && !StringUtils.isEmpty(s)
            && !reference.getAddress().getValue().equals(s)) {
          EndpointReferenceType ref = new EndpointReferenceType();
          AttributedURIType tp = new AttributedURIType();
          tp.setValue(s);
          ref.setAddress(tp);
          ref.setMetadata(reference.getMetadata());
          ref.setReferenceParameters(reference.getReferenceParameters());
          ref.getOtherAttributes().putAll(reference.getOtherAttributes());
          reference = ref;
        }
        maps.setTo(reference);
      }

      // ReplyTo, set if null in MAPs or if set to a generic address
      // (anonymous or none) that may not be appropriate for the
      // current invocation
      EndpointReferenceType replyTo = maps.getReplyTo();
      if (ContextUtils.isGenericAddress(replyTo)) {
        replyTo = getReplyTo(message, replyTo);
        if (replyTo == null
            || (isOneway
                && (replyTo == null
                    || replyTo.getAddress() == null
                    || !Names.WSA_NONE_ADDRESS.equals(replyTo.getAddress().getValue())))) {
          AttributedURIType address =
              ContextUtils.getAttributedURI(
                  isOneway ? Names.WSA_NONE_ADDRESS : Names.WSA_ANONYMOUS_ADDRESS);
          replyTo = ContextUtils.WSA_OBJECT_FACTORY.createEndpointReferenceType();
          replyTo.setAddress(address);
        }
        maps.setReplyTo(replyTo);
      }

      // FaultTo
      if (maps.getFaultTo() == null) {
        maps.setFaultTo(maps.getReplyTo());
      } else if (maps.getFaultTo().getAddress() == null) {
        maps.setFaultTo(null);
      }
    } else {
      // add response-specific MAPs
      AddressingProperties inMAPs = getMAPs(message, false, false);
      maps.exposeAs(inMAPs.getNamespaceURI());
      // To taken from ReplyTo or FaultTo in incoming MAPs (depending
      // on the fault status of the response)
      if (isFault && inMAPs.getFaultTo() != null) {
        maps.setTo(inMAPs.getFaultTo());
      } else if (maps.getTo() == null && inMAPs.getReplyTo() != null) {
        maps.setTo(inMAPs.getReplyTo());
      }

      // RelatesTo taken from MessageID in incoming MAPs
      if (inMAPs.getMessageID() != null
          && !Boolean.TRUE.equals(message.get(Message.PARTIAL_RESPONSE_MESSAGE))) {
        String inMessageID = inMAPs.getMessageID().getValue();
        maps.setRelatesTo(ContextUtils.getRelatesTo(inMessageID));
      } else {
        maps.setRelatesTo(ContextUtils.getRelatesTo(Names.WSA_UNSPECIFIED_RELATIONSHIP));
      }

      // fallback fault action
      if (isFault && maps.getAction() == null) {
        maps.setAction(ContextUtils.getAttributedURI(Names.WSA_DEFAULT_FAULT_ACTION));
      }

      if (isFault && !ContextUtils.isGenericAddress(inMAPs.getFaultTo())) {

        Message m = message.getExchange().getInFaultMessage();
        if (m == null) {
          m = message;
        }
        InternalContextUtils.rebaseResponse(inMAPs.getFaultTo(), inMAPs, m);

        Destination destination =
            InternalContextUtils.createDecoupledDestination(m.getExchange(), inMAPs.getFaultTo());
        m.getExchange().setDestination(destination);
      }
    }
  }