Compojure

310 views
Skip to first unread message

Michael Jaaka

unread,
Aug 24, 2011, 9:13:04 AM8/24/11
to Clojure
RESTFUL in Clojure?
Hi I have found
http://groups.google.com/group/clojure/browse_thread/thread/cfb2e5c29bb1337/92e2b8356a50189c?lnk=gst&q=web+services#92e2b8356a50189c

But it doesn't work anymore. Anyone can point to fresh tutorial?

Bye!

Michael Jaaka

unread,
Aug 24, 2011, 9:21:11 AM8/24/11
to Clojure
Beside this is there any framework for dynamic WebServices in clojure?
I would like to achive usage scenario like.

(declare webservice with its details
(define method with signature of input output parameters types)
(define another method and so on))


What is required from WS stack is ability to generate WSDL in runtime
programatically.
Attaching invocation handler to published end point.
The authentication and attachments could be made with threads vars.

Do you know already such solution?
It would give good flexibility to the potential system.


The reference example usage scenario would look like:


(with-web-service { :wsdl "myservice.wsdl"
:url "http://someurl/"
:name "myservice "}


(^String someQueryFunction[ ^String a ^List b ]
(str "Hello world " a (interpose ", " b)))


(^Map someQueryFunction[ ^Integer a ^Integer b ^Map m ]
(assoc m a (+ b (get m a))))


)

Any suggestions? RESTful seems to be how far the only options ;-( But
I would like to achieve enterprise standard.

Mark Rathwell

unread,
Aug 24, 2011, 10:00:08 AM8/24/11
to clo...@googlegroups.com
You can have a look at Compojure [1], Noir[2], and Conjure[3], but if
you want the "enterprise standard", you will probably need to wrap one
of the Java frameworks that do that stuff well.

[1] https://github.com/weavejester/compojure
[2] https://github.com/ibdknox/noir
[3] https://github.com/macourtney/Conjure

- Mark

> --
> 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

Tal Liron

unread,
Aug 24, 2011, 11:01:59 PM8/24/11
to clo...@googlegroups.com
You can also look at Prudence, which underneath uses Restlet:

http://threecrickets.com/prudence/

Michael Jaaka

unread,
Aug 25, 2011, 11:17:48 AM8/25/11
to Clojure
Ok after two days I manage to write framework for publishing and
calling webservices (yesterday I asked you for such framework but only
RESTful are available). Right now this implementation supports only
primitve types and was tested in Java distributed environment (needs
to extend to arrays, maps,sets and complex types and also test with
C#).

Here is a snippet of usage code:

server.clj


(ns bpml.server
(:use [bpml ws]))



; publish web service with implementing methods
(provide-ws "com.jaaka.michael" "Sales" "http://localhost:8283/"

(String sayHello [ String name String b ]
(str "Hello " name))

(Integer addNumbers [ Integer a Integer b ]
(+ a b))

(void doSomething[ String dom ]
(println dom))

)


and client.clj



(ns bpml.client
(:use [bpml ws]))




; generate client stub
(generate-ws-client-stub "http://localhost:8283/sales?wsdl")

; first compact way but assumes Service and Port
(let [ c (get-jax-ws-client "com.jaaka.michael" "Sales") ]
(println "sum is" (.addNumbers c 2 31))
(.doSomething c "this rox"))


; explicite call of generated stub
(let [ c (.getSalesPort (get-ws-client-stub "com.jaaka.michael"
"SalesService")) ]
(.addNumbers c 2 10))



under the cover we have newest jax-ws so it is possible to implement
in future rest of ws technologies (transactions, security, attachments
and so on).

The idea is simple. Generate java class with proper annotations,
compile, publish, now for client, fetch the wsdl, generate the client
stub with wsimport, call the desired method, and backing to server,
invoke clojure code returning its results back to the client. All is
dynamic and easy in use as for REPL befits.

Jaskirat Singh Veen

unread,
Aug 24, 2011, 3:36:49 PM8/24/11
to clo...@googlegroups.com
You might want to check out this excellent article by Andrew Brehaut that covers a typical web stack in clojure with many examples -> http://brehaut.net/blog/2011/ring_introduction

Jaskirat

Reply all
Reply to author
Forward
0 new messages