You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Martin Grotzke <ma...@javakaffee.de> on 2008/08/07 15:16:14 UTC

T5 How to tell T5 to send 301 (moved permanently)

Hi,

when I return a link in some method T5 send a 302. I want to send a 301
to the client. Is this possible with tapestry, without using the servlet
stuff?

Thanx && cheers,
Martn


Re: T5 How to tell T5 to send 301 (moved permanently)

Posted by "Filip S. Adamsen" <fs...@fsadev.com>.
Hi,

I actually extended HttpStatusCode to take care of this.

Here's the code:

HttpStatusCode.java:

public class HttpStatusCode
     implements Serializable {

   private final int statusCode;
   private final String location;

   public HttpStatusCode(int statusCode) {
     this.statusCode = statusCode;
     this.location = "";
   }

   public HttpStatusCode(int statusCode, String location) {
     this.statusCode = statusCode;
     this.location = location;
   }

   public HttpStatusCode(int statusCode, Link link) {
     this(statusCode, link.toRedirectURI());
   }

   public HttpStatusCode(int statusCode, URL url) {
     this(statusCode, url.toExternalForm());
   }

   public int getStatusCode() {
     return statusCode;
   }

   public String getLocation() {
     return location;
   }
}


AppModule.java:

   public static void contributeComponentEventResultProcessor(
       MappedConfiguration<Class, ComponentEventResultProcessor> 
configuration, final Response response) {
     configuration.add(HttpStatusCode.class, new 
ComponentEventResultProcessor<HttpStatusCode>() {
       public void processResultValue(HttpStatusCode value) throws 
IOException {
         if (!value.getLocation().isEmpty()) 
response.setHeader("Location", value.getLocation());
         response.sendError(value.getStatusCode(), "");
       }
     });
   }

Now all you need to do is:

   return new HttpStatusCode(HttpServletResponse.SC_MOVED_PERMANENTLY, 
link);

Link can be a String, a Link or a URL.

-Filip

On 2008-08-13 19:35, Martin Grotzke wrote:
> Hi Lutz,
> 
> this approach sounds really good, I'll give it a try.
> 
> Thanx && cheers,
> Martin
> 
> 
> On Sat, 2008-08-09 at 00:11 +0200, Lutz Hühnken wrote:
>> I haven't tried it, but I think it should work with the approach described in
>>
>> http://www.nabble.com/Index-page-context-and-404-response-to16649174.html#a16649174
>>
>> It works fine for 404, you might have to extend it to include the URL
>> to the page you are redirecting to.
>>
>> Hth,
>>
>> Lutz
>>
>>
>> On Thu, Aug 7, 2008 at 3:16 PM, Martin Grotzke
>> <ma...@javakaffee.de> wrote:
>>> Hi,
>>>
>>> when I return a link in some method T5 send a 302. I want to send a 301
>>> to the client. Is this possible with tapestry, without using the servlet
>>> stuff?
>>>
>>> Thanx && cheers,
>>> Martn

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


Re: T5 How to tell T5 to send 301 (moved permanently)

Posted by Martin Grotzke <ma...@javakaffee.de>.
Hi Lutz,

this approach sounds really good, I'll give it a try.

Thanx && cheers,
Martin


On Sat, 2008-08-09 at 00:11 +0200, Lutz Hühnken wrote:
> I haven't tried it, but I think it should work with the approach described in
> 
> http://www.nabble.com/Index-page-context-and-404-response-to16649174.html#a16649174
> 
> It works fine for 404, you might have to extend it to include the URL
> to the page you are redirecting to.
> 
> Hth,
> 
> Lutz
> 
> 
> On Thu, Aug 7, 2008 at 3:16 PM, Martin Grotzke
> <ma...@javakaffee.de> wrote:
> > Hi,
> >
> > when I return a link in some method T5 send a 302. I want to send a 301
> > to the client. Is this possible with tapestry, without using the servlet
> > stuff?
> >
> > Thanx && cheers,
> > Martn
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5 How to tell T5 to send 301 (moved permanently)

Posted by Lutz Hühnken <lh...@googlemail.com>.
I haven't tried it, but I think it should work with the approach described in

http://www.nabble.com/Index-page-context-and-404-response-to16649174.html#a16649174

It works fine for 404, you might have to extend it to include the URL
to the page you are redirecting to.

Hth,

Lutz


On Thu, Aug 7, 2008 at 3:16 PM, Martin Grotzke
<ma...@javakaffee.de> wrote:
> Hi,
>
> when I return a link in some method T5 send a 302. I want to send a 301
> to the client. Is this possible with tapestry, without using the servlet
> stuff?
>
> Thanx && cheers,
> Martn
>
>

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