I have a servlet that I want to connect to over a unix domain socket since I cannot start listen on a new TCP port because of a security policy. Unfortunately I have been unable to find a servlet container that can serve over a unix domain socket. So far I've looked at Tomcat and Jetty.
3 Answers
First you'll need to figure out how to support unix domain sockets on java.
Prior questions address this. UNIX Domain Socket in Java and UNIX socket implementation for Java?
Looks like junixsocket might be able to present itself as a Socket, if that's the case, then you'll want to see if you can replace the default Java java.net.Socket implementation using the various bootclasspath facilities. At that point anything that supports classic Sockets, like (early versions of) Jetty with its SocketConnector (not NIO or SSL) should (in theory) work.

- 1
- 1

- 46,896
- 7
- 86
- 136
junixsocket now has dedicated support for Jetty.
Use its AFSocketServerConnector
, which works with jetty 9.4.12 or newer.
If you use jetty 10.0.8 or newer, you can also use junixsocket as a client connector.
Details here: https://kohlschutter.github.io/junixsocket/junixsocket-jetty/

- 3,032
- 1
- 18
- 13
I don't believe the JVM exposes UNIX domain sockets to any Java code. If you want to use UNIX domain sockets, I think you'll have to write your own native code to listen and proxy the bytes up to the container. It sounds doable, but certainly not enjoyable.

- 20,221
- 9
- 60
- 77
-
It would be pleasure to have it working to deal with the java startup time as well C/C++ application startup time if it has load Curl or Boost libraries, and with UNIX socket it would be really reliable and very fast. There isn't point of using default JVM or anything because that would not make sense. – Andrew Sep 26 '14 at 18:38