def call env
      path = env[PATH_INFO]
      if path.end_with?('.mta') and (body = env[BODY].read).length != 0 and env[METHOD] == POST
        # replace ".mta" with ".json"
        env[PATH_INFO] = path[0..-5] + '.json'

        json = JSON.parse body
        raise Exception, "Number of JSON elements > 2: actual #{json.size}" if json.size > 2

        # optional options!
        update_options env, json[1].with_indifferent_access if json.size >= 2

        verify_request_method env

        # any parameters given? otherwise we don't really care for any params
        update_params env, json[0] if json.size >= 1 and json[0] != 0 # 0 is nil in terms of callRemote. JSON has 'null' though!

        # add some CSRF info... maybe.
        add_csrf_info env

        # call the other middlewares
        status, headers, response = @app.call(env)

        # alter only successful status codes to be more mta-ish
        if (200..299).include?(status)
          # mta /can/ handle multiple parameters as response.
          # We do not want and/or need this, but merely wrap the response body in square brackets as to return a single element
          # If render :json => @obj is used in the controller, this should make exactly @obj available in MTA.
          response = to_response(response, headers)

          # overwrite the length if already set
          if headers['Content-Length']
            headers['Content-Length'] = response.length
          end
        end

        return [status, headers, response]
      else
        # normal call, nevermind that whole mta business
        @app.call(env)
      end
    end
def call env
      path = env[PATH_INFO]
      if path.end_with?('.mta') and (body = env[BODY].read).length != 0 and env[METHOD] == POST
        # replace ".mta" with ".json"
        env[PATH_INFO] = path[0..-5] + '.json'

        json = JSON.parse body
        raise Exception, "Number of JSON elements > 2: actual #{json.size}" if json.size > 2

        # optional options!
        update_options env, json[1].with_indifferent_access if json.size >= 2

        verify_request_method env

        # any parameters given? otherwise we don't really care for any params
        update_params env, json[0] if json.size >= 1 and json[0] != 0 # 0 is nil in terms of callRemote. JSON has 'null' though!

        # add some CSRF info... maybe.
        add_csrf_info env

        # call the other middlewares
        status, headers, response = @app.call(env)

        # alter only successful status codes to be more mta-ish
        if (200..299).include?(status)
          # mta /can/ handle multiple parameters as response.
          # We do not want and/or need this, but merely wrap the response body in square brackets as to return a single element
          # If render :json => @obj is used in the controller, this should make exactly @obj available in MTA.
          response = to_response(response, headers)

          # overwrite the length if already set
          if headers['Content-Length']
            headers['Content-Length'] = response.length
          end
        end

        return [status, headers, response]
      else
        # normal call, nevermind that whole mta business
        @app.call(env)
      end
    end
callRemote on the MTA-side may have [0, 1 or 2] parameter(s):
 * if no parameters, params[...] is empty within rails
 * first parameter - as a table - fills the params[...] hash which is accessible in controllers (etc)
   i.e.
     callRemote("http://localhost/auth.mta", function, { name = 'a', password = 'b' })
   makes the following parameters available in the called controller
     params[:name] = 'a'
     params[:password] = 'b'
 * second parameter - as a table - options on how the request is handled. See update_options for details,
   for example { 'method' = 'GET' } allows GET-Requests, while usually callRemote does only POST-Requests.

 This is unlike the PHP-SDK, which may have multiple parameters and allows access via numbers
   $input = mta::getInput();
   $name = $input[0];
   $password = $input[1];
 Rails has named parameters, so there's no explicit support for them numbers.

 callRemote for MTA should always call files ending with .mta, for example:
 * /auth => /auth.mta

 This will call the related JSON-Methods, i.e.
   respond_to do |format|
     format.html { ... } # certainly not this
     format.json { render :json => @object } # this gets called!
   end

 There is no support for elements and/or resources (yet?).