       (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)))
+  (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))))))


(defn- handle-list-beans []
  (fn [request]
    (jmx/with-connection {:host @jmx-remote-host :port @jmx-remote-port}
      (doall (list-beans @object-pattern)))))

(defroutes app-routes
  (GET "/list" [] (handle-list-beans))


(defonce server (atom nil))

(defonce config (atom {:object-pattern "java.lang:*"
                       :jmx-remote-host "localhost"
                       :jmx-remote-port 11080}))

(defn- get-connection-map []
  {:host (:jmx-remote-host @config) :port (:jmx-remote-port @config)})

(defn- handle-describe [operation]
  (fn [request]
    (jmx/with-connection (get-connection-map)
      (let [mbean (get-in request [:params :bean])
            op (keyword operation)]
        (doall (describe mbean op))))))
