Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access Endpoint.publish's web server

Since Endpoint.publish creates / uses a lightweight http server (as described here), is there a way to get access to said web server and, say, deploy a single html document at what would normally be the document root?

So if I did

Endpoint.publish("http://0.0.0.0:1234/webService");

Could I get the web server object and tell it to reply with index.html when somebody browses to http:/my.ip.add.res:1234/?

like image 352
captainroxors Avatar asked Dec 14 '25 01:12

captainroxors


2 Answers

If you want an embedded http server you can try this http://docs.oracle.com/javase/6/docs/jre/api/net/httpserver/spec/com/sun/net/httpserver/package-summary.html

like image 104
Evgeniy Dorofeev Avatar answered Dec 16 '25 19:12

Evgeniy Dorofeev


Thanks to Evgeniy's direction, I just needed to take a closer look at the com.sun.net.httpserver package.

No, you can't get the Endpoint's webserver, but you can first make one and then publish the Endpoint on that server. Something to this effect:

HttpServer server = HttpServer.create(new InetSocketAddress(1234), 0);
HttpContext c = server.createContext("/webService");
Endpoint e = Endpoint.create(new WebService());
e.publish(c);

// Anything else you want to do with your server.

server.setExecutor(null);
server.start();

And presto. You have a web server with a web service published on it.

like image 43
captainroxors Avatar answered Dec 16 '25 18:12

captainroxors



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!