jetty 6.1.11.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +22 -0
- data/README.txt +116 -0
- data/Rakefile +93 -0
- data/assembly.xml +19 -0
- data/bin/jetty-service +85 -0
- data/lib/jetty.rb +268 -0
- data/lib/jetty/base.rb +23 -0
- data/lib/jetty/gravitext-testservlets-1.0.jar +0 -0
- data/lib/jetty/jetty-6.1.11.jar +0 -0
- data/lib/jetty/jetty-rewrite-handler-6.1.11.jar +0 -0
- data/lib/jetty/jetty-util-6.1.11.jar +0 -0
- data/lib/jetty/rewrite.rb +2 -0
- data/lib/jetty/servlet-api-2.5-6.1.11.jar +0 -0
- data/lib/jetty/test-servlets.rb +33 -0
- data/pom.xml +72 -0
- data/src/main/java/com/gravitext/testservlets/PerfTestServlet.java +153 -0
- data/src/main/java/com/gravitext/testservlets/SnoopServlet.java +97 -0
- data/test/test_jetty.rb +161 -0
- data/webapps/test.war +0 -0
- data/webapps/test/WEB-INF/web.xml +28 -0
- data/webapps/test/index.html +11 -0
- metadata +94 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
README.txt
|
4
|
+
Rakefile
|
5
|
+
pom.xml
|
6
|
+
assembly.xml
|
7
|
+
bin/jetty-service
|
8
|
+
lib/jetty.rb
|
9
|
+
lib/jetty/base.rb
|
10
|
+
lib/jetty/rewrite.rb
|
11
|
+
lib/jetty/test-servlets.rb
|
12
|
+
src/main/java/com/gravitext/testservlets/PerfTestServlet.java
|
13
|
+
src/main/java/com/gravitext/testservlets/SnoopServlet.java
|
14
|
+
test/test_jetty.rb
|
15
|
+
webapps/test.war
|
16
|
+
webapps/test/WEB-INF/web.xml
|
17
|
+
webapps/test/index.html
|
18
|
+
lib/jetty/jetty-6.1.11.jar
|
19
|
+
lib/jetty/jetty-util-6.1.11.jar
|
20
|
+
lib/jetty/jetty-rewrite-handler-6.1.11.jar
|
21
|
+
lib/jetty/servlet-api-2.5-6.1.11.jar
|
22
|
+
lib/jetty/gravitext-testservlets-1.0.jar
|
data/README.txt
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
= jetty
|
2
|
+
|
3
|
+
* http://rjack.rubyforge.org
|
4
|
+
* http://rubyforge.org/projects/rjack
|
5
|
+
|
6
|
+
== Description
|
7
|
+
|
8
|
+
A gem packaging of the {Jetty Web Server}[http://www.mortbay.org/jetty/]
|
9
|
+
for JRuby:
|
10
|
+
|
11
|
+
* Provides jetty, jetty-util, servlet-api, and jetty-rewrite-handler
|
12
|
+
jars.
|
13
|
+
* A Jetty::ServerFactory for simple programmatic server setup in ruby.
|
14
|
+
* A set of Jetty::TestServlets containing a SnoopServlet and
|
15
|
+
PerfTestServlet (implemented in Java).
|
16
|
+
* A jetty-service bin script for easy testing from the command line.
|
17
|
+
|
18
|
+
Note that JSP support is provided separately in the companion
|
19
|
+
jetty-jsp[http://rjack.rubyforge.org/jetty-jsp/] gem.
|
20
|
+
|
21
|
+
== Synopsis
|
22
|
+
|
23
|
+
% jetty-service -v
|
24
|
+
Usage: jetty-service [options]
|
25
|
+
-p, --port N Port to listen on (default: auto)
|
26
|
+
-t, --threads N Maximum pool threads (default: 20)
|
27
|
+
-w, --webapp PATH Load PATH as root context webapp
|
28
|
+
(default: gem test.war)
|
29
|
+
-j, --jsp Enable JSP support by loading jetty-jsp gem
|
30
|
+
-d, --debug Enable debug logging
|
31
|
+
-v, --version Show version and exit
|
32
|
+
|
33
|
+
or
|
34
|
+
|
35
|
+
require 'jetty'
|
36
|
+
require 'jetty/test-servlets'
|
37
|
+
|
38
|
+
factory = Jetty::ServerFactory.new
|
39
|
+
factory.port = 8080
|
40
|
+
|
41
|
+
factory.set_context_servlets( '/', '/*' => Jetty::TestServlets::SnoopServlet.new )
|
42
|
+
server = factory.create
|
43
|
+
server.start
|
44
|
+
server.join
|
45
|
+
|
46
|
+
== Requirements
|
47
|
+
|
48
|
+
No hard requirements, however:
|
49
|
+
|
50
|
+
* To load webapps with JSPs, the jetty-jsp[http://rjack.rubyforge.org/jetty-jsp/]
|
51
|
+
gem must be loaded.
|
52
|
+
* Jetty will log to slf4j[http://rjack.rubyforge.org/slf4j] if
|
53
|
+
loaded. The jetty-service script will attempt to load
|
54
|
+
logback[http://rjack.rubyforge.org/logback], and thus slf4j, if
|
55
|
+
available.
|
56
|
+
|
57
|
+
== License
|
58
|
+
|
59
|
+
=== jetty ruby gem, test servlets
|
60
|
+
|
61
|
+
Copyright (C) 2008 David Kellum
|
62
|
+
|
63
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you
|
64
|
+
may not use this file except in compliance with the License. You
|
65
|
+
may obtain a copy of the License at:
|
66
|
+
|
67
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
68
|
+
|
69
|
+
Unless required by applicable law or agreed to in writing, software
|
70
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
71
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
72
|
+
implied. See the License for the specific language governing
|
73
|
+
permissions and limitations under the License.
|
74
|
+
|
75
|
+
=== Jetty Web Container (Java)
|
76
|
+
|
77
|
+
Copyright 1995-2008 Mort Bay Consulting Pty Ltd
|
78
|
+
|
79
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
80
|
+
you may not use this file except in compliance with the License.
|
81
|
+
You may obtain a copy of the License at
|
82
|
+
|
83
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
84
|
+
|
85
|
+
Unless required by applicable law or agreed to in writing, software
|
86
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
87
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
88
|
+
See the License for the specific language governing permissions and
|
89
|
+
limitations under the License.
|
90
|
+
|
91
|
+
The Jetty Web Container is Copyright Mort Bay Consulting Pty Ltd
|
92
|
+
unless otherwise noted. It is licensed under the apache 2.0
|
93
|
+
license.
|
94
|
+
|
95
|
+
The javax.servlet package used by Jetty is copyright
|
96
|
+
Sun Microsystems, Inc and Apache Software Foundation. It is
|
97
|
+
distributed under the Common Development and Distribution License.
|
98
|
+
You can obtain a copy of the license at
|
99
|
+
https://glassfish.dev.java.net/public/CDDLv1.0.html.
|
100
|
+
|
101
|
+
The UnixCrypt.java code ~Implements the one way cryptography used by
|
102
|
+
Unix systems for simple password protection. Copyright 1996 Aki Yoshida,
|
103
|
+
modified April 2001 by Iris Van den Broeke, Daniel Deville.
|
104
|
+
Permission to use, copy, modify and distribute UnixCrypt
|
105
|
+
for non-commercial or commercial purposes and without fee is
|
106
|
+
granted provided that the copyright notice appears in all copies.
|
107
|
+
|
108
|
+
The default JSP implementation is provided by the Glassfish JSP engine
|
109
|
+
from project Glassfish http://glassfish.dev.java.net. Copyright 2005
|
110
|
+
Sun Microsystems, Inc. and portions Copyright Apache Software Foundation.
|
111
|
+
|
112
|
+
Some portions of the code are Copyright:
|
113
|
+
2006 Tim Vernum
|
114
|
+
1999 Jason Gilbert.
|
115
|
+
|
116
|
+
The jboss integration module contains some LGPL code.
|
data/Rakefile
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
#--
|
3
|
+
# Copyright (C) 2008 David Kellum
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you
|
6
|
+
# may not use this file except in compliance with the License. You
|
7
|
+
# may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
14
|
+
# implied. See the License for the specific language governing
|
15
|
+
# permissions and limitations under the License.
|
16
|
+
#++
|
17
|
+
|
18
|
+
require 'rubygems'
|
19
|
+
|
20
|
+
ENV['NODOT'] = "no thank you"
|
21
|
+
require 'hoe'
|
22
|
+
|
23
|
+
$LOAD_PATH << './lib'
|
24
|
+
require 'jetty/base'
|
25
|
+
Jetty = JettyBase
|
26
|
+
|
27
|
+
JARS = %w{ jetty jetty-util jetty-rewrite-handler }.map do |n|
|
28
|
+
"#{n}-#{ Jetty::JETTY_VERSION }.jar"
|
29
|
+
end
|
30
|
+
JARS << "servlet-api-#{ Jetty::SERVLET_API_VERSION }-#{ Jetty::JETTY_VERSION }.jar"
|
31
|
+
JARS << 'gravitext-testservlets-1.0.jar'
|
32
|
+
JAR_FILES = JARS.map { |jar| "lib/jetty/#{jar}" }
|
33
|
+
|
34
|
+
|
35
|
+
desc "Update the Manifest with actual jars"
|
36
|
+
task :manifest do
|
37
|
+
out = File.new( 'Manifest.txt', 'w' )
|
38
|
+
begin
|
39
|
+
out.write <<END
|
40
|
+
History.txt
|
41
|
+
Manifest.txt
|
42
|
+
README.txt
|
43
|
+
Rakefile
|
44
|
+
pom.xml
|
45
|
+
assembly.xml
|
46
|
+
bin/jetty-service
|
47
|
+
lib/jetty.rb
|
48
|
+
lib/jetty/base.rb
|
49
|
+
lib/jetty/rewrite.rb
|
50
|
+
lib/jetty/test-servlets.rb
|
51
|
+
src/main/java/com/gravitext/testservlets/PerfTestServlet.java
|
52
|
+
src/main/java/com/gravitext/testservlets/SnoopServlet.java
|
53
|
+
test/test_jetty.rb
|
54
|
+
webapps/test.war
|
55
|
+
webapps/test/WEB-INF/web.xml
|
56
|
+
webapps/test/index.html
|
57
|
+
END
|
58
|
+
out.puts JAR_FILES
|
59
|
+
ensure
|
60
|
+
out.close
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
ASSEMBLY = "target/gravitext-testservlets-1.0-bin.dir"
|
65
|
+
|
66
|
+
file 'webapps/test.war' => [ 'webapps/test/index.html',
|
67
|
+
'webapps/test/WEB-INF/web.xml' ] do
|
68
|
+
sh( 'jar cvf webapps/test.war -C webapps/test .' )
|
69
|
+
end
|
70
|
+
|
71
|
+
file ASSEMBLY => [ 'pom.xml', 'assembly.xml' ] do
|
72
|
+
sh( 'mvn package' )
|
73
|
+
end
|
74
|
+
|
75
|
+
JARS.each do |jar|
|
76
|
+
file "lib/jetty/#{jar}" => [ ASSEMBLY ] do
|
77
|
+
cp_r( File.join( ASSEMBLY, jar ), 'lib/jetty' )
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
[ :gem, :test ].each { |t| task t => JAR_FILES }
|
82
|
+
|
83
|
+
task :mvn_clean do
|
84
|
+
rm_f( JAR_FILES )
|
85
|
+
sh( 'mvn clean' )
|
86
|
+
end
|
87
|
+
task :clean => :mvn_clean
|
88
|
+
|
89
|
+
hoe = Hoe.new( "jetty", Jetty::VERSION ) do |p|
|
90
|
+
p.developer( "David Kellum", "dek-ruby@gravitext.com" )
|
91
|
+
p.rubyforge_name = "rjack"
|
92
|
+
p.rdoc_pattern = /^(lib.*\.(rb|txt))|[^\/]*\.txt$/
|
93
|
+
end
|
data/assembly.xml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
<assembly>
|
2
|
+
<id>bin</id>
|
3
|
+
<formats>
|
4
|
+
<format>dir</format>
|
5
|
+
</formats>
|
6
|
+
<includeBaseDirectory>false</includeBaseDirectory>
|
7
|
+
<dependencySets>
|
8
|
+
<dependencySet>
|
9
|
+
<includes>
|
10
|
+
<include>org.mortbay.jetty:jetty</include>
|
11
|
+
<include>org.mortbay.jetty:jetty-util</include>
|
12
|
+
<include>org.mortbay.jetty:jetty-rewrite-handler</include>
|
13
|
+
<include>org.mortbay.jetty:servlet-api-2.5</include>
|
14
|
+
<include>com.gravitext:gravitext-testservlets</include>
|
15
|
+
</includes>
|
16
|
+
</dependencySet>
|
17
|
+
</dependencySets>
|
18
|
+
|
19
|
+
</assembly>
|
data/bin/jetty-service
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
#!/usr/bin/env jruby
|
2
|
+
# -*- ruby -*-
|
3
|
+
#--
|
4
|
+
# Copyright (C) 2008 David Kellum
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you
|
7
|
+
# may not use this file except in compliance with the License. You
|
8
|
+
# may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
15
|
+
# implied. See the License for the specific language governing
|
16
|
+
# permissions and limitations under the License.
|
17
|
+
#++
|
18
|
+
|
19
|
+
$LOAD_PATH.unshift File.join( File.dirname(__FILE__), "..", "lib" )
|
20
|
+
|
21
|
+
require 'rubygems'
|
22
|
+
|
23
|
+
begin
|
24
|
+
gem 'logback'
|
25
|
+
require 'logback'
|
26
|
+
Logback.configure do
|
27
|
+
console = Logback::ConsoleAppender.new do |a|
|
28
|
+
a.layout = Logback::PatternLayout.new do |p|
|
29
|
+
p.pattern = "%-4r %-5level %logger{35} - %msg %ex%n"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
Logback.root.add_appender( console )
|
33
|
+
Logback.root.level = Logback::INFO
|
34
|
+
end
|
35
|
+
log = SLF4J[ 'jetty-service' ]
|
36
|
+
rescue Gem::LoadError => e
|
37
|
+
class Log
|
38
|
+
def method_missing( method, *args )
|
39
|
+
$stderr.puts( "#{method.id2name.upcase}: #{args.join(' ')}" )
|
40
|
+
end
|
41
|
+
end
|
42
|
+
log = Log.new
|
43
|
+
log.info( "#{e.to_s.strip}: SLF4J/Logback not loaded, using STDERR." )
|
44
|
+
end
|
45
|
+
|
46
|
+
require 'jetty'
|
47
|
+
require 'jetty/test-servlets'
|
48
|
+
require 'optparse'
|
49
|
+
|
50
|
+
factory = Jetty::ServerFactory.new
|
51
|
+
|
52
|
+
factory.webapp_contexts[ '/' ] = Jetty::TestServlets::WEBAPP_TEST_EXPANDED
|
53
|
+
|
54
|
+
OptionParser.new do |opts|
|
55
|
+
opts.on( "-p", "--port N", Integer,
|
56
|
+
"Port to listen on (default: auto)" ) do |v|
|
57
|
+
factory.port = v
|
58
|
+
end
|
59
|
+
opts.on( "-t", "--threads N", Integer,
|
60
|
+
"Maximum pool threads (default: #{factory.max_threads})" ) do |v|
|
61
|
+
factory.max_threads = v
|
62
|
+
end
|
63
|
+
opts.on( "-w", "--webapp PATH",
|
64
|
+
"Load PATH as root context webapp. (default: gem test.war)" ) do |v|
|
65
|
+
factory.webapp_contexts[ '/' ] = v
|
66
|
+
end
|
67
|
+
opts.on( "-j", "--jsp", "Enable JSP support by loading jetty-jsp gem") do
|
68
|
+
gem( 'jetty-jsp', "~> #{Jetty::JETTY_VERSION}" )
|
69
|
+
require 'jetty-jsp'
|
70
|
+
end
|
71
|
+
opts.on_tail( "-d", "--debug", "Enable debug logging") do
|
72
|
+
Logback.root.level = Logback::DEBUG if defined?( Logback )
|
73
|
+
end
|
74
|
+
opts.on_tail( "-v", "--version", "Show version and exit" ) do
|
75
|
+
puts "jetty gem (#{$0}) version: #{Jetty::VERSION}"
|
76
|
+
exit
|
77
|
+
end
|
78
|
+
end.parse!
|
79
|
+
|
80
|
+
server = factory.create
|
81
|
+
|
82
|
+
server.start
|
83
|
+
log.info( "Listening on port: #{server.connectors[0].local_port}" )
|
84
|
+
server.join
|
85
|
+
log.info( "Server exited." )
|
data/lib/jetty.rb
ADDED
@@ -0,0 +1,268 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (C) 2008 David Kellum
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you
|
5
|
+
# may not use this file except in compliance with the License. You
|
6
|
+
# may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
13
|
+
# implied. See the License for the specific language governing
|
14
|
+
# permissions and limitations under the License.
|
15
|
+
#++
|
16
|
+
|
17
|
+
require 'jetty/base'
|
18
|
+
|
19
|
+
# {Jetty Web Server}[http://www.mortbay.org/jetty/] module including
|
20
|
+
# a ServerFactory
|
21
|
+
module Jetty
|
22
|
+
include JettyBase
|
23
|
+
|
24
|
+
def self.require_jar( name )
|
25
|
+
require File.join( JETTY_DIR, "#{name}-#{ JETTY_VERSION }.jar" )
|
26
|
+
end
|
27
|
+
|
28
|
+
require_jar 'jetty'
|
29
|
+
require_jar 'jetty-util'
|
30
|
+
require_jar "servlet-api-#{ SERVLET_API_VERSION }"
|
31
|
+
|
32
|
+
import 'org.mortbay.jetty.Connector'
|
33
|
+
import 'org.mortbay.jetty.Handler'
|
34
|
+
import 'org.mortbay.jetty.NCSARequestLog'
|
35
|
+
import 'org.mortbay.jetty.Server'
|
36
|
+
import 'org.mortbay.jetty.handler.ContextHandler'
|
37
|
+
import 'org.mortbay.jetty.handler.ContextHandlerCollection'
|
38
|
+
import 'org.mortbay.jetty.handler.DefaultHandler'
|
39
|
+
import 'org.mortbay.jetty.handler.HandlerCollection'
|
40
|
+
import 'org.mortbay.jetty.handler.RequestLogHandler'
|
41
|
+
import 'org.mortbay.jetty.handler.ResourceHandler'
|
42
|
+
import 'org.mortbay.jetty.nio.SelectChannelConnector'
|
43
|
+
import 'org.mortbay.jetty.servlet.Context'
|
44
|
+
import 'org.mortbay.jetty.servlet.ServletHolder'
|
45
|
+
import 'org.mortbay.jetty.webapp.WebAppContext'
|
46
|
+
import 'org.mortbay.thread.QueuedThreadPool'
|
47
|
+
|
48
|
+
# A factory for creating complete org.morbay.jetty.Server
|
49
|
+
# instances. Provides a general purpose facade for setup including
|
50
|
+
# the Server, a ThreadPool, a Connector, and various Handlers. It
|
51
|
+
# is non-exhaustive (not every Jetty facility is provided) but is
|
52
|
+
# designed to be easily extended.
|
53
|
+
#
|
54
|
+
# == Example
|
55
|
+
#
|
56
|
+
# factory = Jetty::ServerFactory.new
|
57
|
+
# factory.max_threads = 20
|
58
|
+
# factory.port = 8080
|
59
|
+
#
|
60
|
+
# # Set static resource context mapping URI to directory
|
61
|
+
# factory.static_contexts[ '/html' ] = '/var/www/html'
|
62
|
+
#
|
63
|
+
# # Implement custom handler and register it.
|
64
|
+
# import 'org.mortbay.jetty.handler.AbstractHandler'
|
65
|
+
# class RedirectHandler < AbstractHandler
|
66
|
+
#
|
67
|
+
# def initialize( redirects )
|
68
|
+
# super()
|
69
|
+
# @redirects = redirects
|
70
|
+
# end
|
71
|
+
#
|
72
|
+
# def handle( target, request, response, dispatch )
|
73
|
+
# goto = @redirects[ target ]
|
74
|
+
# unless goto.nil?
|
75
|
+
# response.send_redirect( goto )
|
76
|
+
# request.handled = true
|
77
|
+
# end
|
78
|
+
# end
|
79
|
+
# end
|
80
|
+
#
|
81
|
+
# def factory.create_pre_handlers
|
82
|
+
# [ RedirectHandler.new( '/' => '/html/' ) ] + super
|
83
|
+
# end
|
84
|
+
#
|
85
|
+
# # Create a webapp context (war file or webapp expanded)
|
86
|
+
# factory.webapp_contexts[ '/test' ] = Jetty::TestServlets::WEBAPP_TEST_WAR
|
87
|
+
#
|
88
|
+
# # Create a context for a custom HelloServlet
|
89
|
+
# import 'javax.servlet.http.HttpServlet'
|
90
|
+
# class HelloServlet < HttpServlet
|
91
|
+
# def doGet( request, response )
|
92
|
+
# response.content_type = "text/plain"
|
93
|
+
# response.writer.write( 'Hello World!' )
|
94
|
+
# end
|
95
|
+
# end
|
96
|
+
#
|
97
|
+
# factory.set_context_servlets( '/hello', { '/*' => HelloServlet.new } )
|
98
|
+
#
|
99
|
+
# # Create, start, and join (wait for shutdown)
|
100
|
+
# server = factory.create
|
101
|
+
# server.start
|
102
|
+
# server.join
|
103
|
+
#
|
104
|
+
class ServerFactory
|
105
|
+
attr_accessor( :port, :max_idle_time_ms,
|
106
|
+
:max_threads, :low_threads, :min_threads,
|
107
|
+
:static_contexts, :static_welcome_files,
|
108
|
+
:webapp_contexts,
|
109
|
+
:servlet_contexts,
|
110
|
+
:stop_at_shutdown,
|
111
|
+
:request_log_file )
|
112
|
+
|
113
|
+
def initialize
|
114
|
+
@port = 0 # Use any available port
|
115
|
+
@max_threads = 20
|
116
|
+
@low_threads = 0 # No low thread threshold
|
117
|
+
@min_threads = nil # Compute from max_threads
|
118
|
+
@max_idle_time_ms = 10000
|
119
|
+
@static_contexts = {}
|
120
|
+
@static_welcome_files = [ 'index.html' ]
|
121
|
+
@webapp_contexts = {}
|
122
|
+
@request_log_file = nil
|
123
|
+
@servlet_contexts = {}
|
124
|
+
@stop_at_shutdown = true
|
125
|
+
end
|
126
|
+
|
127
|
+
# Returns a new org.morbay.jetty.Server that is ready to
|
128
|
+
# be started.
|
129
|
+
def create
|
130
|
+
server = Server.new
|
131
|
+
|
132
|
+
server.thread_pool = create_pool
|
133
|
+
|
134
|
+
server.connectors = create_connectors.to_java( Connector )
|
135
|
+
|
136
|
+
hcol = HandlerCollection.new
|
137
|
+
hcol.handlers = create_handlers.compact.to_java( Handler )
|
138
|
+
server.handler = hcol
|
139
|
+
|
140
|
+
server.stop_at_shutdown = @stop_at_shutdown
|
141
|
+
|
142
|
+
server
|
143
|
+
end
|
144
|
+
|
145
|
+
# Return a org.mortbay.thread.ThreadPool implementation.
|
146
|
+
#
|
147
|
+
# This implementation creates a QueuedThreadPool with min_threads
|
148
|
+
# (default max_threads / 4), any low_threads, and max_threads
|
149
|
+
# (default 20).
|
150
|
+
def create_pool
|
151
|
+
pool = QueuedThreadPool.new
|
152
|
+
pool.min_threads = [ @min_threads || ( @max_threads / 4 ), 1 ].max
|
153
|
+
pool.low_threads = @low_threads
|
154
|
+
pool.max_threads = [ @max_threads, 2 ].max
|
155
|
+
pool
|
156
|
+
end
|
157
|
+
|
158
|
+
# Return array of org.mortbay.jetty.Connector instances.
|
159
|
+
#
|
160
|
+
# This implementation returns a single SelectChannelConnector
|
161
|
+
# listening to the given port or an auto-selected avaiable
|
162
|
+
# port. Connections are retained for max_idle_time_ms.
|
163
|
+
def create_connectors
|
164
|
+
connector = SelectChannelConnector.new
|
165
|
+
connector.port = @port
|
166
|
+
connector.max_idle_time = @max_idle_time_ms
|
167
|
+
[ connector ]
|
168
|
+
end
|
169
|
+
|
170
|
+
# Returns an Array of org.mortbay.jetty.Handler instances.
|
171
|
+
#
|
172
|
+
# This implementation concatenates create_pre_handlers and
|
173
|
+
# create_post_handlers.
|
174
|
+
def create_handlers
|
175
|
+
( create_pre_handlers + create_post_handlers )
|
176
|
+
end
|
177
|
+
|
178
|
+
# Returns an Array of "pre" org.mortbay.jetty.Handler instances.
|
179
|
+
#
|
180
|
+
# This implementation returns an array containing a single
|
181
|
+
# ContextHandlerCollection which itself contains the context
|
182
|
+
# handlers set by create_context_handlers, or an empty array
|
183
|
+
# if no context handlers were set.
|
184
|
+
def create_pre_handlers
|
185
|
+
ctx_handlers = ContextHandlerCollection.new
|
186
|
+
create_context_handlers( ctx_handlers )
|
187
|
+
h = ctx_handlers.handlers
|
188
|
+
if( h.nil? || h.length == 0 )
|
189
|
+
[ ]
|
190
|
+
else
|
191
|
+
[ ctx_handlers ]
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
# Returns an Array of "post" org.mortbay.jetty.Handler instances.
|
196
|
+
#
|
197
|
+
# This implementation returns a DefaultHandler instance, and any
|
198
|
+
# handler returned by create_request_log_handler.
|
199
|
+
def create_post_handlers
|
200
|
+
[ DefaultHandler.new, # Handle errors, etc.
|
201
|
+
create_request_log_handler ]
|
202
|
+
end
|
203
|
+
|
204
|
+
# Create context handlers on the provided ContextHandlerCollection
|
205
|
+
#
|
206
|
+
# This implementation calls create_static_contexts,
|
207
|
+
# create_webapp_contexts, and create_servlet_context.
|
208
|
+
def create_context_handlers( context_handler_collection )
|
209
|
+
create_static_contexts( context_handler_collection )
|
210
|
+
create_webapp_contexts( context_handler_collection )
|
211
|
+
create_servlet_contexts( context_handler_collection )
|
212
|
+
end
|
213
|
+
|
214
|
+
# Create context handlers for static resources from static_contexts
|
215
|
+
def create_static_contexts( context_handler_collection )
|
216
|
+
@static_contexts.each do |ctx, rpath|
|
217
|
+
ch = ContextHandler.new( context_handler_collection, ctx )
|
218
|
+
ch.resource_base = rpath
|
219
|
+
ch.handler = ResourceHandler.new
|
220
|
+
ch.handler.welcome_files =
|
221
|
+
@static_welcome_files.to_java( java.lang.String )
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
# Set a context of servlets given context_path, a servlets hash
|
226
|
+
# (mapping path to Servlet), and options.
|
227
|
+
def set_context_servlets( context_path, servlets,
|
228
|
+
options = Context::NO_SESSIONS )
|
229
|
+
@servlet_contexts[ context_path ] = [ servlets, options ]
|
230
|
+
end
|
231
|
+
|
232
|
+
# Create context handlers from servlet_contexts.
|
233
|
+
def create_servlet_contexts( context_handler_collection )
|
234
|
+
@servlet_contexts.each do |ctx, s_o|
|
235
|
+
servlets, options = s_o
|
236
|
+
context = Context.new( context_handler_collection, ctx, options )
|
237
|
+
servlets.each do |path, servlet|
|
238
|
+
context.add_servlet( ServletHolder.new( servlet ), path )
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
# Create webapp context handlers from webapp_contexts.
|
244
|
+
def create_webapp_contexts( context_handler_collection )
|
245
|
+
@webapp_contexts.each do |ctx, webapp_path|
|
246
|
+
WebAppContext.new( context_handler_collection, webapp_path, ctx )
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
# Create RequestLogHandler from any set request_log_file
|
251
|
+
def create_request_log_handler
|
252
|
+
if @request_log_file
|
253
|
+
log_handler = RequestLogHandler.new
|
254
|
+
log_handler.request_log = create_request_log( @request_log_file )
|
255
|
+
log_handler
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
# Create a NCSARequestLog to append to log_file
|
260
|
+
def create_request_log( log_file )
|
261
|
+
log = NCSARequestLog.new( log_file )
|
262
|
+
log.log_time_zone = java.util.TimeZone::getDefault.getID
|
263
|
+
log.append = true;
|
264
|
+
log
|
265
|
+
end
|
266
|
+
|
267
|
+
end
|
268
|
+
end
|
data/lib/jetty/base.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (C) 2008 David Kellum
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you
|
5
|
+
# may not use this file except in compliance with the License. You
|
6
|
+
# may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
13
|
+
# implied. See the License for the specific language governing
|
14
|
+
# permissions and limitations under the License.
|
15
|
+
#++
|
16
|
+
|
17
|
+
module JettyBase
|
18
|
+
JETTY_VERSION = '6.1.11'
|
19
|
+
VERSION = JETTY_VERSION + '.1'
|
20
|
+
SERVLET_API_VERSION = '2.5'
|
21
|
+
|
22
|
+
JETTY_DIR = File.dirname( __FILE__ ) # :nodoc:
|
23
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (C) 2008 David Kellum
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you
|
5
|
+
# may not use this file except in compliance with the License. You
|
6
|
+
# may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
13
|
+
# implied. See the License for the specific language governing
|
14
|
+
# permissions and limitations under the License.
|
15
|
+
#++
|
16
|
+
|
17
|
+
require 'jetty'
|
18
|
+
|
19
|
+
module Jetty
|
20
|
+
|
21
|
+
# Loads testservlets jar.
|
22
|
+
module TestServlets
|
23
|
+
require File.join( Jetty::JETTY_DIR, "gravitext-testservlets-1.0.jar" )
|
24
|
+
import 'com.gravitext.testservlets.SnoopServlet'
|
25
|
+
import 'com.gravitext.testservlets.PerfTestServlet'
|
26
|
+
|
27
|
+
# Webapps directory containing "test/" expanded webapp and "test.war"
|
28
|
+
WEBAPPS_DIR = File.join( Jetty::JETTY_DIR, '..', '..', 'webapps' )
|
29
|
+
|
30
|
+
WEBAPP_TEST_EXPANDED = File.join( WEBAPPS_DIR, 'test' )
|
31
|
+
WEBAPP_TEST_WAR = File.join( WEBAPPS_DIR, 'test.war' )
|
32
|
+
end
|
33
|
+
end
|
data/pom.xml
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
2
|
+
|
3
|
+
<modelVersion>4.0.0</modelVersion>
|
4
|
+
<groupId>com.gravitext</groupId>
|
5
|
+
<artifactId>gravitext-testservlets</artifactId>
|
6
|
+
<packaging>jar</packaging>
|
7
|
+
<version>1.0</version>
|
8
|
+
<name>Gravitext Test Servlets</name> -->
|
9
|
+
|
10
|
+
<dependencies>
|
11
|
+
<dependency>
|
12
|
+
<groupId>org.mortbay.jetty</groupId>
|
13
|
+
<artifactId>servlet-api-2.5</artifactId>
|
14
|
+
<version>6.1.11</version>
|
15
|
+
</dependency>
|
16
|
+
|
17
|
+
<dependency>
|
18
|
+
<groupId>org.mortbay.jetty</groupId>
|
19
|
+
<artifactId>jetty</artifactId>
|
20
|
+
<version>6.1.11</version>
|
21
|
+
</dependency>
|
22
|
+
|
23
|
+
<dependency>
|
24
|
+
<groupId>org.mortbay.jetty</groupId>
|
25
|
+
<artifactId>jetty-util</artifactId>
|
26
|
+
<version>6.1.11</version>
|
27
|
+
</dependency>
|
28
|
+
|
29
|
+
<dependency>
|
30
|
+
<groupId>org.mortbay.jetty</groupId>
|
31
|
+
<artifactId>jetty-rewrite-handler</artifactId>
|
32
|
+
<version>6.1.11</version>
|
33
|
+
</dependency>
|
34
|
+
|
35
|
+
</dependencies>
|
36
|
+
|
37
|
+
<build>
|
38
|
+
<plugins>
|
39
|
+
<plugin>
|
40
|
+
<artifactId>maven-assembly-plugin</artifactId>
|
41
|
+
<configuration>
|
42
|
+
<descriptors>
|
43
|
+
<descriptor>assembly.xml</descriptor>
|
44
|
+
</descriptors>
|
45
|
+
<tarLongFileMode>gnu</tarLongFileMode>
|
46
|
+
</configuration>
|
47
|
+
<executions>
|
48
|
+
<execution>
|
49
|
+
<id>assembly</id>
|
50
|
+
<phase>package</phase>
|
51
|
+
<goals>
|
52
|
+
<goal>attached</goal>
|
53
|
+
</goals>
|
54
|
+
</execution>
|
55
|
+
</executions>
|
56
|
+
</plugin>
|
57
|
+
<plugin>
|
58
|
+
<artifactId>maven-compiler-plugin</artifactId>
|
59
|
+
<configuration>
|
60
|
+
<source>1.5</source>
|
61
|
+
<target>1.5</target>
|
62
|
+
<optimize>true</optimize>
|
63
|
+
<debug>true</debug>
|
64
|
+
<encoding>UTF-8</encoding>
|
65
|
+
<showDeprecation>true</showDeprecation>
|
66
|
+
<showWarnings>true</showWarnings>
|
67
|
+
</configuration>
|
68
|
+
</plugin>
|
69
|
+
</plugins>
|
70
|
+
</build>
|
71
|
+
|
72
|
+
</project>
|
@@ -0,0 +1,153 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (C) 2008 David Kellum
|
3
|
+
*
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
* you may not use this file except in compliance with the License.
|
6
|
+
* You may obtain a copy of the License at
|
7
|
+
*
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
*
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
* See the License for the specific language governing permissions and
|
14
|
+
* limitations under the License.
|
15
|
+
*/
|
16
|
+
|
17
|
+
package com.gravitext.testservlets;
|
18
|
+
|
19
|
+
import java.io.IOException;
|
20
|
+
import java.io.PrintWriter;
|
21
|
+
import java.math.BigInteger;
|
22
|
+
import java.util.Random;
|
23
|
+
|
24
|
+
import javax.servlet.ServletException;
|
25
|
+
import javax.servlet.http.HttpServlet;
|
26
|
+
import javax.servlet.http.HttpServletRequest;
|
27
|
+
import javax.servlet.http.HttpServletResponse;
|
28
|
+
|
29
|
+
/**
|
30
|
+
* Servlet for perform and chunked output testing.
|
31
|
+
* @author David Kellum
|
32
|
+
*/
|
33
|
+
public class PerfTestServlet extends HttpServlet
|
34
|
+
{
|
35
|
+
|
36
|
+
@Override
|
37
|
+
protected void doGet( HttpServletRequest req, HttpServletResponse resp )
|
38
|
+
throws ServletException, IOException
|
39
|
+
{
|
40
|
+
int delayConst = getParam( req, "delay", 0 );
|
41
|
+
int delayRandom = getParam( req, "rdelay", 0 );
|
42
|
+
|
43
|
+
int burnConst = getParam( req, "burn", 0 );
|
44
|
+
int burnRandom = getParam( req, "rburn", 0 );
|
45
|
+
|
46
|
+
int size = getParam( req, "size", 0 );
|
47
|
+
int sizeRandom = getParam( req, "rsize", 0 );
|
48
|
+
|
49
|
+
int count = getParam( req, "count", 0 );
|
50
|
+
count += random( getParam( req, "rcount", 0 ) );
|
51
|
+
|
52
|
+
resp.setContentType("text/html; charset=ISO-8859-1" );
|
53
|
+
|
54
|
+
PrintWriter out = resp.getWriter();
|
55
|
+
|
56
|
+
out.println( "<html>" );
|
57
|
+
out.println( "<head>" );
|
58
|
+
out.println( "<title>Wait/Flush Test</title>" );
|
59
|
+
out.println( "</head>" );
|
60
|
+
out.println( "<body>" );
|
61
|
+
|
62
|
+
out.println( "<h2>Usage</h2>" );
|
63
|
+
out.println( "<table><tr><th>GET Parameter</th><th>Meaning</th></tr>" );
|
64
|
+
out.println( "<tr><td>size</td><td>Chunk constant size ~characters.</td></tr>" );
|
65
|
+
out.println( "<tr><td>rsize</td><td>Chunk random [0,n) size ~characters.</td></tr>" );
|
66
|
+
out.println( "<tr><td>delay</td><td>Constant chunk delay in ms</td></tr>" );
|
67
|
+
out.println( "<tr><td>rdelay</td><td>Random [0,n) chunk delay in ms</td></tr>" );
|
68
|
+
out.println( "<tr><td>burn</td><td>Constant chunk CPU burn time in ms</td></tr>" );
|
69
|
+
out.println( "<tr><td>rburn</td><td>Random [0,n) chunk burn time in ms</td></tr>" );
|
70
|
+
out.println( "</table>" );
|
71
|
+
|
72
|
+
out.println( "<h2>Output</h2>" );
|
73
|
+
out.flush();
|
74
|
+
|
75
|
+
out.println( "<p>Writing " + count + " (delayed) chunks...</p>" );
|
76
|
+
out.flush();
|
77
|
+
|
78
|
+
try {
|
79
|
+
for( int b = 0; b < count; ++b ) {
|
80
|
+
|
81
|
+
long delay = delayConst + random( delayRandom );
|
82
|
+
if( delay > 0 ) Thread.sleep( delay );
|
83
|
+
|
84
|
+
int burn = burnConst + random ( burnRandom );
|
85
|
+
if( burn > 0 ) {
|
86
|
+
delay += burnTime( burn );
|
87
|
+
}
|
88
|
+
|
89
|
+
out.println( "<p>(Delayed " + delay + " ms) " );
|
90
|
+
|
91
|
+
int f = size + random( sizeRandom );
|
92
|
+
while( f > 0 ) {
|
93
|
+
out.print( FILLER );
|
94
|
+
f -= FILLER.length();
|
95
|
+
}
|
96
|
+
|
97
|
+
out.println( "</p>" );
|
98
|
+
out.flush();
|
99
|
+
}
|
100
|
+
}
|
101
|
+
catch( InterruptedException x ) {}
|
102
|
+
out.println( "</body>" );
|
103
|
+
out.println( "</html>" );
|
104
|
+
out.flush();
|
105
|
+
}
|
106
|
+
|
107
|
+
private long burnTime( int burn_ms )
|
108
|
+
{
|
109
|
+
long prime = 2;
|
110
|
+
long begin = System.currentTimeMillis();
|
111
|
+
long endTime = begin + burn_ms;
|
112
|
+
long last = 0;
|
113
|
+
do {
|
114
|
+
prime = BigInteger.probablePrime( 64, new Random() ).longValue();
|
115
|
+
last = System.currentTimeMillis();
|
116
|
+
} while( last < endTime );
|
117
|
+
|
118
|
+
if( prime == 2 ) {
|
119
|
+
throw new IllegalStateException( "Not a prime!" );
|
120
|
+
}
|
121
|
+
return last - begin;
|
122
|
+
}
|
123
|
+
|
124
|
+
private int getParam( HttpServletRequest req, String name, int defVal )
|
125
|
+
{
|
126
|
+
int value = defVal;
|
127
|
+
String strVal = req.getParameter( name );
|
128
|
+
if( strVal != null ) {
|
129
|
+
value = Integer.parseInt( strVal );
|
130
|
+
}
|
131
|
+
|
132
|
+
return value;
|
133
|
+
}
|
134
|
+
|
135
|
+
private int random( int range )
|
136
|
+
{
|
137
|
+
Random _random = new Random();
|
138
|
+
if( range > 0 ) return _random.nextInt( range );
|
139
|
+
return 0;
|
140
|
+
}
|
141
|
+
|
142
|
+
private static final String FILLER =
|
143
|
+
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, " +
|
144
|
+
"sed do eiusmod tempor incididunt ut labore et dolore magna " +
|
145
|
+
"aliqua. Ut enim ad minim veniam, quis nostrud exercitation " +
|
146
|
+
"ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis " +
|
147
|
+
"aute irure dolor in reprehenderit in voluptate velit esse cillum " +
|
148
|
+
"dolore eu fugiat nulla pariatur. Excepteur sint occaecat " +
|
149
|
+
"cupidatat non proident, sunt in culpa qui officia deserunt " +
|
150
|
+
"mollit anim id est laborum. ";
|
151
|
+
|
152
|
+
private static final long serialVersionUID = 1L;
|
153
|
+
}
|
@@ -0,0 +1,97 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (C) 2008 David Kellum
|
3
|
+
*
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
* you may not use this file except in compliance with the License.
|
6
|
+
* You may obtain a copy of the License at
|
7
|
+
*
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
*
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
* See the License for the specific language governing permissions and
|
14
|
+
* limitations under the License.
|
15
|
+
*/
|
16
|
+
|
17
|
+
package com.gravitext.testservlets;
|
18
|
+
|
19
|
+
import java.io.IOException;
|
20
|
+
import java.io.PrintWriter;
|
21
|
+
import java.util.Enumeration;
|
22
|
+
|
23
|
+
import javax.servlet.ServletException;
|
24
|
+
import javax.servlet.http.Cookie;
|
25
|
+
import javax.servlet.http.HttpServlet;
|
26
|
+
import javax.servlet.http.HttpServletRequest;
|
27
|
+
import javax.servlet.http.HttpServletResponse;
|
28
|
+
|
29
|
+
public class SnoopServlet extends HttpServlet
|
30
|
+
{
|
31
|
+
|
32
|
+
@Override
|
33
|
+
protected void doGet( HttpServletRequest request,
|
34
|
+
HttpServletResponse response )
|
35
|
+
throws ServletException, IOException
|
36
|
+
{
|
37
|
+
response.setContentType("text/html; charset=UTF-8" );
|
38
|
+
|
39
|
+
PrintWriter out = response.getWriter();
|
40
|
+
|
41
|
+
out.println( "<html>" );
|
42
|
+
out.println( "<head>" );
|
43
|
+
out.println( "<title>Wait/Flush Test</title>" );
|
44
|
+
out.println( "</head>" );
|
45
|
+
out.println( "<body>" );
|
46
|
+
|
47
|
+
writeTableHeader( out, "Request Properties", "Property" );
|
48
|
+
writeRow( out, "Request URI", request.getRequestURI() );
|
49
|
+
writeRow( out, "HTTP Method", request.getMethod() );
|
50
|
+
writeRow( out, "Path Info", request.getPathInfo() );
|
51
|
+
writeRow( out, "Path Trans", request.getPathTranslated() );
|
52
|
+
writeRow( out, "Query String", request.getQueryString() );
|
53
|
+
writeRow( out, "Context Path", request.getContextPath() );
|
54
|
+
writeRow( out, "Servlet Path", request.getServletPath() );
|
55
|
+
writeRow( out, "Is Secure", String.valueOf( request.isSecure() ) );
|
56
|
+
writeRow( out, "Auth Type", request.getAuthType() );
|
57
|
+
writeRow( out, "Remote User", request.getRemoteUser() );
|
58
|
+
out.println( "</table>" );
|
59
|
+
|
60
|
+
writeTableHeader( out, "Request Headers", "Header" );
|
61
|
+
Enumeration<?> hNames = request.getHeaderNames();
|
62
|
+
while( hNames.hasMoreElements() ) {
|
63
|
+
String hname = hNames.nextElement().toString();
|
64
|
+
String hvalue = request.getHeader( hname );
|
65
|
+
writeRow( out, hname, hvalue );
|
66
|
+
}
|
67
|
+
out.println( "</table>" );
|
68
|
+
|
69
|
+
Cookie[] cookies = request.getCookies();
|
70
|
+
if (cookies != null) {
|
71
|
+
writeTableHeader( out, "Cookies", "Cookie" );
|
72
|
+
for( Cookie cookie : cookies ) {
|
73
|
+
writeRow( out, cookie.getName(), cookie.getValue() );
|
74
|
+
}
|
75
|
+
out.println( "</table>" );
|
76
|
+
}
|
77
|
+
|
78
|
+
out.println( "</body>" );
|
79
|
+
out.println( "</html>" );
|
80
|
+
out.close();
|
81
|
+
}
|
82
|
+
|
83
|
+
private void writeTableHeader( PrintWriter out,
|
84
|
+
String heading, String name )
|
85
|
+
{
|
86
|
+
out.println( "<h2>" + heading + "</h2>" );
|
87
|
+
out.println( "<table><tr><th>" + name + "</th><th>Value</th></tr>" );
|
88
|
+
}
|
89
|
+
|
90
|
+
private void writeRow( PrintWriter out, String name, String value )
|
91
|
+
{
|
92
|
+
out.println( String.format( "<tr><td>%s</td><td>%s</td></tr>",
|
93
|
+
name, value ) );
|
94
|
+
}
|
95
|
+
|
96
|
+
private static final long serialVersionUID = 1L;
|
97
|
+
}
|
data/test/test_jetty.rb
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
#!/usr/bin/env jruby
|
2
|
+
#.hashdot.profile += jruby-shortlived
|
3
|
+
#--
|
4
|
+
# Copyright (C) 2008 David Kellum
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you
|
7
|
+
# may not use this file except in compliance with the License. You
|
8
|
+
# may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
15
|
+
# implied. See the License for the specific language governing
|
16
|
+
# permissions and limitations under the License.
|
17
|
+
#++
|
18
|
+
|
19
|
+
TEST_DIR = File.dirname(__FILE__)
|
20
|
+
|
21
|
+
$LOAD_PATH.unshift File.join( TEST_DIR, "..", "lib" )
|
22
|
+
|
23
|
+
require 'rubygems'
|
24
|
+
|
25
|
+
# Disable jetty logging if slf4j is available
|
26
|
+
begin
|
27
|
+
gem( 'slf4j', '~> 1.5' )
|
28
|
+
require 'slf4j'
|
29
|
+
require 'slf4j/nop'
|
30
|
+
rescue Gem::LoadError
|
31
|
+
end
|
32
|
+
|
33
|
+
require 'jetty'
|
34
|
+
require 'jetty/test-servlets'
|
35
|
+
require 'test/unit'
|
36
|
+
require 'net/http'
|
37
|
+
|
38
|
+
class TestJetty < Test::Unit::TestCase
|
39
|
+
|
40
|
+
def default_factory
|
41
|
+
factory = Jetty::ServerFactory.new
|
42
|
+
factory.max_threads = 1
|
43
|
+
factory.stop_at_shutdown = false
|
44
|
+
factory
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_start_stop
|
48
|
+
10.times do
|
49
|
+
factory = default_factory
|
50
|
+
factory.static_contexts[ '/' ] = TEST_DIR
|
51
|
+
server = factory.create
|
52
|
+
server.start
|
53
|
+
assert( server.is_started )
|
54
|
+
assert( server.connectors[0].local_port > 0 )
|
55
|
+
server.stop
|
56
|
+
assert( server.is_stopped )
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_static_context
|
61
|
+
factory = default_factory
|
62
|
+
factory.static_contexts[ '/' ] = TEST_DIR
|
63
|
+
server = factory.create
|
64
|
+
server.start
|
65
|
+
port = server.connectors[0].local_port
|
66
|
+
test_text = Net::HTTP.get( 'localhost', '/test.txt', port )
|
67
|
+
assert_equal( File.read( File.join( TEST_DIR, 'test.txt' ) ), test_text )
|
68
|
+
server.stop
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
import 'org.mortbay.jetty.handler.AbstractHandler'
|
73
|
+
class TestHandler < AbstractHandler
|
74
|
+
TEST_TEXT = 'test handler text'
|
75
|
+
|
76
|
+
def handle( target, request, response, dispatch )
|
77
|
+
response.content_type = "text/plain"
|
78
|
+
response.writer.write( TEST_TEXT )
|
79
|
+
request.handled = true
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
def test_custom_handler
|
85
|
+
factory = default_factory
|
86
|
+
def factory.create_pre_handlers
|
87
|
+
super << TestHandler.new
|
88
|
+
end
|
89
|
+
server = factory.create
|
90
|
+
server.start
|
91
|
+
port = server.connectors[0].local_port
|
92
|
+
assert_equal( TestHandler::TEST_TEXT,
|
93
|
+
Net::HTTP.get( 'localhost', '/whatever', port ) )
|
94
|
+
server.stop
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
import 'javax.servlet.http.HttpServlet'
|
99
|
+
class TestServlet < HttpServlet
|
100
|
+
def initialize( text )
|
101
|
+
super()
|
102
|
+
@text = text
|
103
|
+
end
|
104
|
+
|
105
|
+
def doGet( request, response )
|
106
|
+
response.content_type = "text/plain"
|
107
|
+
response.writer.write( @text )
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_servlet_handler
|
112
|
+
factory = default_factory
|
113
|
+
factory.set_context_servlets( '/some',
|
114
|
+
{ '/test' => TestServlet.new( 'resp-test' ),
|
115
|
+
'/other' => TestServlet.new( 'resp-other' ) } )
|
116
|
+
|
117
|
+
factory.set_context_servlets( '/',
|
118
|
+
{ '/one' => TestServlet.new( 'resp-one' ),
|
119
|
+
'/snoop' => Jetty::TestServlets::SnoopServlet.new } )
|
120
|
+
|
121
|
+
server = factory.create
|
122
|
+
server.start
|
123
|
+
port = server.connectors[0].local_port
|
124
|
+
|
125
|
+
assert_equal( 'resp-test',
|
126
|
+
Net::HTTP.get( 'localhost', '/some/test', port ) )
|
127
|
+
assert_equal( 'resp-other',
|
128
|
+
Net::HTTP.get( 'localhost', '/some/other', port ) )
|
129
|
+
assert_equal( 'resp-one',
|
130
|
+
Net::HTTP.get( 'localhost', '/one', port ) )
|
131
|
+
|
132
|
+
response = Net::HTTP.get_response( 'localhost', '/', port )
|
133
|
+
assert( response.is_a?( Net::HTTPNotFound ) )
|
134
|
+
|
135
|
+
response = Net::HTTP.get_response( 'localhost', '/snoop', port )
|
136
|
+
assert( response.is_a?( Net::HTTPSuccess ) )
|
137
|
+
|
138
|
+
server.stop
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_webapp
|
142
|
+
factory = default_factory
|
143
|
+
index_html = File.read(
|
144
|
+
File.join( Jetty::TestServlets::WEBAPP_TEST_EXPANDED, 'index.html' ) )
|
145
|
+
|
146
|
+
factory.webapp_contexts[ '/test' ] = Jetty::TestServlets::WEBAPP_TEST_WAR
|
147
|
+
factory.webapp_contexts[ '/expanded' ] = Jetty::TestServlets::WEBAPP_TEST_EXPANDED
|
148
|
+
|
149
|
+
server = factory.create
|
150
|
+
server.start
|
151
|
+
port = server.connectors[0].local_port
|
152
|
+
|
153
|
+
assert_equal( index_html, Net::HTTP.get( 'localhost', '/test/', port ) )
|
154
|
+
assert_equal( index_html, Net::HTTP.get( 'localhost', '/expanded/', port ) )
|
155
|
+
|
156
|
+
response = Net::HTTP.get_response( 'localhost', '/test/snoop/info?i=33', port )
|
157
|
+
assert( response.is_a?( Net::HTTPSuccess ) )
|
158
|
+
|
159
|
+
server.stop
|
160
|
+
end
|
161
|
+
end
|
data/webapps/test.war
ADDED
Binary file
|
@@ -0,0 +1,28 @@
|
|
1
|
+
<!DOCTYPE web-app PUBLIC
|
2
|
+
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
|
3
|
+
"http://java.sun.com/dtd/web-app_2_3.dtd" >
|
4
|
+
|
5
|
+
<web-app>
|
6
|
+
<display-name>Gravitext Test Webapp</display-name>
|
7
|
+
|
8
|
+
<servlet>
|
9
|
+
<servlet-name>PerfTest</servlet-name>
|
10
|
+
<servlet-class>com.gravitext.testservlets.PerfTestServlet</servlet-class>
|
11
|
+
</servlet>
|
12
|
+
|
13
|
+
<servlet>
|
14
|
+
<servlet-name>Snoop</servlet-name>
|
15
|
+
<servlet-class>com.gravitext.testservlets.SnoopServlet</servlet-class>
|
16
|
+
</servlet>
|
17
|
+
|
18
|
+
<servlet-mapping>
|
19
|
+
<servlet-name>PerfTest</servlet-name>
|
20
|
+
<url-pattern>/perf</url-pattern>
|
21
|
+
</servlet-mapping>
|
22
|
+
|
23
|
+
<servlet-mapping>
|
24
|
+
<servlet-name>Snoop</servlet-name>
|
25
|
+
<url-pattern>/snoop/*</url-pattern>
|
26
|
+
</servlet-mapping>
|
27
|
+
|
28
|
+
</web-app>
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
3
|
+
requirements:
|
4
|
+
- - '>='
|
5
|
+
- !ruby/object:Gem::Version
|
6
|
+
version: "0"
|
7
|
+
version:
|
8
|
+
email:
|
9
|
+
- dek-ruby@gravitext.com
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
summary: 'A gem packaging of the {Jetty Web Server}[http://www.mortbay.org/jetty/] for
|
13
|
+
JRuby: * Provides jetty, jetty-util, servlet-api, and jetty-rewrite-handler jars'
|
14
|
+
post_install_message:
|
15
|
+
extra_rdoc_files:
|
16
|
+
- History.txt
|
17
|
+
- Manifest.txt
|
18
|
+
- README.txt
|
19
|
+
homepage: http://rjack.rubyforge.org
|
20
|
+
signing_key:
|
21
|
+
name: jetty
|
22
|
+
rdoc_options:
|
23
|
+
- --main
|
24
|
+
- README.txt
|
25
|
+
autorequire:
|
26
|
+
rubyforge_project: rjack
|
27
|
+
executables:
|
28
|
+
- jetty-service
|
29
|
+
description: 'A gem packaging of the {Jetty Web Server}[http://www.mortbay.org/jetty/] for
|
30
|
+
JRuby: * Provides jetty, jetty-util, servlet-api, and jetty-rewrite-handler jars.
|
31
|
+
* A Jetty::ServerFactory for simple programmatic server setup in ruby. * A set
|
32
|
+
of Jetty::TestServlets containing a SnoopServlet and PerfTestServlet (implemented
|
33
|
+
in Java). * A jetty-service bin script for easy testing from the command line. Note
|
34
|
+
that JSP support is provided separately in the companion jetty-jsp[http://rjack.rubyforge.org/jetty-jsp/]
|
35
|
+
gem.'
|
36
|
+
specification_version: 2
|
37
|
+
default_executable:
|
38
|
+
files:
|
39
|
+
- History.txt
|
40
|
+
- Manifest.txt
|
41
|
+
- README.txt
|
42
|
+
- Rakefile
|
43
|
+
- pom.xml
|
44
|
+
- assembly.xml
|
45
|
+
- bin/jetty-service
|
46
|
+
- lib/jetty.rb
|
47
|
+
- lib/jetty/base.rb
|
48
|
+
- lib/jetty/rewrite.rb
|
49
|
+
- lib/jetty/test-servlets.rb
|
50
|
+
- src/main/java/com/gravitext/testservlets/PerfTestServlet.java
|
51
|
+
- src/main/java/com/gravitext/testservlets/SnoopServlet.java
|
52
|
+
- test/test_jetty.rb
|
53
|
+
- webapps/test.war
|
54
|
+
- webapps/test/WEB-INF/web.xml
|
55
|
+
- webapps/test/index.html
|
56
|
+
- lib/jetty/jetty-6.1.11.jar
|
57
|
+
- lib/jetty/jetty-util-6.1.11.jar
|
58
|
+
- lib/jetty/jetty-rewrite-handler-6.1.11.jar
|
59
|
+
- lib/jetty/servlet-api-2.5-6.1.11.jar
|
60
|
+
- lib/jetty/gravitext-testservlets-1.0.jar
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: "0"
|
66
|
+
version:
|
67
|
+
extensions: []
|
68
|
+
|
69
|
+
rubygems_version: 1.3.1
|
70
|
+
requirements: []
|
71
|
+
|
72
|
+
authors:
|
73
|
+
- David Kellum
|
74
|
+
date: 2008-11-03 08:00:00 +00:00
|
75
|
+
platform: ruby
|
76
|
+
test_files:
|
77
|
+
- test/test_jetty.rb
|
78
|
+
version: !ruby/object:Gem::Version
|
79
|
+
version: 6.1.11.1
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
dependencies:
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 1.8.2
|
89
|
+
version:
|
90
|
+
type: :development
|
91
|
+
version_requirement:
|
92
|
+
name: hoe
|
93
|
+
bindir: bin
|
94
|
+
has_rdoc: true
|