compojure

ring.middleware and compojure: params with keywords

感情迁移 提交于 2019-12-10 17:45:06
问题 In my web handler, I have the following defined: (:require ... [ring.middleware.cookies :refer [wrap-cookies]] [ring.middleware.multipart-params :refer [wrap-multipart-params]] [ring.middleware.params :refer [wrap-params]] [ring.middleware.keyword-params :refer [wrap-keyword-params]] [ring.middleware.content-type :refer [wrap-content-type]] [ring.middleware.format-response :refer [wrap-restful-response] ...) (def app (-> (routes home/my-routes) (wrap-cookies) (wrap-params) (wrap-multipart

Clojure + Compojure + Maven application doesn't work in Tomcat

本小妞迷上赌 提交于 2019-12-10 08:59:28
问题 I'm working on a simple web application written in Clojure, using the Compojure web application framework and Maven. This is a simplified version of my servlet: (ns core (:use compojure.core ring.util.servlet) (:require [compojure.route :as route]) (:gen-class :extends javax.servlet.http.HttpServlet)) (defroutes main-routes (GET "/" _ {:status 302 :headers {"Location" "/about"}}) (GET "/about" [] "This is the about page") (route/not-found "File not found.")) (defservice main-routes) This

How to get repeating request parameters in Compojure

泄露秘密 提交于 2019-12-10 03:59:43
问题 I can get to the request parameters easily with: (:foo params) However, when I have a request like this: /api?foo=1&foo=2&foo=3 I only get back "3" while I would expect an array ["1","2","3"] . I'm not sure why this is happening because when I look at the code in: https://github.com/ring-clojure/ring-codec/blob/master/src/ring/util/codec.clj#L128 It seems to call assoc-conj which is supposed to turn multiple params of the same name into a vector containing the values. Am I missing something

Combining routes in Compojure

前提是你 提交于 2019-12-10 01:31:59
问题 I have two different web applications in Clojure developed with Compojure. Each use defroutes to create its handler. How can I combine the two different definitions of defroutes into one defroute? I want to reuse the routes of the first app into the second. 回答1: You can use compojure.core/routes to combine routes: (def my-handler (routes some-handler some-other-handler)) 来源: https://stackoverflow.com/questions/8329173/combining-routes-in-compojure

Limiting the number of threads Compojure spawns

北城以北 提交于 2019-12-09 23:29:38
问题 I'm running compojure on Heroku. They have a limit of a 100 threads per process. So when I go over that limit, I get: java.lang.OutOfMemoryError: unable to create new native thread. Compojure is using the jetty ring adapter. Is there away of configuring the the server to only accept a hundred threads to the servlet at a time? 回答1: The solution comes from Chris Perkins over at the compojure google group. (run-jetty app {:configurator #(.setThreadPool % (QueuedThreadPool. 5))}) This initializes

Compojure: lein-ring in production?

让人想犯罪 __ 提交于 2019-12-09 18:03:01
问题 It seems that people sugget the use of lein-ring for a no-brainer deploy of a Compojure application. Isn't it just meant for development? I've benchmarked the same app running with lein-ring vs packed by leiningen with uberjar (executed with java -jar, it contains ring-jetty). To my surprise, the performance is even slightly better with lein-ring! Am I missing something? How can i keep on using lein-ring but avoid printing out stacktraces in case of exceptions and avoid checking for modified

http request from Google App Engine

折月煮酒 提交于 2019-12-08 02:13:29
问题 I'm trying to make http requests from my Google App Engine webapp, and discovered I have to use URLConnection since it's the only whitelisted class. The corresponding Clojure library is clojure.contrib.http.agent, and my code is as follows: (defroutes example (GET "/" [] (http/string (http/http-agent "http://www.example.com"))) (route/not-found "Page not found")) This works fine in my development environment- the browser displays the text for example.com. But when I test it out with Google's

No implementation of method: :make-reader of protocol: #'clojure.java.io/IOFactory found for class: nil

流过昼夜 提交于 2019-12-07 07:32:52
问题 I'm very new to Clojure and I'm having a great time playing with it. One thing I'm having some trouble with is how to read the errors, I personally think they're not very descriptive, but that's probably due to my "newbieness". For example, the issue I'm having now is when I try to start up my ring server (I can provide more details if needed): Started server on port 3000 java.lang.IllegalArgumentException: No implementation of method: :make-reader of protocol: #'clojure.java.io/IOFactory

Compojure handler friend/authenticate eats body of POST request

核能气质少年 提交于 2019-12-07 05:56:42
问题 How can I safely get the content of the :body InputStream from compojure? See related but different question for background. I'm trying to authenticate my ring routes with Friend using compojure handler/site but when I try to read the :body from an http POST request (which is a Java InputStream ), it is closed: 23:01:20.505 ERROR [io.undertow.request] (XNIO-1 task-3) Undertow request failed HttpServerExchange{ POST /paypal/ipn} java.io.IOException: UT000034: Stream is closed at io.undertow.io

Serving binary files from the database with compojure

守給你的承諾、 提交于 2019-12-07 03:56:00
问题 I have the following routes definition: (require '[compojure.core :as ccore] '[ring.util.response :as response]) (def *main-routes* (ccore/defroutes avalanche-routes (ccore/GET "/" [] "Hello World 2") (ccore/GET "/images/:id" [id] (get-image-response id)))) In this example, requesting / works like a charm and returns the expected Hello World 2 . The get-images-response method is defined like this: (defn get-image-response [id] (let [record (db/get-image id false)] (-> (response/response (