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