1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
package org.kuali.rice.ksb.messaging.serviceconnectors; |
15 | |
|
16 | |
import org.kuali.rice.core.config.Config; |
17 | |
import org.kuali.rice.core.config.ConfigContext; |
18 | |
import org.kuali.rice.core.exception.RiceRuntimeException; |
19 | |
import org.kuali.rice.core.security.credentials.CredentialsSource; |
20 | |
import org.kuali.rice.core.security.credentials.CredentialsSourceFactory; |
21 | |
import org.kuali.rice.ksb.messaging.JavaServiceDefinition; |
22 | |
import org.kuali.rice.ksb.messaging.RESTServiceDefinition; |
23 | |
import org.kuali.rice.ksb.messaging.SOAPServiceDefinition; |
24 | |
import org.kuali.rice.ksb.messaging.ServiceDefinition; |
25 | |
import org.kuali.rice.ksb.messaging.ServiceInfo; |
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | 0 | public class ServiceConnectorFactory { |
43 | |
|
44 | |
public static ServiceConnector getServiceConnector(final ServiceInfo serviceInfo) { |
45 | 0 | final ServiceDefinition serviceDefinition = serviceInfo.getServiceDefinition(); |
46 | 0 | final CredentialsSourceFactory credentialsSourceFactory = (CredentialsSourceFactory) ConfigContext.getCurrentContextConfig() |
47 | |
.getObjects().get(Config.CREDENTIALS_SOURCE_FACTORY); |
48 | 0 | final CredentialsSource credentialsSource = credentialsSourceFactory != null ? credentialsSourceFactory |
49 | |
.getCredentialsForType(serviceDefinition.getCredentialsType()) : null; |
50 | 0 | ServiceConnector serviceConnector = null; |
51 | |
|
52 | 0 | if (serviceDefinition.getCredentialsType() != null && credentialsSource == null) { |
53 | 0 | throw new RiceRuntimeException( |
54 | |
"Service requires credentials but no factory or CredentialsSource could be located."); |
55 | |
} |
56 | |
|
57 | |
|
58 | 0 | if (ConfigContext.getCurrentContextConfig().getDevMode()) { |
59 | 0 | serviceConnector = new BusLocalConnector(serviceInfo); |
60 | 0 | } else if (serviceDefinition instanceof JavaServiceDefinition) { |
61 | 0 | serviceConnector = new HttpInvokerConnector(serviceInfo); |
62 | 0 | } else if (serviceDefinition instanceof SOAPServiceDefinition) { |
63 | 0 | serviceConnector = new SOAPConnector(serviceInfo); |
64 | 0 | } else if (serviceDefinition instanceof RESTServiceDefinition) { |
65 | 0 | serviceConnector = new RESTConnector(serviceInfo); |
66 | |
} |
67 | |
|
68 | 0 | if (serviceConnector == null) { |
69 | 0 | throw new RiceRuntimeException("Don't support service type of " + serviceInfo.getServiceDefinition()); |
70 | |
} |
71 | |
|
72 | 0 | serviceConnector.setCredentialsSource(credentialsSource); |
73 | |
|
74 | 0 | return serviceConnector; |
75 | |
} |
76 | |
|
77 | |
|
78 | |
} |