Hmm. I on further thought, "Referer" is not the proper header to use.
Something more like this instead:
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 host =
cycle.getWebRequest().getHttpServletRequest().getHeader("Host");
String context =
cycle.getWebRequest().getHttpServletRequest().getContextPath();
StringBuffer url = new StringBuffer();
url.append("http://
").append(host).append(context).append("/").append(urn);
return url.toString();
}
On Fri, Jun 27, 2008 at 9:58 AM, Matthew Hanlon <[EMAIL PROTECTED]> wrote:
> 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<http://wikipedia.org/wiki/Hanlon%27s_razor>
--
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