예제 #1
0
  /** {@inheritDoc} */
  @Override
  public void mapFrom(CamelBindingData source, Context context) throws Exception {
    Message message = source.getMessage();
    Exchange exchange = message.getExchange();

    for (Map.Entry<String, Object> header : message.getHeaders().entrySet()) {
      String name = header.getKey();
      if (matches(name) && !name.startsWith("org.switchyard.bus.camel")) {
        Object value = header.getValue();
        if (value != null) {
          context.setProperty(name, value, Scope.MESSAGE).addLabels(getCamelLabels());
        }
      }
    }
    if (exchange != null) {
      for (Map.Entry<String, Object> property : exchange.getProperties().entrySet()) {
        String name = property.getKey();
        if (matches(name) && !name.startsWith("org.switchyard.bus.camel")) {
          Object value = property.getValue();
          if (value != null) {
            context.setProperty(name, value, Scope.EXCHANGE).addLabels(getCamelLabels());
          }
        }
      }
    }
  }
예제 #2
0
  /** {@inheritDoc} */
  @Override
  public void mapTo(Context context, CamelBindingData target) throws Exception {
    Message message = target.getMessage();
    Exchange exchange = message.getExchange();

    for (Property property : context.getProperties(Scope.MESSAGE)) {
      String name = property.getName();
      if (matches(name) && !name.startsWith("org.switchyard.bus.camel")) {
        Object value = property.getValue();
        if (value != null) {
          message.setHeader(name, value);
        }
      }
    }
    if (exchange != null) {
      for (Property property : context.getProperties(Scope.EXCHANGE)) {
        String name = property.getName();
        if (matches(name) && !name.startsWith("org.switchyard.bus.camel")) {
          Object value = property.getValue();
          if (value != null) {
            exchange.setProperty(name, value);
          }
        }
      }
    }
  }
예제 #3
0
  /** {@inheritDoc} */
  @Override
  public void mapTo(Context context, JMSBindingData target) throws Exception {
    super.mapTo(context, target);

    Message message = target.getMessage();
    for (Property property : context.getProperties()) {
      String name = property.getName();

      if (matches(name)) {
        Object value = property.getValue();
        if (value == null) {
          continue;
        }

        try {
          // process JMS headers
          if (name.equals(HEADER_JMS_DESTINATION)) {
            message.setJMSDestination(Destination.class.cast(value));
          } else if (name.equals(HEADER_JMS_DELIVERY_MODE)) {
            message.setJMSDeliveryMode(Integer.parseInt(value.toString()));
          } else if (name.equals(HEADER_JMS_EXPIRATION)) {
            message.setJMSExpiration(Long.parseLong(value.toString()));
          } else if (name.equals(HEADER_JMS_PRIORITY)) {
            message.setJMSPriority(Integer.parseInt(value.toString()));
          } else if (name.equals(HEADER_JMS_MESSAGE_ID)) {
            message.setJMSMessageID(value.toString());
          } else if (name.equals(HEADER_JMS_TIMESTAMP)) {
            message.setJMSTimestamp(Long.parseLong(value.toString()));
          } else if (name.equals(HEADER_JMS_CORRELATION_ID)) {
            message.setJMSCorrelationID(value.toString());
          } else if (name.equals(HEADER_JMS_REPLY_TO)) {
            message.setJMSReplyTo(Destination.class.cast(value));
          } else if (name.equals(HEADER_JMS_TYPE)) {
            message.setJMSType(value.toString());
          } else if (name.equals(HEADER_JMS_REDELIVERED)) {
            message.setJMSRedelivered(Boolean.parseBoolean(value.toString()));

            // process JMS properties
          } else {
            message.setObjectProperty(name, value);
          }
        } catch (Throwable t) {
          continue;
        }
      } else if (matches(name, getIncludeRegexes(), new ArrayList<Pattern>())) {
        Object value = property.getValue();
        if (value == null) {
          continue;
        }
        message.setObjectProperty(name, value);
      }
    }
  }
 /** {@inheritDoc} */
 @Override
 public void mapFrom(ClientMessage source, Context context) throws Exception {
   for (SimpleString key : source.getPropertyNames()) {
     String name = key.toString();
     if (matches(name)) {
       Object value = source.getObjectProperty(key);
       if (value != null) {
         // HornetQ ClientMessage properties -> Context EXCHANGE properties
         context.setProperty(name, value, EXCHANGE).addLabels(HORNETQ_MESSAGE_PROPERTY);
       }
     }
   }
 }
 /** {@inheritDoc} */
 @Override
 public void mapTo(Context context, ClientMessage target) throws Exception {
   for (Property property : context.getProperties(EXCHANGE)) {
     String name = property.getName();
     if (matches(name)) {
       Object value = property.getValue();
       if (value != null) {
         try {
           // Context EXCHANGE properties -> HornetQ ClientMessage properties
           target.putObjectProperty(name, value);
         } catch (PropertyConversionException pce) {
           // ignore and keep going (here just to keep checkstyle happy)
           pce.getMessage();
         }
       }
     }
   }
 }
