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.server;
018    
019    import org.apache.camel.Endpoint;
020    import org.apache.camel.Exchange;
021    import org.aspectj.lang.annotation.Aspect;
022    import org.aspectj.lang.annotation.Before;
023    import org.springframework.beans.factory.annotation.Required;
024    
025    // START SNIPPET: e1
026    /**
027     * For audit tracking of all incoming invocations of our business (Multiplier)
028     */
029    @Aspect
030    public class AuditTracker {
031    
032        // endpoint we use for backup store of audit tracks
033        private Endpoint store;
034    
035        @Required
036        public void setStore(Endpoint store) {
037            this.store = store;
038        }
039    
040        @Before("execution(int org.apache.camel.example.server.Multiplier.multiply(int)) && args(originalNumber)")
041        public void audit(int originalNumber) throws Exception {
042            String msg = "Someone called us with this number " + originalNumber;
043            System.out.println(msg);
044    
045            // now send the message to the backup store using the Camel Message Endpoint pattern
046            Exchange exchange = store.createExchange();
047            exchange.getIn().setBody(msg);
048            store.createProducer().process(exchange);
049        }
050        
051    }
052    // END SNIPPET: e1