示例#1
0
  private void processResponse(MessageExchange exchange) throws MessagingException {

    if (exchange.getStatus() == ExchangeStatus.ACTIVE) {

      System.out.println("Endpoint: " + exchange.getEndpoint().getServiceName());

      String id = (String) exchange.getProperty(CORRELATION_ID);
      MessageExchange request = (MessageExchange) this.exchanges.remove(id);
      if (request == null) {
        throw new MessagingException("No exchange found for ID: " + id);
      }

      NormalizedMessage response = request.createMessage();
      String xml = null;
      try {
        xml = new SourceTransformer().contentToString(exchange.getMessage("out"));
      } catch (Exception ex) {
        throw new MessagingException("Error getting content: " + ex.getMessage(), ex);
      }
      System.out.println("XML FROM SVC: " + xml);
      response.setContent(new StreamSource(new ByteArrayInputStream(xml.getBytes())));

      done(exchange);
      request.setMessage(response, "out");
      send(request);
    }
  }
示例#2
0
  public void onMessage(MessageExchange messageExchange, NormalizedMessage message)
      throws MessagingException {
    if (messageExchange.getRole() == MessageExchange.Role.PROVIDER) {
      return;
    }
    NormalizedMessage in = messageExchange.getMessage("in");

    try {
      NormalizedMessage out = messageExchange.createMessage();
      transform(messageExchange, in, out);

      if (messageExchange instanceof InOut) {
        messageExchange.setMessage(out, OUT);
      } else {
        InOnly outExchange = exchangeFactory.createInOnlyExchange();
        outExchange.setInMessage(out);
        deliveryChannel.sendSync(outExchange);
      }
      done(messageExchange);
    } catch (Exception e) {
      error(messageExchange, e);
    }
  }