Hi,
What's your host in the server.xml?
Le 5 févr. 2013 06:30, "Chet Hosey" <[email protected]> a écrit :
> 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
>
> uriInfo.getBaseUriBuilder()
> .path(User.class, "getUserInfo")
> .path(userId).build();
>
> 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:
>
> @GET
> @Produces({MediaType.TEXT_PLAIN})
> 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.getLocalAddr(): 1.2.3.4
> httpServletRequest.getLocalName(): www.example.com
> httpServletRequest.getLocalPort(): 8081
> httpServletRequest.getServerName(): www.example.com
> httpServletRequest.getServerPort(): 8081
>
> host:
> www.example.com: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
>