You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Matthew Hanlon <mr...@gmail.com> on 2008/06/27 16:58:09 UTC

Obtaining full URLs behind a proxy

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

Re: Obtaining full URLs behind a proxy

Posted by Matthew Hanlon <mr...@gmail.com>.
Yeah, that's what I'd found.  I had looked at the "Wicket Behind a Proxy"
wiki page.  I'm using mod_proxy and proxypassreverse, but not the preserve
host setting.
I had originally set much of the host information in settings files, but
when I moved from wicket 2.0 to 1.4 some of that code broke due to how
wicket was handling relative urls.  I thought about setting a custom header
in the request, but instead I have gone back to setting the hostname in a
settings file and then using wicket to discover the context and page path,
and then building the url from the three.

Thanks for the help!

Regards,
Matthew.

On Sat, Jun 28, 2008 at 1:52 AM, Nino Saturnino Martinez Vazquez Wael <
nino.martinez@jayway.dk> wrote:

> true, as you write it's actually the proxy that fuddles it up..
>
> Timo Rantalaiho wrote:
>
>> On Fri, 27 Jun 2008, Matthew Hanlon wrote:
>>
>>
>>> I was having a problem getting the full url of a page or resource after
>>> deploying my application behind a proxy.
>>>
>> ...
>>
>>
>>> 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
>>>
>>>
>>
>> I have been told that in the end of the day, the only surely universal way
>> to get the host name you want is to put it manually in some configuration
>> file in your application.
>>
>> In a specific context, you might get it right by configuring
>> the proxy to pass on the original request hostname either directly in the
>> proxied request or in a custom header.
>>
>> This is not a Wicket specific thing.
>>
>> Best wishes,
>> Timo
>>
>>
>>
>
> --
> -Wicket for love
>
> Nino Martinez Wael
> Java Specialist @ Jayway DK
> http://www.jayway.dk
> +45 2936 7684
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
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

Re: Obtaining full URLs behind a proxy

Posted by Nino Saturnino Martinez Vazquez Wael <ni...@jayway.dk>.
true, as you write it's actually the proxy that fuddles it up..

Timo Rantalaiho wrote:
> On Fri, 27 Jun 2008, Matthew Hanlon wrote:
>   
>> I was having a problem getting the full url of a page or resource after
>> deploying my application behind a proxy.  
>>     
> ...
>   
>> 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
>>     
>
> I have been told that in the end of the day, the only surely 
> universal way to get the host name you want is to put it 
> manually in some configuration file in your application.
>
> In a specific context, you might get it right by configuring
> the proxy to pass on the original request hostname either 
> directly in the proxied request or in a custom header.
>
> This is not a Wicket specific thing.
>
> Best wishes,
> Timo
>
>   

-- 
-Wicket for love

Nino Martinez Wael
Java Specialist @ Jayway DK
http://www.jayway.dk
+45 2936 7684


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Obtaining full URLs behind a proxy

Posted by Timo Rantalaiho <Ti...@ri.fi>.
On Fri, 27 Jun 2008, Matthew Hanlon wrote:
> I was having a problem getting the full url of a page or resource after
> deploying my application behind a proxy.  
...
> 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

I have been told that in the end of the day, the only surely 
universal way to get the host name you want is to put it 
manually in some configuration file in your application.

In a specific context, you might get it right by configuring
the proxy to pass on the original request hostname either 
directly in the proxied request or in a custom header.

This is not a Wicket specific thing.

Best wishes,
Timo

-- 
Timo Rantalaiho           
Reaktor Innovations Oy    <URL: http://www.ri.fi/ >

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Obtaining full URLs behind a proxy

Posted by Nino Saturnino Martinez Vazquez Wael <ni...@jayway.dk>.
Resin, havent heard about that in years:) So it's still there..

Are you using mod proxy..? You could try to set proxypreserve host on... 
but I havent been able to get it to work... But never matter what, your 
url should be rewritten whats your apache vhost conf? And are you using 
proxypassreverse..? And you can also get apache to add headers for 
you(im not sure if thats what your doing?)..

Did you see this:

http://cwiki.apache.org/WICKET/wicket-behind-a-front-end-proxy.html

Matthew Hanlon wrote:
> Yes, it's running on Resin behind Apache.  I think I'm probably missing
> something in my configurations somewhere.  I don't like either of the
> methods I mentioned below.  Still trying to figure out the best solution.
>
> On Fri, Jun 27, 2008 at 4:29 PM, Nino Saturnino Martinez Vazquez Wael <
> nino.martinez@jayway.dk> wrote:
>
>   
>> Which proxy are it? apache2 httpd?
>>
>> Matthew Hanlon wrote:
>>
>>     
>>> 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 <mr...@gmail.com>
>>> 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>
>>>> <http://wikipedia.org/wiki/Hanlon%27s_razor>
>>>>
>>>>
>>>>         
>>>
>>>
>>>
>>>
>>>       
>> --
>> -Wicket for love
>>
>> Nino Martinez Wael
>> Java Specialist @ Jayway DK
>> http://www.jayway.dk
>> +45 2936 7684
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>>     
>
>
>   

-- 
-Wicket for love

Nino Martinez Wael
Java Specialist @ Jayway DK
http://www.jayway.dk
+45 2936 7684


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Obtaining full URLs behind a proxy

Posted by Matthew Hanlon <mr...@gmail.com>.
Yes, it's running on Resin behind Apache.  I think I'm probably missing
something in my configurations somewhere.  I don't like either of the
methods I mentioned below.  Still trying to figure out the best solution.

On Fri, Jun 27, 2008 at 4:29 PM, Nino Saturnino Martinez Vazquez Wael <
nino.martinez@jayway.dk> wrote:

> Which proxy are it? apache2 httpd?
>
> Matthew Hanlon wrote:
>
>> 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 <mr...@gmail.com>
>> 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>
>>> <http://wikipedia.org/wiki/Hanlon%27s_razor>
>>>
>>>
>>
>>
>>
>>
>>
>>
>
> --
> -Wicket for love
>
> Nino Martinez Wael
> Java Specialist @ Jayway DK
> http://www.jayway.dk
> +45 2936 7684
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
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

Re: Obtaining full URLs behind a proxy

Posted by Nino Saturnino Martinez Vazquez Wael <ni...@jayway.dk>.
Which proxy are it? apache2 httpd?

Matthew Hanlon wrote:
> 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 <mr...@gmail.com> 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>
>>     
>
>
>
>
>   

-- 
-Wicket for love

Nino Martinez Wael
Java Specialist @ Jayway DK
http://www.jayway.dk
+45 2936 7684


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Obtaining full URLs behind a proxy

Posted by Matthew Hanlon <mr...@gmail.com>.
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 <mr...@gmail.com> 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