SHARE
TWEET

Untitled

a guest Feb 23rd, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (ns rudkus.core
  2.   (:require [clojure.tools.cli :as cli]
  3.             [ring.adapter.jetty :as jetty])
  4.   (:gen-class))
  5.  
  6. (defn handler [request]
  7.   {:status 200
  8.    :headers {"Content-Type" "text/html"}
  9.    :body "Hello, World!"})
  10.  
  11. (def ^{:private true} server (atom nil))
  12.  
  13. (defn start [port]
  14.   (swap! server #(if (not (nil? %))
  15.                   (throw (IllegalStateException. "Server already started."))
  16.                   (jetty/run-jetty handler
  17.                                    {:port port
  18.                                     :join? false}))))
  19.  
  20. (defn stop []
  21.   (swap! server #(if (nil? %)
  22.                   (throw (IllegalStateException. "Server already stopped."))
  23.                   (do (.stop %)
  24.                       nil))))
  25.  
  26. (defn -main [& args]
  27.   (let [[options extra-args banner] (cli/cli args
  28.                                              ["-p" "--port" "Port" :default 80 :parse-fn #(Integer. %)])]
  29.     (if (not-empty extra-args)
  30.       (println banner)
  31.       (start (:port options)))))
  32.    
  33. lein run
  34.    
  35. lein trampoline run
  36.    
  37. $ java -jar rudkus-0.1.0-SNAPSHOT-standalone.jar
  38. 2012-09-09 15:54:59.664:INFO:oejs.Server:jetty-7.x.y-SNAPSHOT
  39. 2012-09-09 15:54:59.803:WARN:oejuc.AbstractLifeCycle:FAILED SelectChannelConnector@0.0.0.0:80: java.net.SocketException: Permission denied
  40. java.net.SocketException: Permission denied
  41.     at sun.nio.ch.Net.bind(Native Method)
  42.     at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:124)
  43.     at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:59)
  44.     at org.eclipse.jetty.server.nio.SelectChannelConnector.open(SelectChannelConnector.java:173)
  45.     at org.eclipse.jetty.server.AbstractConnector.doStart(AbstractConnector.java:311)
  46.     at org.eclipse.jetty.server.nio.SelectChannelConnector.doStart(SelectChannelConnector.java:251)
  47.     at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
  48.     at org.eclipse.jetty.server.Server.doStart(Server.java:272)
  49.     at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
  50.     at ring.adapter.jetty$run_jetty.invoke(jetty.clj:86)
  51.     at rudkus.core$start$fn__16.invoke(core.clj:16)
  52.     at clojure.lang.Atom.swap(Atom.java:37)
  53.     at clojure.core$swap_BANG_.invoke(core.clj:2108)
  54.     at rudkus.core$start.invoke(core.clj:14)
  55.     at rudkus.core$_main.doInvoke(core.clj:31)
  56.     at clojure.lang.RestFn.invoke(RestFn.java:397)
  57.     at clojure.lang.AFn.applyToHelper(AFn.java:159)
  58.     at clojure.lang.RestFn.applyTo(RestFn.java:132)
  59.     at rudkus.core.main(Unknown Source)
  60. 2012-09-09 15:54:59.806:WARN:oejuc.AbstractLifeCycle:FAILED org.eclipse.jetty.server.Server@6e5dfaf1: java.net.SocketException: Permission denied
  61. java.net.SocketException: Permission denied
  62.     at sun.nio.ch.Net.bind(Native Method)
  63.     at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:124)
  64.     at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:59)
  65.     at org.eclipse.jetty.server.nio.SelectChannelConnector.open(SelectChannelConnector.java:173)
  66.     at org.eclipse.jetty.server.AbstractConnector.doStart(AbstractConnector.java:311)
  67.     at org.eclipse.jetty.server.nio.SelectChannelConnector.doStart(SelectChannelConnector.java:251)
  68.     at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
  69.     at org.eclipse.jetty.server.Server.doStart(Server.java:272)
  70.     at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
  71.     at ring.adapter.jetty$run_jetty.invoke(jetty.clj:86)
  72.     at rudkus.core$start$fn__16.invoke(core.clj:16)
  73.     at clojure.lang.Atom.swap(Atom.java:37)
  74.     at clojure.core$swap_BANG_.invoke(core.clj:2108)
  75.     at rudkus.core$start.invoke(core.clj:14)
  76.     at rudkus.core$_main.doInvoke(core.clj:31)
  77.     at clojure.lang.RestFn.invoke(RestFn.java:397)
  78.     at clojure.lang.AFn.applyToHelper(AFn.java:159)
  79.     at clojure.lang.RestFn.applyTo(RestFn.java:132)
  80.     at rudkus.core.main(Unknown Source)
  81. Exception in thread "main" java.net.SocketException: Permission denied
  82.     at sun.nio.ch.Net.bind(Native Method)
  83.     at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:124)
  84.     at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:59)
  85.     at org.eclipse.jetty.server.nio.SelectChannelConnector.open(SelectChannelConnector.java:173)
  86.     at org.eclipse.jetty.server.AbstractConnector.doStart(AbstractConnector.java:311)
  87.     at org.eclipse.jetty.server.nio.SelectChannelConnector.doStart(SelectChannelConnector.java:251)
  88.     at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
  89.     at org.eclipse.jetty.server.Server.doStart(Server.java:272)
  90.     at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
  91.     at ring.adapter.jetty$run_jetty.invoke(jetty.clj:86)
  92.     at rudkus.core$start$fn__16.invoke(core.clj:16)
  93.     at clojure.lang.Atom.swap(Atom.java:37)
  94.     at clojure.core$swap_BANG_.invoke(core.clj:2108)
  95.     at rudkus.core$start.invoke(core.clj:14)
  96.     at rudkus.core$_main.doInvoke(core.clj:31)
  97.     at clojure.lang.RestFn.invoke(RestFn.java:397)
  98.     at clojure.lang.AFn.applyToHelper(AFn.java:159)
  99.     at clojure.lang.RestFn.applyTo(RestFn.java:132)
  100.     at rudkus.core.main(Unknown Source)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top