001 /** 002 * 003 * Licensed to the Apache Software Foundation (ASF) under one or more 004 * contributor license agreements. See the NOTICE file distributed with 005 * this work for additional information regarding copyright ownership. 006 * The ASF licenses this file to You under the Apache License, Version 2.0 007 * (the "License"); you may not use this file except in compliance with 008 * the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 package org.apache.camel.spring.remoting; 019 020 import org.apache.camel.CamelContext; 021 import org.apache.camel.component.pojo.PojoComponent; 022 import org.springframework.beans.factory.DisposableBean; 023 import org.springframework.beans.factory.InitializingBean; 024 import org.springframework.remoting.support.RemoteExporter; 025 026 /** 027 * Exports a Spring defined service to Camel as a Pojo endpoint. 028 * 029 * @author chirino 030 */ 031 public class CamelServiceExporter extends RemoteExporter implements InitializingBean, DisposableBean { 032 033 CamelContext camelContext; 034 PojoComponent pojoComponent; 035 String serviceName; 036 037 public void afterPropertiesSet() throws Exception { 038 if( serviceName == null ) { 039 throw new IllegalArgumentException("The serviceName must be configured."); 040 } 041 if( pojoComponent == null ) { 042 if( camelContext == null ) { 043 throw new IllegalArgumentException("A pojoComponent or camelContext must be configured."); 044 } 045 pojoComponent = (PojoComponent) camelContext.getComponent("pojo"); 046 if( pojoComponent == null ) { 047 throw new IllegalArgumentException("The pojoComponent could not be found."); 048 } 049 } 050 pojoComponent.addService(serviceName, getProxyForService()); 051 } 052 053 public void destroy() throws Exception { 054 if( serviceName!=null ) { 055 pojoComponent.removeService(serviceName); 056 } 057 } 058 059 060 public PojoComponent getPojoComponent() { 061 return pojoComponent; 062 } 063 public void setPojoComponent(PojoComponent pojoComponent) { 064 this.pojoComponent = pojoComponent; 065 } 066 067 public CamelContext getCamelContext() { 068 return camelContext; 069 } 070 public void setCamelContext(CamelContext camelContext) { 071 this.camelContext = camelContext; 072 } 073 074 public String getServiceName() { 075 return serviceName; 076 } 077 public void setServiceName(String serviceName) { 078 this.serviceName = serviceName; 079 } 080 081 }