예제 #6
0
 /** {@inheritDoc} */
 @Override
 public void mapTo(Context context, JMSBindingData target) throws Exception {
   Message message = target.getMessage();
   for (Property property : context.getProperties(Scope.EXCHANGE)) {
     String name = property.getName();
     if (matches(name)) {
       Object value = property.getValue();
       if (value != null) {
         try {
           // Context EXCHANGE properties -> JMS Message properties
           message.setObjectProperty(name, value);
         } catch (Throwable t) {
           // ignore and keep going (here just to keep checkstyle happy)
           t.getMessage();
         }
       }
     }
   }
 }
 @Override
 public void mapTo(Context context, SOAPBindingData target) throws Exception {
   SOAPMessage soapMessage = target.getSOAPMessage();
   MimeHeaders mimeHeaders = soapMessage.getMimeHeaders();
   SOAPHeader soapHeader = soapMessage.getSOAPHeader();
   for (Property property : context.getProperties(Scope.IN)) {
     Object value = property.getValue();
     if (value != null) {
       String name = property.getName();
       QName qname = XMLHelper.createQName(name);
       boolean qualifiedForSoapHeader = Strings.trimToNull(qname.getNamespaceURI()) != null;
       if (qualifiedForSoapHeader && matches(qname)) {
         if (value instanceof Node) {
           Node domNode = soapHeader.getOwnerDocument().importNode((Node) value, true);
           soapHeader.appendChild(domNode);
         } else if (value instanceof Configuration) {
           Element configElement = new ElementPuller().pull(new StringReader(value.toString()));
           Node configNode = soapHeader.getOwnerDocument().importNode(configElement, true);
           soapHeader.appendChild(configNode);
         } else {
           String v = value.toString();
           if (SOAPHeadersType.XML.equals(getSOAPHeadersType())) {
             try {
               Element xmlElement = new ElementPuller().pull(new StringReader(v));
               Node xmlNode = soapHeader.getOwnerDocument().importNode(xmlElement, true);
               soapHeader.appendChild(xmlNode);
             } catch (Throwable t) {
               soapHeader.addChildElement(qname).setValue(v);
             }
           } else {
             soapHeader.addChildElement(qname).setValue(v);
           }
         }
       } else {
         if (matches(name)) {
           mimeHeaders.addHeader(name, String.valueOf(value));
         }
       }
     }
   }
 }
예제 #8
0
 /** {@inheritDoc} */
 @Override
 public void mapFrom(JMSBindingData source, Context context) throws Exception {
   Message message = source.getMessage();
   Enumeration<?> e = message.getPropertyNames();
   while (e.hasMoreElements()) {
     String key = e.nextElement().toString();
     if (matches(key)) {
       Object value = null;
       try {
         value = message.getObjectProperty(key);
       } catch (JMSException pce) {
         // ignore and keep going (here just to keep checkstyle happy)
         pce.getMessage();
       }
       if (value != null) {
         // JMS Message properties -> Context EXCHANGE properties
         context
             .setProperty(key, value, Scope.EXCHANGE)
             .addLabels(JCAComposition.JCA_MESSAGE_PROPERTY);
       }
     }
   }
 }
