1 Reply Latest reply on Sep 25, 2012 6:11 PM by Nick Peng

    RhoController search callback return encoding questions?

    Nick Peng

      I have two language encoding issues on non-English languages

       

      Question 1: Send param but Callback return parameter encoding error

      After I use search callback to send Chinese param, I received results non-I was originally left out of the parameters string.

      #!/usr/bin/env ruby -w
      # encoding: UTF-8

      class IncomingShipmentController < Rho::RhoController

        def process
             
          urlparam = Rho::RhoSupport.url_encode("測試")
          puts "urlparam  = #{urlparam}"

          IncomingShipment.search(
          :from => 'search',
          :search_params => {
            :state => 'done'
          },
          :callback => url_for(:action => :process_callback),
          :callback_param => "name=#{urlparam}"
          )

          @response['headers']['Wait-Page'] = 'true'
          render :action => :wait
        end

        def process_callback
          puts "process_callback @params=#{@params}"

          name = @params['name']   

          puts "name = #{name}"
          name2 = Rho::RhoSupport.url_decode(name)
          puts "name2 = #{name2}"   

       

          k1 = {"sync_type"=>"incremental", "status"=>"error", "error_code"=>"8", "error_message"=>"", "server_errors"=>{"search-error"=>{"message"=>"\"warning -- %0-17%0-74%0-51%0-18%0-56%0-5c

      %0-11%0-44%0-7f\\n\\n%0-1c%0-48%0-73%0-18%0-7d%0-43%0-18%0-67%0-6b%0-19%0-70%0-7a%0-1a%0-71%0-70%0-18%0-4e%0-58%0-11%0-44%0-74%0-1b%0-65%0-60%0-19%0-7c%0-5f%0-1b%0-46%0-55%0-1b%0-53%0-68%0

      -18%0-56%0-41%0-1b%0-75%0-6b\""}}, "rho_callback"=>"1", "name"=>"\u6E2C\u8A66", "search_params"=>{"state"=>"done"}}
          name3 = k1['name']
          puts "name3 = #{name3}"

         end

      end

       

      #run process_callback outpot:
      process_callback @params={"sync_type"=>"incremental", "status"=>"error", "error_code"=>"8", "error_message"=>"", "server_errors"=>{"search-error"=>{"message"=>"\"warning -- %0-17%0-74%0-

      51%0-18%0-56%0-5c%0-11%0-44%0-7f\\n\\n%0-1c%0-48%0-73%0-18%0-7d%0-43%0-18%0-67%0-6b%0-19%0-70%0-7a%0-1a%0-71%0-70%0-18%0-4e%0-58%0-11%0-44%0-74%0-1b%0-65%0-60%0-19%0-7c%0-5f%0-1b%0-46%0-

      55%0-1b%0-53%0-68%0-18%0-56%0-41%0-1b%0-75%0-6b\""}}, "rho_callback"=>"1", "name"=>"\u6E2C\u8A66", "search_params"=>{"state"=>"done"}}
      I 09/14/2012 15:44:34:874 000027b8                  APP| name = 皜祈岫
      E 09/14/2012 15:44:34:874 000027b8               RubyVM| C:/MotorolaRhoMobileSuite2.0.5/ruby/lib/ruby/gems/1.9.1/gems/rhodes-3.3.3/lib/framework/rho/rhosupport.rb:77: warning: regexp match

      /.../n against to UTF-8 string
      I 09/14/2012 15:44:34:874 000027b8                  APP| name2 = 皜祈岫
      I 09/14/2012 15:44:34:874 000027b8                  APP| name3 = 皜祈岫

       

      The correct result should be "測試"

      Why become "皜祈岫"?

       

      I directly use Ruby implementation is correct, but I through the results of the RhoMobile is wrong

       


      Question 2: RhoConnect return error encoding error

       

      IncomingShipment.search use RhoConnect SourceAdapter search method

       

      #RhoConnect

      #!/usr/bin/env ruby -w

      # encoding: UTF-8

      class IncomingShipment < SourceAdapter

        def search(params)
          #use xmlrpc to call webservices
          ws = CallXMLRPC.new
          puts "search params = #{params}"
          updated_status = ws.picking_validate(params)
        end

      end

       

      When an error occurs, RhoMobile @params error message made coding errors
      #RhoMobile

      search_err = @params['server_errors']['search-error']
      The correct result should be "warning -- 錯誤!\n\n不能處理提貨,因無庫存調動"
      Why become "\"warning -- %0-17%0-74%0-51%0-18%0-56%0-5c%0-11%0-44%0-7f\\n\\n%0-1c%0-48%0-73%0-18%0-7d%0-43%0-18%0-67%0-6b%0-19%0-70%0-7a%0-1a%0-71%0-70%0-18%0-4e%0-58%0-11%0-44%0-74%0-1b%0

      -65%0-60%0-19%0-7c%0-5f%0-1b%0-46%0-55%0-1b%0-53%0-68%0-18%0-56%0-41%0-1b%0-75%0-6b\""

       

      If I directly use Ruby implementation of WebService is correct, but I through the results of the RhoConnect in RhoMobile is wrong

       


        • Re: RhoController search callback return encoding questions?
          Nick Peng

          I solved it by myself.

           

          Question 1: Send param but Callback return parameter encoding error

          =>Answer: use RhoStudio 2.1.1.7

           

          Question 2: RhoConnect return error encoding error

          =>Answer: RhoConnect SourceAdapter Exception use CGI.escape(e.message) to return

                           RhoMobile Controller use Rho::RhoSupport.url_decode(err) to parser server_errors

          1 of 1 people found this helpful