5 Replies Latest reply on Nov 23, 2016 2:56 PM by emeuwese

    request.getLocalName() always returning an IP address

    natedrake2

      After upgrading from JBoss 7.1.1 to Wildfly 10.1 we are seeing different behavior with request.getLocalName().  In JBoss 7.1.1, request.getLocalName() was returning the hostname of the requested resource.  In Wildfly 10.1, it always seems to return an IP address.  The Javadoc for getLocalName() in JEE 7 doesn't indicate changes in this methods behavior.  Is this a bug in Wildfly or Undertow?

       

      Attached is a simple WAR file (based on Maven's maven-archetype-webapp archetype) with the following scriptlet to dump the output of request.getLocalName().

       

      Server: <%=request.getLocalName()%>

       

      Here is some sample output when running this test WAR on JBoss and Wildfly.  All tests done on Mac OS 10.11.6, but have seen similar behavior in Linux.

       

       

      Wildfly 10.1 / Java 1.8.0_112

       

      Requested URL: http://localhost:8085/tt/

      Server: 127.0.0.1

       

      Requested URL: http://192.168.1.7:8085/tt/

      Server: 192.168.1.7

       

      Requested URL: http://flannelcat.local:8085/tt/

      Server: 192.168.1.7

       

       

      JBoss 7.1.1 / Java 1.7.0_67

       

      Requested URL: http://localhost:8085/tt/

      Server: localhost

       

      Requested URL: http://192.168.1.7:8085/tt/

      Server: flannelcat.home

       

      Requested URL: http://flannelcat.local:8085/tt/

      Server: flannelcat.home

       

       

      Thanks!

       

      Nate

        • 1. Re: request.getLocalName() always returning an IP address
          mayerw01

          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

            configuration of undertow subsystem?

            how do you run server? what kind of parameters?

            • 3. Re: request.getLocalName() always returning an IP address
              mayerw01

              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

                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

                  My Wildfly-10.1.0.Final server on jdk 1.8.0_112 on Windows 10 HttpServletRequest#getLocalName() returns the correct host name.

                   

                  https://github.com/undertow-io/undertow/blob/master/servlet/src/main/java/io/undertow/servlet/spec/HttpServletRequestImpl.java#L948

                  https://github.com/undertow-io/undertow/blob/master/core/src/main/java/io/undertow/server/HttpServerExchange.java#L981

                   

                  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