1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
package org.apache.camel.component.rmi; |
19 |
|
|
20 |
|
import java.rmi.AccessException; |
21 |
|
import java.rmi.NotBoundException; |
22 |
|
import java.rmi.Remote; |
23 |
|
import java.rmi.RemoteException; |
24 |
|
import java.rmi.registry.Registry; |
25 |
|
|
26 |
|
import org.apache.camel.component.pojo.PojoEndpoint; |
27 |
|
import org.apache.camel.component.pojo.PojoExchange; |
28 |
|
import org.apache.camel.impl.DefaultProducer; |
29 |
|
import org.apache.camel.Exchange; |
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
public class RmiProducer extends DefaultProducer { |
35 |
|
|
36 |
|
private final RmiEndpoint endpoint; |
37 |
|
private Remote remote; |
38 |
|
|
39 |
|
public RmiProducer(RmiEndpoint endpoint) throws AccessException, RemoteException, NotBoundException { |
40 |
1 |
super(endpoint); |
41 |
1 |
this.endpoint = endpoint; |
42 |
1 |
} |
43 |
|
|
44 |
|
public void process(Exchange exchange) throws AccessException, RemoteException, NotBoundException { |
45 |
1 |
PojoExchange pojoExchange = endpoint.toExchangeType(exchange); |
46 |
1 |
PojoEndpoint.invoke(getRemote(), pojoExchange); |
47 |
1 |
exchange.copyFrom(pojoExchange); |
48 |
1 |
} |
49 |
|
|
50 |
|
public Remote getRemote() throws AccessException, RemoteException, NotBoundException { |
51 |
1 |
if( remote == null ) { |
52 |
1 |
Registry registry = endpoint.getRegistry(); |
53 |
1 |
remote = registry.lookup(endpoint.getName()); |
54 |
|
} |
55 |
1 |
return remote; |
56 |
|
} |
57 |
|
|
58 |
|
} |