 
 (defn- handle-list-beans []
   (fn [request]
-    (jmx/with-connection {:host @jmx-remote-host :port @jmx-remote-port}
-      (doall (list-beans @object-pattern)))))
+    (jmx/with-connection (get-connection-map)
+      (doall (list-beans (:object-pattern @config))))))
 
 (defroutes app-routes
   (GET "/list" [] (handle-list-beans))

      (wrap-json-response)
      (wrap-defaults api-defaults)))

(defn- reset-if-set [config key atom]
  (when-let [value (key config)]
    (reset! atom value)))

(defn -main [& args]
  (when-let [config-file-path (first args)]
    (let [config (edn/read-string (slurp config-file-path))]
      (reset-if-set config :object-pattern object-pattern)
      (reset-if-set config :jmx-remote-host jmx-remote-host)
      (reset-if-set config :jmx-remote-port jmx-remote-port)))
  (reset! server (run-server app {:port 0}))
  (with-open [my-writer (writer "/var/tmp/mbeanz.port")]
    (.write my-writer (str (:local-port (meta @server))))))


(defn- handle-invoke [operation]
  (fn [request]
    (jmx/with-connection (get-connection-map)
      (let [mbean (get-in request [:params :bean])
            args (get-in request [:params :args])
            types (get-in request [:params :types])]
