 (defn load-polling-stores []
   (doall (map add-polling-store (storemodel/all))))
 
+(defn get-capabilities->layer-names [caps]
+  (let [layer-names (->> caps
+                         .getBytes
+                         java.io.ByteArrayInputStream.
+                         xml/parse
+                         :content
+                         (filter #(= :FeatureTypeList (:tag %)))
+                         first
+                         :content
+                         (filter #(= :FeatureType (:tag %)))
+                         (map #(first (:content (first (:content %))))))]
+    layer-names))
+
+(defn http-get-capabilities [context]
+  (let [url (get-in context [:query-params :url])
+        res (client/get (str url "?service=WFS&version=1.1.0&request=GetCapabilities"))
+        status (:status res)
+        body (:body res)]
+    (if (= status 200)
+      (response/ok (get-capabilities->layer-names body))
+      (response/error (str "Could not get capabilities from " url)))))
+
 (defn- routes [mqtt] #{["/api/stores" :get
                         (conj intercept/common-interceptors `http-get)]
                        ["/api/stores-error" :get

            [spacon.components.mqtt :as mqttapi]
            [spacon.entity.scmessage :as scm]
            [clojure.data.json :as json]
            [overtone.at-at :refer [every,mk-pool]])
  (:import (com.boundlessgeo.spatialconnect.schema SCCommand)))

(defn http-get [context]

                       ["/api/stores" :post
                        (conj intercept/common-interceptors (partial http-post-store mqtt)) :route-name :http-post-store]
                       ["/api/stores/:id" :delete
                        (conj intercept/common-interceptors (partial http-delete-store mqtt)) :route-name :http-delete-store]
                       ["/api/wfs/getCapabilities" :get
                        (conj intercept/common-interceptors `http-get-capabilities)]})

(defrecord StoreComponent [mqtt trigger]
  component/Lifecycle
