-
1. Re: request.getLocalName() always returning an IP address
mayerw01 Nov 20, 2016 6:47 AM (in response to natedrake2)I made the same experience. But I am not sure if this is a bug. Did you try if this issue persists when not using an address from the private network range?
Acccording to the API docs getLocalName() returns the host name of the Internet Protocol (IP) interface on which the request was received.
While getServerName() returns the host name of the server to which the request was sent. It is the value of the part before ":" in the
Host
header value, if any, or the resolved server name, or the server IP address.So maybe this is rather the method you should use here.
-
2. Re: request.getLocalName() always returning an IP address
ctomc Nov 21, 2016 3:50 AM (in response to natedrake2)configuration of undertow subsystem?
how do you run server? what kind of parameters?
-
3. Re: request.getLocalName() always returning an IP address
mayerw01 Nov 21, 2016 5:00 AM (in response to ctomc)Does this mean that you can't reproduce this behaviour?
Anyway, this is my configuration in the standalone.xml (which I think is the default configuration).
<subsystem xmlns="urn:jboss:domain:undertow:3.1">
<buffer-cache name="default"/>
<server name="default-server">
<http-listener name="default" socket-binding="http" redirect-socket="https" enable-http2="true"/>
<https-listener name="https" socket-binding="https" security-realm="ApplicationRealm" enable-http2="true"/>
<host name="default-host" alias="localhost">
<location name="/" handler="welcome-content"/>
<filter-ref name="server-header"/>
<filter-ref name="x-powered-by-header"/>
<filter-ref name="Access-Control-Allow-Origin"/>
<filter-ref name="Access-Control-Allow-Methods"/>
<filter-ref name="Access-Control-Allow-Headers"/>
<filter-ref name="Access-Control-Allow-Credentials"/>
<filter-ref name="Access-Control-Max-Age"/>
</host>
</server>
<servlet-container name="default">
<jsp-config/>
<websockets/>
</servlet-container>
<handlers>
<file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>
</handlers>
<filters>
<response-header name="server-header" header-name="Server" header-value="WildFly/10"/>
<response-header name="x-powered-by-header" header-name="X-Powered-By" header-value="Undertow/1"/>
<response-header name="Access-Control-Allow-Origin" header-name="Access-Control-Allow-Origin" header-value="*"/>
<response-header name="Access-Control-Allow-Methods" header-name="Access-Control-Allow-Methods" header-value="GET, POST, OPTIONS, PUT"/>
<response-header name="Access-Control-Allow-Headers" header-name="Access-Control-Allow-Headers" header-value="accept, authorization, content-type, x-requested-with"/>
<response-header name="Access-Control-Allow-Credentials" header-name="Access-Control-Allow-Credentials" header-value="true"/>
<response-header name="Access-Control-Max-Age" header-name="Access-Control-Max-Age" header-value="1"/>
</filters>
</subsystem>
I am also executiong the standandard ./standalone.sh (without any parameters)
-
4. Re: request.getLocalName() always returning an IP address
natedrake2 Nov 21, 2016 8:30 AM (in response to ctomc)We start like so:
~/wildfly-10.1.0.Final//bin/standalone.sh -c standalone-full.xml -b 0.0.0.0
The undertow subsystem config is the default from standalone-full.xml:
<subsystem xmlns="urn:jboss:domain:undertow:3.1"> <buffer-cache name="default"/> <server name="default-server"> <http-listener name="default" socket-binding="http" redirect-socket="https" enable-http2="true"/> <https-listener name="https" socket-binding="https" security-realm="ApplicationRealm" enable-http2="true"/> <host name="default-host" alias="localhost"> <location name="/" handler="welcome-content"/> <filter-ref name="server-header"/> <filter-ref name="x-powered-by-header"/> </host> </server> <servlet-container name="default"> <jsp-config/> <websockets/> </servlet-container> <handlers> <file name="welcome-content" path="${jboss.home.dir}/welcome-content"/> </handlers> <filters> <response-header name="server-header" header-name="Server" header-value="WildFly/10"/> <response-header name="x-powered-by-header" header-name="X-Powered-By" header-value="Undertow/1"/> </filters> </subsystem>
-
5. Re: request.getLocalName() always returning an IP address
emeuwese Nov 23, 2016 2:56 PM (in response to natedrake2)My Wildfly-10.1.0.Final server on jdk 1.8.0_112 on Windows 10 HttpServletRequest#getLocalName() returns the correct host name.
HttpServletRequestImpl getLocalName() calls getDestinationAddress() on a HttpServerExchange object.
The HttpServerExchange getDestinationAddress() returns a java.net.InetSocketAddress object.
And then getHostString() on the java.net.InetSocketAddress object returns the host name
Does java.net.InetSocketAddress return the correct host name without using Wildfly?
java.net.InetSocketAddress isa1 = new java.net.InetSocketAddress("192.168.1.7", 8085); String hostname1 = isa1.getHostName(); // should be flannelcat.home java.net.InetSocketAddress isa2 = new java.net.InetSocketAddress("flannelcat.home", 8085); String hostname2 = isa2.getHostName(); // should be flannelcat.home