On Fri, Oct 19, 2012 at 6:39 PM, larry google groups < lawrencecloj...@gmail.com> wrote:
> >you have `username` a symbol as the key in your map, but you are > >looking for `:username` they keyword as a key > > Ah, interesting, perhaps I tested this somewhere else. To be sure, I tried > this again: > > > (defn add-to-logged-in-registry [this-users-params] > (let [right-now (. (Date.) getTime) > new-user-entry (conj this-users-params { "updated" right-now })] > (println apply str new-user-entry) > (if-not (nil? (get new-user-entry "username")) > > (swap! registry assoc (:username new-user-entry) new-user-entry)))) > also don't forget this here ^^^^ > > And now I am back to the error I had before I had any if() statement, so > now I think data is getting into registry. My problem with JSON must be > elsewhere, but I don't understand what, exactly, the problem is. > > #<core$apply clojure.core$apply@2797fd81> #<core$str > clojure.core$str@34902478> {updated 1350664352323, username Raer, > first_name Raier, last_name Lis, user_image Raier_phptZ2nEJ.jpg, site > www.javascriptquestions.com} > 2012-10-19 > 12:32:32.324:WARN:oejs.AbstractHttpConnection:/?username=Raier&first_name=Raier&last_name=Lis&user_image=Raier_phptZ2nEJ.jpg&site= > www.javascriptquestions.com > > java.lang.Exception: JSON object properties may not be nil > at clojure.data.json$default_write_key_fn.invoke(json.clj:28) > at clojure.data.json$write_object.invoke(json.clj:313) > at clojure.data.json$fn__109$G__104__116.invoke(json.clj:279) > at clojure.data.json$write.doInvoke(json.clj:423) > at clojure.lang.RestFn.invoke(RestFn.java:425) > at clojure.lang.AFn.applyToHelper(AFn.java:163) > at clojure.lang.RestFn.applyTo(RestFn.java:132) > at clojure.core$apply.invoke(core.clj:604) > at clojure.data.json$write_str.doInvoke(json.clj:430) > at clojure.lang.RestFn.invoke(RestFn.java:410) > at who_is_logged_in.core$current_users.invoke(core.clj:43) > at clojure.lang.AFn.applyToHelper(AFn.java:161) > at clojure.lang.AFn.applyTo(AFn.java:151) > at clojure.core$apply.invoke(core.clj:602) > at net.cgrand.moustache$delegate$fn__397.invoke(moustache.clj:186) > at who_is_logged_in.core$fn__536.invoke(core.clj:50) > at ring.middleware.params$wrap_params$fn__271.invoke(params.clj:55) > at clojure.lang.Var.invoke(Var.java:401) > at ring.adapter.jetty$proxy_handler$fn__496.invoke(jetty.clj:18) > at > ring.adapter.jetty.proxy$org.eclipse.jetty.server.handler.AbstractHandler$0.handle(Unknown > Source) > at > org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:111) > at org.eclipse.jetty.server.Server.handle(Server.java:349) > at > org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:452) > at > org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:884) > at > org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:938) > at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:634) > at > org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:230) > at > org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:76) > at > org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:609) > at > org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:45) > at > org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:599) > at > org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:534) > at java.lang.Thread.run(Unknown Source) > > > > > > > > > > > > On Friday, October 19, 2012 12:26:15 PM UTC-4, larry google groups wrote: >> >> >you have `username` a symbol as the key in your map, but you are >> >looking for `:username` they keyword as a key >> >> At some point I tried: >> >> (get new-user-entry "username") >> >> but that had the same result. >> >> Username is clearly a key, yes? >> >> What would you suggest? >> >> >> >> >> On Friday, October 19, 2012 12:06:10 PM UTC-4, red...@gmail.com wrote: >>> >>> you have `username` a symbol as the key in your map, but you are >>> looking for `:username` they keyword as a key >>> >>> On Fri, Oct 19, 2012 at 8:47 AM, larry google groups >>> <lawrenc...@gmail.com> wrote: >>> > >>> > >>> > Also: >>> > >>> > >>> > >>> >> I suggesting adding printlns or logging or a debugger and checking >>> the >>> >> value of this-users-params, it is almost certainly not what you >>> expect >>> >> it to be. >>> > >>> > I showed the output previously, but I will do it again. >>> > >>> > If I add a println like this: >>> > >>> > >>> > (defn add-to-logged-in-registry [this-users-params] >>> > (let [right-now (. (Date.) getTime) >>> > new-user-entry (conj this-users-params { "updated" right-now >>> })] >>> > (println apply str new-user-entry) >>> > >>> > (if (:username new-user-entry) >>> > (swap! registry assoc (:username new-user-entry) >>> new-user-entry)))) >>> > >>> > This code works perfectly at the REPL so to show a problem I have to >>> upload >>> > this to the live server. So I compile this and upload it to the server >>> and >>> > start it up and immediately the Javascript in the browsers of dozens >>> of >>> > users starts to bombard the app: >>> > >>> > java -jar who-is-logged-in-1.0.1-**standalone.jar 40000 >>> > App 'Who is logged in?' is starting >>> > port: 40000 >>> > 2012-10-19 11:37:02.731:INFO:oejs.Server:**jetty-7.x.y-SNAPSHOT >>> > 2012-10-19 11:37:02.846:INFO:oejs.**AbstractConnector:Started >>> > SelectChannelConnector@0.0.0.**0:40000<http://SelectChannelConnector@0.0.0.0:40000> >>> > >>> > #<core$apply clojure.core$apply@d1fba79> #<core$str >>> > clojure.core$str@7dfde44e> {updated 1350661023079, username rumbella, >>> > first_name , last_name , user_image , site www.wpquestions.com} >>> > >>> > #<core$apply clojure.core$apply@d1fba79> #<core$str >>> > clojure.core$str@7dfde44e> {updated 1350661023140, username >>> karlorihoo, >>> > first_name Karlo, last_name Rihoo, user_image , site >>> www.wpquestions.com} >>> > >>> > #<core$apply clojure.core$apply@d1fba79> #<core$str >>> > clojure.core$str@7dfde44e> {updated 1350661023698} >>> > >>> > #<core$apply clojure.core$apply@d1fba79> #<core$str >>> > clojure.core$str@7dfde44e> {updated 1350661024149, username Rainner, >>> > first_name Rainner, last_name Lins, user_image Rainner_phptZ2nEJ.jpg, >>> site >>> > www.javascriptquestions.com} >>> > >>> > #<core$apply clojure.core$apply@d1fba79> #<core$str >>> > clojure.core$str@7dfde44e> {updated 1350661024159} >>> > >>> > #<core$apply clojure.core$apply@d1fba79> #<core$str >>> > clojure.core$str@7dfde44e> {updated 1350661024269} >>> > >>> > #<core$apply clojure.core$apply@d1fba79> #<core$str >>> > clojure.core$str@7dfde44e> {updated 1350661024646} >>> > >>> > #<core$apply clojure.core$apply@d1fba79> #<core$str >>> > clojure.core$str@7dfde44e> {updated 1350661024833, username dbranes, >>> > first_name Dbranes, last_name , user_image dbranes_phpPJVl3f.jpg, site >>> > www.wpquestions.com} >>> > >>> > #<core$apply clojure.core$apply@d1fba79> #<core$str >>> > clojure.core$str@7dfde44e> {updated 1350661025140, username >>> Christianto, >>> > first_name Christianto, last_name , user_image >>> Christianto_phpqESzHW.jpg, >>> > site www.wpquestions.com} >>> > >>> > #<core$apply clojure.core$apply@d1fba79> #<core$str >>> > clojure.core$str@7dfde44e> {updated 1350661025337, username jsoni, >>> > first_name Jatin, last_name Soni, user_image jsoni_phpYlWQTr.jpg, site >>> > www.wpquestions.com} >>> > >>> > #<core$apply clojure.core$apply@d1fba79> #<core$str >>> > clojure.core$str@7dfde44e> {updated 1350661025651} >>> > >>> > #<core$apply clojure.core$apply@d1fba79> #<core$str >>> > clojure.core$str@7dfde44e> {updated 1350661025996} >>> > >>> > So, why does this not work? And what is the right way to be sure that >>> this: >>> > >>> > {updated 1350661025996} >>> > >>> > Is never added to the registry (since there is no username). >>> > >>> > >>> > >>> > >>> > >>> > >>> > >>> > >>> > >>> > >>> > On Friday, October 19, 2012 3:53:26 AM UTC-4, red...@gmail.com wrote: >>> >> >>> >> conj can surely produce maps, and does so happily in the following >>> cases: >>> >> >>> >> (conj {} [:foo :bar]) >>> >> (conj {} {:foo :bar}) >>> >> >>> >> I suggesting adding printlns or logging or a debugger and checking >>> the >>> >> value of this-users-params, it is almost certainly not what you >>> expect >>> >> it to be. >>> >> >>> >> as a side note creating a date object just to call getTime is kind of >>> >> gross, try (System/currentTimeMillis) >>> >> >>> >> On Fri, Oct 19, 2012 at 12:42 AM, Sean Corfield <seanco...@gmail.com> >>> >>> >> wrote: >>> >> > On Fri, Oct 19, 2012 at 12:10 AM, larry google groups >>> >> > <lawrenc...@gmail.com> wrote: >>> >> >> >>> >> >> (defn add-to-logged-in-registry [this-users-params] >>> >> >> (let [right-now (. (Date.) getTime) >>> >> >> new-user-entry (conj this-users-params { "updated" >>> right-now >>> >> >> })] >>> >> >> (if (:username new-user-entry) >>> >> >> (swap! registry assoc (:username new-user-entry) >>> >> >> new-user-entry)))) >>> >> >> >>> >> >> The if statement seems to never be true. >>> >> > >>> >> > >>> >> > conj produces a sequence, not a map, so the lookup of :username >>> fails. >>> >> > Try >>> >> > new-user-entry (assoc this-users-params "updated" right-now) >>> >> > -- >>> >> > Sean A Corfield -- (904) 302-SEAN >>> >> > An Architect's View -- http://corfield.org/ >>> >> > World Singles, LLC. -- http://worldsingles.com/ >>> >> > >>> >> > "Perfection is the enemy of the good." >>> >> > -- Gustave Flaubert, French realist novelist (1821-1880) >>> >> > >>> >> > -- >>> >> > You received this message because you are subscribed to the Google >>> >> > Groups "Clojure" group. >>> >> > To post to this group, send email to clo...@googlegroups.com >>> >> > Note that posts from new members are moderated - please be patient >>> with >>> >> > your >>> >> > first post. >>> >> > To unsubscribe from this group, send email to >>> >> > clojure+u...@googlegroups.com >>> >> > For more options, visit this group at >>> >> > http://groups.google.com/**group/clojure?hl=en<http://groups.google.com/group/clojure?hl=en> >>> >> >>> >> >>> >> >>> >> -- >>> >> And what is good, Phaedrus, >>> >> And what is not good— >>> >> Need we ask anyone to tell us these things? >>> > >>> > -- >>> > You received this message because you are subscribed to the Google >>> > Groups "Clojure" group. >>> > To post to this group, send email to clo...@googlegroups.com >>> > Note that posts from new members are moderated - please be patient >>> with your >>> > first post. >>> > To unsubscribe from this group, send email to >>> > clojure+u...@googlegroups.com >>> > For more options, visit this group at >>> > http://groups.google.com/**group/clojure?hl=en<http://groups.google.com/group/clojure?hl=en> >>> >>> >>> >>> -- >>> And what is good, Phaedrus, >>> And what is not good— >>> Need we ask anyone to tell us these things? >>> >> -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > -- I may be wrong or incomplete. Please express any corrections / additions, they are encouraged and appreciated. At least one entity is bound to be transformed if you do ;) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en