Coverage Report - org.apache.camel.spring.remoting.SendBeforeInterceptor
 
Classes in this File Line Coverage Branch Coverage Complexity
SendBeforeInterceptor
0% 
0% 
0
 
 1  
 /**
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.camel.spring.remoting;
 18  
 
 19  
 import org.aopalliance.intercept.MethodInterceptor;
 20  
 import org.aopalliance.intercept.MethodInvocation;
 21  
 
 22  
 import org.apache.camel.CamelContext;
 23  
 import org.apache.camel.CamelContextAware;
 24  
 import org.apache.camel.Endpoint;
 25  
 import org.apache.camel.Producer;
 26  
 import org.apache.camel.component.bean.CamelInvocationHandler;
 27  
 import org.apache.camel.util.CamelContextHelper;
 28  
 
 29  
 import org.springframework.beans.factory.DisposableBean;
 30  
 import org.springframework.beans.factory.InitializingBean;
 31  
 
 32  
 import static org.apache.camel.util.ObjectHelper.notNull;
 33  
 
 34  
 /**
 35  
  * A Spring interceptor which sends a message exchange to an endpoint before the method is invoked
 36  
  * 
 37  
  * @version $Revision: $
 38  
  */
 39  0
 public class SendBeforeInterceptor implements MethodInterceptor, CamelContextAware, InitializingBean, DisposableBean {
 40  
     private String uri;
 41  
     private CamelContext camelContext;
 42  
     private CamelInvocationHandler invocationHandler;
 43  
     private Producer producer;
 44  
 
 45  
     public Object invoke(MethodInvocation invocation) throws Throwable {
 46  0
         invocationHandler.invoke(invocation.getThis(), invocation.getMethod(), invocation.getArguments());
 47  0
         return invocation.proceed();
 48  
     }
 49  
 
 50  
     public void afterPropertiesSet() throws Exception {
 51  0
         notNull(uri, "uri");
 52  0
         notNull(camelContext, "camelContext");
 53  
 
 54  0
         Endpoint endpoint = CamelContextHelper.getMandatoryEndpoint(camelContext, uri);
 55  0
         producer = endpoint.createProducer();
 56  0
         producer.start();
 57  0
         invocationHandler = new CamelInvocationHandler(endpoint, producer);
 58  0
     }
 59  
 
 60  
     public void destroy() throws Exception {
 61  0
         if (producer != null) {
 62  0
             producer.stop();
 63  
         }
 64  0
     }
 65  
 
 66  
     public void setCamelContext(CamelContext camelContext) {
 67  0
         this.camelContext = camelContext;
 68  0
     }
 69  
 
 70  
     // Properties
 71  
     //-----------------------------------------------------------------------
 72  
     public String getUri() {
 73  0
         return uri;
 74  
     }
 75  
 
 76  
     public void setUri(String uri) {
 77  0
         this.uri = uri;
 78  0
     }
 79  
 }