コード例 #1
0
ファイル: HttpHeaderTrans.java プロジェクト: NCIP/caaers
  private void processRequest(MessageExchange exchange) throws MessagingException {
    if (exchange.getStatus() == ExchangeStatus.ACTIVE) {

      String id = exchange.getExchangeId();
      this.exchanges.put(id, exchange);

      InOut inOut = createInOutExchange(QName.valueOf(getTargetServiceQName()), null, null);
      inOut.setProperty(CORRELATION_ID, id);

      NormalizedMessage inMsg = getInMessage(exchange);
      removeHeader(inMsg);

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

      //            inOut.setInMessage(msg);
      inOut.setInMessage(inMsg);
      send(inOut);
    }
  }
コード例 #2
0
 @Override
 protected void configureExchange(ServiceMixClient client, MessageExchange exchange) {
   ServiceEndpoint endpoint =
       client.getContext().getEndpoint(CamelProviderEndpoint.SERVICE_NAME, "cheese");
   assertNotNull("Should have a Camel endpoint exposed in JBI!", endpoint);
   exchange.setEndpoint(endpoint);
 }
コード例 #3
0
  @Override
  protected void checkResult(MessageExchange exchange) {
    NormalizedMessage fault = exchange.getMessage("fault");

    assertNotNull(fault);
    assertNotNull(fault.getContent());
    assertEquals(VALUE, fault.getProperty(KEY));
  }
コード例 #4
0
ファイル: HttpHeaderTrans.java プロジェクト: NCIP/caaers
  /*
   * (non-Javadoc)
   *
   * @see org.apache.servicemix.MessageExchangeListener#onMessageExchange(javax.jbi.messaging.MessageExchange)
   */
  public void onMessageExchange(MessageExchange exchange) throws MessagingException {

    if (exchange.getRole() == Role.PROVIDER) {
      processRequest(exchange);
    } else {
      processResponse(exchange);
    }
  }
コード例 #5
0
ファイル: HttpHeaderTrans.java プロジェクト: NCIP/caaers
  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);
    }
  }
コード例 #6
0
  public void onExchangeSent(MessageExchange exchange) {

    try {
      strategy.processExchange(exchange, getSession());
      getSession().save();

      marshaler = getMarshaler();
      System.out.println("&&&&&&&&&&&&&&&&&" + marshaler.toString());

      LOG.info(
          "Successfully stored information about message exchange "
              + exchange.getExchangeId()
              + " in the JCR repository");

      log.info("Marshaler is set to: " + marshaler.toString());

    } catch (Exception e) {
      LOG.error(
          "Unable to store information about message exchange " + exchange.getExchangeId(), e);
    }
  }
コード例 #7
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);
    }
  }
コード例 #8
0
 public boolean sendSync(MessageExchange exchange, long timeout) throws MessagingException {
   if (this.closed) {
     throw new MessagingException("Channel is closed");
   }
   if (!(exchange instanceof MessageExchangeProxy)) {
     throw new MessagingException("exchange should be created with MessageExchangeFactory");
   }
   MessageExchangeProxy me = (MessageExchangeProxy) exchange;
   String target;
   if (me.getRole() == MessageExchange.Role.CONSUMER) {
     if (me.getConsumer() == null) {
       me.setConsumer(this.componentName);
       ServiceEndpoint se = this.container.getRouter().getTargetEndpoint(exchange);
       me.setEndpoint(se);
       target = ((AbstractServiceEndpoint) se).getComponent();
       me.setProvider(target);
     } else {
       target = me.getProvider();
     }
   } else {
     target = me.getConsumer();
   }
   me.handleSend(true);
   DeliveryChannelImpl ch =
       (DeliveryChannelImpl) this.container.getRegistry().getComponent(target).getChannel();
   ch.enqueue(me.getTwin());
   try {
     synchronized (exchange) {
       exchange.wait(timeout);
       if (me.getSyncState() == MessageExchangeProxy.SYNC_STATE_SYNC_RECEIVED) {
         me.handleAccept();
         return true;
       } else {
         return false;
       }
     }
   } catch (InterruptedException e) {
     throw new MessagingException(e);
   }
 }