public RackResponse call(final RackEnvironment env) {
final Ruby runtime = getRuntime();
try {
final RackInput io = new RackInput(runtime, env);
try {
IRubyObject servlet_env = JavaEmbedUtils.javaToRuby(runtime, env);
if (env instanceof RackEnvironment.ToIO) {
((RackEnvironment.ToIO) env).setIO(io);
}
else {
runtime.evalScriptlet("require 'jruby/rack/environment'");
adapter.setInstanceVariable(servlet_env, "@_io", io);
}
IRubyObject response = adapter.callMethod(getApplication(), "call", servlet_env);
return (RackResponse) JavaEmbedUtils.rubyToJava(runtime, response, RackResponse.class);
}
finally {
io.close();
}
}
catch (IOException e) {
throw RaiseException.createNativeRaiseException(runtime, e);
}
}