示例#1
0
 public void testInOptOutWithRepAndConsumerFault() throws Exception {
   // Send message exchange
   MessageExchangeFactory mef = consumer.getChannel().createExchangeFactory(endpoint);
   InOptionalOut mec = mef.createInOptionalOutExchange();
   NormalizedMessage m = mec.createMessage();
   m.setContent(new StreamSource(new ByteArrayInputStream(PAYLOAD.getBytes())));
   mec.setInMessage(m);
   consumer.getChannel().send(mec);
   // Provider side
   InOptionalOut mep = (InOptionalOut) provider.getChannel().accept(10L);
   assertNotNull(mep);
   assertEquals(ExchangeStatus.ACTIVE, mep.getStatus());
   m = mep.createMessage();
   m.setContent(new StreamSource(new ByteArrayInputStream(RESPONSE.getBytes())));
   mep.setOutMessage(m);
   provider.getChannel().send(mep);
   // Consumer side
   assertSame(mec, consumer.getChannel().accept(10L));
   assertEquals(ExchangeStatus.ACTIVE, mec.getStatus());
   mec.setStatus(ExchangeStatus.ERROR);
   consumer.getChannel().send(mec);
   // Provider site
   assertSame(mep, provider.getChannel().accept(10L));
   assertEquals(ExchangeStatus.ERROR, mep.getStatus());
   mep.setStatus(ExchangeStatus.DONE);
   provider.getChannel().send(mep);
   // Consumer side
   assertSame(mec, consumer.getChannel().accept(10L));
   assertEquals(ExchangeStatus.DONE, mec.getStatus());
   // Nothing left
   assertNull(consumer.getChannel().accept(10L)); // receive in
   assertNull(provider.getChannel().accept(10L)); // receive in
 }
示例#2
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);
    }
  }
示例#3
0
 public void testInOnlySync() throws Exception {
   // Create thread to answer
   new Thread(
           new Runnable() {
             public void run() {
               try {
                 // Provider side
                 InOnly mep = (InOnly) provider.getChannel().accept(10000L);
                 assertNotNull(mep);
                 assertEquals(ExchangeStatus.ACTIVE, mep.getStatus());
                 mep.setStatus(ExchangeStatus.DONE);
                 provider.getChannel().send(mep);
               } catch (Exception e) {
                 e.printStackTrace();
                 fail();
               }
             }
           })
       .start();
   // Send message exchange
   MessageExchangeFactory mef = consumer.getChannel().createExchangeFactory(endpoint);
   InOnly mec = mef.createInOnlyExchange();
   NormalizedMessage m = mec.createMessage();
   m.setContent(new StreamSource(new ByteArrayInputStream(PAYLOAD.getBytes())));
   mec.setInMessage(m);
   consumer.getChannel().sendSync(mec, 10000L);
   assertEquals(ExchangeStatus.DONE, mec.getStatus());
   // Nothing left
   assertNull(consumer.getChannel().accept(10L)); // receive in
   assertNull(provider.getChannel().accept(10L)); // receive in
 }
示例#4
0
 protected void transform(MessageExchange exchange, NormalizedMessage in, NormalizedMessage out)
     throws TransformerException, MessagingException {
   Object result = transformer.transform(in.getContent());
   if (result instanceof Source) {
     out.setContent((Source) result);
   } else {
     throw new UnsupportedOperationException(
         "Support for Source transformation is not yet implemented");
   }
 }
示例#5
0
  /* (non-Javadoc)
   * @see org.apache.servicemix.components.util.TransformComponentSupport#transform(javax.jbi.messaging.MessageExchange, javax.jbi.messaging.NormalizedMessage, javax.jbi.messaging.NormalizedMessage)
   */
  @Override
  protected boolean transform(
      MessageExchange exchange, NormalizedMessage inMsg, NormalizedMessage outMsg)
      throws Exception {
    boolean success = false;

    try {
      Subject subject = inMsg.getSecuritySubject();

      // Get principal
      Principal principal = null;
      Set<GridIdentifierPrincipal> principals =
          subject.getPrincipals(GridIdentifierPrincipal.class);
      if (principals == null || principals.size() == 0) {
        throw new RuntimeException("No GridIdentifierPrincipal found!");
      } else if (principals.size() > 1) {
        throw new RuntimeException(principals.size() + " GridIdentifierPrincipals found!");
      }
      principal = principals.iterator().next();
      System.out.println("## Principal is: " + principal.getName());

      // Get cert chain
      X509Certificate[] chain = null;
      Set<X509Certificate[]> chains = subject.getPublicCredentials(X509Certificate[].class);
      if (chains == null || chains.size() == 0) {
        throw new RuntimeException("No X509Certificate[] found!");
      } else if (chains.size() > 1) {
        throw new RuntimeException(chains.size() + " X509Certificate[]s found!");
      }
      chain = chains.iterator().next();

      // Get private key
      PrivateKey privateKey = null;
      Set<PrivateKey> privateKeys = subject.getPrivateCredentials(PrivateKey.class);
      if (privateKeys == null || privateKeys.size() == 0) {
        throw new RuntimeException("No PrivateKey found!");
      } else if (privateKeys.size() > 1) {
        throw new RuntimeException(chains.size() + " PrivateKeys found!");
      }
      privateKey = privateKeys.iterator().next();

      GlobusCredential cred = new GlobusCredential(privateKey, chain);

      System.out.println("## Identity is: " + cred.getIdentity());

      String inMsgXml = new SourceTransformer().contentToString(inMsg);
      outMsg.setContent(new StreamSource(new ByteArrayInputStream(inMsgXml.getBytes())));

      success = true;
    } catch (Exception ex) {
      ex.printStackTrace();
    }

    return success;
  }
示例#6
0
 public void testRobustInOnly() throws Exception {
   // Send message exchange
   MessageExchangeFactory mef = consumer.getChannel().createExchangeFactory(endpoint);
   RobustInOnly mec = mef.createRobustInOnlyExchange();
   NormalizedMessage m = mec.createMessage();
   m.setContent(new StreamSource(new ByteArrayInputStream(PAYLOAD.getBytes())));
   mec.setInMessage(m);
   consumer.getChannel().send(mec);
   // Provider side
   RobustInOnly mep = (RobustInOnly) provider.getChannel().accept(10L);
   assertNotNull(mep);
   assertEquals(ExchangeStatus.ACTIVE, mep.getStatus());
   mep.setStatus(ExchangeStatus.DONE);
   provider.getChannel().send(mep);
   // Consumer side
   assertSame(mec, consumer.getChannel().accept(10L));
   assertEquals(ExchangeStatus.DONE, mec.getStatus());
   // Nothing left
   assertNull(consumer.getChannel().accept(10L)); // receive in
   assertNull(provider.getChannel().accept(10L)); // receive in
 }
示例#7
0
  @Override
  public void sendEvent(Event event, String targetNamespace, String targetService) {
    try {
      QName service = new QName(targetNamespace, targetService);
      InOnly inOnly = new InOnlyImpl(UUID.randomUUID().toString());
      inOnly.setService(service);
      inOnly.setOperation(new QName("event"));

      NormalizedMessage msg = inOnly.createMessage();
      inOnly.setInMessage(msg);
      msgProperties.applyToMessage(msg);

      String xml = Transformer.toXml(event);
      msg.setContent(new StringSource(xml));

      endpoint.sendSync(inOnly);
    } catch (MessagingException e) {
      throw new RuntimeException(e);
    } catch (SerializationException e) {
      throw new RuntimeException(e);
    }
  }