11
11
import java .io .File ;
12
12
import java .io .IOException ;
13
13
import java .io .InputStream ;
14
- import java .lang .reflect .InvocationTargetException ;
15
- import java .lang .reflect .Method ;
16
14
import java .net .URISyntaxException ;
17
15
import java .net .URL ;
18
16
import java .util .Map ;
@@ -99,11 +97,7 @@ public void init(final RackContext rackContext) {
99
97
*/
100
98
@ Override
101
99
public RackApplication newApplication () {
102
- return createApplication (new ApplicationObjectFactory () {
103
- public IRubyObject create (Ruby runtime ) {
104
- return createApplicationObject (runtime );
105
- }
106
- });
100
+ return createApplication (this ::createApplicationObject );
107
101
}
108
102
109
103
/**
@@ -209,13 +203,7 @@ public RackApplication newErrorApplication() {
209
203
return new DefaultErrorApplication (rackContext );
210
204
}
211
205
try {
212
- RackApplication app = createErrorApplication (
213
- new ApplicationObjectFactory () {
214
- public IRubyObject create (Ruby runtime ) {
215
- return createErrorApplicationObject (runtime );
216
- }
217
- }
218
- );
206
+ RackApplication app = createErrorApplication (this ::createErrorApplicationObject );
219
207
app .init ();
220
208
return app ;
221
209
}
@@ -250,7 +238,7 @@ protected IRubyObject createRackServletWrapper(Ruby runtime, String rackup, Stri
250
238
);
251
239
}
252
240
253
- static interface ApplicationObjectFactory {
241
+ interface ApplicationObjectFactory {
254
242
IRubyObject create (Ruby runtime ) ;
255
243
}
256
244
@@ -267,21 +255,7 @@ protected RubyInstanceConfig initRuntimeConfig(final RubyInstanceConfig config)
267
255
// Don't affect the container and sibling web apps when ENV changes are
268
256
// made inside the Ruby app ...
269
257
// There are quite a such things made in a typical Bundler based app.
270
- try { // config.setUpdateNativeENVEnabled(false) using reflection :
271
- final Method setUpdateNativeENVEnabled =
272
- config .getClass ().getMethod ("setUpdateNativeENVEnabled" , Boolean .TYPE );
273
- setUpdateNativeENVEnabled .invoke (config , false );
274
- }
275
- catch (NoSuchMethodException e ) { // ignore method has been added in JRuby 1.6.7
276
- rackContext .log (DEBUG , "envronment changes made inside one app " +
277
- "might affect another, consider updating JRuby if this is an issue" );
278
- }
279
- catch (IllegalAccessException e ) {
280
- rackContext .log (WARN , "failed to disable updating native environment" , e );
281
- }
282
- catch (InvocationTargetException e ) {
283
- throw new RackException (e .getTargetException ());
284
- }
258
+ config .setUpdateNativeENVEnabled (false );
285
259
286
260
final Map <String , String > newEnv = rackConfig .getRuntimeEnvironment ();
287
261
if ( newEnv != null ) {
@@ -297,7 +271,6 @@ protected RubyInstanceConfig initRuntimeConfig(final RubyInstanceConfig config)
297
271
else {
298
272
// allow to work (backwards) "compatibly" with previous `ENV.clear`
299
273
// RUBYOPT was processed since it happens on config.processArguments
300
- @ SuppressWarnings ("unchecked" )
301
274
final Map <String , String > env = config .getEnvironment ();
302
275
if ( env != null && env .containsKey ("RUBYOPT" ) ) {
303
276
newEnv .put ( "RUBYOPT" , env .get ("RUBYOPT" ) );
@@ -355,9 +328,7 @@ protected void loadJRubyRack(final Ruby runtime) {
355
328
public void initRuntime (final Ruby runtime ) {
356
329
loadJRubyRack (runtime );
357
330
// set $servlet_context :
358
- runtime .getGlobalVariables ().set (
359
- "$servlet_context" , JavaUtil .convertJavaToRuby (runtime , rackContext )
360
- );
331
+ runtime .getGlobalVariables ().set ("$servlet_context" , JavaUtil .convertJavaToRuby (runtime , rackContext ));
361
332
// load our (servlet) Rack handler :
362
333
runtime .evalScriptlet ("require 'rack/handler/servlet'" );
363
334
@@ -411,9 +382,6 @@ public String checkAndSetRackVersion(final Ruby runtime) {
411
382
rackContext .log (DEBUG , "could not read 'rack.version' magic comment from rackup" , e );
412
383
}
413
384
414
- if ( rackVersion == null ) {
415
- // NOTE: try matching a `require 'bundler/setup'` line ... maybe not ?!
416
- }
417
385
if ( rackVersion != null ) {
418
386
runtime .evalScriptlet ("require 'rubygems'" );
419
387
@@ -462,10 +430,22 @@ public void destroy() {
462
430
runtime .tearDown (false );
463
431
}
464
432
433
+ private void captureMessage (final RaiseException re ) {
434
+ try {
435
+ IRubyObject rubyException = re .getException ();
436
+ ThreadContext context = rubyException .getRuntime ().getCurrentContext ();
437
+ // JRuby-Rack internals (@see jruby/rack/capture.rb) :
438
+ rubyException .callMethod (context , "capture" );
439
+ rubyException .callMethod (context , "store" );
440
+ }
441
+ catch (Exception e ) {
442
+ rackContext .log (INFO , "failed to capture exception message" , e );
443
+ // won't be able to capture anything
444
+ }
445
+ }
465
446
}
466
447
467
448
private RackApplication createErrorApplication (final ApplicationObjectFactory appFactory ) {
468
- // final Ruby runtime = newRuntime();
469
449
return new ErrorApplicationImpl (appFactory );
470
450
}
471
451
@@ -482,29 +462,13 @@ public void init() {
482
462
483
463
}
484
464
485
- private void captureMessage (final RaiseException re ) {
486
- try {
487
- IRubyObject rubyException = re .getException ();
488
- ThreadContext context = rubyException .getRuntime ().getCurrentContext ();
489
- // JRuby-Rack internals (@see jruby/rack/capture.rb) :
490
- rubyException .callMethod (context , "capture" );
491
- rubyException .callMethod (context , "store" );
492
- }
493
- catch (Exception e ) {
494
- rackContext .log (INFO , "failed to capture exception message" , e );
495
- // won't be able to capture anything
496
- }
497
- }
498
-
499
465
private String findConfigRuPathInSubDirectories (final String path , int level ) {
500
- @ SuppressWarnings ("unchecked" )
501
466
final Set <String > entries = rackContext .getResourcePaths (path );
502
467
if (entries != null ) {
503
468
String config_ru = path + "config.ru" ;
504
469
if ( entries .contains (config_ru ) ) {
505
470
return config_ru ;
506
471
}
507
-
508
472
if (level > 0 ) {
509
473
level --;
510
474
for ( String subpath : entries ) {
@@ -526,11 +490,9 @@ private static String getContextLoaderScript(final String name, final boolean si
526
490
InputStream is = contextLoader .getResourceAsStream (name );
527
491
return IOHelpers .inputStreamToString (is );
528
492
}
529
- catch (IOException e ) {
530
- if ( silent ) return null ; throw e ;
531
- }
532
- catch (RuntimeException e ) {
533
- if ( silent ) return null ; throw e ;
493
+ catch (IOException |RuntimeException e ) {
494
+ if ( silent ) return null ;
495
+ throw e ;
534
496
}
535
497
}
536
498
@@ -565,7 +527,7 @@ private String resolveRackupScript() throws RackInitializationException {
565
527
}
566
528
catch (IOException ex ) { /* won't happen */ }
567
529
568
- rackContext .log (RackLogger . ERROR , "failed to read rackup from '" + rackup + "' (" + e + ")" );
530
+ rackContext .log (ERROR , "failed to read rackup from '" + rackup + "' (" + e + ")" );
569
531
throw new RackInitializationException ("failed to read rackup input" , e );
570
532
}
571
533
}
0 commit comments