1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
package org.apache.camel.component.file.remote; |
19 |
|
|
20 |
|
import org.apache.camel.CamelContext; |
21 |
|
import org.apache.camel.RuntimeCamelException; |
22 |
|
import org.apache.camel.impl.DefaultComponent; |
23 |
|
import org.apache.camel.util.IntrospectionSupport; |
24 |
|
|
25 |
|
import java.net.URI; |
26 |
|
import java.util.Map; |
27 |
|
|
28 |
7 |
public class RemoteFileComponent extends DefaultComponent<RemoteFileExchange> { |
29 |
|
private RemoteFileConfiguration configuration; |
30 |
|
|
31 |
7 |
public RemoteFileComponent() { |
32 |
7 |
this.configuration = new RemoteFileConfiguration(); |
33 |
7 |
} |
34 |
|
|
35 |
0 |
public RemoteFileComponent(RemoteFileConfiguration configuration) { |
36 |
0 |
this.configuration = configuration; |
37 |
0 |
} |
38 |
|
|
39 |
|
public RemoteFileComponent(CamelContext context) { |
40 |
0 |
super(context); |
41 |
0 |
this.configuration = new RemoteFileConfiguration(); |
42 |
0 |
} |
43 |
|
|
44 |
|
public static RemoteFileComponent remoteFileComponent() { |
45 |
0 |
return new RemoteFileComponent(); |
46 |
|
} |
47 |
|
|
48 |
|
protected RemoteFileEndpoint createEndpoint(String uri, String remaining, Map parameters) throws Exception { |
49 |
7 |
RemoteFileConfiguration config = getConfiguration().copy(); |
50 |
7 |
config.configure(new URI(uri)); |
51 |
|
|
52 |
|
|
53 |
|
final RemoteFileEndpoint endpoint; |
54 |
7 |
if ("ftp".equals(config.getProtocol())) { |
55 |
4 |
endpoint = new FtpEndpoint(uri, this, config); |
56 |
4 |
} |
57 |
3 |
else if ("sftp".equals(config.getProtocol())) { |
58 |
3 |
endpoint = new SftpEndpoint(uri, this, config); |
59 |
3 |
} |
60 |
|
else { |
61 |
0 |
throw new RuntimeCamelException("Unsupported protocol: " + config.getProtocol()); |
62 |
|
} |
63 |
|
|
64 |
7 |
IntrospectionSupport.setProperties(endpoint.getConfiguration(), parameters); |
65 |
7 |
return endpoint; |
66 |
|
} |
67 |
|
|
68 |
|
public RemoteFileConfiguration getConfiguration() { |
69 |
7 |
return configuration; |
70 |
|
} |
71 |
|
|
72 |
|
public void setConfiguration(RemoteFileConfiguration configuration) { |
73 |
0 |
this.configuration = configuration; |
74 |
0 |
} |
75 |
|
} |