tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chet Hosey <>
Subject UriInfo always returning "localhost" in URIs
Date Mon, 04 Feb 2013 22:35:22 GMT
I've been using apache-tomee-1.5.1-jaxrs as a platform for learning JAX-RS
and have run into some confusion about UriInfo determines the base URI. In
my testing the URIs returned by UriInfo include the correct port number.
But the host name is always "localhost", even when I'm accessing TomEE from
a remote machine.

It's possible that UriInfo is meant to build identifiers, and not locators.
This would explain why it's not called UrlInfo. But the design of
UriBuilder suggests that one should be able to call

         .path(User.class, "getUserInfo")

and use the result as a hyperlink in a JAX-RS response.

Having used mod_jk with JBoss, I know that it can override the values
returned by HttpServletRequest methods with parameters like JK_LOCAL_NAME.
But since this is just a sandbox I'm accessing Tomcat directly, without an
Apache httpd proxy. But this led me to wonder what
httpServletRequest.getlocalName() would return. So I created a test method
to find out, using the following signature:

   public String defaultPage(@Context UriInfo uriInfo,
         @Context HttpHeaders hh,
         @Context HttpServletRequest httpServletRequest) {

The output surprised me. The HttpServletRequest methods use the correct
host name and IP address, and the "Host" header uses the public address.
The UriInfo methods get the port correct, but they still use "localhost" as
the host name.

   uriInfo.getAbsolutePath(): http://localhost:8081/sample-app-1.0-SNAPSHOT/
   uriInfo.getBaseUri(): http://localhost:8081/sample-app-1.0-SNAPSHOT
   uriInfo.getRequestUri(): http://localhost:8081/sample-app-1.0-SNAPSHOT/
   httpServletRequest.getLocalPort(): 8081
   httpServletRequest.getServerPort(): 8081


Is there a way to use TomEE's embedded CXF REST implementation to generate
URIs that can be used by external clients to locate other resources within
the same application? Or am I making bad assumptions about the purpose of
the UriInfo methods that return UriBuilders?

-- Chet

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message