I was having a problem getting the full url of a page or resource after
deploying my application behind a proxy.  I was previously doing the
following:

public String getUrl(MyResource res) {
PageParameters params = new PageParameters();
params.put(Constants.MY_RESOURCE, res.getId());
WebRequestCycle cycle = (WebRequestCycle)RequestCycle.get();
return RequestUtils.toAbsolutePath(cycle.urlFor(MyResponsePage.class,
params).toString());
  }

However, after deploying behind a proxy, I was expecting to get "
http://my.domain.com/MyResourcePage/resouce/xxx"; and instead was getting "
http://localhost:8080/MyResourcePage/resouce/xxx";.  So I adjusted to doing
the following:

  public String getUrl(MyResource res) {
        PageParameters params = new PageParameters();
        params.put(Constants.MY_RESOURCE, res.getId());
        WebRequestCycle cycle = (WebRequestCycle)RequestCycle.get();
        String urn = cycle.urlFor(MyResponsePage.class, params).toString();
        String referer =
cycle.getWebRequest().getHttpServletRequest().getHeader("Referer");
        String context =
cycle.getWebRequest().getHttpServletRequest().getContextPath();
        PrependingStringBuffer url = new PrependingStringBuffer(urn);
        url.prepend(referer.substring(0, referer.indexOf(context) +
context.length() + 1));
        return url.toString();
  }

It's working, but I was curious if anyone had any input or a better method
of accomplishing this.  Thanks!

Regards,
Matthew.

-- 
Matthew Rollins Hanlon
http://squareoftwo.org
_____________________
Hanlon's Razor:
"Never attribute to malice that which can be adequately explained by
stupidity."
http://wikipedia.org/wiki/Hanlon's_razor

Reply via email to