C
C
cyberorg2012-11-14 08:12:03
Java
cyberorg, 2012-11-14 08:12:03

How to properly link a Java application and Nginx?

Good afternoon, Habraspetsy!

There was a question about the optimal way to connect Nginx and a Java application.

Given:

There is a Java application that takes data as a string as the first argument (args[0]) and returns it via System.out.println(). Input and output strings in JSON format.
It also works with the database through activeJDBC and implements the business logic.
Now it looks like an Executable jar

. There is a bunch of ngnix + php-fpm.

Now the interaction with the web looks like this:
1) The client sends a POST request to site/some.php with JSON
2) Nginx receives the request and sends the request via fastCGI to PHP
3) PHP launches the jar (java -jar app.jar json)
4) Java application responds
5) PHP relays the response to Nginx, who responds to the client.

All this works for a very long time, since each one is loaded by the JVM.

Question:
How to get rid of the not really necessary layer in the form of PHP?
Without resorting to JavaEE technologies and heavy servers like GlassFish.

Ideally, I would like to see examples with code in order to quickly understand.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
relgames, 2012-11-14
@kyberorg

Running java on every request is, of course, tough.
The correct approach is to run the application once and it should work, while there should be a mechanism for sending requests to the application. The simplest way, as already pointed out here, is Jetty, but personally I would use Embedded Jetty , see how HelloHandler is implemented there

M
Moxa, 2012-11-14
@Moxa

you can write a simple servlet, push it into jetty ... it will accept json, process it using the existing logic and return it back ...

M
mitaichik, 2016-04-19
@mitaichik

Maybe https://www.nginx.com/resources/wiki/modules/java_...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question