Coverage Report - org.apache.camel.spring.remoting.CamelProxyFactoryBean
 
Classes in this File Line Coverage Branch Coverage Complexity
CamelProxyFactoryBean
79% 
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.Endpoint;
 22  
 import org.apache.camel.component.bean.ProxyHelper;
 23  
 
 24  
 import org.springframework.beans.factory.FactoryBean;
 25  
 import org.springframework.remoting.support.UrlBasedRemoteAccessor;
 26  
 
 27  
 /**
 28  
  * A {@link FactoryBean} to create a Proxy to a a Camel Pojo Endpoint.
 29  
  * 
 30  
  * @author chirino
 31  
  */
 32  6
 public class CamelProxyFactoryBean extends UrlBasedRemoteAccessor implements FactoryBean, CamelContextAware {
 33  
     private CamelContext camelContext;
 34  
     private Endpoint endpoint;
 35  
     private Object serviceProxy;
 36  
 
 37  
     @Override
 38  
     public void afterPropertiesSet() {
 39  6
         super.afterPropertiesSet();
 40  
         try {
 41  6
             if (endpoint == null) {
 42  6
                 if (getServiceUrl() == null || camelContext == null) {
 43  3
                     throw new IllegalArgumentException("If endpoint is not specified, the serviceUrl and camelContext must be specified.");
 44  
                 }
 45  
 
 46  3
                 endpoint = camelContext.getEndpoint(getServiceUrl());
 47  3
                 if (endpoint == null) {
 48  0
                     throw new IllegalArgumentException("Could not resolve endpoint: " + getServiceUrl());
 49  
                 }
 50  
             }
 51  
 
 52  3
             this.serviceProxy = ProxyHelper.createProxy(endpoint, getServiceInterface());
 53  3
         } catch (Exception e) {
 54  3
             throw new IllegalArgumentException(e);
 55  3
         }
 56  3
     }
 57  
 
 58  
     public Class getServiceInterface() {
 59  12
         return super.getServiceInterface();
 60  
     }
 61  
 
 62  
     public String getServiceUrl() {
 63  15
         return super.getServiceUrl();
 64  
     }
 65  
 
 66  
     public Object getObject() throws Exception {
 67  3
         return serviceProxy;
 68  
     }
 69  
 
 70  
     public Class getObjectType() {
 71  9
         return getServiceInterface();
 72  
     }
 73  
 
 74  
     public boolean isSingleton() {
 75  6
         return true;
 76  
     }
 77  
 
 78  
     public Endpoint getEndpoint() {
 79  0
         return endpoint;
 80  
     }
 81  
 
 82  
     public void setEndpoint(Endpoint endpoint) {
 83  0
         this.endpoint = endpoint;
 84  0
     }
 85  
 
 86  
     public CamelContext getCamelContext() {
 87  0
         return camelContext;
 88  
     }
 89  
 
 90  
     public void setCamelContext(CamelContext camelContext) {
 91  3
         this.camelContext = camelContext;
 92  3
     }
 93  
 }