private void checkAddressingResponses(
     EndpointReferenceType replyTo, EndpointReferenceType faultTo) {
   if (this.addressingResponses == WSAddressingFeature.AddressingResponses.ALL) {
     return;
   }
   boolean passed = false;
   boolean anonReply = ContextUtils.isGenericAddress(replyTo);
   boolean anonFault = ContextUtils.isGenericAddress(faultTo);
   boolean isAnonymous = anonReply && anonFault;
   if (WSAddressingFeature.AddressingResponses.ANONYMOUS == addressingResponses && isAnonymous) {
     passed = true;
   } else if (WSAddressingFeature.AddressingResponses.NON_ANONYMOUS == addressingResponses
       && (!anonReply && (faultTo.getAddress() != null && !anonFault)
           || !anonReply && faultTo.getAddress() == null)) {
     passed = true;
   }
   if (!passed) {
     String reason = BUNDLE.getString("INVALID_ADDRESSING_PROPERTY_MESSAGE");
     QName detail =
         WSAddressingFeature.AddressingResponses.ANONYMOUS == addressingResponses
             ? Names.ONLY_ANONYMOUS_ADDRESS_SUPPORTED_QNAME
             : Names.ONLY_NONANONYMOUS_ADDRESS_SUPPORTED_QNAME;
     throw new SoapFault(reason, detail);
   }
 }
 /** Set up the decoupled Destination if necessary. */
 private Destination setUpDecoupledDestination(Bus bus, String replyToAddress, Message message) {
   EndpointReferenceType reference = EndpointReferenceUtils.getEndpointReference(replyToAddress);
   if (reference != null) {
     String decoupledAddress = reference.getAddress().getValue();
     LOG.info("creating decoupled endpoint: " + decoupledAddress);
     try {
       Destination dest = getDestination(bus, replyToAddress, message);
       bus.getExtension(ClientLifeCycleManager.class).registerListener(DECOUPLED_DEST_CLEANER);
       return dest;
     } catch (Exception e) {
       // REVISIT move message to localizable Messages.properties
       LOG.log(Level.WARNING, "decoupled endpoint creation failed: ", e);
     }
   }
   return null;
 }
 public Conduit getConduit(EndpointInfo ei, EndpointReferenceType target, Bus bus)
     throws IOException {
   String address = target == null ? ei.getAddress() : target.getAddress().getValue();
   BindingInfo bi = ei.getBinding();
   String transId = ei.getTransportId();
   if (bi instanceof SoapBindingInfo) {
     transId = ((SoapBindingInfo) bi).getTransportURI();
     if (transId == null) {
       transId = ei.getTransportId();
     }
   }
   ConduitInitiator conduitInit;
   try {
     ConduitInitiatorManager mgr = bus.getExtension(ConduitInitiatorManager.class);
     if (StringUtils.isEmpty(address)
         || address.startsWith("http")
         || address.startsWith("jms")
         || address.startsWith("soap.udp")) {
       conduitInit = mgr.getConduitInitiator(mapTransportURI(transId, address));
     } else {
       conduitInit = mgr.getConduitInitiatorForUri(address);
     }
     if (conduitInit == null) {
       throw new RuntimeException(String.format(CANNOT_GET_CONDUIT_ERROR, address, transId));
     }
     return conduitInit.getConduit(ei, target, bus);
   } catch (BusException e) {
     throw new RuntimeException(String.format(CANNOT_GET_CONDUIT_ERROR, address, transId));
   }
 }
 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);
      }
    }
  }
Example #6
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;
  }
 public String getAddress() {
   return (null != address) ? address.getAddress().getValue() : null;
 }