1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.jumpmind.symmetric.transport;
22
23 import javax.net.ssl.HostnameVerifier;
24 import javax.net.ssl.HttpsURLConnection;
25 import javax.net.ssl.SSLSession;
26
27 import org.apache.commons.lang.StringUtils;
28 import org.jumpmind.symmetric.common.Constants;
29 import org.jumpmind.symmetric.common.ParameterConstants;
30 import org.jumpmind.symmetric.service.INodeService;
31 import org.jumpmind.symmetric.service.IParameterService;
32 import org.jumpmind.symmetric.transport.http.HttpTransportManager;
33 import org.jumpmind.symmetric.transport.internal.InternalTransportManager;
34 import org.springframework.beans.factory.FactoryBean;
35
36 public class TransportManagerFactoryBean implements FactoryBean {
37
38 private INodeService nodeService;
39
40 private IParameterService parameterService;
41
42 public Object getObject() throws Exception {
43 String transport = parameterService.getString(ParameterConstants.TRANSPORT_TYPE);
44 if (Constants.PROTOCOL_HTTP.equalsIgnoreCase(transport)) {
45 final String httpSslVerifiedServerNames = parameterService
46 .getString(ParameterConstants.TRANSPORT_HTTPS_VERIFIED_SERVERS);
47 HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
48 public boolean verify(String s, SSLSession sslsession) {
49 if (!StringUtils.isBlank(httpSslVerifiedServerNames)) {
50 String[] names = httpSslVerifiedServerNames.split(",");
51 for (String string : names) {
52 if (s != null && s.equals(string.trim())) {
53 return true;
54 }
55 }
56 }
57 return false;
58 }
59 });
60 return new HttpTransportManager(nodeService, parameterService);
61 } else if (Constants.PROTOCOL_INTERNAL.equalsIgnoreCase(transport)) {
62 return new InternalTransportManager(nodeService, parameterService);
63 } else {
64 throw new IllegalStateException("An invalid transport type of " + transport + " was specified.");
65 }
66 }
67
68 public Class<ITransportManager> getObjectType() {
69 return ITransportManager.class;
70 }
71
72 public boolean isSingleton() {
73 return true;
74 }
75
76 public void setNodeService(INodeService nodeService) {
77 this.nodeService = nodeService;
78 }
79
80 public void setParameterService(IParameterService parameterService) {
81 this.parameterService = parameterService;
82 }
83
84 }