0

Short version: Is it possible to run from a HttpServer (com.sun.net.httpserver.HttpServer) a Servlet on a different port ?

Long version: I have a project in which I fire a HttpServer to handle client request and provide them REST endpoint and I would like to use a Servlet on a different port.

So basically my Servlet would act like a middleware between the user and the actual HttpServer, to communicate between both entity.

Is it possible ? If so does there's some documentation about that ?

Josey
  • 23
  • 1
  • 5
  • Why would you need a different port for that? Wouldn't the servlet be just another view on the data provided by httpserver? – Jan Mar 07 '18 at 13:15
  • So you want to make a HTTP proxy? I'd recommend against using `com.sun.net.httpserver.HttpServer` for several reasons. – Kayaman Mar 07 '18 at 13:24
  • @Kayaman: Unfortunately it's legacy code that I can't change so I have to stick with com.sun.net.httpserver.HttpServer – Josey Mar 07 '18 at 13:47
  • @Jan: No the servlet won't be another view on the data, the servlet will deal with some authentification – Josey Mar 07 '18 at 13:47
  • Duplicate of: [*How to use Servlet for HttpServer*](https://stackoverflow.com/q/25263696/642706) – Basil Bourque Mar 12 '19 at 02:07
  • Does this answer your question? [ServletContextListener isn't invoked when using com.sun.net.httpserver.HttpServer](https://stackoverflow.com/questions/53847095/servletcontextlistener-isnt-invoked-when-using-com-sun-net-httpserver-httpserve) – Dmitry Spikhalskiy Aug 02 '22 at 22:48

0 Answers0