This week's book giveaway is in the Java in General forum.
We're giving away four copies of Event Streams in Action and have Alexander Dean & Valentin Crettaz on-line!
See this thread for details.
Win a copy of Event Streams in Action this week in the Java in General forum!

Dan King

Ranch Hand
+ Follow
since Mar 18, 2009
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Dan King

I don't believe learning a different lisp dialect will be all that helpful, but Land of Lisp did help me better understand general Lisp conventions.
7 years ago
I've been learning/using Clojure for a few months now. While I'm comfortable with it, I still find myself trying to address problems as I would using Java, Ruby or Groovy only to later ask, what's the "Clojure way?" I'd appreciate suggestions on books and/or presentation that can help me with adjusting to the paradigm shift. Thanks.
7 years ago
The web section does have a great explanation of Ring, which should help you in understanding how to integrate either your own security or a preexisting security library.
7 years ago
Hi Matt/Aslak:

As I understand it, there are a few gems that make using Cucumber with Rails trivial. But what about situations in which Rails isn't used? Further, I'm especially interested in testing Rails and non-rails RESTful web services and heavily AJAX dependant UIs. Can you elaborate on how Cucumber can help in this regard?
7 years ago

Matt Wynne wrote:Hi Dan,

Cucumber and RSpec are complimentary tools. You use Cucumber to write high-level end-to-end tests that you can share with project stakeholders, and RSpec to write microtests for individual classes and modules. The RSpec Book explains the process of moving between these two levels of tests very well:

http://pragprog.com/book/achbd/the-rspec-book



Hi Matt,

Thanks for the clarification; however the source of confusion was my lack of clarity on RSpec Stories. I've since searched for more information and clarified my understanding.
7 years ago
I've recently dabbled in testing a Rails application with Rspec, and I'm curious to know: how easy is it to use Rspec with Cucumber? Also, is there any benefits and/or issues with using Rspec with Cucumber?
7 years ago

ntumba lobo wrote:can you show the error message stating that the context initialization failed ?



The message is below:


2011-09-21 15:52:05 org.springframework.beans.factory.support.DisposableBeanAdapter
[DEBUG] Invoking destroy() on bean with name 'entityManagerFactory'
2011-09-21 15:52:05 org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean
[INFO] Closing JPA EntityManagerFactory for persistence unit 'regulation'
2011-09-21 15:52:05 org.springframework.beans.factory.support.DefaultListableBeanFactory
[DEBUG] Retrieved dependent beans for bean 'org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter#b80f1c': [entityManagerFactory]
2011-09-21 15:52:05 org.springframework.web.context.ContextLoader
[ERROR] Context initialization failed

7 years ago
When I deploy my application war file to tomcat, the log files indicate that spring creates and injects the beans declared in the various context files of my application. However, once all the beans are created the Spring container destroys all the beans and then throws an error stating context initialization failed. I've set the logging level of Spring to debug, but there is nothing in the log files that indicate what is causing the Spring container to destroy all beans and shutdown. Anyone have any suggestions on how I can determine the root of the problem? Thanks.

Below are the messages I get right before I'm notified that Spring will destroy all the beans:


