1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.camel.spring; |
18 |
|
|
19 |
|
import javax.xml.bind.annotation.XmlAccessType; |
20 |
|
import javax.xml.bind.annotation.XmlAccessorType; |
21 |
|
import javax.xml.bind.annotation.XmlAttribute; |
22 |
|
import javax.xml.bind.annotation.XmlRootElement; |
23 |
|
import javax.xml.bind.annotation.XmlTransient; |
24 |
|
|
25 |
|
import org.apache.camel.CamelContext; |
26 |
|
import org.apache.camel.CamelContextAware; |
27 |
|
import org.apache.camel.CamelTemplate; |
28 |
|
import org.apache.camel.Endpoint; |
29 |
|
|
30 |
|
import org.springframework.beans.factory.FactoryBean; |
31 |
|
import org.springframework.beans.factory.InitializingBean; |
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
@XmlRootElement(name = "camelTemplate") |
40 |
|
@XmlAccessorType(XmlAccessType.FIELD) |
41 |
0 |
public class CamelTemplateFactoryBean implements FactoryBean, InitializingBean, CamelContextAware { |
42 |
|
@XmlAttribute(required = false) |
43 |
|
private String defaultEndpoint; |
44 |
|
@XmlTransient |
45 |
|
private CamelContext camelContext; |
46 |
|
|
47 |
|
public void afterPropertiesSet() throws Exception { |
48 |
0 |
if (camelContext == null) { |
49 |
0 |
throw new IllegalArgumentException("A CamelContext must be injected!"); |
50 |
|
} |
51 |
0 |
} |
52 |
|
|
53 |
|
public Object getObject() throws Exception { |
54 |
0 |
CamelContext context = getCamelContext(); |
55 |
0 |
if (defaultEndpoint != null) { |
56 |
0 |
Endpoint endpoint = context.getEndpoint(defaultEndpoint); |
57 |
0 |
if (endpoint == null) { |
58 |
0 |
throw new IllegalArgumentException("No endpoint found for URI: " + defaultEndpoint); |
59 |
|
} else { |
60 |
0 |
return new CamelTemplate(context, endpoint); |
61 |
|
} |
62 |
|
} |
63 |
0 |
return new CamelTemplate(context); |
64 |
|
} |
65 |
|
|
66 |
|
public Class getObjectType() { |
67 |
0 |
return CamelTemplate.class; |
68 |
|
} |
69 |
|
|
70 |
|
public boolean isSingleton() { |
71 |
0 |
return true; |
72 |
|
} |
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
public CamelContext getCamelContext() { |
77 |
0 |
return camelContext; |
78 |
|
} |
79 |
|
|
80 |
|
public void setCamelContext(CamelContext camelContext) { |
81 |
0 |
this.camelContext = camelContext; |
82 |
0 |
} |
83 |
|
|
84 |
|
public String getDefaultEndpoint() { |
85 |
0 |
return defaultEndpoint; |
86 |
|
} |
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
public void setDefaultEndpoint(String defaultEndpoint) { |
93 |
0 |
this.defaultEndpoint = defaultEndpoint; |
94 |
0 |
} |
95 |
|
} |