예제 #9
0
  /** {@inheritDoc} */
  @Override
  public void mapFrom(JMSBindingData source, Context context) throws Exception {
    super.mapFrom(source, context);

    Message message = source.getMessage();

    // process JMS headers
    if (matches(HEADER_JMS_DESTINATION)) {
      context
          .setProperty(HEADER_JMS_DESTINATION, message.getJMSDestination())
          .addLabels(JMS_HEADER_LABELS);
    }
    if (matches(HEADER_JMS_DELIVERY_MODE)) {
      context
          .setProperty(HEADER_JMS_DELIVERY_MODE, message.getJMSDeliveryMode())
          .addLabels(JMS_HEADER_LABELS);
    }
    if (matches(HEADER_JMS_EXPIRATION)) {
      context
          .setProperty(HEADER_JMS_EXPIRATION, message.getJMSExpiration())
          .addLabels(JMS_HEADER_LABELS);
    }
    if (matches(HEADER_JMS_PRIORITY)) {
      context
          .setProperty(HEADER_JMS_PRIORITY, message.getJMSPriority())
          .addLabels(JMS_HEADER_LABELS);
    }
    if (matches(HEADER_JMS_MESSAGE_ID)) {
      context
          .setProperty(HEADER_JMS_MESSAGE_ID, message.getJMSMessageID())
          .addLabels(JMS_HEADER_LABELS);
    }
    if (matches(HEADER_JMS_TIMESTAMP)) {
      context
          .setProperty(HEADER_JMS_TIMESTAMP, message.getJMSTimestamp())
          .addLabels(JMS_HEADER_LABELS);
    }
    if (matches(HEADER_JMS_CORRELATION_ID)) {
      context
          .setProperty(HEADER_JMS_CORRELATION_ID, message.getJMSCorrelationID())
          .addLabels(JMS_HEADER_LABELS);
    }
    if (matches(HEADER_JMS_REPLY_TO)) {
      context
          .setProperty(HEADER_JMS_REPLY_TO, message.getJMSReplyTo())
          .addLabels(JMS_HEADER_LABELS);
    }
    if (matches(HEADER_JMS_TYPE)) {
      context.setProperty(HEADER_JMS_TYPE, message.getJMSType()).addLabels(JMS_HEADER_LABELS);
    }
    if (matches(HEADER_JMS_REDELIVERED)) {
      context
          .setProperty(HEADER_JMS_REDELIVERED, message.getJMSRedelivered())
          .addLabels(JMS_HEADER_LABELS);
    }

    // process JMS properties
    Enumeration<?> e = message.getPropertyNames();
    while (e.hasMoreElements()) {
      String key = e.nextElement().toString();
      if (matches(key)) {
        Object value = null;
        try {
          value = message.getObjectProperty(key);
        } catch (JMSException pce) {
          // ignore and keep going (here just to keep checkstyle happy)
          pce.getMessage();
        }
        if (value != null) {
          context.setProperty(key, value).addLabels(JMS_PROPERTY_LABELS);
        }
      } else if (matches(key, getIncludeRegexes(), new ArrayList<Pattern>())) {
        Object value = null;
        try {
          value = message.getObjectProperty(key);
        } catch (JMSException pce) {
          // ignore and keep going (here just to keep checkstyle happy)
          pce.getMessage();
        }
        if (value != null) {
          context.setProperty(key, value).addLabels(JMS_PROPERTY_LABELS);
        }
      }
    }
  }
 /** {@inheritDoc} */
 @Override
 public void handleMessage(Exchange exchange) throws HandlerException {
   if (!ExchangePhase.IN.equals(exchange.getPhase())) {
     return;
   }
   Context context = exchange.getContext();
   ServiceOperation serviceOperation = exchange.getContract().getServiceOperation();
   ProcessActionModel processActionModel = _actionModels.get(serviceOperation.getName());
   ProcessActionType processActionType = getProcessActionType(context, processActionModel);
   Message messageIn = exchange.getMessage();
   Long processInstanceId = null;
   ProcessInstance processInstance = null;
   switch (processActionType) {
     case START_PROCESS:
       if (_processId != null) {
         Object messageContentIn = messageIn.getContent();
         if (messageContentIn != null) {
           Map<String, Object> parameters = new HashMap<String, Object>();
           parameters.put(_messageContentInName, messageContentIn);
           processInstance = _ksession.startProcess(_processId, parameters);
         } else {
           processInstance = _ksession.startProcess(_processId);
         }
         processInstanceId = Long.valueOf(processInstance.getId());
       } else {
         throwNullParameterException(processActionType, PROCESS_ID_VAR);
       }
       break;
     case SIGNAL_EVENT:
       String processEventType = getProcessEventType(context, processActionModel);
       Object processEvent = getProcessEvent(context, messageIn);
       processInstanceId = getProcessInstanceId(context);
       if (processInstanceId != null) {
         _ksession.signalEvent(processEventType, processEvent, processInstanceId.longValue());
       } else {
         throwNullParameterException(processActionType, PROCESS_INSTANCE_ID_VAR);
       }
       break;
     case ABORT_PROCESS_INSTANCE:
       processInstanceId = getProcessInstanceId(context);
       if (processInstanceId != null) {
         _ksession.abortProcessInstance(processInstanceId.longValue());
       } else {
         throwNullParameterException(processActionType, PROCESS_INSTANCE_ID_VAR);
       }
       break;
   }
   if (processInstanceId != null) {
     context.setProperty(PROCESS_INSTANCE_ID_VAR, processInstanceId, Scope.EXCHANGE);
     ExchangePattern exchangePattern = serviceOperation.getExchangePattern();
     if (ExchangePattern.IN_OUT.equals(exchangePattern)) {
       if (processInstance == null) {
         processInstance = _ksession.getProcessInstance(processInstanceId.longValue());
       }
       Message messageOut = exchange.createMessage();
       Object messageContentOut = null;
       if (processInstance != null) {
         messageContentOut =
             ((WorkflowProcessInstance) processInstance).getVariable(_messageContentOutName);
       }
       if (messageContentOut != null) {
         messageOut.setContent(messageContentOut);
       }
       exchange.send(messageOut);
     }
   }
 }