/
ConfigurationBootstrap.java
executable file
·308 lines (260 loc) · 11.2 KB
/
ConfigurationBootstrap.java
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
package org.jboss.resteasy.plugins.server.servlet;
import org.jboss.resteasy.resteasy_jaxrs.i18n.LogMessages;
import org.jboss.resteasy.resteasy_jaxrs.i18n.Messages;
import org.jboss.resteasy.spi.ResteasyConfiguration;
import org.jboss.resteasy.spi.ResteasyDeployment;
import org.jboss.resteasy.util.HttpHeaderNames;
import javax.ws.rs.core.Application;
import java.util.HashMap;
import java.util.Map;
/**
* Create a deployment from String-based configuration data
*
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $
*/
abstract public class ConfigurationBootstrap implements ResteasyConfiguration
{
private ResteasyDeployment deployment = new ResteasyDeployment();
public ResteasyDeployment createDeployment()
{
String deploymentSensitive = getParameter("resteasy.use.deployment.sensitive.factory");
if (deploymentSensitive != null)
deployment.setDeploymentSensitiveFactoryEnabled(Boolean.valueOf(deploymentSensitive.trim()));
else deployment.setDeploymentSensitiveFactoryEnabled(true);
String async = getParameter("resteasy.async.job.service.enabled");
if (async != null) deployment.setAsyncJobServiceEnabled(Boolean.valueOf(async.trim()));
if (deployment.isAsyncJobServiceEnabled())
{
String maxJobResults = getParameter("resteasy.async.job.service.max.job.results");
if (maxJobResults != null)
{
int maxJobs = Integer.valueOf(maxJobResults);
deployment.setAsyncJobServiceMaxJobResults(maxJobs);
}
String maxWaitStr = getParameter("resteasy.async.job.service.max.wait");
if (maxWaitStr != null)
{
long maxWait = Long.valueOf(maxWaitStr);
deployment.setAsyncJobServiceMaxWait(maxWait);
}
String threadPool = getParameter("resteasy.async.job.service.thread.pool.size");
if (threadPool != null)
{
int threadPoolSize = Integer.valueOf(threadPool);
deployment.setAsyncJobServiceThreadPoolSize(threadPoolSize);
}
String basePath = getParameter("resteasy.async.job.service.base.path");
if (basePath != null)
{
deployment.setAsyncJobServiceBasePath(basePath);
}
}
String applicationConfig = getParameter(Application.class.getName());
if (applicationConfig == null)
{
// stupid spec doesn't use FQN of Application class name
applicationConfig = getParameter("javax.ws.rs.Application");
}
else
{
LogMessages.LOGGER.useOfApplicationClass(Application.class.getName());
}
String providers = getParameter(ResteasyContextParameters.RESTEASY_PROVIDERS);
if (providers != null && ! "".equals(providers.trim()))
{
String[] p = providers.split(",");
for (String pr : p) deployment.getProviderClasses().add(pr.trim());
}
String resourceMethodInterceptors = getParameter(ResteasyContextParameters.RESTEASY_RESOURCE_METHOD_INTERCEPTORS);
if (resourceMethodInterceptors != null)
{
throw new RuntimeException(Messages.MESSAGES.noLongerASupportedContextParam(ResteasyContextParameters.RESTEASY_RESOURCE_METHOD_INTERCEPTORS));
}
String resteasySecurity = getParameter(ResteasyContextParameters.RESTEASY_ROLE_BASED_SECURITY);
if (resteasySecurity != null) {
boolean useResteasySecurity = parseBooleanParam(ResteasyContextParameters.RESTEASY_ROLE_BASED_SECURITY, resteasySecurity);
deployment.setSecurityEnabled(Boolean.valueOf(useResteasySecurity));
}
String builtin = getParameter(ResteasyContextParameters.RESTEASY_USE_BUILTIN_PROVIDERS);
if (builtin != null) {
boolean useBuiltin = parseBooleanParam(ResteasyContextParameters.RESTEASY_USE_BUILTIN_PROVIDERS, builtin);
deployment.setRegisterBuiltin(useBuiltin);
}
String sProviders = getParameter(ResteasyContextParameters.RESTEASY_SCAN_PROVIDERS);
if (sProviders != null)
{
LogMessages.LOGGER.noLongerSupported(ResteasyContextParameters.RESTEASY_SCAN_PROVIDERS);
}
String scanAll = getParameter(ResteasyContextParameters.RESTEASY_SCAN);
if (scanAll != null)
{
LogMessages.LOGGER.noLongerSupported(ResteasyContextParameters.RESTEASY_SCAN);
}
String sResources = getParameter(ResteasyContextParameters.RESTEASY_SCAN_RESOURCES);
if (sResources != null)
{
LogMessages.LOGGER.noLongerSupported(ResteasyContextParameters.RESTEASY_SCAN_RESOURCES);
}
// Check to see if scanning is being done by deployer (i.e. JBoss App Server)
String sScannedByDeployer = getParameter(ResteasyContextParameters.RESTEASY_SCANNED_BY_DEPLOYER);
if (sScannedByDeployer != null)
{
}
String scannedProviders = getParameter(ResteasyContextParameters.RESTEASY_SCANNED_PROVIDERS);
if (scannedProviders != null)
{
String[] p = scannedProviders.split(",");
for (String pr : p) deployment.getScannedProviderClasses().add(pr.trim());
}
String scannedResources = getParameter(ResteasyContextParameters.RESTEASY_SCANNED_RESOURCES);
if (scannedResources != null)
{
String[] p = scannedResources.split(",");
for (String pr : p) deployment.getScannedResourceClasses().add(pr.trim());
}
String scannedJndi = getParameter(ResteasyContextParameters.RESTEASY_SCANNED_JNDI_RESOURCES);
if (scannedJndi != null)
{
processScannedJndiComponentResources(scannedJndi);
}
String jndiResources = getParameter(ResteasyContextParameters.RESTEASY_JNDI_RESOURCES);
if (jndiResources != null && ! "".equals(jndiResources.trim()))
{
processJndiResources(jndiResources);
}
String jndiComponentResources = getParameter(ResteasyContextParameters.RESTEASY_JNDI_COMPONENT_RESOURCES);
if (jndiComponentResources != null)
{
processJndiComponentResources(jndiComponentResources);
}
String resources = getParameter(ResteasyContextParameters.RESTEASY_RESOURCES);
if (resources != null && ! "".equals(resources.trim()))
{
processResources(resources);
}
String unwrapped = getParameter(ResteasyContextParameters.RESTEASY_UNWRAPPED_EXCEPTIONS);
if (unwrapped != null)
{
processUnwrapped(unwrapped);
}
String paramMapping = getParameter(ResteasyContextParameters.RESTEASY_MEDIA_TYPE_PARAM_MAPPING);
if (paramMapping != null)
{
paramMapping = paramMapping.trim();
if (paramMapping.length() > 0)
{
deployment.setMediaTypeParamMapping(paramMapping);
}
else
{
deployment.setMediaTypeParamMapping(HttpHeaderNames.ACCEPT.toLowerCase());
}
}
String contextObjects = getParameter(ResteasyContextParameters.RESTEASY_CONTEXT_OBJECTS);
if (contextObjects != null)
{
Map<String, String> map = parseMap(contextObjects);
deployment.setConstructedDefaultContextObjects(map);
}
String mimeExtentions = getParameter(ResteasyContextParameters.RESTEASY_MEDIA_TYPE_MAPPINGS);
if (mimeExtentions != null)
{
Map<String, String> map = parseMap(mimeExtentions);
deployment.setMediaTypeMappings(map);
}
String languageExtensions = getParameter(ResteasyContextParameters.RESTEASY_LANGUAGE_MAPPINGS);
if (languageExtensions != null)
{
Map<String, String> map = parseMap(languageExtensions);
deployment.setLanguageExtensions(map);
}
String useContainerFormParams = getParameter(ResteasyContextParameters.RESTEASY_USE_CONTAINER_FORM_PARAMS);
if (useContainerFormParams != null)
{
boolean useContainer = parseBooleanParam(ResteasyContextParameters.RESTEASY_USE_CONTAINER_FORM_PARAMS, useContainerFormParams);
deployment.setUseContainerFormParams(useContainer);
}
String widerMatching = getParameter(ResteasyContextParameters.RESTEASY_WIDER_REQUEST_MATCHING);
if (widerMatching != null)
{
boolean wider = parseBooleanParam(ResteasyContextParameters.RESTEASY_WIDER_REQUEST_MATCHING, widerMatching);
deployment.setWiderRequestMatching(wider);
}
String addCharset = getParameter(ResteasyContextParameters.RESTEASY_ADD_CHARSET);
if (addCharset != null)
{
boolean add = parseBooleanParam(ResteasyContextParameters.RESTEASY_ADD_CHARSET, addCharset);
deployment.setAddCharset(add);
}
String injectorFactoryClass = getParameter("resteasy.injector.factory");
if (injectorFactoryClass != null)
{
deployment.setInjectorFactoryClass(injectorFactoryClass);
}
if (applicationConfig != null) deployment.setApplicationClass(applicationConfig);
deployment.getDefaultContextObjects().put(ResteasyConfiguration.class, this);
return deployment;
}
protected boolean parseBooleanParam(String key, String value) {
value = value.trim().toLowerCase();
if (value.equals("true") || value.equals("1")) {
return true;
} else if (value.equals("false") || value.equals("0")) {
return false;
} else {
throw new RuntimeException(Messages.MESSAGES.keyCouldNotBeParsed(key));
}
}
protected Map<String, String> parseMap(String map)
{
Map<String, String> parsed = new HashMap<String, String>();
String[] entries = map.trim().split(",");
for (String entry : entries)
{
String[] split = entry.trim().split(":");
parsed.put(split[0].trim(), split[1].trim());
}
return parsed;
}
protected void processJndiResources(String jndiResources)
{
String[] resources = jndiResources.trim().split(",");
for (String resource : resources)
{
deployment.getJndiResources().add(resource);
}
}
protected void processJndiComponentResources(String jndiResources)
{
String[] resources = jndiResources.trim().split(",");
for (String resource : resources)
{
deployment.getJndiComponentResources().add(resource);
}
}
protected void processScannedJndiComponentResources(String jndiResources)
{
String[] resources = jndiResources.trim().split(",");
for (String resource : resources)
{
deployment.getScannedJndiComponentResources().add(resource);
}
}
protected void processResources(String list)
{
String[] resources = list.trim().split(",");
for (String resource : resources)
{
deployment.getResourceClasses().add(resource);
}
}
protected void processUnwrapped(String list)
{
String[] resources = list.trim().split(",");
for (String resource : resources)
{
deployment.getUnwrappedExceptions().add(resource);
}
}
}