 
 (defn- handle-invoke [operation]
   (fn [request]
-    (jmx/with-connection {:host @jmx-remote-host :port @jmx-remote-port}
+    (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])]


(defonce server (atom nil))

(defonce object-pattern (atom "java.lang:*"))

(defonce jmx-remote-host (atom "localhost"))

(defonce jmx-remote-port (atom 1080))

(defn- handle-describe [operation]
  (fn [request]
    (jmx/with-connection {:host @jmx-remote-host :port @jmx-remote-port}
      (let [mbean (get-in request [:params :bean])
            op (keyword operation)]
        (doall (describe mbean op))))))

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

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