Example #1
0
    /** @param ctx message context for the unacked message */
    protected ResendCandidate(Message m) {
      message = m;
      retries = 0;
      RMConfiguration cfg = manager.getEffectiveConfiguration(message);
      long baseRetransmissionInterval = cfg.getBaseRetransmissionInterval().longValue();
      backoff = cfg.isExponentialBackoff() ? RetransmissionQueue.DEFAULT_EXPONENTIAL_BACKOFF : 1;
      next = new Date(System.currentTimeMillis() + baseRetransmissionInterval);
      nextInterval = baseRetransmissionInterval * backoff;
      RetryPolicyType rmrp =
          null != manager.getSourcePolicy() ? manager.getSourcePolicy().getRetryPolicy() : null;
      maxRetries = null != rmrp ? rmrp.getMaxRetries() : -1;

      AddressingProperties maps = RMContextUtils.retrieveMAPs(message, false, true);
      AttributedURIType to = null;
      if (null != maps) {
        to = maps.getTo();
      }
      if (to != null && RMUtils.getAddressingConstants().getAnonymousURI().equals(to.getValue())) {
        LOG.log(Level.INFO, "Cannot resend to anonymous target.  Not scheduling a resend.");
        return;
      }
      RMProperties rmprops = RMContextUtils.retrieveRMProperties(message, true);
      if (null != rmprops) {
        number = rmprops.getSequence().getMessageNumber();
      }
      if (null != manager.getTimer() && maxRetries != 0) {
        schedule();
      }
    }