[DEBUG] Eagerly caching bean 'uploadService' to allow for resolving potential circular references
2011-09-21 15:19:08 org.springframework.beans.factory.annotation.InjectionMetadata
[DEBUG] Processing injected method of bean 'uploadService': AutowiredFieldElement for private org.apache.commons.fileupload.disk.DiskFileItemFactory com.mass.ws.services.UploadService.diskFileFactory
2011-09-21 15:19:08 org.springframework.beans.factory.support.DefaultListableBeanFactory
[DEBUG] Creating shared instance of singleton bean 'diskFileItemFactory'
2011-09-21 15:19:08 org.springframework.beans.factory.support.DefaultListableBeanFactory
[DEBUG] Creating instance of bean 'diskFileItemFactory'
2011-09-21 15:19:08 org.springframework.beans.factory.support.DefaultListableBeanFactory
[INFO] Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@b0ede6: defining beans [org.springframework.beans.

7 years ago

Sean Corfield wrote:No, because they do completely different things. :methods is purely about the generated method signatures (and if you specify argument types other than Object I don't expect you'll get reflection warnings from operations on the arguments within the function itself). Type hints are used anywhere that you need to eliminate a reflection warning - which is not always arguments. In fact, more often I've seen it in let forms on on actual arguments in a specific Java method call, e.g., (.someCall ^SomeType obj ^String s)



Essentially curious if there was a way to mandate a method signature inline, like type hints, rather than through a "stub."

Thanks for the explanation.

Best,
Dan
8 years ago

Sean Corfield wrote:The type hints were meant more as an illustration of where types would go if they were needed, just to show syntax. You'd only need them if you were trying to get rid of reflection warnings. Sorry, probably more confusing than helpful.

To control the actual generated signatures of methods, you might need :methods on the :gen-class directive, if you don't want default types.



So, if I understand it correctly: the type hints -- ^String -- only deal with reflection warnings, however, in order to control the generated method signature the :methods directive is required. Is there a way to combine both in a singular action?

8 years ago

Sean Corfield wrote:Simple answer: start here http://clojure.org/compilation

Longer answer:

You need to remember that Java "functions" all have this passed as a first argument so typically when you have String foo(String greeting) { ... } in Java, you're going to have something like (defn -foo ^String [this ^String greeting] ...) in Clojure. -foo tells the Clojure compiler to preserve the function name when generating bytecode.

In your namespace declaration, you'll specify :gen-class to indicate you want the namespace compiled to a Java class.



So essentially, I need to do the following:
  • Add the :gen-class directive
  • Add "this" as a parameter to each function


  • But why are you adding read-time metadata i.e. (defn -foo ^String [this ^String greeting] ...)?
    8 years ago
    I'd like to compile the following Clojure code into a Java class ahead of time. Can anyone explain how to do so?

    8 years ago
    Sean,

    Out of curiosity and for future reference, what tool(s) do you use for debugging Clojure?

    Also, if you don't mind I'd like to ask you a non-clojure web application development question. Would you prefer I ask my question here on javaranch, another forum or by email? Thanks.
    8 years ago

    Sean Corfield wrote:Hope that helps?


    Thanks for the explanation; it did help. I was had misimpression that in order to use 'map' I had to use 'doall' to realize the resulting sequence.

    Furthermore, I found the cause of the NPE. Within an 'if' statement I check for false rather than nil values. After correcting this issue the code almost functions as desired; unfortunately, there is one remaining issue:

    The collection returned from "cmp-time-dept" contains nil values, when it should not (see line 32 in posted code). How can I eliminate the nil values?

    NOTE: After posting the above, I saw that you had already posted a message. I read your post that I failed to include the 'fmt' function in the second (version) posting of my code; I'm sorry for the confusion/inconvenience. But impressively, you found a work-around AND read my mind about removing the nil values. Thanks a bunch.

    I've corrected the earlier (second version) code posting and I've included a final version below.

    I agree that 'first' and 'second' function are better than 'nth coll n'; I've changed my code to use 'first' or 'second' but there is one instance were I used 'nth' to preserve stylistic continuity, since there is no 'third' function.


    8 years ago

    Sean Corfield wrote:
    2. You don't need doall in strip-data - doall is needed inside with-open to realize the sequence but not after that



    Could you elaborate on why "doall" isn't needed in "strip-data"? As I understand it, "doall" forces lazy-sequences to be fully realized, and since "map" produces a lazy-sequence, shouldn't it be needed?

    Also, I've modified the code to match time intervals (via java interop) rather than straight string matches. Unfortunately, however, I'm encountering a null pointer exception when I attempt to determine interval overlaps. I've posted the code below, do you see where or what is causing the problem?

    Note: Everything up to "prep-data" works as expected - i.e. a collection of collections is made, where each sub-collection has two parts 1. A Joda-Time Interval 2. A String representing a department.

    Also the input data structure has changed; see below the code. Lastly, I too am now using leiningen, so I had to add [joda-time "1.6.2"] to dependencies in project.clj.




    Employee Id Name Time In Time Out Dept.
    pdm1705 Jane 01/01/2011 06:00 AM 01/01/2011 02:00 PM ER
    pdm1705 Jane 01/02/2011 06:00 AM 01/02/2011 02:00 PM ER
    pdm1705 Jane 01/04/2011 06:00 AM 01/04/2011 01:00 PM ER
    pdm1705 Jane 01/05/2011 05:00 AM 01/05/2011 11:00 PM ER



    Employee Id Name Time In Time Out Dept.
    mce0518 Jon 01/01/2011 06:00 AM 01/01/2011 02:00 PM ER
    mce0518 Jon 01/02/2011 06:00 AM 01/02/2011 02:00 PM ER
    mce0518 Jon 01/04/2011 06:00 AM 01/04/2011 01:00 PM ICU
    mce0518 Jon 01/05/2011 06:00 AM 01/05/2011 01:00 PM ICU
    mce0518 Jon 01/05/2011 05:00 PM 01/05/2011 11:00 PM ER




    8 years ago