Coverage Report - org.apache.camel.spring.remoting.CamelProxyFactoryBean
 
Classes in this File Line Coverage Branch Coverage Complexity
CamelProxyFactoryBean
64% 
100% 
0
 
 1  
 /**
 2  
  *
 3  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 4  
  * contributor license agreements.  See the NOTICE file distributed with
 5  
  * this work for additional information regarding copyright ownership.
 6  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 7  
  * (the "License"); you may not use this file except in compliance with
 8  
  * the License.  You may obtain a copy of the License at
 9  
  *
 10  
  * http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 package org.apache.camel.spring.remoting;
 19  
 
 20  
 import org.apache.camel.CamelContext;
 21  
 import org.apache.camel.Endpoint;
 22  
 import org.apache.camel.component.pojo.PojoComponent;
 23  
 import org.springframework.beans.factory.FactoryBean;
 24  
 import org.springframework.remoting.support.UrlBasedRemoteAccessor;
 25  
 
 26  
 /**
 27  
  * Creates a Proxy to Camel Pojo Endpoint.
 28  
  *  
 29  
  * @author chirino
 30  
  */
 31  1
 public class CamelProxyFactoryBean extends UrlBasedRemoteAccessor implements FactoryBean {
 32  
 
 33  
         private CamelContext camelContext;
 34  
         private Endpoint endpoint;
 35  
         private Object serviceProxy;
 36  
         
 37  
         @Override
 38  
         public void afterPropertiesSet() {
 39  1
                 super.afterPropertiesSet();
 40  
                 try {
 41  1
                         if( endpoint == null ) {
 42  1
                                 if( getServiceUrl() == null || camelContext==null ) {
 43  0
                                         throw new IllegalArgumentException("If endpoint is not specified, the serviceUrl and camelContext must be specified.");
 44  
                                 }
 45  
                                 
 46  1
                                 endpoint = camelContext.getEndpoint(getServiceUrl());
 47  1
                                 if( endpoint == null ) {
 48  0
                                         throw new IllegalArgumentException("Could not resolve endpoint: "+getServiceUrl());
 49  
                                 }
 50  
                         }
 51  
                         
 52  1
                         this.serviceProxy = PojoComponent.createProxy(endpoint, getServiceInterface());
 53  0
                 } catch (Exception e) {
 54  0
                         throw new IllegalArgumentException(e);
 55  1
                 }
 56  1
         }
 57  
         
 58  
         public Object getObject() throws Exception {
 59  1
                 return serviceProxy;
 60  
         }
 61  
 
 62  
         public Class getObjectType() {
 63  2
                 return getServiceInterface();
 64  
         }
 65  
 
 66  
         public boolean isSingleton() {
 67  2
                 return true;
 68  
         }
 69  
 
 70  
         public Endpoint getEndpoint() {
 71  0
                 return endpoint;
 72  
         }
 73  
 
 74  
         public void setEndpoint(Endpoint endpoint) {
 75  0
                 this.endpoint = endpoint;
 76  0
         }
 77  
 
 78  
         public CamelContext getCamelContext() {
 79  0
                 return camelContext;
 80  
         }
 81  
 
 82  
         public void setCamelContext(CamelContext camelContext) {
 83  1
                 this.camelContext = camelContext;
 84  1
         }
 85  
         
 86  
 }