Java Code Examples for org.apache.camel.Exchange.getProperty()

The following are Jave code examples for showing how to use getProperty() of the org.apache.camel.Exchange class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: camel-cookbook   File: SignalAggregationStrategy.java   Source Code and License Vote up 8 votes
@Override
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
    Exchange exchange = super.aggregate(oldExchange, newExchange);

    List<Exchange> aggregatedExchanges = exchange.getProperty("CamelGroupedExchange", List.class);

    // Complete aggregation if we have "numberOfSystems" (currently 3) different messages (where "system" headers are different)
    // https://github.com/apache/camel/blob/master/camel-core/src/main/docs/eips/aggregate-eip.adoc#completing-current-group-decided-from-the-aggregationstrategy
    if (numberOfSystems == aggregatedExchanges.stream().map(e -> e.getIn().getHeader("system", String.class)).distinct().count()) {
        exchange.setProperty(Exchange.AGGREGATION_COMPLETE_CURRENT_GROUP, true);
    }

    return exchange;
}
 
Example 2
Project: eds   File: AbstractLogicConsumer.java   Source Code and License Vote up 5 votes
@Override
public void process(Exchange exchange) throws Exception {
  try {
    String requestId = exchange.getProperty(RequestIdManager.REQUEST_ID, String.class);
    ThreadContext.put(RequestIdManager.REQUEST_ID, requestId);
    doProcess(exchange);
  } finally {
    ThreadContext.remove(RequestIdManager.REQUEST_ID);
  }
}
 
Example 3
Project: eds   File: PerformanceLogHelper.java   Source Code and License Vote up 5 votes
public void success(Exchange exchange){
  Object obj = exchange.getProperty(EXCHANGE_PERF_PROPERTY);
  long cost = -1;
  if(obj != null){
    cost = System.currentTimeMillis() - (long) obj;
    exchange.removeProperty(EXCHANGE_PERF_PROPERTY);
  }
  logger.debug("success|{}|{}|{}",cost,exchange.getIn().getHeaders(),exchange.getIn().getBody());
  requestIdManager.clean(exchange);
}
 
Example 4
Project: eds   File: PerformanceLogHelper.java   Source Code and License Vote up 5 votes
public void error(Exchange exchange){
  Object obj = exchange.getProperty(EXCHANGE_PERF_PROPERTY);
  long cost = -1;
  if(obj != null){
    cost = System.currentTimeMillis() - (long) obj;
    exchange.removeProperty(EXCHANGE_PERF_PROPERTY);
  }
  String ex = "";
  if(exchange.getException() != null){
    ex = exchange.getException().getMessage();
    exchange.removeProperty(EXCHANGE_PERF_PROPERTY);
  }
  logger.debug("error{}|{}|{}|{}",ex,cost,exchange.getIn().getHeaders(),exchange.getIn().getBody());
  requestIdManager.clean(exchange);
}
 
Example 5
Project: eds   File: RequestIdManager.java   Source Code and License Vote up 4 votes
public static String currentRequestId(Exchange exchange) {
  return exchange == null ? ThreadContext.get(REQUEST_ID)
      : exchange.getProperty(REQUEST_ID, String.class);
}
 
Example 6
Project: fis-amq-producer   File: PrepareHttpResponseProcessor.java   Source Code and License Vote up 4 votes
@Override
public void process(Exchange exchange) throws Exception {
	int messageCount = exchange.getProperty("messageToSend", Integer.class);
	
	int transactionBatchSize = new Integer(exchange.getContext().resolvePropertyPlaceholders("{{default.transaction.batch.size}}"));
	if (exchange.getProperty("requestTransactionBatchSize") != null)
		transactionBatchSize = exchange.getProperty("requestTransactionBatchSize", Integer.class);
	
	boolean transacted = new Boolean(exchange.getContext().resolvePropertyPlaceholders("{{default.transacted}}"));
	if (exchange.getProperty("transacted") != null)
		transacted = exchange.getProperty("transacted", Boolean.class);
	
	int messageSize = new Integer(exchange.getContext().resolvePropertyPlaceholders("{{default.message.size}}"));
	
	long msgTTL = new Long(exchange.getContext().resolvePropertyPlaceholders("{{default.message.ttl}}"));
	if (exchange.getProperty("msgTTL") != null) {
		msgTTL = exchange.getProperty("msgTTL", Long.class);
	}
	
	String deliveryMode = "PERSISTENT";
	if (exchange.getProperty("persistent") != null) {
		if (exchange.getProperty("persistent",String.class).equalsIgnoreCase("false"))
			deliveryMode = "NON_PERSISTENT";
	}
	
	String jmsxGroupID = null;
	if (exchange.getProperty("messageSize") != null) {
		messageSize = exchange.getProperty("messageSize", Integer.class);
	}
	if (exchange.getProperty("JMSXGroupID") != null) {
		jmsxGroupID = exchange.getProperty("JMSXGroupID", String.class);
	}
	
	String amqServiceName = exchange.getContext().resolvePropertyPlaceholders("{{activemq.service.name}}");

	String message =
			messageCount + " JMS Messages published to " +
			"[" + exchange.getProperty("destination", String.class) + "] " +
		    "in " + exchange.getProperty("duration") + " :\n" +
		    "- AMQ Service Name in OpenShift: " + amqServiceName + " \n" +
		    "- Message size: " + messageSize + " bytes\n" +
		    "- Delivery mode: " + deliveryMode + "\n" +
		    "- Message TTL (JMSExpiration): " + msgTTL + " ms\n";
	if (jmsxGroupID != null) 
		message += "- Message group (JMSXGroupID) : " + jmsxGroupID + "\n";
	message += "- Transaction batch size: " + transactionBatchSize + "\n" +
			   "- Transaction activated: " + transacted + "\n";
	exchange.getIn().setBody(message);
}
 
Example 7
Project: fis-amq-producer   File: JmsTransactionBatchProcessor.java   Source Code and License Vote up 4 votes
@Override
public void process(Exchange exchange) throws Exception {
	
	String messageToSend = generateMessagePayload(exchange.getProperty("messageSize", Integer.class));
	
	int batchSize = exchange.getProperty("transactionBatchSize", Integer.class);
	boolean transacted = exchange.getProperty("transacted", Boolean.class);
	int messageCount = exchange.getProperty("messageCount", Integer.class);
	
	// Avoid having batch size == 0
	if (batchSize == 0) { 
		batchSize = 1; 
		exchange.setProperty("transactionBatchSize", batchSize);
	}
	
	// Avoid batchSize > total number of message to process
	if  (batchSize > messageCount) {
		exchange.setProperty("transactionBatchSize", messageCount);
		batchSize = messageCount;
	}
	
	exchange.setProperty("messageCount", messageCount - batchSize);
	
	// Prepare message headers
	Map<String, Object> messageHeader = null;
	if (exchange.getProperty("JMSXGroupID") != null) {
		messageHeader = new HashMap<String, Object>();
		messageHeader.put("JMSXGroupID", exchange.getProperty("JMSXGroupID", String.class));
	}
	
	// Prepare batch messages
	List<BatchMessage<String>> messages = new ArrayList<BatchMessage<String>>();
	for (int i = 1; i <= batchSize; i++) {
		
	    BatchMessage<String> message = new BatchMessage<String>(messageToSend, messageHeader);
	    messages.add(message);
	}
	
	String destination = exchange.getProperty("destination", String.class);
	Long msgTTL = exchange.getProperty("msgTTL", Long.class);
	boolean persistent = exchange.getProperty("persistent", Boolean.class);
	
	String sjmsUri = "sjms:" + destination +
					 "?ttl=" + msgTTL + 
				     "&persistent=" + persistent +
					 "&transacted=" + transacted;
	exchange.setProperty("sjmsUri", sjmsUri);
	exchange.getIn().setBody(messages);
}
 
Example 8
Project: syndesis   File: AdaptObjectForUpdateProcessor.java   Source Code and License Vote up 3 votes
private String determineIdProperty(final Exchange exchange) throws URISyntaxException {
    final String uri = exchange.getProperty(Exchange.TO_ENDPOINT, String.class);

    final Map<String, Object> endpointParameters = URISupport.parseParameters(URI.create(uri));

    return (String) endpointParameters.getOrDefault(SalesforceEndpointConfig.SOBJECT_EXT_ID_NAME, "Id");
}