getServers().add(....) always bind to 0.0.0.0

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

getServers().add(....) always bind to 0.0.0.0

Bluesoft70
This post was updated on .
I've spesified component.getServers().add(Protocol.HTTP,"x.x.x.x",8080) to bind to one of my two ipadresses (on the same host). One ip is intended to run the stable release and the other ip my test/beta release. I define two virtual hosts, one for http and another for https

I need the HTTP/HTTPS connectors to listen to one spesific ip address. BUT even if i spesify this ip-address it will not bind to it, only to 0.0.0.0 (which is all interfaces).

code:
component.getServers().add(Protocol.HTTP,"myFirstIp",Protocol.HTTP.getDefaultPort());
component.getServers().add(Protocol.HTTPS,"myFirstIp",Protocol.HTTPS.getDefaultPort());
component.getServers().add(Protocol.FILE);
component.getClients().add(Protocol.HTTP);
component.getClients().add(Protocol.FILE);

hostHttps = new VirtualHost(component.getContext());
hostHttps.setHostScheme("https");
hostHttps.setServerPort(pref.get("<defaultHttpsPort>");
                hostHttps.setServerAddress("myFirstIp");

component.getHosts().add(hostHttps);

Any light on this?

Update: It seems support for this is missing in the implementation, even if the docs states it is not. See my reply for a solution.
Reply | Threaded
Open this post in threaded view
|

Re: getServers().add(....) always bind to 0.0.0.0

Bluesoft70
This post was updated on .
I checked the source code for the HttpServerHelper.java where the http server is created. Its only setting for the InetSocketAddress is the port and not the bind address. I hardcoded my ipaddress just to test and updated restlet.jar and the server was bound correctly to the correct Ip address as Server.java promises.

The same is not handled in HttpsServerHelper either.

I changed line 59 in HttpServerHelper to:
                if(getHelped().getAddress()!=null) {
                        this.server = HttpServer.create(new InetSocketAddress(getHelped().getAddress(),getHelped()
                .getPort()), 0);
                } else {
                        this.server = HttpServer.create(new InetSocketAddress(getHelped()
                .getPort()), 0);
                }


And line 112 in HttpsServerHelper to:
        this.server = HttpsServer.create(getAddress(), 0);

I guess this should be updated in the next Restlet release...espesially since the api docs states on the Server.java contructor: address - The optional listening IP address (useful if multiple IP addresses available). You can also use a domain name as an alias for the IP address to listen to.

Reply | Threaded
Open this post in threaded view
|

Re: getServers().add(....) always bind to 0.0.0.0

Jerome Louvel-3
Hi Jon,

The VirtualHost is indeed only used for routing to match incoming HTTP calls.
Which HTTP connector are you using?
If you think this is a bug, could you submit a pull request?

Thanks,
Jerome


On Sun, Sep 11, 2016 at 2:35 PM, Jon Finanger <[hidden email]> wrote:
I checked the source code for the HttpServerHelper.java where the http server
is created. Its only setting for the InetSocketAddress is the port and not
the bind address. I hardcoded my ipaddress just to test and updated
restlet.jar and the server was bound correctly to the correct Ip address as
Server.java promises.
I guess the same goes for httpsserverhelper.





--
View this message in context: http://restlet-discuss.1400322.n2.nabble.com/getServers-add-always-bind-to-0-0-0-0-tp7579464p7579465.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3185492

Reply | Threaded
Open this post in threaded view
|

Re: getServers().add(....) always bind to 0.0.0.0

Bluesoft70
I've not installed another connector, so it should be the internal (i'll verify it). I would guess the Jetty connector works in multihomed environments so I'll check it out - didn't think of using another connector :-)

I'll file a bug report on the internal one later today, hopefully
Reply | Threaded
Open this post in threaded view
|

Re: getServers().add(....) always bind to 0.0.0.0

Bluesoft70
In reply to this post by Jerome Louvel-3
I've checked the Jetty connector, and its fine.
I'll make that pull request for the internal connector when i have som spare time here...
Reply | Threaded
Open this post in threaded view
|

Re: getServers().add(....) always bind to 0.0.0.0

Jerome Louvel-3
Thanks Jon for the update.
A PR would be nice.

Jerome

On Tue, Sep 13, 2016 at 1:25 PM, Jon Finanger <[hidden email]> wrote:
I've checked the Jetty connector, and its fine.
I'll make that pull request for the internal connector when i have som spare
time here...



--
View this message in context: http://restlet-discuss.1400322.n2.nabble.com/getServers-add-always-bind-to-0-0-0-0-tp7579464p7579468.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3185647