org.apache.camel.impl.DefaultMessage Java Examples

The following examples show how to use org.apache.camel.impl.DefaultMessage. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultMessageConverter.java    From hazelcastmq with Apache License 2.0 6 votes vote down vote up
/**
 * Converts from a Camel message to a HzMq message. The headers are simply
 * copied unmodified. The body is mapped by type:
 * <ul>
 * <li>If the content type is text/plain, the body is set as a String</li>
 * <li>all others: the body is set as a byte[] (or null)</li>
 * </ul>
 *
 * @param mqMsg the HzMq message to convert
 *
 * @return the new Camel message
 */
@Override
public Message toCamelMessage(HazelcastMQMessage mqMsg) {
  DefaultMessage camelMsg = new DefaultMessage();

  camelMsg.setHeaders((Map) mqMsg.getHeaders().getHeaderMap());

  if (mqMsg.getContentType() != null && mqMsg.getContentType().equals(
      "text/plain")) {
    camelMsg.setBody(mqMsg.getBodyAsString());
  }
  else {
    camelMsg.setBody(mqMsg.getBody());
  }

  return camelMsg;
}
 
Example #2
Source File: DeploymentDistributionDecisionMaker.java    From container with Apache License 2.0 5 votes vote down vote up
/**
 * Match the given NodeType and properties against instance data from remote OpenTOSCA Containers. The matching is
 * successful if a NodeTemplateInstance with the same NodeType and the same values for the properties is found in
 * their instance data. The method sends a request via MQTT to all subscribed OpenTOSCA Containers. Afterwards, it
 * waits for a reply which contains the host name of the OpenTOSCA Container that found matching instance data. If
 * it receives a reply in time, it returns the host name. Otherwise, it returns null.
 *
 * @param infrastructureNodeType   the NodeType of the NodeTemplate which has to be matched
 * @param infrastructureProperties the set of properties of the NodeTemplate which has to be matched
 * @return the host name of the OpenTOSCA Container which found a matching NodeTemplateInstance if one is found,
 * <tt>null</tt> otherwise.
 */
private String performRemoteInstanceDataMatching(final QName infrastructureNodeType,
                                                 final Map<String, String> infrastructureProperties) {

    LOG.debug("Creating collaboration message for remote instance data matching...");

    // transform infrastructureProperties for the message body
    final KeyValueMap properties = new KeyValueMap();
    final List<KeyValueType> propertyList = properties.getKeyValuePair();
    infrastructureProperties.entrySet().forEach((entry) -> propertyList.add(new KeyValueType(entry.getKey(),
        entry.getValue())));

    // create collaboration message
    final BodyType content = new BodyType(new InstanceDataMatchingRequest(infrastructureNodeType, properties));
    final CollaborationMessage collaborationMessage = new CollaborationMessage(new KeyValueMap(), content);

    // perform remote instance data matching and wait 10s for a response
    final Exchange response = sender.sendRequestToRemoteContainer(new DefaultMessage(),
        RemoteOperations.INVOKE_INSTANCE_DATA_MATCHING,
        collaborationMessage, 10000);

    if (Objects.nonNull(response)) {
        LOG.debug("Received a response in time.");

        // read the deployment location from the reply
        return response.getIn().getHeader(MBHeader.DEPLOYMENTLOCATION_STRING.toString(), String.class);
    } else {
        LOG.debug("No response received within the timeout interval.");
        return null;
    }
}
 
Example #3
Source File: InputGenerator.java    From java-course-ee with MIT License 3 votes vote down vote up
@Override
public void process(Exchange exchange) throws Exception {

    DefaultMessage message = new DefaultMessage();
    message.setBody("current time: " + new Date());

    exchange.setOut(message);

}
 
Example #4
Source File: InputGenerator.java    From java-course-ee with MIT License 3 votes vote down vote up
@Override
public void process(Exchange exchange) throws Exception {

    DefaultMessage message = new DefaultMessage();
    message.setBody("current time: " + new Date());

    exchange.setOut(message);

}