Class: SOAP::RPC::SOAPlet

Inherits:
WEBrick::HTTPServlet::AbstractServlet
  • Object
show all
Defined in:
lib/soap/rpc/soaplet.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(router = nil) ⇒ SOAPlet

Returns a new instance of SOAPlet.



46
47
48
49
50
51
# File 'lib/soap/rpc/soaplet.rb', line 46

def initialize(router = nil)
  @router = router || ::SOAP::RPC::Router.new(self.class.name)
  @options = {}
  @authenticator = nil
  @config = {}
end

Instance Attribute Details

#authenticatorObject

Returns the value of attribute authenticator.



44
45
46
# File 'lib/soap/rpc/soaplet.rb', line 44

def authenticator
  @authenticator
end

#optionsObject (readonly)

Returns the value of attribute options.



43
44
45
# File 'lib/soap/rpc/soaplet.rb', line 43

def options
  @options
end

Class Method Details

.cookiesObject



104
105
106
# File 'lib/soap/rpc/soaplet.rb', line 104

def self.cookies
  get_variable(:Cookies)
end

.cookies=(cookies) ⇒ Object



108
109
110
# File 'lib/soap/rpc/soaplet.rb', line 108

def self.cookies=(cookies)
  set_variable(:Cookies, cookies)
end

.userObject



112
113
114
# File 'lib/soap/rpc/soaplet.rb', line 112

def self.user
  get_variable(:User)
end

.user=(user) ⇒ Object



116
117
118
# File 'lib/soap/rpc/soaplet.rb', line 116

def self.user=(user)
  set_variable(:User, user)
end

Instance Method Details

#allow_content_encoding_gzip=(allow) ⇒ Object



53
54
55
# File 'lib/soap/rpc/soaplet.rb', line 53

def allow_content_encoding_gzip=(allow)
  @options[:allow_content_encoding_gzip] = allow
end

#do_GET(req, res) ⇒ Object

Raises:

  • (WEBrick::HTTPStatus::MethodNotAllowed)


69
70
71
72
# File 'lib/soap/rpc/soaplet.rb', line 69

def do_GET(req, res)
  res.header['Allow'] = 'POST'
  raise WEBrick::HTTPStatus::MethodNotAllowed, "GET request not allowed"
end

#do_POST(req, res) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/soap/rpc/soaplet.rb', line 74

def do_POST(req, res)
  logger.debug { "SOAP request: " + req.body } if logger
  if @authenticator
    @authenticator.authenticate(req, res)
    # you can check authenticated user with SOAP::RPC::SOAPlet.user
  end
  begin
    conn_data = ::SOAP::StreamHandler::ConnectionData.new
    setup_req(conn_data, req)
    @router.external_ces = @options[:external_ces]
    Mapping.protect_threadvars(:SOAPlet) do
      SOAPlet.user = req.user
      SOAPlet.cookies = req.cookies
      conn_data = @router.route(conn_data)
      setup_res(conn_data, req, res)
    end
  rescue Exception => e
    conn_data = @router.create_fault_response(e)
    res.status = WEBrick::HTTPStatus::RC_INTERNAL_SERVER_ERROR
    res.body = conn_data.send_string
    res['content-type'] = conn_data.send_contenttype || "text/xml"
  end
  if res.body.is_a?(IO)
    res.chunked = true
    logger.debug { "SOAP response: (chunked response not logged)" } if logger
  else
    logger.debug { "SOAP response: " + res.body } if logger
  end
end

#get_instance(config, *options) ⇒ Object

Servlet interfaces for WEBrick.



60
61
62
63
# File 'lib/soap/rpc/soaplet.rb', line 60

def get_instance(config, *options)
  @config = config
  self
end

#require_path_info?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/soap/rpc/soaplet.rb', line 65

def require_path_info?
  false
end