1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 package org.kuali.rice.ksb.messaging.serviceconnectors;
32
33 import org.kuali.rice.core.api.config.property.ConfigContext;
34 import org.kuali.rice.core.api.util.ClassLoaderUtils;
35
36 import java.util.HashSet;
37 import java.util.Set;
38
39
40
41
42
43
44
45
46
47
48
49
50 public enum HttpClientParams {
51
52
53
54
55
56 USE_EXPECT_CONTINUE("http.protocol.expect-continue", Boolean.class),
57 HTTP_CONTENT_CHARSET("http.protocol.content-charset"),
58 COOKIE_POLICY("http.protocol.cookie-policy"),
59
60
61
62
63
64 SO_TIMEOUT("http.socket.timeout", Integer.class),
65 TCP_NODELAY("http.tcp.nodelay", Boolean.class),
66 SO_SNDBUF("http.socket.sendbuffer", Integer.class),
67 SO_RCVBUF("http.socket.receivebuffer", Integer.class),
68 SO_LINGER("http.socket.linger", Integer.class),
69 CONNECTION_TIMEOUT("http.connection.timeout", Integer.class),
70 STALE_CONNECTION_CHECK("http.connection.stalecheck", Boolean.class),
71
72
73
74
75
76 MAX_TOTAL_CONNECTIONS("http.connection-manager.max-total", Integer.class),
77
78
79
80
81
82 CONNECTION_MANAGER_TIMEOUT("http.connection-manager.timeout", Integer.class),
83 REJECT_RELATIVE_REDIRECT("http.protocol.reject-relative-redirect", Boolean.class),
84 MAX_REDIRECTS("http.protocol.max-redirects", Integer.class),
85 ALLOW_CIRCULAR_REDIRECTS("http.protocol.allow-circular-redirects", Boolean.class);
86
87 private String paramName;
88 private Class paramValueClass;
89
90 private static final Set<String> supportedParamNames = new HashSet<String>();
91
92 private HttpClientParams(String paramName, Class paramValueClass) {
93 this.paramName = paramName;
94 this.paramValueClass = paramValueClass;
95 }
96
97 private HttpClientParams(String paramName) {
98 this(paramName, String.class);
99 }
100
101 public <T> T getValue() {
102 return getValueOrDefault(null);
103 }
104
105 public <T> T getValueOrDefault(T defaultValue) {
106 T value = null;
107 String strValue = ConfigContext.getCurrentContextConfig().getProperty(getParamName());
108
109 if (strValue == null) {
110 return defaultValue;
111 }
112
113 Class<?> paramType = getParamValueClass();
114
115 if (paramType.equals(Boolean.class)) {
116 value = (T) ConfigContext.getCurrentContextConfig().getBooleanProperty(getParamName());
117 } else if (paramType.equals(Integer.class)) {
118 value = (T) Integer.valueOf(strValue);
119 } else if (paramType.equals(Long.class)) {
120 value = (T) Long.valueOf(strValue);
121 } else if (paramType.equals(Double.class)) {
122 value = (T) Double.valueOf(strValue);
123 } else if (paramType.equals(String.class)) {
124 value = (T) strValue;
125 } else if (paramType.equals(Class.class)) {
126 try {
127 value = (T) Class.forName(ConfigContext.getCurrentContextConfig().getProperty(getParamName()),
128 true, ClassLoaderUtils.getDefaultClassLoader());
129 } catch (ClassNotFoundException e) {
130 throw new RuntimeException("Could not locate the class needed to configure the HttpClient.", e);
131 }
132 } else {
133 throw new RuntimeException("Attempted to configure an HttpClient parameter '" + getParamName() + "' " +
134 "of a type not supported through Workflow configuration: " + getParamValueClass().getName());
135 }
136
137
138 if (value == null) {
139 return defaultValue;
140 }
141
142 return value;
143 }
144
145 public String getParamName() {
146 return paramName;
147 }
148
149 public Class getParamValueClass() {
150 return paramValueClass;
151 }
152 }