1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.ksb.messaging;
17
18 import static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.assertFalse;
20 import static org.junit.Assert.assertTrue;
21 import static org.junit.Assert.fail;
22
23 import javax.xml.namespace.QName;
24
25 import org.apache.commons.httpclient.HttpClient;
26 import org.apache.commons.httpclient.HttpConnectionManager;
27 import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
28 import org.apache.commons.httpclient.SimpleHttpConnectionManager;
29 import org.apache.commons.httpclient.cookie.CookiePolicy;
30 import org.junit.Test;
31 import org.kuali.rice.core.api.config.property.Config;
32 import org.kuali.rice.core.api.config.property.ConfigContext;
33 import org.kuali.rice.core.impl.config.property.JAXBConfigImpl;
34 import org.kuali.rice.core.framework.config.property.SimpleConfig;
35 import org.kuali.rice.ksb.api.bus.support.JavaServiceConfiguration;
36 import org.kuali.rice.ksb.api.bus.support.JavaServiceDefinition;
37 import org.kuali.rice.ksb.messaging.serviceconnectors.HttpInvokerConnector;
38
39
40
41
42
43
44 public class HttpInvokerConnectorConfigurationTest {
45
46 private static String simpleConfig = "SIMPLE_CONFIG";
47 private static String jaxbConfig = "JAXB_CONFIG";
48
49
50 protected Config getConfigObject(String configType){
51 Config cRet = null;
52 if(simpleConfig.equals(configType)){
53 cRet = new SimpleConfig();
54 }else if(jaxbConfig.equals(configType)){
55 cRet = new JAXBConfigImpl();
56 }
57 return cRet;
58 }
59
60
61
62
63
64 @Test public void testHttpClientConfiguration() throws Exception {
65 testHttpClientConfigurationImpl(simpleConfig);
66 testHttpClientConfigurationImpl(jaxbConfig);
67 }
68 protected void testHttpClientConfigurationImpl(String configType) throws Exception {
69
70 JavaServiceDefinition javaServiceDefinition = new JavaServiceDefinition();
71 javaServiceDefinition.setServiceName(new QName("test", "test"));
72 JavaServiceConfiguration configuration = JavaServiceConfiguration.fromServiceDefinition(javaServiceDefinition);
73
74
75 ConfigContext.init(getConfigObject(configType));
76 HttpInvokerConnector httpConnector = new HttpInvokerConnector(configuration, null);
77 HttpClient httpClient = httpConnector.getHttpClient();
78
79 HttpConnectionManager connectionManager = httpClient.getHttpConnectionManager();
80 assertTrue("Should be a multi-threaded connection manager.", connectionManager instanceof MultiThreadedHttpConnectionManager);
81 int defaultMaxConnectionsPerHost = connectionManager.getParams().getDefaultMaxConnectionsPerHost();
82 assertEquals(20, defaultMaxConnectionsPerHost);
83 assertEquals(20, connectionManager.getParams().getMaxTotalConnections());
84 assertEquals(10000, connectionManager.getParams().getConnectionTimeout());
85 assertEquals(10000, httpClient.getParams().getConnectionManagerTimeout());
86 assertEquals(CookiePolicy.RFC_2109, httpClient.getParams().getCookiePolicy());
87
88
89 Config config = getConfigObject(configType);
90 config.putProperty("http.connection-manager.max-total", "500");
91 config.putProperty("http.connection-manager.timeout", "5000");
92 config.putProperty("http.connection.timeout", "15000");
93 config.putProperty("http.somerandomproperty", "thisismyproperty");
94 config.putProperty("http.authentication.preemptive", "false");
95 ConfigContext.init(config);
96
97 httpConnector = new HttpInvokerConnector(configuration, null);
98 httpClient = httpConnector.getHttpClient();
99
100 connectionManager = httpClient.getHttpConnectionManager();
101 assertTrue("Should be a multi-threaded connection manager.", connectionManager instanceof MultiThreadedHttpConnectionManager);
102 defaultMaxConnectionsPerHost = connectionManager.getParams().getDefaultMaxConnectionsPerHost();
103 assertEquals(20, defaultMaxConnectionsPerHost);
104 assertEquals(500, connectionManager.getParams().getMaxTotalConnections());
105 assertEquals(15000, connectionManager.getParams().getConnectionTimeout());
106 assertEquals(5000, httpClient.getParams().getConnectionManagerTimeout());
107 assertEquals(CookiePolicy.RFC_2109, httpClient.getParams().getCookiePolicy());
108 assertFalse(httpClient.getParams().isAuthenticationPreemptive());
109
110
111 config = getConfigObject(configType);
112 config.putProperty("http.authentication.preemptive", "true");
113 ConfigContext.init(config);
114
115 httpConnector = new HttpInvokerConnector(configuration, null);
116 httpClient = httpConnector.getHttpClient();
117
118 assertTrue(httpClient.getParams().isAuthenticationPreemptive());
119
120
121 config = getConfigObject(configType);
122 config.putProperty("http.connection-manager.class", MyHttpConnectionManager.class.getName());
123 ConfigContext.init(config);
124
125 httpConnector = new HttpInvokerConnector(configuration, null);
126 httpClient = httpConnector.getHttpClient();
127
128 connectionManager = httpClient.getHttpConnectionManager();
129 assertTrue("Should be a MyHttpConnectionManager.", connectionManager instanceof MyHttpConnectionManager);
130
131
132
133
134 config = getConfigObject(configType);
135 config.putProperty("http.method.retry-handler", "badparm");
136 ConfigContext.init(config);
137
138 try {
139 httpConnector = new HttpInvokerConnector(configuration, null);
140 fail("An exception should have been thrown because the retry handler is an illegal parameter.");
141 } catch (Exception e) {
142
143 }
144
145 }
146
147 public static class MyHttpConnectionManager extends SimpleHttpConnectionManager {
148
149 }
150
151 }