Example #2
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);
      }
    }
  }
 /**
  * Check for NONE ReplyTo value in request-response MEP
  *
  * @param message the current message
  * @param maps the incoming MAPs
  */
 private void checkReplyTo(Message message, AddressingProperties maps) {
   // if ReplyTo address is none then 202 response status is expected
   // However returning a fault is more appropriate for request-response MEP
   if (!message.getExchange().isOneWay()
       && !MessageUtils.isPartialResponse(message)
       && ContextUtils.isNoneAddress(maps.getReplyTo())) {
     String reason =
         MessageFormat.format(
             BUNDLE.getString("REPLYTO_NOT_SUPPORTED_MSG"),
             maps.getReplyTo().getAddress().getValue());
     throw new SoapFault(reason, new QName(Names.WSA_NAMESPACE_NAME, Names.WSA_NONE_ADDRESS));
   }
 }
  /**
   * Assemble the generic MAPs (for both requests and responses).
   *
   * @param message the current message
   * @return AddressingProperties containing the generic MAPs
   */
  private AddressingProperties assembleGeneric(Message message) {
    AddressingProperties maps = getMAPs(message, true, true);
    // MessageID
    if (maps.getMessageID() == null) {
      String messageID = ContextUtils.generateUUID();
      maps.setMessageID(ContextUtils.getAttributedURI(messageID));
    }

    // Action
    if (ContextUtils.hasEmptyAction(maps)) {
      maps.setAction(InternalContextUtils.getAction(message));

      if (ContextUtils.hasEmptyAction(maps) && ContextUtils.isOutbound(message)) {
        maps.setAction(ContextUtils.getAttributedURI(getActionUri(message, true)));
      }
    }

    return maps;
  }
 private void setupNamespace(AddressingProperties maps, Message message) {
   AssertionInfoMap aim = message.get(AssertionInfoMap.class);
   if (null == aim) {
     return;
   }
   Collection<AssertionInfo> aic =
       aim.getAssertionInfo(MetadataConstants.USING_ADDRESSING_2004_QNAME);
   if (aic != null && !aic.isEmpty()) {
     maps.exposeAs(Names200408.WSA_NAMESPACE_NAME);
   }
 }
 private void handleAddressing(SoapMessage message) {
   final AddressingProperties maps =
       (AddressingProperties)
           message.getContextualProperty(JAXWSAConstants.ADDRESSING_PROPERTIES_INBOUND);
   if (maps == null) {
     return;
   }
   final EndpointReferenceType rpl = maps.getReplyTo();
   if (rpl == null) {
     return;
   }
   final AttributedURIType addr = rpl.getAddress();
   if (addr == null) {
     return;
   }
   final String replyTo = addr.getValue();
   final Exchange exchange = message.getExchange();
   if (exchange.getDestination() instanceof JMSDestination) {
     ContextUtils.storePartialResponseSent(message);
     if (!exchange.isOneWay()) {
       exchange.setOneWay(true);
     }
   } else {
     if (exchange.isOneWay()) {
       if (!Names.WSA_NONE_ADDRESS.equals(replyTo)) {
         // disable creation of "partial" response
         // by CXF decoupled response feature
         exchange.setOneWay(false);
       }
     } else {
       // A generic default exchange has been created.
       // Provide it to MAP aggregator as anon. request-response
       // and convert it afterwards to one-way.
       if (Names.WSA_NONE_ADDRESS.equals(replyTo)) {
         addr.setValue(Names.WSA_ANONYMOUS_ADDRESS);
       }
     }
   }
 }
  /**
   * 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);
      }
    }
  }
  /**
   * Mediate message flow.
   *
   * @param message the current message
   * @param isFault true if a fault is being mediated
   * @return true if processing should continue on dispatch path
   */
  protected boolean mediate(Message message, boolean isFault) {
    boolean continueProcessing = true;
    if (ContextUtils.isOutbound(message)) {
      if (usingAddressing(message)) {
        // request/response MAPs must be aggregated
        aggregate(message, isFault);
      }
      AddressingProperties theMaps =
          ContextUtils.retrieveMAPs(message, false, ContextUtils.isOutbound(message));
      if (null != theMaps) {
        if (ContextUtils.isRequestor(message)) {
          assertAddressing(message, theMaps.getReplyTo(), theMaps.getFaultTo());
        } else {
          checkReplyTo(message, theMaps);
        }
      }
    } else if (!ContextUtils.isRequestor(message)) {
      // responder validates incoming MAPs
      AddressingProperties maps = getMAPs(message, false, false);
      // check responses
      if (maps != null) {
        checkAddressingResponses(maps.getReplyTo(), maps.getFaultTo());
        assertAddressing(message, maps.getReplyTo(), maps.getFaultTo());
      }
      boolean isOneway = message.getExchange().isOneWay();
      if (null == maps && !addressingRequired) {
        return false;
      }
      continueProcessing = validateIncomingMAPs(maps, message);
      if (maps != null) {
        AddressingProperties theMaps =
            ContextUtils.retrieveMAPs(message, false, ContextUtils.isOutbound(message));
        if (null != theMaps) {
          assertAddressing(message, theMaps.getReplyTo(), theMaps.getFaultTo());
        }

        if (isOneway || !ContextUtils.isGenericAddress(maps.getReplyTo())) {
          InternalContextUtils.rebaseResponse(maps.getReplyTo(), maps, message);
        }
        if (!isOneway) {
          if (ContextUtils.isNoneAddress(maps.getReplyTo())) {
            LOG.warning("Detected NONE value in ReplyTo WSA header for request-respone MEP");
          } else {
            // ensure the inbound MAPs are available in both the full & fault
            // response messages (used to determine relatesTo etc.)
            ContextUtils.propogateReceivedMAPs(maps, message.getExchange());
          }
        }
      }
      if (continueProcessing) {
        // any faults thrown from here on can be correlated with this message
        message.put(FaultMode.class, FaultMode.LOGICAL_RUNTIME_FAULT);
      } else {
        // validation failure => dispatch is aborted, response MAPs
        // must be aggregated
        // isFault = true;
        // aggregate(message, isFault);
        if (isSOAP12(message)) {
          SoapFault soap12Fault =
              new SoapFault(
                  ContextUtils.retrieveMAPFaultReason(message), Soap12.getInstance().getSender());
          soap12Fault.setSubCode(
              new QName(Names.WSA_NAMESPACE_NAME, ContextUtils.retrieveMAPFaultName(message)));
          throw soap12Fault;
        }
        throw new SoapFault(
            ContextUtils.retrieveMAPFaultReason(message),
            new QName(Names.WSA_NAMESPACE_NAME, ContextUtils.retrieveMAPFaultName(message)));
      }
    } else {
      AddressingProperties theMaps =
          ContextUtils.retrieveMAPs(message, false, ContextUtils.isOutbound(message));
      if (null != theMaps) {
        assertAddressing(message, theMaps.getReplyTo(), theMaps.getFaultTo());
      }
      // If the wsa policy is enabled , but the client sets the
      // WSAddressingFeature.isAddressingRequired to false , we need to assert all WSA assertion to
      // true
      if (!ContextUtils.isOutbound(message)
          && ContextUtils.isRequestor(message)
          && getWSAddressingFeature(message) != null
          && !getWSAddressingFeature(message).isAddressingRequired()) {
        assertAddressing(message);
      }
      // CXF-3060 :If wsa policy is not enforced, AddressingProperties map is null and
      // AddressingFeature.isRequired, requestor checks inbound message and throw exception
      if (null == theMaps
          && !ContextUtils.isOutbound(message)
          && ContextUtils.isRequestor(message)
          && getWSAddressingFeature(message) != null
          && getWSAddressingFeature(message).isAddressingRequired()) {
        boolean missingWsaHeader = false;
        AssertionInfoMap aim = message.get(AssertionInfoMap.class);
        if (aim == null || aim.size() == 0) {
          missingWsaHeader = true;
        }
        if (aim != null && aim.size() > 0) {
          missingWsaHeader = true;
          QName[] types =
              new QName[] {
                MetadataConstants.ADDRESSING_ASSERTION_QNAME,
                MetadataConstants.USING_ADDRESSING_2004_QNAME,
                MetadataConstants.USING_ADDRESSING_2005_QNAME,
                MetadataConstants.USING_ADDRESSING_2006_QNAME
              };
          for (QName type : types) {
            for (AssertionInfo assertInfo : aim.getAssertionInfo(type)) {
              if (assertInfo.isAsserted()) {
                missingWsaHeader = false;
              }
            }
          }
        }
        if (missingWsaHeader) {
          throw new SoapFault(
              "MISSING_ACTION_MESSAGE",
              BUNDLE,
              new QName(Names.WSA_NAMESPACE_NAME, Names.HEADER_REQUIRED_NAME));
        }
      }
      if (MessageUtils.isPartialResponse(message)
          && message.getExchange().getOutMessage() != null) {
        // marked as a partial response, let's see if it really is
        MessageInfo min = message.get(MessageInfo.class);
        MessageInfo mout = message.getExchange().getOutMessage().get(MessageInfo.class);
        if (min != null
            && mout != null
            && min.getOperation() == mout.getOperation()
            && message.getContent(List.class) != null) {
          // the in and out messages are on the same operation
          // and we were able to get a response for it.
          message.remove(Message.PARTIAL_RESPONSE_MESSAGE);
        }
      }
    }
    return continueProcessing;
  }
  /**
   * Validate incoming MAPs
   *
   * @param maps the incoming MAPs
   * @param message the current message
   * @return true if incoming MAPs are valid
   * @pre inbound message, not requestor
   */
  private boolean validateIncomingMAPs(AddressingProperties maps, Message message) {
    boolean valid = true;

    if (maps != null) {
      // WSAB spec, section 4.2 validation (SOAPAction must match action
      String sa = SoapActionInInterceptor.getSoapAction(message);
      String s1 = this.getActionUri(message, false);

      if (maps.getAction() == null || maps.getAction().getValue() == null) {
        String reason = BUNDLE.getString("MISSING_ACTION_MESSAGE");

        ContextUtils.storeMAPFaultName(Names.HEADER_REQUIRED_NAME, message);
        ContextUtils.storeMAPFaultReason(reason, message);
        valid = false;
      }

      if (!StringUtils.isEmpty(sa)
          && valid
          && !MessageUtils.isTrue(message.get(MAPAggregator.ACTION_VERIFIED))) {
        if (sa.startsWith("\"")) {
          sa = sa.substring(1, sa.lastIndexOf('"'));
        }
        String action = maps.getAction() == null ? "" : maps.getAction().getValue();
        if (!StringUtils.isEmpty(sa) && !sa.equals(action)) {
          // don't match, must send fault back....
          String reason = BUNDLE.getString("INVALID_ADDRESSING_PROPERTY_MESSAGE");

          ContextUtils.storeMAPFaultName(Names.ACTION_MISMATCH_NAME, message);
          ContextUtils.storeMAPFaultReason(reason, message);
          valid = false;
        } else if (!StringUtils.isEmpty(s1)
            && !action.equals(s1)
            && !action.equals(s1 + "Request")
            && !s1.equals(action + "Request")) {
          // if java first, it's likely to have "Request", if wsdl first,
          // it will depend if the wsdl:input has a name or not. Thus, we'll
          // check both plain and with the "Request" trailer

          // doesn't match what's in the wsdl/annotations
          String reason =
              BundleUtils.getFormattedString(BUNDLE, "ACTION_NOT_SUPPORTED_MSG", action);

          ContextUtils.storeMAPFaultName(Names.ACTION_NOT_SUPPORTED_NAME, message);
          ContextUtils.storeMAPFaultReason(reason, message);
          valid = false;
        }
      }

      AttributedURIType messageID = maps.getMessageID();

      if (!message.getExchange().isOneWay()
          && (messageID == null || messageID.getValue() == null)
          && valid) {
        String reason = BUNDLE.getString("MISSING_ACTION_MESSAGE");

        ContextUtils.storeMAPFaultName(Names.HEADER_REQUIRED_NAME, message);
        ContextUtils.storeMAPFaultReason(reason, message);

        valid = false;
      }

      // Always cache message IDs, even when the message is not valid for some
      // other reason.
      if (!allowDuplicates
          && messageID != null
          && messageID.getValue() != null
          && !messageIdCache.checkUniquenessAndCacheId(messageID.getValue())) {

        LOG.log(Level.WARNING, "DUPLICATE_MESSAGE_ID_MSG", messageID.getValue());

        // Only throw the fault if something else has not already marked the
        // message as invalid.
        if (valid) {
          String reason = BUNDLE.getString("DUPLICATE_MESSAGE_ID_MSG");
          String l7dReason = MessageFormat.format(reason, messageID.getValue());
          ContextUtils.storeMAPFaultName(Names.DUPLICATE_MESSAGE_ID_NAME, message);
          ContextUtils.storeMAPFaultReason(l7dReason, message);
        }

        valid = false;
      }
    } else if (usingAddressingAdvisory) {
      String reason = BUNDLE.getString("MISSING_ACTION_MESSAGE");

      ContextUtils.storeMAPFaultName(Names.HEADER_REQUIRED_NAME, message);
      ContextUtils.storeMAPFaultReason(reason, message);
      valid = false;
    }

    if (Names.INVALID_CARDINALITY_NAME.equals(ContextUtils.retrieveMAPFaultName(message))) {
      valid = false;
    }

    return valid;
  }
