Sha256: fb95d02a7e5273a8e81c1c435c1d26d2730e97ca808200f4c5e59cbce8edb455

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

class WashOutFork::Middleware
  def initialize app
    @app = app
  end

  def call env
    begin
      @app.call env
    rescue REXML::ParseException => e
      self.class.raise_or_render_rexml_parse_error e, env
    end
  end

  def self.raise_or_render_rexml_parse_error e, env
    raise e unless env.has_key? 'HTTP_SOAPACTION'
  
    # Normally input would be a StringIO, but Passenger has a different API:
    input = env['rack.input']
    req = if input.respond_to? :string then input.string else input.read end

    env['rack.errors'].puts <<-EOERR
WashOutFork::Exception: #{e.continued_exception} for:
#{req}
    EOERR
    [400, {'Content-Type' => 'text/xml'},
      [render_client_soap_fault("Error parsing SOAP Request XML")]]
  end

  def self.render_client_soap_fault msg
    xml = Builder::XmlMarkup.new
    xml.tag! 'soap:Envelope', 'xmlns:soap' => 'http://schemas.xmlsoap.org/soap/envelope/',
      'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance' do
        xml.tag! 'soap:Body' do
          xml.tag! 'soap:Fault', :encodingStyle => 'http://schemas.xmlsoap.org/soap/encoding/' do
            xml.faultcode 'Client'
            xml.faultstring msg
          end
        end
      end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wash_out_fork-0.0.1 lib/wash_out_fork/middleware.rb