summaryrefslogtreecommitdiffstats
path: root/lib/puppet/server/servlet.rb
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2005-08-23 16:55:24 +0000
committerLuke Kanies <luke@madstop.com>2005-08-23 16:55:24 +0000
commitf68fe0045d3519d545d8e63b7ee470ece74fcc3f (patch)
treeb945d424aa203553d44e82c220724eb374074c47 /lib/puppet/server/servlet.rb
parent129dad73edf2307a36f88c563a347417f75bcc12 (diff)
downloadpuppet-f68fe0045d3519d545d8e63b7ee470ece74fcc3f.tar.gz
puppet-f68fe0045d3519d545d8e63b7ee470ece74fcc3f.tar.xz
puppet-f68fe0045d3519d545d8e63b7ee470ece74fcc3f.zip
moving all server handlers into a specific server subdirectory
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@579 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/server/servlet.rb')
-rw-r--r--lib/puppet/server/servlet.rb112
1 files changed, 112 insertions, 0 deletions
diff --git a/lib/puppet/server/servlet.rb b/lib/puppet/server/servlet.rb
new file mode 100644
index 000000000..4db9f6c0e
--- /dev/null
+++ b/lib/puppet/server/servlet.rb
@@ -0,0 +1,112 @@
+require 'xmlrpc/server'
+
+module Puppet
+class Server
+ class ServletError < RuntimeError; end
+ class Servlet < XMLRPC::WEBrickServlet
+ attr_accessor :request
+
+ # this is just a duplicate of the normal method; it's here for
+ # debugging when i need it
+ def self.get_instance(server, *options)
+ self.new(server, *options)
+ end
+
+ def initialize(server, handlers)
+ #Puppet.info server.inspect
+
+ # the servlet base class does not consume any arguments
+ # and its BasicServer base class only accepts a 'class_delim'
+ # option which won't change in Puppet at all
+ # thus, we don't need to pass any args to our base class,
+ # and we can consume them all ourselves
+ super()
+
+ handlers.each { |handler|
+ Puppet.debug "adding handler for %s" % handler.class
+ self.add_handler(handler.class.interface, handler)
+ }
+
+ @request = nil
+ self.set_service_hook { |obj, *args|
+ #raise "crap!"
+ if @request
+ args.push @request
+ #obj.call(args, @request)
+ end
+ begin
+ obj.call(*args)
+ rescue => detail
+ Puppet.warning obj.inspect
+ Puppet.err "Could not call: %s" % detail.to_s
+ end
+ }
+ end
+
+ def service(request, response)
+ @request = request
+ if @request.client_cert
+ Puppet.info "client cert is %s" % @request.client_cert
+ end
+ if @request.server_cert
+ Puppet.info "server cert is %s" % @request.server_cert
+ end
+ #p @request
+ begin
+ super
+ rescue => detail
+ Puppet.err "Could not service request: %s: %s" %
+ [detail.class, detail]
+ end
+ @request = nil
+ end
+
+ private
+
+ # this is pretty much just a copy of the original method but with more
+ # feedback
+ def dispatch(methodname, *args)
+ #Puppet.warning "dispatch on %s called with %s" %
+ # [methodname, args.inspect]
+ for name, obj in @handler
+ if obj.kind_of? Proc
+ unless methodname == name
+ Puppet.debug "obj is proc but %s != %s" %
+ [methodname, name]
+ next
+ end
+ else
+ unless methodname =~ /^#{name}(.+)$/
+ Puppet.debug "methodname did not match"
+ next
+ end
+ unless obj.respond_to? $1
+ Puppet.debug "methodname does not respond to %s" % $1
+ next
+ end
+ obj = obj.method($1)
+ end
+
+ if check_arity(obj, args.size)
+ if @service_hook.nil?
+ return obj.call(*args)
+ else
+ return @service_hook.call(obj, *args)
+ end
+ else
+ Puppet.debug "arity is incorrect"
+ end
+ end
+
+ if @default_handler.nil?
+ raise XMLRPC::FaultException.new(
+ ERR_METHOD_MISSING,
+ "Method #{methodname} missing or wrong number of parameters!"
+ )
+ else
+ @default_handler.call(methodname, *args)
+ end
+ end
+ end
+end
+end