title: sending data back in response after SOAP call
body: <p>So I would like to to this:</p>
  
  <ol>
  <li>receive a POST from external url in controller and capture data </li>
  <li>use this data in SOAP request; use response back from SOAP request to modify data and then </li>
  <li>send data back to external client in the response to external url in step 1.</li>
  </ol>
  
  <p>It seems I have some timing issues in my approach as the object returned to external client is empty. If I comment out my Savon code doing the SOAP call the object is complete. Here is the short version of what I am doing using Rails 3.0.9, Savon 0.9.7</p>
  
  <p>1) works great</p>
  
  <pre><code>#
  # get object from POST
  #
  string = request.body.read
  @myobject = ActiveSupport::JSON.decode(string)
  </code></pre>
  
  <p>2) also works great (leaving out most of Savon magic as response has precisely what it should)</p>
  
  <pre><code>...
  response = client.request :urn, "MySOAPOperation" do
  ...
  </code></pre>
  
  <p>3) Here is where I am a little "off"</p>
  
  <pre><code>response_hash =response.to_hash[:my_soap_operation_response]
  @myobject.status = response_hash[:status].to_s
  logger.info ("Status:    " + @myobject.status)
  #
  # at this point myobject updated values are confirmed in log
  #
  respond_to do |format|
     format.json { render :json =&gt; @myobject }
  end
  </code></pre>
  
  <p>Now the response is correctly forwarded back to Step 1. external client but with @myobject empty. If I comment out the SOAP request and response the full @myobject is sent along with response to the client. I am thinking this is a timing issue as I also obtained the same result by commenting out the SOAP request and adding </p>
  
  <pre><code>sleep 20 
  </code></pre>
  
  <p>in its place. Any suggestions will be greatly appreciated. Thank you for reading.</p>
  
  <p>Dan</p>