001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.camel.example.bam;
018
019 import org.apache.camel.Exchange;
020 import org.apache.camel.Processor;
021 import org.apache.camel.bam.ActivityBuilder;
022 import org.apache.camel.bam.ProcessBuilder;
023 import org.apache.commons.logging.Log;
024 import org.apache.commons.logging.LogFactory;
025
026 import org.springframework.orm.jpa.JpaTemplate;
027 import org.springframework.transaction.support.TransactionTemplate;
028
029 import static org.apache.camel.builder.xml.XPathBuilder.xpath;
030 import static org.apache.camel.util.Time.seconds;
031
032 /**
033 * @version $Revision: $
034 */
035 // START SNIPPET: example
036 public class MyActivities extends ProcessBuilder {
037 private static final Log LOG = LogFactory.getLog(MyActivities.class);
038
039 protected MyActivities(JpaTemplate jpaTemplate, TransactionTemplate transactionTemplate) {
040 super(jpaTemplate, transactionTemplate);
041 }
042
043 public void configure() throws Exception {
044
045 // lets define some activities, correlating on an XPath on the message bodies
046 ActivityBuilder purchaseOrder = activity("file:src/data/purchaseOrders?noop=true")
047 .correlate(xpath("/purchaseOrder/@id"));
048
049 ActivityBuilder invoice = activity("file:src/data/invoices?noop=true")
050 .correlate(xpath("/invoice/@purchaseOrderId"));
051
052 // now lets add some rules
053 invoice.starts().after(purchaseOrder.completes())
054 .expectWithin(seconds(1))
055 .errorIfOver(seconds(2)).to("log:org.apache.camel.example.bam.BamFailures?level=error");
056
057 from("seda:failures").process(new Processor() {
058 public void process(Exchange exchange) throws Exception {
059 LOG.info("Failed process!: " + exchange + " with body: " + exchange.getIn().getBody());
060 }
061 });
062 }
063 };
064 // END SNIPPET: example