| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 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 |
|
|
| 37 |
|
|
| 38 |
|
|
| 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 |
|
|
| 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 |
|
} |