Exemple #1
0
 public void testInOutWithFault() throws Exception {
   // Send message exchange
   MessageExchangeFactory mef = consumer.getChannel().createExchangeFactory(endpoint);
   InOut mec = mef.createInOutExchange();
   NormalizedMessage m = mec.createMessage();
   m.setContent(new StreamSource(new ByteArrayInputStream(PAYLOAD.getBytes())));
   mec.setInMessage(m);
   consumer.getChannel().send(mec);
   // Provider side
   InOut mep = (InOut) provider.getChannel().accept(10L);
   assertNotNull(mep);
   assertEquals(ExchangeStatus.ACTIVE, mep.getStatus());
   m = mep.createMessage();
   m.setContent(new StreamSource(new ByteArrayInputStream(RESPONSE.getBytes())));
   mep.setStatus(ExchangeStatus.ERROR);
   provider.getChannel().send(mep);
   // Consumer side
   assertSame(mec, consumer.getChannel().accept(10L));
   assertEquals(ExchangeStatus.ERROR, mec.getStatus());
   mec.setStatus(ExchangeStatus.DONE);
   consumer.getChannel().send(mec);
   // Provider site
   assertSame(mep, provider.getChannel().accept(10L));
   assertEquals(ExchangeStatus.DONE, mec.getStatus());
   // Nothing left
   assertNull(consumer.getChannel().accept(10L)); // receive in
   assertNull(provider.getChannel().accept(10L)); // receive in
 }
Exemple #2
0
  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);
    }
  }
Exemple #3
0
 public void testInOutSyncSync() throws Exception {
   // Create thread to answer
   Thread t =
       new Thread(
           new Runnable() {
             public void run() {
               try {
                 // Provider side
                 InOut mep = (InOut) provider.getChannel().accept(10000L);
                 assertNotNull(mep);
                 assertEquals(ExchangeStatus.ACTIVE, mep.getStatus());
                 NormalizedMessage m = mep.createMessage();
                 m.setContent(new StreamSource(new ByteArrayInputStream(RESPONSE.getBytes())));
                 mep.setOutMessage(m);
                 provider.getChannel().sendSync(mep);
                 assertEquals(ExchangeStatus.DONE, mep.getStatus());
               } catch (Exception e) {
                 e.printStackTrace();
                 fail();
               }
             }
           });
   t.start();
   // Send message exchange
   MessageExchangeFactory mef = consumer.getChannel().createExchangeFactory(endpoint);
   InOut mec = mef.createInOutExchange();
   NormalizedMessage m = mec.createMessage();
   m.setContent(new StreamSource(new ByteArrayInputStream(PAYLOAD.getBytes())));
   mec.setInMessage(m);
   consumer.getChannel().sendSync(mec, 10000L);
   assertEquals(ExchangeStatus.ACTIVE, mec.getStatus());
   mec.setStatus(ExchangeStatus.DONE);
   consumer.getChannel().send(mec);
   // Wait until other thread end
   t.join(1000L);
   // Nothing left
   assertNull(consumer.getChannel().accept(10L)); // receive in
   assertNull(provider.getChannel().accept(10L)); // receive in
 }