Pass thru backend query parameters
diff --git a/api-gateway-config/scripts/lua/lib/filemgmt.lua b/api-gateway-config/scripts/lua/lib/filemgmt.lua
index c8f7b85..3be5256 100644
--- a/api-gateway-config/scripts/lua/lib/filemgmt.lua
+++ b/api-gateway-config/scripts/lua/lib/filemgmt.lua
@@ -40,6 +40,7 @@
   local prefix = utils.concatStrings({"\tinclude /etc/api-gateway/conf.d/commons/common-headers.conf;\n",
                                       "\tset $upstream https://172.17.0.1;\n",
                                       "\tset $tenant ", tenant, ";\n",
+                                      "\tset $backendUrl '';\n",
                                       "\tset $gatewayPath ",  utils.concatStrings({"\"", ngx.unescape_uri(gatewayPath),
                                       "\""}), ";\n\n"})
   if decoded.apiId ~= nil then
diff --git a/api-gateway-config/scripts/lua/lib/utils.lua b/api-gateway-config/scripts/lua/lib/utils.lua
index a064037..fe49819 100644
--- a/api-gateway-config/scripts/lua/lib/utils.lua
+++ b/api-gateway-config/scripts/lua/lib/utils.lua
@@ -75,24 +75,6 @@
   return concatStrings({"(?<path_" , x , ">([a-zA-Z0-9\\-\\s\\_\\%]*))"})
 end
 
-
---- Convert JSON body to Lua table using the cjson module
--- @param args Lua table with its key as the string representation of a JSON body
--- @return Lua table representation of JSON
-function convertJSONBody(args)
-  local jsonStringList = {}
-  for key, value in pairs(args) do
-    table.insert(jsonStringList, key)
-    -- Handle case where the "=" character is inside any of the strings in the json body
-    if(value ~= true) then
-      table.insert(jsonStringList, concatStrings({"=", value}))
-    end
-  end
-  return cjson.decode(concatStrings(jsonStringList))
-end
-
-
-_Utils.convertJSONBody = convertJSONBody
 _Utils.concatStrings = concatStrings
 _Utils.serializeTable = serializeTable
 _Utils.convertTemplatedPathParam = convertTemplatedPathParam
diff --git a/api-gateway-config/scripts/lua/management.lua b/api-gateway-config/scripts/lua/management.lua
index ef7aad6..ada9f4a 100644
--- a/api-gateway-config/scripts/lua/management.lua
+++ b/api-gateway-config/scripts/lua/management.lua
@@ -55,12 +55,12 @@
 function _M.addResource()
   -- Read in the PUT JSON Body
   ngx.req.read_body()
-  local args = ngx.req.get_post_args()
+  local args = ngx.req.get_body_data()
   if not args then
     request.err(400, "Missing Request body")
   end
   -- Convert json into Lua table
-  local decoded = utils.convertJSONBody(args)
+  local decoded = cjson.decode(args)
   -- Error handling for required fields in the request body
   local gatewayMethod = decoded.gatewayMethod
   if not gatewayMethod then
diff --git a/api-gateway-config/scripts/lua/policies/mapping.lua b/api-gateway-config/scripts/lua/policies/mapping.lua
index 0ad97e3..a970bf4 100644
--- a/api-gateway-config/scripts/lua/policies/mapping.lua
+++ b/api-gateway-config/scripts/lua/policies/mapping.lua
@@ -24,7 +24,6 @@
 local logger = require "lib/logger"
 local utils = require "lib/utils"
 local cjson = require "cjson"
-local url = require "url"
 
 local _M = {}
 
@@ -54,13 +53,16 @@
 --- Get request body, params, and headers from incoming requests
 function getRequestParams()
   ngx.req.read_body()
-  body = ngx.req.get_post_args()
-  if next(body) then
-    body = utils.convertJSONBody(body)
-  end
-  query = ngx.req.get_uri_args()
+  body = ngx.req.get_body_data()
+  body = (body and cjson.decode(body)) or {}
   headers = ngx.req.get_headers()
   path = ngx.var.uri
+  query = parseUrl(ngx.var.backendUrl)
+  local incomingQuery = ngx.req.get_uri_args()
+  for k, v in pairs (incomingQuery) do
+    query[k] = v
+  end
+
 end
 
 --- Insert parameter value to header, body, or query params into request
@@ -174,6 +176,7 @@
 function finalize()
   local bodyJson = cjson.encode(body)
   ngx.req.set_body_data(bodyJson)
+  ngx.req.set_uri_args(query)
 end
 
 function insertHeader(k, v)
@@ -182,7 +185,6 @@
 
 function insertQuery(k, v)
   query[k] = v
-  ngx.req.set_uri_args(query)
 end
 
 function insertBody(k, v)
@@ -207,6 +209,20 @@
   body[k] = nil
 end
 
+function parseUrl(url)
+  local map = {}
+  for k,v in url:gmatch('([^&=?]+)=([^&=?]+)' ) do
+    map[ k ] = decodeQuery(v)
+  end
+  return map
+end
+
+function decodeQuery(param)
+  local decoded = param:gsub('+', ' '):gsub('%%(%x%x)',
+    function(hex) return string.char(tonumber(hex, 16)) end)
+  return decoded
+end
+
 _M.processMap = processMap
 
 return _M
\ No newline at end of file
diff --git a/api-gateway-config/scripts/lua/routing.lua b/api-gateway-config/scripts/lua/routing.lua
index 3278d16..aab80f5 100644
--- a/api-gateway-config/scripts/lua/routing.lua
+++ b/api-gateway-config/scripts/lua/routing.lua
@@ -54,6 +54,7 @@
       -- Parse backend url
       local u = url.parse(opFields.backendUrl)
       ngx.req.set_uri(getUriPath(u.path))
+      ngx.var.backendUrl = opFields.backendUrl
       -- Set upstream - add port if it's in the backendURL
       local upstream = utils.concatStrings({u.scheme, '://', u.host})
       if u.port ~= nil and u.port ~= '' then