5

I have an old legacy java web application that I want to deploy on the same server as my asp.net-applications (running on IIS 7). And I need to have all applications running on port 80, so I can't just install two web servers on different ports.

The java-application is really simple, just a couple of serverlets (no JSP) with functionality pretty close to "Hello World". So I want the servlet engine to be as lightweight as possible. I consider Tomcat to be overkill for this.

Does such a product exist or I'm I stuck with Tomcat?

Ola Herrdahl
  • 4,216
  • 3
  • 29
  • 23

5 Answers5

9

Have a look at Jetty. It can be invoked from a standard Main invocation, and handles servlet containers pretty well (GWT debugging is hosted in a Jetty environment, for example).

I've used this for debugging Lift applications, and been pretty impressed.

To forward requests through IIS to Jetty you can try mod_jk. The problem is that IIS and Java/JSP don't Just Work because IIS needs add-ons to support the loading of the VM and the reflection of JSP/Java content. There is an excellent article on how this can be done here.

butterchicken
  • 13,583
  • 2
  • 33
  • 43
  • Thanks for your quick answer! Yes, Jetty is nice product. I use it locally when developing java applications as well. But how well does it integrate with IIS? Is it the same procedures as with Tomcat? Or is it, as I suspect, much worse? Have you or anyone else tested it with good results? (Is it even possible to get good results in a setup like this?) – Ola Herrdahl Aug 27 '09 at 23:59
1

I'm sure you don't want to get too exotic but if you don't find something to your liking, you could always run Tomcat on a different port and then do some reverse proxying and send everything heading to a specific context to your Tomcat install running on port XYZ, although admittedly I'm only familiar with this in the Apache world, and not the IIS world.

MattC
  • 12,285
  • 10
  • 54
  • 78
1

Check out JK, it has an Apache module and I think it also has an IIS module to connect with Tomcat (maybe Jetty, I don't know). This will allow you to run your app on Tomcat on some other port (even on some other host) and access it through your IIS.

http://tomcat.apache.org/connectors-doc/

Chochos
  • 5,155
  • 22
  • 27
1

If you use Java 6, there is a HTTP server built-in,

http://java.sun.com/javase/6/docs/jre/api/net/httpserver/spec/com/sun/net/httpserver/package-summary.html

Of course, this wouldn't be a good solution if you care about portability.

ZZ Coder
  • 74,484
  • 29
  • 137
  • 169
0

Use HTTP server that comes with java version 6 or more. Straight forward code. As suggested above, REST can be implemented using Servlet technology.We cannot compare both.

Servelet is an adapter(Java) that converts http request to Java object/s and triggers a method(doGet/doPost) when ever the request Arrives and sends http response as per instructed in Java programatically.

        public class server {
    public static void main(String[] args) throws Exception {
        //Start server
        HttpServer server = HttpServer.create(new InetSocketAddress(8000, 0);
        server.createContext("/monitor", new MyHandler());
        server.createContext("/usage", new MyHandler());
        server.setExecutor(java.util.concurrent.Executors.newCachedThreadPool()); //Uses New Thread every time
        server.start();
        System.out.println("Server Started at 8000...");
    }

    static class MyHandler implements HttpHandler {
        @Override
        public void handle(HttpExchange t) throws IOException {
            URI uri = t.getRequestURI();
            String path = uri.getPath();
            InputStreamReader isr = new InputStreamReader(t.getRequestBody(), StandardCharsets.UTF_8);
            BufferedReader br = new BufferedReader(isr);
            int b;
            StringBuilder buf = new StringBuilder(512);
            while ((b = br.read()) != -1) {
                buf.append((char) b);
            }
            br.close();
            isr.close();
            JSONObject body = null;
            try {
                body = new JSONObject(buf.toString());
            } catch (Exception e) {
                System.out.println(e.getMessage());
            }           
            if (path.equals("/monitor")) {
                //your Logic
                //Use any other Library - I use GSON
                Gson gson = new Gson();
                String json = gson.toJson(POJO_OBJECT);
                t.getResponseHeaders().set("Content-Type", "application/json");
                t.getResponseHeaders().set("Access-Control-Allow-Origin", "*");
                t.getResponseHeaders().set("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
                t.sendResponseHeaders(200, json.length());
                OutputStream os = t.getResponseBody();
                os.write(json.getBytes());
                os.close();
            }
            if (path.equals("/monitor")) {
                //Your Logic
                //Use any other Library - I use GSON
                Gson gson = new Gson();
                String json = gson.toJson(POJO_OBJECT);
                //System.out.println(json);
                t.getResponseHeaders().set("Content-Type", "application/json");
                t.getResponseHeaders().set("Access-Control-Allow-Origin", "*");
                t.getResponseHeaders().set("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
                t.sendResponseHeaders(200, json.length());
                OutputStream os = t.getResponseBody();
                os.write(json.getBytes());
                os.close();
            }
        }
    }
}
Balu mallisetty
  • 603
  • 9
  • 19