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.aopalliance.intercept.MethodInterceptor; |
20 |
|
import org.aopalliance.intercept.MethodInvocation; |
21 |
|
|
22 |
|
import org.apache.camel.CamelContext; |
23 |
|
import org.apache.camel.CamelContextAware; |
24 |
|
import org.apache.camel.Endpoint; |
25 |
|
import org.apache.camel.Producer; |
26 |
|
import org.apache.camel.component.bean.CamelInvocationHandler; |
27 |
|
import org.apache.camel.util.CamelContextHelper; |
28 |
|
|
29 |
|
import org.springframework.beans.factory.DisposableBean; |
30 |
|
import org.springframework.beans.factory.InitializingBean; |
31 |
|
|
32 |
|
import static org.apache.camel.util.ObjectHelper.notNull; |
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
0 |
public class SendBeforeInterceptor implements MethodInterceptor, CamelContextAware, InitializingBean, DisposableBean { |
40 |
|
private String uri; |
41 |
|
private CamelContext camelContext; |
42 |
|
private CamelInvocationHandler invocationHandler; |
43 |
|
private Producer producer; |
44 |
|
|
45 |
|
public Object invoke(MethodInvocation invocation) throws Throwable { |
46 |
0 |
invocationHandler.invoke(invocation.getThis(), invocation.getMethod(), invocation.getArguments()); |
47 |
0 |
return invocation.proceed(); |
48 |
|
} |
49 |
|
|
50 |
|
public void afterPropertiesSet() throws Exception { |
51 |
0 |
notNull(uri, "uri"); |
52 |
0 |
notNull(camelContext, "camelContext"); |
53 |
|
|
54 |
0 |
Endpoint endpoint = CamelContextHelper.getMandatoryEndpoint(camelContext, uri); |
55 |
0 |
producer = endpoint.createProducer(); |
56 |
0 |
producer.start(); |
57 |
0 |
invocationHandler = new CamelInvocationHandler(endpoint, producer); |
58 |
0 |
} |
59 |
|
|
60 |
|
public void destroy() throws Exception { |
61 |
0 |
if (producer != null) { |
62 |
0 |
producer.stop(); |
63 |
|
} |
64 |
0 |
} |
65 |
|
|
66 |
|
public void setCamelContext(CamelContext camelContext) { |
67 |
0 |
this.camelContext = camelContext; |
68 |
0 |
} |
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
public String getUri() { |
73 |
0 |
return uri; |
74 |
|
} |
75 |
|
|
76 |
|
public void setUri(String uri) { |
77 |
0 |
this.uri = uri; |
78 |
0 |
} |
79 |
|
} |