forked from jruby/jruby-rack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig.java
More file actions
239 lines (193 loc) · 6.42 KB
/
Config.java
File metadata and controls
239 lines (193 loc) · 6.42 KB
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
/*
* The MIT License
*
* Copyright (c) 2013-2014 Karol Bucek LTD.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.jruby.rack.embed;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.Map;
import org.jruby.CompatVersion;
import org.jruby.Ruby;
import org.jruby.rack.DefaultRackConfig;
import org.jruby.rack.RackConfig;
import org.jruby.rack.RackLogger;
/**
* A rack config for an embedded environment.
*
* @author kares
*/
public class Config implements RackConfig {
private final DefaultRackConfig delegate;
private RackLogger logger;
private Map<String, String> rubyENV;
public Config() {
delegate = new DefaultRackConfig() {
@Override
public String getProperty(String key, String defaultValue) {
String value = Config.this.resolveProperty(key);
return value != null ? value : super.getProperty(key, defaultValue);
}
@Override
public RackLogger defaultLogger() { return null; }
};
}
@SuppressWarnings("unchecked")
public void doInitialize(final Ruby runtime) {
setOut( runtime.getOut() );
setErr( runtime.getErr() );
rubyENV = runtime.getENV();
}
protected String resolveProperty(String key) {
String value = null;
if ( rubyENV != null ) value = rubyENV.get(key);
return value;
}
@Override
public final String getProperty(String key) {
return delegate.getProperty(key);
}
@Override
public final String getProperty(String key, String defaultValue) {
return delegate.getProperty(key, defaultValue);
}
@Override
public final Boolean getBooleanProperty(String key) {
return delegate.getBooleanProperty(key);
}
@Override
public final Boolean getBooleanProperty(String key, Boolean defaultValue) {
return delegate.getBooleanProperty(key, defaultValue);
}
@Override
public final Number getNumberProperty(String key) {
return delegate.getNumberProperty(key);
}
@Override
public final Number getNumberProperty(String key, Number defaultValue) {
return delegate.getNumberProperty(key, defaultValue);
}
/**
* @return Always CompatVersion.RUBY2_1, consistent with JRuby 9.3+
*
* @deprecated Since jruby-rack 1.2 (and JRuby 9.2), for removal in 1.3.0
*/
@Deprecated
@Override
public CompatVersion getCompatVersion() {
return CompatVersion.RUBY2_1;
}
@Override
public RackLogger getLogger() {
if (logger == null) {
logger = delegate.getLogger();
}
return logger;
}
public void setLogger(RackLogger logger) {
this.logger = logger;
}
@Override
public PrintStream getOut() {
return delegate.getOut();
}
public void setOut(OutputStream out) {
delegate.setOut(out);
}
@Override
public PrintStream getErr() {
return delegate.getErr();
}
public void setErr(OutputStream err) {
delegate.setErr(err);
}
@Override
public boolean isRewindable() {
return delegate.isRewindable();
}
@Override
public Integer getInitialMemoryBufferSize() {
return delegate.getInitialMemoryBufferSize();
}
@Override
public Integer getMaximumMemoryBufferSize() {
return delegate.getMaximumMemoryBufferSize();
}
@Override
public String getRackup() {
return delegate.getRackup();
}
@Override
public String getRackupPath() {
return delegate.getRackupPath();
}
// runtime pooling in embedded ENVs not implemented :
@Override
public Integer getRuntimeTimeoutSeconds() {
throw new UnsupportedOperationException("getRuntimeTimeoutSeconds()");
}
@Override
public Integer getInitialRuntimes() {
throw new UnsupportedOperationException("getInitialRuntimes()");
}
@Override
public Integer getMaximumRuntimes() {
throw new UnsupportedOperationException("getMaximumRuntimes()");
}
@Override
public String[] getRuntimeArguments() {
throw new UnsupportedOperationException("getRuntimeArguments()");
}
@Override
public Integer getNumInitializerThreads() {
throw new UnsupportedOperationException("getNumInitializerThreads()");
}
@Override
public boolean isSerialInitialization() {
throw new UnsupportedOperationException("isSerialInitialization()");
}
@Override
public boolean isIgnoreEnvironment() {
throw new UnsupportedOperationException("isIgnoreEnvironment()");
}
@Override
public Map<String, String> getRuntimeEnvironment() {
throw new UnsupportedOperationException("getRuntimeEnvironment()");
}
// RackFilter aint's used with embed :
@Override
public boolean isFilterAddsHtml() {
throw new UnsupportedOperationException("isFilterAddsHtml()");
}
@Override
public boolean isFilterVerifiesResource() {
throw new UnsupportedOperationException("isFilterVerifiesResource()");
}
// JMS configuration not used with embed :
@Override
public String getJmsConnectionFactory() {
throw new UnsupportedOperationException("getJmsConnectionFactory()");
}
@Override
public String getJmsJndiProperties() {
throw new UnsupportedOperationException("getJmsJndiProperties()");
}
}