3 Replies Latest reply on Aug 25, 2004 1:03 PM by starksm64

    HttpServletRequest.getServerPort() incorrectly returns 80 ?

    danorris

      All,

      I'm using JBoss 3.2.5 in a highly vanilla configuration. Specifically, Tomcat's got an HTTP connector on 8080, and I'm *not* using an AJP connector to tunnel requests through Apache.

      When I'm in a servlet and I call request.getServerPort(), though, it returns port 80, even though I'm accessing it over port 8080. I checked in deploy/jbossweb-tomcat50.sar/server.xml to make sure there was no proxyPort defined, and indeed there isn't.

      Any ideas why I'm seeing this behavior?

      Many thanks,
      --
      David Norris
      danorris@gmail.com

        • 1. Re: HttpServletRequest.getServerPort() incorrectly returns 8
          danorris

          Followup: I tried adding proxyPort="8080" to server.xml. After that, getServerPort() does correctly return 8080. But shouldn't proxyPort default to the actual port setting, which is 8080? I shouldn't need to explicitly specify a proxyPort.

          Thanks again,
          --
          David Norris
          danorris@gmail.com

          • 2. Re: HttpServletRequest.getServerPort() incorrectly returns 8
            danorris

            Another followup: I don't see this behavior in JBoss 3.2.3; getServerPort() correctly returns 8080 with the stock configuration. Is it possible this is a bug introduced between .3 and .5?

            --
            David Norris
            danorris@gmail.com

            • 3. Re: HttpServletRequest.getServerPort() incorrectly returns 8
              starksm64

              This works fine for me. The following snoop.jsp shows the ServerPort to be 8080 using the out of the box default configuration.

              <%@page import="java.io.*,javax.naming.*,
               java.util.Date,
               java.util.Enumeration" %>
              <html>
              
              <body bgcolor="white">
              <h1> Session Info</h1>
              SessionID: <%= session.getId() %><br>
              CreationTime: <%= new Date(session.getCreationTime()) %><br>
              LastAccessedTime: <%= new Date(session.getLastAccessedTime()) %><br>
              
              <h1> Request Information </h1>
              <font size="4">
              JSP Request Method: <%= request.getMethod() %>
              <br>
              Request URL: <%= request.getRequestURL() %>
              <br>
              Request URI: <%= request.getRequestURI() %>
              <br>
              Request Protocol: <%= request.getProtocol() %>
              <br>
              Servlet path: <%= request.getServletPath() %>
              <br>
              Path info: <%= request.getPathInfo() %>
              <br>
              Path translated: <%= request.getPathTranslated() %>
              <br>
              Query string: <%= request.getQueryString() %>
              <br>
              Content length: <%= request.getContentLength() %>
              <br>
              Content type: <%= request.getContentType() %>
              <br>
              Server name: <%= request.getServerName() %>
              <br>
              Server port: <%= request.getServerPort() %>
              <br>
              UserPrincipal: <%= request.getUserPrincipal() %>
              <br>
              Remote user: <%= request.getRemoteUser() %>
              <br>
              Remote address: <%= request.getRemoteAddr() %>
              <br>
              Remote host: <%= request.getRemoteHost() %>
              <br>
              Authorization scheme: <%= request.getAuthType() %>
              <br>
              Is secure: <%= request.isSecure() %>
              <br>
              Locale: <%= request.getLocale() %>
              <hr>
              The browser you are using is <%= request.getHeader("User-Agent") %>
              <hr>
              </font>
              </body>
              </html>
              
              


              Session Info
              SessionID: 7E160FE21A6A44A0DBF4D8614FF4FB29
              CreationTime: Wed Aug 25 09:53:38 PDT 2004
              LastAccessedTime: Wed Aug 25 09:53:38 PDT 2004
              Request Information
              JSP Request Method: GET
              Request URL: http://localhost:8080/jmx-console/snoop.jsp
              Request URI: /jmx-console/snoop.jsp
              Request Protocol: HTTP/1.1
              Servlet path: /snoop.jsp
              Path info: null
              Path translated: null
              Query string: null
              Content length: -1
              Content type: null
              Server name: localhost
              Server port: 8080
              UserPrincipal: null
              Remote user: null
              Remote address: 127.0.0.1
              Remote host: 127.0.0.1
              Authorization scheme: null
              Is secure: false
              Locale: en_US The browser you are using is Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20040616