SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast thebasti's Avatar
    Join Date
    Aug 2004
    Location
    Novi Sad, Serbia
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    System call different when calling from controller and from console

    Hello,

    I have a problem with making a system call to a Java program via Rails. When I call it through controller it doesn't seem to work, but when I do the same thing in console it works perfectly.

    There are two models Order and Payment (Order has one Payment). Payment model that has following method:

    Code Ruby:
    def transaction_register()
      output_raw = `java -jar #{JAR} #{MERCHANT} -a #{(self.amount*100).to_i.to_s} #{CURRENCY} #{self.ip_address}`
     
      output = YAML.parse output_raw
      # ...removed rest of the code...
    end
    It runs a Java program that should contact the payment gateway and return transaction information. It is called in controller like this (some code removed for clarity):

    Code Ruby:
    def save_order
      order = Order.new
      order.order_items << @cart.items
      order.payment = Payment.new
      order.payment.ip_address = request.env["REMOTE_ADDR"]
      order.payment.amount = order.total_cost
      order.payment.transaction_register
     
      # ...removed rest of the code...
    end

    The problem is that when this code is run through a controller it doesn't seem to execute, but when I do almost (I only fake ip_address) the same thing in console it works.

    Does anyone has any ideas what might be the problem?

    Thanks.
    "Strategy without tactics is the slowest route to victory.
    Tactics without strategy is the noise before defeat."
    - Sun Tzu
    Icebergist - a web dev blog | Orange Iceberg Web App Development

  2. #2
    SitePoint Addict ruby-lang's Avatar
    Join Date
    Aug 2007
    Posts
    389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It may be that java is in your PATH environment var when you run it from the console, but not when run from the webserver, with a different user.

    I'd try adding the whole path to your command line, for example `/usr/bin/java ...`.

  3. #3
    SitePoint Enthusiast thebasti's Avatar
    Join Date
    Aug 2004
    Location
    Novi Sad, Serbia
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. That helped.

    I should have thought of that sooner.
    "Strategy without tactics is the slowest route to victory.
    Tactics without strategy is the noise before defeat."
    - Sun Tzu
    Icebergist - a web dev blog | Orange Iceberg Web App Development

  4. #4
    SitePoint Addict ruby-lang's Avatar
    Join Date
    Aug 2007
    Posts
    389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That kind of thing is pretty hard to spot without a second, rested pair of eyes.

    I'm glad I could help.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •