1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.ksb.messaging.serviceconnectors; |
17 | |
|
18 | |
import org.apache.cxf.endpoint.Client; |
19 | |
import org.apache.cxf.frontend.ClientProxy; |
20 | |
import org.apache.cxf.transport.http.HTTPConduit; |
21 | |
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy; |
22 | |
import org.kuali.rice.core.security.credentials.CredentialsSource; |
23 | |
import org.kuali.rice.ksb.messaging.BusClientFailureProxy; |
24 | |
import org.kuali.rice.ksb.messaging.ServiceInfo; |
25 | |
import org.kuali.rice.ksb.messaging.bam.BAMClientProxy; |
26 | |
import org.kuali.rice.ksb.service.KSBServiceLocator; |
27 | |
import org.springframework.util.Assert; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
public abstract class AbstractServiceConnector implements ServiceConnector { |
39 | |
|
40 | |
private static final String HTTP_CLIENT_POLICY_BEAN = "httpClientPolicy"; |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
private ServiceInfo serviceInfo; |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
private CredentialsSource credentialsSource; |
51 | |
|
52 | 0 | public AbstractServiceConnector(final ServiceInfo serviceInfo) { |
53 | 0 | Assert.notNull(serviceInfo, "serviceInfo cannot be null"); |
54 | 0 | this.serviceInfo = serviceInfo; |
55 | 0 | } |
56 | |
|
57 | |
public ServiceInfo getServiceInfo() { |
58 | 0 | return this.serviceInfo; |
59 | |
} |
60 | |
|
61 | |
public void setServiceInfo(final ServiceInfo serviceInfo) { |
62 | 0 | this.serviceInfo = serviceInfo; |
63 | 0 | } |
64 | |
|
65 | |
public void setCredentialsSource(final CredentialsSource credentialsSource) { |
66 | 0 | this.credentialsSource = credentialsSource; |
67 | 0 | } |
68 | |
|
69 | |
protected CredentialsSource getCredentialsSource() { |
70 | 0 | return this.credentialsSource; |
71 | |
} |
72 | |
|
73 | |
protected Object getServiceProxyWithFailureMode(final Object service, |
74 | |
final ServiceInfo serviceInfo) { |
75 | |
|
76 | |
|
77 | 0 | HTTPClientPolicy policy = |
78 | |
(HTTPClientPolicy)KSBServiceLocator.getService(HTTP_CLIENT_POLICY_BEAN); |
79 | 0 | if (policy != null) { |
80 | |
try { |
81 | 0 | Client cl = ClientProxy.getClient(service); |
82 | 0 | ((HTTPConduit)cl.getConduit()).setClient(policy); |
83 | 0 | } catch (ClassCastException e) { |
84 | |
|
85 | 0 | } |
86 | |
} |
87 | |
|
88 | 0 | Object bamWrappedClientProxy = BAMClientProxy |
89 | |
.wrap(service, serviceInfo); |
90 | 0 | return BusClientFailureProxy.wrap(bamWrappedClientProxy, serviceInfo); |
91 | |
} |
92 | |
} |