Class: Trinidad::Extensions::SandboxServerExtension

Inherits:
ServerExtension
  • Object
show all
Defined in:
lib/trinidad_sandbox_extension.rb

Constant Summary collapse

VERSION =
'1.0.2'

Instance Method Summary collapse

Instance Method Details

#configure(tomcat) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/trinidad_sandbox_extension.rb', line 11

def configure(tomcat)
  opts = prepare_options

  app_context = create_application_context(tomcat, opts)

  web_app = Trinidad::RackupWebApp.new({}, opts,
    'org.jruby.trinidad.SandboxRackServlet', 'SandboxServlet')

  app_context.add_lifecycle_listener(Trinidad::Lifecycle::Default.new(web_app))
  web_app
end

#create_application_context(tomcat, opts) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/trinidad_sandbox_extension.rb', line 40

def create_application_context(tomcat, opts)
  app_ctx = tomcat.addWebapp(opts[:context_path], opts[:web_app_dir])
  app_ctx.privileged = true

  if opts[:username] && opts[:password]
    app_ctx.servlet_context.set_attribute("sandbox_username", opts[:username].to_s);
    app_ctx.servlet_context.set_attribute("sandbox_password", opts[:password].to_s);
  end

  app_ctx.servlet_context.set_attribute('deploy_token', opts[:deploy_token]) if opts[:deploy_token]
  app_ctx.servlet_context.set_attribute('host_name', opts[:host_name]) if opts[:host_name]

  app_ctx.servlet_context.set_attribute('enable_default', boolean_option(opts[:enable_default]))

  app_ctx.servlet_context.set_attribute('readonly', boolean_option(opts[:readonly], false))

  app_ctx
end

#prepare_optionsObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/trinidad_sandbox_extension.rb', line 23

def prepare_options
  opts = {
    :context_path => '/sandbox',
    :jruby_min_runtimes => 1,
    :jruby_max_runtimes => 2,
    :libs_dir => 'libs',
    :classes_dir => 'classes',
    :public => 'app/public',
    :environment => 'production'
  }

  opts.deep_merge!(@options)
  opts[:rackup] = 'config.ru'
  opts[:web_app_dir] = File.expand_path('../trinidad_sandbox_extension', __FILE__)
  opts
end