Пример #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
  private void removeHeader(NormalizedMessage msg) {
    for (Iterator i = msg.getPropertyNames().iterator(); i.hasNext(); ) {
      String name = (String) i.next();
      Object value = msg.getProperty(name);

      if ("javax.jbi.messaging.protocol.headers".equals(name)) {
        Map headers = (Map) value;
        headers.remove("Transfer-Encoding");
      }

      if ("org.apache.servicemix.soap.headers".equals(name)) {
        Map headers = (Map) value;
        for (Iterator j = headers.entrySet().iterator(); j.hasNext(); ) {
          Entry entry = (Entry) j.next();
          Object entryKey = entry.getKey();
          Object entryValue = entry.getValue();
          String out = entryKey.toString();
          if (entryValue != null) {
            out += "=" + entryValue.getClass().getName();
          } else {
            out += "=null";
          }
          System.out.println("SOAP HEADER: " + out);
        }
      }

      //            System.out.println("### " + name + "=" + value + " ###");
    }
  }
Пример #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
 public void testRobustInOnlyWithFault() 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.ERROR);
   provider.getChannel().send(mep);
   // Consumer side
   assertSame(mec, consumer.getChannel().accept(10L));
   assertEquals(ExchangeStatus.ERROR, mec.getStatus());
   mec.setStatus(ExchangeStatus.DONE);
   provider.getChannel().send(mec);
   // Provider site
   assertSame(mep, provider.getChannel().accept(10L));
   assertEquals(ExchangeStatus.DONE, mep.getStatus());
   // Nothing left
   assertNull(consumer.getChannel().accept(10L)); // receive in
   assertNull(provider.getChannel().accept(10L)); // receive in
 }
  @Override
  protected void checkResult(MessageExchange exchange) {
    NormalizedMessage fault = exchange.getMessage("fault");

    assertNotNull(fault);
    assertNotNull(fault.getContent());
    assertEquals(VALUE, fault.getProperty(KEY));
  }
Пример #6
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");
   }
 }
Пример #7
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;
  }
Пример #8
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);
    }
  }