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.http.client.HttpClient;
19 import org.apache.http.impl.client.HttpClientBuilder;
20 import org.apache.log4j.Logger;
21 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
22 import org.kuali.rice.ksb.api.bus.support.JavaServiceConfiguration;
23 import org.kuali.rice.ksb.messaging.KSBHttpInvokerProxyFactoryBean;
24 import org.kuali.rice.ksb.messaging.KSBHttpInvokerRequestExecutor;
25 import org.kuali.rice.ksb.security.httpinvoker.AuthenticationCommonsHttpInvokerRequestExecutor;
26
27 import java.net.URL;
28
29
30
31
32
33 public class HttpInvokerConnector extends AbstractServiceConnector {
34
35 private static final Logger LOG = Logger.getLogger(HttpInvokerConnector.class);
36
37 private static final String HTTP_CLIENT_CONFIG_BEAN = "rice.ksb.httpClientConfigurer";
38
39
40
41
42
43
44
45 public HttpInvokerConnector(final JavaServiceConfiguration serviceConfiguration, final URL alternateEndpointUrl) {
46 super(serviceConfiguration, alternateEndpointUrl);
47 }
48
49 @Override
50 public JavaServiceConfiguration getServiceConfiguration() {
51 return (JavaServiceConfiguration) super.getServiceConfiguration();
52 }
53
54 public Object getService() {
55 LOG.debug("Getting connector for endpoint " + getActualEndpointUrl());
56 KSBHttpInvokerProxyFactoryBean client = new KSBHttpInvokerProxyFactoryBean();
57 client.setServiceUrl(getActualEndpointUrl().toExternalForm());
58 client.setServiceConfiguration(getServiceConfiguration());
59
60 KSBHttpInvokerRequestExecutor executor;
61
62 if (getCredentialsSource() != null) {
63 executor = new AuthenticationCommonsHttpInvokerRequestExecutor(getHttpClient(), getCredentialsSource(), getServiceConfiguration());
64 } else {
65 executor = new KSBHttpInvokerRequestExecutor(getHttpClient());
66 }
67 executor.setSecure(getServiceConfiguration().getBusSecurity());
68 client.setHttpInvokerRequestExecutor(executor);
69 client.afterPropertiesSet();
70 return getServiceProxyWithFailureMode(client.getObject(), getServiceConfiguration());
71 }
72
73
74
75
76
77
78 public HttpClient getHttpClient() {
79 HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
80
81 getHttpClientConfigurer().customizeHttpClient(httpClientBuilder);
82
83 return httpClientBuilder.build();
84 }
85
86
87
88
89 private static class HttpClientConfigurerHolder {
90 static final HttpClientConfigurer httpClientConfigurer =
91 GlobalResourceLoader.getService(HTTP_CLIENT_CONFIG_BEAN);
92 }
93
94
95
96
97
98
99
100
101 private static HttpClientConfigurer getHttpClientConfigurer() {
102 return HttpClientConfigurerHolder.httpClientConfigurer;
103 }
104 }