Exemplo n.º 1
0
 private EndpointReferenceType getReplyTo(Message message, EndpointReferenceType originalReplyTo) {
   Exchange exchange = message.getExchange();
   Endpoint info = exchange.getEndpoint();
   if (info == null) {
     return originalReplyTo;
   }
   synchronized (info) {
     EndpointInfo ei = info.getEndpointInfo();
     Destination dest = ei.getProperty(DECOUPLED_DESTINATION, Destination.class);
     if (dest == null) {
       dest = createDecoupledDestination(message);
       if (dest != null) {
         info.getEndpointInfo().setProperty(DECOUPLED_DESTINATION, dest);
       }
     }
     if (dest != null) {
       // if the decoupled endpoint context prop is set and the address is relative, return the
       // absolute url.
       final String replyTo = dest.getAddress().getAddress().getValue();
       if (replyTo.startsWith("/")) {
         String debase =
             (String)
                 message.getContextualProperty(WSAContextUtils.DECOUPLED_ENDPOINT_BASE_PROPERTY);
         if (debase != null) {
           return EndpointReferenceUtils.getEndpointReference(debase + replyTo);
         }
       }
       return dest.getAddress();
     }
   }
   return originalReplyTo;
 }
Exemplo n.º 2
0
 public void clientDestroyed(Client client) {
   Destination dest =
       client
           .getEndpoint()
           .getEndpointInfo()
           .getProperty(DECOUPLED_DESTINATION, Destination.class);
   if (dest != null) {
     dest.setMessageObserver(null);
     dest.shutdown();
   }
 }
Exemplo n.º 3
0
  /**
   * @param address the address
   * @return a Destination for the address
   */
  private Destination getDestination(Bus bus, String address, Message message) throws IOException {
    Destination destination = null;
    DestinationFactoryManager factoryManager = bus.getExtension(DestinationFactoryManager.class);
    DestinationFactory factory = factoryManager.getDestinationFactoryForUri(address);
    if (factory != null) {
      Endpoint ep = message.getExchange().getEndpoint();

      EndpointInfo ei = new EndpointInfo();
      ei.setName(
          new QName(
              ep.getEndpointInfo().getName().getNamespaceURI(),
              ep.getEndpointInfo().getName().getLocalPart() + ".decoupled"));
      ei.setAddress(address);
      destination = factory.getDestination(ei, bus);
      Conduit conduit = ContextUtils.getConduit(null, message);
      if (conduit != null) {
        MessageObserver ob = ((Observable) conduit).getMessageObserver();
        ob = new InterposedMessageObserver(bus, ob);
        destination.setMessageObserver(ob);
      }
    }
    return destination;
  }
Exemplo n.º 4
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;
  }
  @Override
  public synchronized void addListener(Destination d, Endpoint e) {
    MessageObserver mo = d.getMessageObserver();
    if (d.getAddress() != null
        && d.getAddress().getAddress() != null
        && d.getAddress().getAddress().getValue() != null
        && d.getAddress().getAddress().getValue().startsWith("soap.udp")) {
      // soap.udp REQUIRES usage of WS-Addressing... we need to turn this on
      setupUDP(e, e.getEndpointInfo());
    }
    if (mo == null) {
      super.addListener(d, e);
      return;
    }

    if (mo instanceof ChainInitiationObserver) {
      ChainInitiationObserver cio = (ChainInitiationObserver) mo;

      Binding b = e.getBinding();
      Binding b2 = cio.getEndpoint().getBinding();
      if (b == b2) {
        // re-registering the same endpoint?
        return;
      }
      Object o = cio.getEndpoint().get("allow-multiplex-endpoint");
      if (o instanceof String) {
        o = Boolean.parseBoolean((String) o);
      } else if (o == null) {
        o = Boolean.FALSE;
      }

      if (b instanceof org.apache.cxf.binding.soap.SoapBinding
          && b2 instanceof org.apache.cxf.binding.soap.SoapBinding
          && ((org.apache.cxf.binding.soap.SoapBinding) b)
              .getSoapVersion()
              .equals(((org.apache.cxf.binding.soap.SoapBinding) b2).getSoapVersion())
          && Boolean.FALSE.equals(o)) {

        throw new RuntimeException(
            "Soap "
                + ((org.apache.cxf.binding.soap.SoapBinding) b).getSoapVersion().getVersion()
                + " endpoint already registered on address "
                + e.getEndpointInfo().getAddress());
      }

      MultipleEndpointObserver newMO =
          new MultipleEndpointObserver(getBus()) {
            @Override
            protected Message createMessage(Message message) {
              return new SoapMessage(message);
            }
          };

      newMO.getBindingInterceptors().add(new AttachmentInInterceptor());
      newMO.getBindingInterceptors().add(new StaxInInterceptor());

      // This will not work if one of the endpoints disables message
      // processing. But, if you've disabled message processing, you
      // probably aren't going to use this feature.

      newMO.getBindingInterceptors().add(new ReadHeadersInterceptor(getBus(), (SoapVersion) null));
      newMO.getBindingInterceptors().add(new StartBodyInterceptor());
      newMO.getBindingInterceptors().add(new CheckFaultInterceptor());

      // Add in a default selection interceptor
      newMO.getRoutingInterceptors().add(new EndpointSelectionInterceptor());

      newMO.getEndpoints().add(cio.getEndpoint());

      mo = newMO;
    }

    if (mo instanceof MultipleEndpointObserver) {
      MultipleEndpointObserver meo = (MultipleEndpointObserver) mo;
      meo.getEndpoints().add(e);
    }

    d.setMessageObserver(mo);
  }