tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chet Hosey <ChetHo...@gmail.com>
Subject Re: UriInfo always returning "localhost" in URIs
Date Tue, 05 Feb 2013 22:45:52 GMT
After building httpd 2.2.23 and mod_jk 1.2.37, I configured an AJP proxy
for the TomEE test instance and set the jvmRoute in server.xml to match the
worker name from workers.properties.

A request through httpd shows httpd's port number for the
httpServletRequest methods, but still shows the TomEE HTTP connector port
in the URIs returned by the uriInfo methods.

Doing string replacements seems fairly inelegant but I suppose it's an
option for custom apps. It would be surprising to learn that the only other
option is to configure the TomEE instances' HTTP connectors on the same
port as the httpd server, since each TomEE instance would then need a
dedicated IP.

I've filed TOMEE-757 in JIRA, as it's hard to imagine that this behavior is
intended.


On Tue, Feb 5, 2013 at 9:17 AM, Chet Hosey <ChetHosey@gmail.com> wrote:

> Ahh, that's a good thought. It was the default value of "localhost". After
> changing the "name" attribute on the Host entry and updating the
> defaultHost on the Engine, I'm getting the expected host name in the
> response.
>
> This leads me to wonder what happens when using AJP. I'm picturing a setup
> where httpd runs on port 80 and proxies to multiple TomEE instances via
> AJP. If the HTTP connector port is still used by the UriInfo methods, then
> TomEE would require special access (root or authbind) to bind to port 80 to
> work around this behavior. And it wouldn't be possible to run multiple
> TomEE instances on the same IP, since they'd all have to bind to port 80 to
> ensure URI correctness.
>
> I'll have to experiment to find out. If I get the chance to do so, I'll
> report results back.
>
> Thanks!
>
>
> On Tue, Feb 5, 2013 at 1:16 AM, Romain Manni-Bucau <rmannibucau@gmail.com>wrote:
>
>> Hi,
>>
>> What's your host in the server.xml?
>> Le 5 févr. 2013 06:30, "Chet Hosey" <ChetHosey@gmail.com> 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
>> >
>>
>
>

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