immutant https://www.e-learn.cn/tag/immutant zh-hans Clojure Immutant 2 server Undertow; how to handle http POST? https://www.e-learn.cn/topic/1946461 <span>Clojure Immutant 2 server Undertow; how to handle http POST?</span> <span><span lang="" about="/user/184" typeof="schema:Person" property="schema:name" datatype="">柔情痞子</span></span> <span>2019-12-07 23:13:58</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>Putting the following line into my <code>compojure</code> <code>defroutes</code> to use <code>clojure-paypal-ipn</code> calling the two handler functions.</p> <pre><code>(POST "/paypal/ipn" [] (make-ipn-handler payment/paypal-data payment/paypal-error)) </code></pre> <p>How do I handle a <code>POST</code> request within Immutant?</p> <p>I'm using Immutant 2.0 with Clojure 1.7-beta1 and building off the Immutant feature demo. Posting directly with cURL give these same results, although I'm trying to use PayPal IPN.</p> <pre><code>17:29:40.220 ERROR [io.undertow.request] (XNIO-1 task-1) Undertow request failed HttpServerExchange{ POST /paypal/ipn} java.io.IOException: mark/reset not supported at java.io.InputStream.reset(InputStream.java:348) ~[na:1.8.0_45] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_45] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_45] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_45] at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_45] at clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:93) ~[clojure-1.7.0-beta1.jar:na] at clojure.lang.Reflector.invokeNoArgInstanceMember(Reflector.java:313) ~[clojure-1.7.0-beta1.jar:na] at clojure_paypal_ipn.core$req__GT_raw_body_str.invoke(core.clj:59) ~[na:na] at clojure_paypal_ipn.core$make_ipn_handler$fn__16823.invoke(core.clj:69) ~[na:na] at compojure.response$eval6101$fn__6102.invoke(response.clj:34) ~[na:na] at compojure.response$eval6068$fn__6069$G__6059__6076.invoke(response.clj:7) ~[na:na] at compojure.core$make_route$fn__7513.invoke(core.clj:113) ~[na:na] at compojure.core$wrap_route_middleware$fn__7509.invoke(core.clj:103) ~[na:na] at compojure.core$if_route$fn__7488.invoke(core.clj:41) ~[na:na] at compojure.core$if_method$fn__7480.invoke(core.clj:27) ~[na:na] at compojure.core$routing$fn__7519.invoke(core.clj:127) ~[na:na] at clojure.core$some.invoke(core.clj:2568) ~[clojure-1.7.0-beta1.jar:na] at compojure.core$routing.doInvoke(core.clj:127) ~[na:na] at clojure.lang.RestFn.applyTo(RestFn.java:139) ~[clojure-1.7.0-beta1.jar:na] at clojure.core$apply.invoke(core.clj:630) ~[clojure-1.7.0-beta1.jar:na] at compojure.core$routes$fn__7523.invoke(core.clj:132) ~[na:na] at immutant.web.internal.undertow$wrap_undertow_session$fn__5292.invoke(undertow.clj:69) ~[na:na] at immutant.web.internal.undertow$create_http_handler$reify__5362.handleRequest(undertow.clj:130) ~[na:na] at org.projectodd.wunderboss.web.async.websocket.UndertowWebsocket$2.handleRequest(UndertowWebsocket.java:96) ~[wunderboss-web-0.6.1.jar:na] at io.undertow.server.session.SessionAttachmentHandler.handleRequest(SessionAttachmentHandler.java:68) ~[undertow-core-1.1.0.Final.jar:1.1.0.Final] at io.undertow.server.Connectors.executeRootHandler(Connectors.java:197) ~[undertow-core-1.1.0.Final.jar:1.1.0.Final] at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:759) ~[undertow-core-1.1.0.Final.jar:1.1.0.Final] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_45] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_45] at java.lang.Thread.run(Thread.java:745) [na:1.8.0_45] </code></pre> <br /><h3>回答1:</h3><br /><p>I don't think this is necessarily a problem with Immutant handling a POST. The problem occurs during the dispatch to the IPN handler, which is attempting to invoke <code>reset</code> on Undertow's <code>InputStream</code>. I would expect the stream's <code>markSupported</code> method to return false. It's not clear to me why reset is being called here, since it doesn't appear <code>mark</code> is ever called. Without being familiar with that library, I might suggest buffering the input somehow... maybe invoke <code>parse-paypal-ipn-string</code> directly? I'm really just guessing, though. </p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/29834778/clojure-immutant-2-server-undertow-how-to-handle-http-post</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/clojure" hreflang="zh-hans">clojure</a></div> <div class="field--item"><a href="/tag/http-post" hreflang="zh-hans">http-post</a></div> <div class="field--item"><a href="/tag/paypal-ipn" hreflang="zh-hans">paypal-ipn</a></div> <div class="field--item"><a href="/tag/undertow" hreflang="zh-hans">undertow</a></div> <div class="field--item"><a href="/tag/immutant" hreflang="zh-hans">immutant</a></div> </div> </div> Sat, 07 Dec 2019 15:13:58 +0000 柔情痞子 1946461 at https://www.e-learn.cn Clojure Immutant 2 server Undertow; how to handle http POST? https://www.e-learn.cn/topic/1798243 <span>Clojure Immutant 2 server Undertow; how to handle http POST?</span> <span><span lang="" about="/user/107" typeof="schema:Person" property="schema:name" datatype="">守給你的承諾、</span></span> <span>2019-12-06 06:01:30</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><div class="alert alert-danger" role="alert"> <p>Putting the following line into my <code>compojure</code> <code>defroutes</code> to use <code>clojure-paypal-ipn</code> calling the two handler functions.</p> <pre><code>(POST "/paypal/ipn" [] (make-ipn-handler payment/paypal-data payment/paypal-error)) </code></pre> <p>How do I handle a <code>POST</code> request within Immutant?</p> <p>I'm using Immutant 2.0 with Clojure 1.7-beta1 and building off the Immutant feature demo. Posting directly with cURL give these same results, although I'm trying to use PayPal IPN.</p> <pre><code>17:29:40.220 ERROR [io.undertow.request] (XNIO-1 task-1) Undertow request failed HttpServerExchange{ POST /paypal/ipn} java.io.IOException: mark/reset not supported at java.io.InputStream.reset(InputStream.java:348) ~[na:1.8.0_45] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_45] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_45] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_45] at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_45] at clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:93) ~[clojure-1.7.0-beta1.jar:na] at clojure.lang.Reflector.invokeNoArgInstanceMember(Reflector.java:313) ~[clojure-1.7.0-beta1.jar:na] at clojure_paypal_ipn.core$req__GT_raw_body_str.invoke(core.clj:59) ~[na:na] at clojure_paypal_ipn.core$make_ipn_handler$fn__16823.invoke(core.clj:69) ~[na:na] at compojure.response$eval6101$fn__6102.invoke(response.clj:34) ~[na:na] at compojure.response$eval6068$fn__6069$G__6059__6076.invoke(response.clj:7) ~[na:na] at compojure.core$make_route$fn__7513.invoke(core.clj:113) ~[na:na] at compojure.core$wrap_route_middleware$fn__7509.invoke(core.clj:103) ~[na:na] at compojure.core$if_route$fn__7488.invoke(core.clj:41) ~[na:na] at compojure.core$if_method$fn__7480.invoke(core.clj:27) ~[na:na] at compojure.core$routing$fn__7519.invoke(core.clj:127) ~[na:na] at clojure.core$some.invoke(core.clj:2568) ~[clojure-1.7.0-beta1.jar:na] at compojure.core$routing.doInvoke(core.clj:127) ~[na:na] at clojure.lang.RestFn.applyTo(RestFn.java:139) ~[clojure-1.7.0-beta1.jar:na] at clojure.core$apply.invoke(core.clj:630) ~[clojure-1.7.0-beta1.jar:na] at compojure.core$routes$fn__7523.invoke(core.clj:132) ~[na:na] at immutant.web.internal.undertow$wrap_undertow_session$fn__5292.invoke(undertow.clj:69) ~[na:na] at immutant.web.internal.undertow$create_http_handler$reify__5362.handleRequest(undertow.clj:130) ~[na:na] at org.projectodd.wunderboss.web.async.websocket.UndertowWebsocket$2.handleRequest(UndertowWebsocket.java:96) ~[wunderboss-web-0.6.1.jar:na] at io.undertow.server.session.SessionAttachmentHandler.handleRequest(SessionAttachmentHandler.java:68) ~[undertow-core-1.1.0.Final.jar:1.1.0.Final] at io.undertow.server.Connectors.executeRootHandler(Connectors.java:197) ~[undertow-core-1.1.0.Final.jar:1.1.0.Final] at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:759) ~[undertow-core-1.1.0.Final.jar:1.1.0.Final] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_45] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_45] at java.lang.Thread.run(Thread.java:745) [na:1.8.0_45] </code></pre> </div><div class="panel panel-info"><div class="panel-heading"></div><div class="panel-body"> <p>I don't think this is necessarily a problem with Immutant handling a POST. The problem occurs during the dispatch to the IPN handler, which is attempting to invoke <code>reset</code> on Undertow's <code>InputStream</code>. I would expect the stream's <code>markSupported</code> method to return false. It's not clear to me why reset is being called <a href="https://github.com/smallhelm/clojure-paypal-ipn/blob/master/src/clojure_paypal_ipn/core.clj#L59" rel="nofollow">here</a>, since it doesn't appear <code>mark</code> is ever called. Without being familiar with that library, I might suggest buffering the input somehow... maybe invoke <code>parse-paypal-ipn-string</code> directly? I'm really just guessing, though. </p> </div></div><div class="alert alert-warning" role="alert"><p>来源:<code>https://stackoverflow.com/questions/29834778/clojure-immutant-2-server-undertow-how-to-handle-http-post</code></p></div></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/clojure" hreflang="zh-hans">clojure</a></div> <div class="field--item"><a href="/tag/http-post" hreflang="zh-hans">http-post</a></div> <div class="field--item"><a href="/tag/paypal-ipn" hreflang="zh-hans">paypal-ipn</a></div> <div class="field--item"><a href="/tag/undertow" hreflang="zh-hans">undertow</a></div> <div class="field--item"><a href="/tag/immutant" hreflang="zh-hans">immutant</a></div> </div> </div> Thu, 05 Dec 2019 22:01:30 +0000 守給你的承諾、 1798243 at https://www.e-learn.cn