Coverage Report - org.apache.camel.spring.remoting.CamelServiceExporter
 
Classes in this File Line Coverage Branch Coverage Complexity
CamelServiceExporter
84% 
100% 
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.apache.camel.CamelContext;
 20  
 import org.apache.camel.CamelContextAware;
 21  
 import org.apache.camel.Consumer;
 22  
 import org.apache.camel.Endpoint;
 23  
 import org.apache.camel.component.bean.BeanProcessor;
 24  
 import org.apache.camel.util.CamelContextHelper;
 25  
 
 26  
 import org.springframework.beans.BeansException;
 27  
 import org.springframework.beans.factory.DisposableBean;
 28  
 import org.springframework.beans.factory.InitializingBean;
 29  
 import org.springframework.context.ApplicationContext;
 30  
 import org.springframework.context.ApplicationContextAware;
 31  
 import org.springframework.remoting.support.RemoteExporter;
 32  
 
 33  
 import static org.apache.camel.util.ObjectHelper.notNull;
 34  
 
 35  
 /**
 36  
  * A {@link FactoryBean} to create a proxy to a service exposing a given {@link #getServiceInterface()}
 37  
  *
 38  
  * @author chirino
 39  
  */
 40  2
 public class CamelServiceExporter extends RemoteExporter implements InitializingBean, DisposableBean, ApplicationContextAware, CamelContextAware {
 41  
     private String uri;
 42  
     private CamelContext camelContext;
 43  
     private Consumer consumer;
 44  
     private String serviceRef;
 45  
     private ApplicationContext applicationContext;
 46  
 
 47  
     public String getUri() {
 48  0
         return uri;
 49  
     }
 50  
 
 51  
     public void setUri(String uri) {
 52  2
         this.uri = uri;
 53  2
     }
 54  
 
 55  
     public CamelContext getCamelContext() {
 56  0
         return camelContext;
 57  
     }
 58  
 
 59  
     public void setCamelContext(CamelContext camelContext) {
 60  2
         this.camelContext = camelContext;
 61  2
     }
 62  
 
 63  
     public String getServiceRef() {
 64  0
         return serviceRef;
 65  
     }
 66  
 
 67  
     public void setServiceRef(String serviceRef) {
 68  1
         this.serviceRef = serviceRef;
 69  1
     }
 70  
 
 71  
     public ApplicationContext getApplicationContext() {
 72  0
         return applicationContext;
 73  
     }
 74  
 
 75  
     public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
 76  2
         this.applicationContext = applicationContext;
 77  2
     }
 78  
 
 79  
     public void afterPropertiesSet() throws Exception {
 80  
         // lets bind the URI to a pojo
 81  2
         notNull(uri, "uri");
 82  2
         notNull(camelContext, "camelContext");
 83  2
         if (serviceRef != null && getService() == null && applicationContext != null) {
 84  1
             setService(applicationContext.getBean(serviceRef));
 85  
         }
 86  
 
 87  2
         Endpoint endpoint = CamelContextHelper.getMandatoryEndpoint(camelContext, uri);
 88  2
         Object proxy = getProxyForService();
 89  
 
 90  2
         consumer = endpoint.createConsumer(new BeanProcessor(proxy, camelContext));
 91  2
         consumer.start();
 92  2
     }
 93  
 
 94  
     public void destroy() throws Exception {
 95  2
         if (consumer != null) {
 96  2
             consumer.stop();
 97  
         }
 98  2
     }
 99  
 
 100  
 }