Module: Buildr::Jetty

Defined in:
lib/java/jetty.rb

Defined Under Namespace

Classes: JettyTask

Constant Summary collapse

VERSION =
"6.1.1"
REQUIRES =
[ "org.mortbay.jetty:jetty:jar:#{VERSION}",
  "org.mortbay.jetty:jetty-util:jar:#{VERSION}",
  "org.mortbay.jetty:servlet-api-2.5:jar:#{VERSION}",
  "log4j:log4j:jar:1.2.13",
  "commons-logging:commons-logging:jar:1.1"
]
OPTIONS =
[ :classpath, :war_path, :context_path, :noop, :base_url, :process_alias ]

Class Method Summary collapse

Class Method Details

.bounce(options) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/java/jetty.rb', line 18

def self.bounce(options)
  fu_check_options options, *OPTIONS
  options[:classpath] ||= []
  
  begin
    verbose { puts "Bouncing webapp #{options[:war_path]}" }
    res = jetty_call('/bounce', :post, options)
    verbose { puts "done." }
  rescue Errno::ECONNREFUSED => e
    puts "Web server not found, spawning it."
    runtool options.merge(:class=>"JettyWrapper",
                          :args=>[ options[:war_path], options[:context_path] ],
                          :classpath=>options[:classpath] + ['buildr/lib/java/jetty'])
  end

  case res
  when Net::HTTPNotFound
    fail "A web server seems to be already running without Buildr deployment hooks."
  when Net::HTTPInternalServerError
    fail "Server error occured when redeploying the WAR, see the web server logs."
  end
end

.jetty_call(rel_url, get_post, options) ⇒ Object



41
42
43
44
45
# File 'lib/java/jetty.rb', line 41

def self.jetty_call(rel_url, get_post, options)
  base_url = URI.parse((options[:base_url] || 'http://localhost:8080/buildr') + rel_url)
  req = get_post == :post ? Net::HTTP::Post.new(base_url.path) : Net::HTTP::Get.new(base_url.path)
  res = Net::HTTP.start(base_url.host, base_url.port) {|http| http.request(req) }
end