5

I have to call a servlet written in Java from Clojure web application, and I don't understand how to do that.

Developing a webapp in Java, I had to describe all mappings in web.xml. In Compojure, I see, I must describe routes. So, can I bind the Java servlet to one such route?

Sorry if my question is stupid, but I've searched a lot and didn't find an answer; I'm just starting to develop for the web.

amalloy
  • 89,153
  • 8
  • 140
  • 205
  • Now i'm exploring the test packages provided by Ring. I've found, that Ring allows to transform its handlers into servlets. There is a function run-servlet that does in fact what i want - it calls the servlet constructed from handler by invoking its service method. But at the moment i can't say that i know how to use it in a right way, 'cos there's still alot to explore and try. – Lexx Cherry Aug 30 '11 at 14:40

2 Answers2

2

Two helpful pointers:

There's an example on how to generate the Vaadin servlet completely from Clojure on github

And here's a SO question on how to map a java filter to routes

Community
  • 1
  • 1
Nicolas Modrzyk
  • 13,961
  • 2
  • 36
  • 40
  • I've watched the same example for Vaadin where servlet class was implemented in Clojure with proxy. It works perfectly and partly meets my goals, but not at all. I've watched the question about servlet filter. The solution is based on the level of servlet container. It doesn't matches my wishes, because it's based on servlet container level, but Ring provides an adapter only for jetty. Fix me if i'm wrong. I need to handle all the mappings for both Java and Clojure stuff by Compojure/ring regardless of the specific servlet container. – Lexx Cherry Aug 30 '11 at 03:07
0

I suggest, there is only one way to cope with my tasks. I have to manually instantiate Java servlets in Clojure web app and form their request and response parameters. Test package for ring.util.servlet library describes this approach in details, but in case of turning Ring handler into a Java servlet.

In case of deploying Clojure app and Java servlets to servlet container separately there's no need to define additional Compojure routes or Ring handlers to paths mapped by container.

Please tell me whether my suggestions are incorrect.