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.
Comments
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/
Comments
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.