| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
package org.apache.camel.component.rmi; |
| 18 |
|
|
| 19 |
|
import java.net.URI; |
| 20 |
|
import java.net.URISyntaxException; |
| 21 |
|
import java.rmi.RemoteException; |
| 22 |
|
import java.rmi.registry.LocateRegistry; |
| 23 |
|
import java.rmi.registry.Registry; |
| 24 |
|
import java.util.Arrays; |
| 25 |
|
import java.util.List; |
| 26 |
|
|
| 27 |
|
import org.apache.camel.Consumer; |
| 28 |
|
import org.apache.camel.Processor; |
| 29 |
|
import org.apache.camel.Producer; |
| 30 |
|
import org.apache.camel.RuntimeCamelException; |
| 31 |
|
import org.apache.camel.component.bean.BeanExchange; |
| 32 |
|
import org.apache.camel.impl.DefaultEndpoint; |
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
1 |
public class RmiEndpoint extends DefaultEndpoint<BeanExchange> { |
| 38 |
|
|
| 39 |
|
private List<Class> remoteInterfaces; |
| 40 |
|
private ClassLoader classLoader; |
| 41 |
|
private URI uri; |
| 42 |
|
private int port; |
| 43 |
|
|
| 44 |
|
protected RmiEndpoint(String endpointUri, RmiComponent component) throws URISyntaxException { |
| 45 |
2 |
super(endpointUri, component); |
| 46 |
2 |
this.uri = new URI(endpointUri); |
| 47 |
2 |
} |
| 48 |
|
|
| 49 |
|
public boolean isSingleton() { |
| 50 |
2 |
return false; |
| 51 |
|
} |
| 52 |
|
|
| 53 |
|
public BeanExchange createExchange() { |
| 54 |
1 |
return new BeanExchange(getContext()); |
| 55 |
|
} |
| 56 |
|
|
| 57 |
|
public Consumer<BeanExchange> createConsumer(Processor processor) throws Exception { |
| 58 |
1 |
if (remoteInterfaces == null || remoteInterfaces.size() == 0) { |
| 59 |
0 |
throw new RuntimeCamelException("To create an RMI consumer, the RMI endpoint's remoteInterfaces property must be be configured."); |
| 60 |
|
} |
| 61 |
1 |
return new RmiConsumer(this, processor); |
| 62 |
|
} |
| 63 |
|
|
| 64 |
|
public Producer<BeanExchange> createProducer() throws Exception { |
| 65 |
1 |
return new RmiProducer(this); |
| 66 |
|
} |
| 67 |
|
|
| 68 |
|
public String getName() { |
| 69 |
3 |
String path = uri.getPath(); |
| 70 |
3 |
if (path == null) { |
| 71 |
0 |
path = uri.getSchemeSpecificPart(); |
| 72 |
|
} |
| 73 |
3 |
return path; |
| 74 |
|
} |
| 75 |
|
|
| 76 |
|
public Registry getRegistry() throws RemoteException { |
| 77 |
3 |
if (uri.getHost() != null) { |
| 78 |
3 |
if (uri.getPort() == -1) { |
| 79 |
0 |
return LocateRegistry.getRegistry(uri.getHost()); |
| 80 |
|
} else { |
| 81 |
3 |
return LocateRegistry.getRegistry(uri.getHost(), uri.getPort()); |
| 82 |
|
} |
| 83 |
|
} else { |
| 84 |
0 |
return LocateRegistry.getRegistry(); |
| 85 |
|
} |
| 86 |
|
} |
| 87 |
|
|
| 88 |
|
public List<Class> getRemoteInterfaces() { |
| 89 |
2 |
return remoteInterfaces; |
| 90 |
|
} |
| 91 |
|
|
| 92 |
|
public void setRemoteInterfaces(List<Class> remoteInterfaces) { |
| 93 |
1 |
this.remoteInterfaces = remoteInterfaces; |
| 94 |
1 |
if (classLoader == null && !remoteInterfaces.isEmpty()) { |
| 95 |
1 |
classLoader = remoteInterfaces.get(0).getClassLoader(); |
| 96 |
|
} |
| 97 |
1 |
} |
| 98 |
|
|
| 99 |
|
public void setRemoteInterfaces(Class... remoteInterfaces) { |
| 100 |
1 |
setRemoteInterfaces(Arrays.asList(remoteInterfaces)); |
| 101 |
1 |
} |
| 102 |
|
|
| 103 |
|
public ClassLoader getClassLoader() { |
| 104 |
1 |
return classLoader; |
| 105 |
|
} |
| 106 |
|
|
| 107 |
|
public void setClassLoader(ClassLoader classLoader) { |
| 108 |
0 |
this.classLoader = classLoader; |
| 109 |
0 |
} |
| 110 |
|
|
| 111 |
|
public int getPort() { |
| 112 |
1 |
return port; |
| 113 |
|
} |
| 114 |
|
|
| 115 |
|
public void setPort(int port) { |
| 116 |
0 |
this.port = port; |
| 117 |
0 |
} |
| 118 |
|
|
| 119 |
|
} |