Example #10
0
  private void doResend(SoapMessage message) {
    try {

      // initialize copied interceptor chain for message
      PhaseInterceptorChain retransmitChain = manager.getRetransmitChain(message);
      ProtocolVariation protocol = RMContextUtils.getProtocolVariation(message);
      Endpoint endpoint = manager.getReliableEndpoint(message).getEndpoint(protocol);
      PhaseChainCache cache = new PhaseChainCache();
      boolean after = true;
      if (retransmitChain == null) {

        // no saved retransmit chain, so construct one from scratch (won't work for WS-Security on
        // server, so
        //  need to fix)
        retransmitChain = buildRetransmitChain(endpoint, cache);
        after = false;
      }
      message.setInterceptorChain(retransmitChain);

      // clear flag for SOAP out interceptor so envelope will be written
      message.remove(SoapOutInterceptor.WROTE_ENVELOPE_START);

      // discard all saved content
      Set<Class<?>> formats = message.getContentFormats();
      List<CachedOutputStreamCallback> callbacks = null;
      for (Class<?> clas : formats) {
        Object content = message.getContent(clas);
        if (content != null) {
          LOG.info(
              "Removing "
                  + clas.getName()
                  + " content of actual type "
                  + content.getClass().getName());
          message.removeContent(clas);
          if (clas == OutputStream.class && content instanceof WriteOnCloseOutputStream) {
            callbacks = ((WriteOnCloseOutputStream) content).getCallbacks();
          }
        }
      }

      // read SOAP headers from saved input stream
      RewindableInputStream is =
          (RewindableInputStream) message.get(RMMessageConstants.SAVED_CONTENT);
      is.rewind();
      XMLStreamReader reader = StaxUtils.createXMLStreamReader(is, "UTF-8");
      message.getHeaders().clear();
      if (reader.getEventType() != XMLStreamConstants.START_ELEMENT
          && reader.nextTag() != XMLStreamConstants.START_ELEMENT) {
        throw new IllegalStateException("No document found");
      }
      readHeaders(reader, message);
      int event;
      while ((event = reader.nextTag()) != XMLStreamConstants.START_ELEMENT) {
        if (event == XMLStreamConstants.END_ELEMENT) {
          throw new IllegalStateException("No body content present");
        }
      }

      // set message addressing properties
      AddressingProperties maps = new MAPCodec().unmarshalMAPs(message);
      RMContextUtils.storeMAPs(maps, message, true, MessageUtils.isRequestor(message));
      AttributedURIType to = null;
      if (null != maps) {
        to = maps.getTo();
      }
      if (null == to) {
        LOG.log(Level.SEVERE, "NO_ADDRESS_FOR_RESEND_MSG");
        return;
      }
      if (RMUtils.getAddressingConstants().getAnonymousURI().equals(to.getValue())) {
        LOG.log(Level.FINE, "Cannot resend to anonymous target");
        return;
      }

      // initialize conduit for new message
      Conduit c = message.getExchange().getConduit(message);
      if (c == null) {
        c = buildConduit(message, endpoint, to);
      }
      c.prepare(message);

      // replace standard message marshaling with copy from saved stream
      ListIterator<Interceptor<? extends Message>> iterator = retransmitChain.getIterator();
      while (iterator.hasNext()) {
        Interceptor<? extends Message> incept = iterator.next();

        // remove JAX-WS interceptors which handle message modes and such
        if (incept.getClass().getName().startsWith("org.apache.cxf.jaxws.interceptors")) {
          retransmitChain.remove(incept);
        } else if (incept instanceof PhaseInterceptor
            && (((PhaseInterceptor<?>) incept).getPhase() == Phase.MARSHAL)) {

          // remove any interceptors from the marshal phase
          retransmitChain.remove(incept);
        }
      }
      retransmitChain.add(new CopyOutInterceptor(reader));

      // restore callbacks on output stream
      if (callbacks != null) {
        OutputStream os = message.getContent(OutputStream.class);
        if (os != null) {
          WriteOnCloseOutputStream woc;
          if (os instanceof WriteOnCloseOutputStream) {
            woc = (WriteOnCloseOutputStream) os;
          } else {
            woc = new WriteOnCloseOutputStream(os);
            message.setContent(OutputStream.class, woc);
          }
          for (CachedOutputStreamCallback cb : callbacks) {
            woc.registerCallback(cb);
          }
        }
      }

      // send the message
      message.put(RMMessageConstants.RM_RETRANSMISSION, Boolean.TRUE);
      if (after) {
        retransmitChain.doInterceptStartingAfter(message, RMCaptureOutInterceptor.class.getName());
      } else {
        retransmitChain.doIntercept(message);
      }
      if (LOG.isLoggable(Level.INFO)) {
        RMProperties rmps = RMContextUtils.retrieveRMProperties(message, true);
        SequenceType seq = rmps.getSequence();
        LOG.log(
            Level.INFO,
            "Retransmitted message "
                + seq.getMessageNumber()
                + " in sequence "
                + seq.getIdentifier().getValue());
        rmps = new RMProperties();
      }

    } catch (Exception ex) {
      LOG.log(Level.SEVERE, "RESEND_FAILED_MSG", ex);
    }
  }
Example #11
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;
  }
Example #12
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;
  }