Re: t5: adding http header

2012-09-23 Thread netdawg
Thanks!! 

Yep, even though java -version on command line shows 1.6, the Eclipse (right
click) project --> properties --> java compiler shows using "JDK 1.5
compliance".  Changed that to 1.6 and sure enough no complaints on the
@Override annotation anymore.

And thanks for that typo catch  ;-).  

In fact, off-topic, but in case anyone would  like to use this code, the
whole expires date can be made redundant by using max-age in the HTTP
request header, per RFC 2616 14.21.  

response.setHeader(CACHE_CTRL, "no-cache, no-store, max-age=0,
must-revalidate"); 

Also see: http://www.mnot.net/blog/2007/05/15/expires_max-age

(this also has a link to an excellent tutorial on caches - must read - basic
message being cache control is probably best handled by web server, if you
can control it,  rather than in your application)



--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/t5-adding-http-header-tp3369097p5716463.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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



Re: t5: adding http header

2012-09-23 Thread Chris Mylonas
you've got a typo here :)

>  private static final String EXPIRE_DATE = "Exprires";


s/Exprires/Expires/g


i haven't tried it but may give it a go l8r, useful looking service!


off topic but [1] seems relevant
there is a jquery prefilter suggestion when using jquery

[1] = 
http://stackoverflow.com/questions/12506897/is-safari-on-ios-6-caching-ajax-results



On 24/09/2012, at 5:25 AM, netdawg wrote:

> Wulf:  Why (rather how) the @Override annotation ?  I actually had to remove
> it for it work.   
> 
> Anyhooo...here is the complete working example (right or wrong, not
> sure)...comments welcome...
> 
> Step 1.  Created a class in your src/main/java -- SERVICES package - where
> you will find AppModule.java already installed by Tapestry.  In my case, I
> created a class called RevalidateHTTPHeader 
> 
> package org.yourGroupId.yourArtifactId.services;
> 
> import java.io.IOException;
> 
> import org.apache.tapestry5.services.Request;
> import org.apache.tapestry5.services.RequestFilter;
> import org.apache.tapestry5.services.RequestHandler;
> import org.apache.tapestry5.services.Response;
> 
> 
> public class RevalidateHTTPHeader implements RequestFilter 
> {
> 
>  private static final String CACHE_CTRL = "Cache-Control";
>  private static final String EXPIRE_DATE = "Exprires";
> 
>  public boolean service(Request request, Response response,  RequestHandler
> handler) throws IOException 
>  { 
>response.setHeader(CACHE_CTRL, "no-cache, no-store, must-revalidate"); 
>response.setHeader(EXPIRE_DATE, "Sun, 07 Dec 1941  07:55:00 GMT"); 
>return handler.service(request, response);   
>  }
> }
> 
> 
> Step 2.  Within AppModule.java, do two things - 
> 
> a.  declare the following member variable
> 
> RevalidateHTTPHeader nocache = new RevalidateHTTPHeader();
> 
> b.  add the following within contributeRequestHandler method:
> 
>public void contributeRequestHandler(OrderedConfiguration
> configuration,
> @Local
> RequestFilter filter)
>{
>// Each contribution to an ordered configuration has a name, When
> necessary, you may
>// set constraints to precisely control the invocation order of the
> contributed filter
>// within the pipeline.
> 
>///
>//  ADD the custom nocache HTTP header(s)  
> 
>   configuration.add("NoCache", nocache);  
> 
>   //
>  //
> 
> 
>configuration.add("Timing", filter);
>}
> 
> Step 3:   Run Jetty to verify/examine headers - I am using Google Chrome -
> which has a free HTTP Headers extension.  
> http://localhost:8080/yourArtifactId/[yourPage]
> 
> Name   Extension
> Content-Encoding  gzip
> Exprires Sun, 07 Dec 1941  07:55:00 GMT
> Transfer-Encoding  chunked
> Server  Jetty(6.1.26)
> Content-Type text/html; charset=utf-8
> Cache-Controlno-cache, no-store, must-revalidate
> 
> 
> 
> 
> 
> --
> View this message in context: 
> http://tapestry.1045711.n5.nabble.com/t5-adding-http-header-tp3369097p5716459.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
> 
> -
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
> 



Re: t5: adding http header

2012-09-23 Thread Bob Harner
"probably", not "problem", sorry.

On Sun, Sep 23, 2012 at 3:36 PM, Bob Harner  wrote:
> If the compiler complained about @Override, you are problem using a
> 1.5 JDK and Wulf (I assume) was using 1.6.
>
> On Sun, Sep 23, 2012 at 3:25 PM, netdawg  wrote:
>> Wulf:  Why (rather how) the @Override annotation ?  I actually had to remove
>> it for it work.
>>
>> Anyhooo...here is the complete working example (right or wrong, not
>> sure)...comments welcome...
>>
>> Step 1.  Created a class in your src/main/java -- SERVICES package - where
>> you will find AppModule.java already installed by Tapestry.  In my case, I
>> created a class called RevalidateHTTPHeader
>>
>> package org.yourGroupId.yourArtifactId.services;
>>
>> import java.io.IOException;
>>
>> import org.apache.tapestry5.services.Request;
>> import org.apache.tapestry5.services.RequestFilter;
>> import org.apache.tapestry5.services.RequestHandler;
>> import org.apache.tapestry5.services.Response;
>>
>>
>> public class RevalidateHTTPHeader implements RequestFilter
>> {
>>
>>   private static final String CACHE_CTRL = "Cache-Control";
>>   private static final String EXPIRE_DATE = "Exprires";
>>
>>   public boolean service(Request request, Response response,  RequestHandler
>> handler) throws IOException
>>   {
>> response.setHeader(CACHE_CTRL, "no-cache, no-store, must-revalidate");
>> response.setHeader(EXPIRE_DATE, "Sun, 07 Dec 1941  07:55:00 GMT");
>> return handler.service(request, response);
>>   }
>> }
>>
>>
>> Step 2.  Within AppModule.java, do two things -
>>
>> a.  declare the following member variable
>>
>> RevalidateHTTPHeader nocache = new RevalidateHTTPHeader();
>>
>> b.  add the following within contributeRequestHandler method:
>>
>> public void contributeRequestHandler(OrderedConfiguration
>> configuration,
>>  @Local
>>  RequestFilter filter)
>> {
>> // Each contribution to an ordered configuration has a name, When
>> necessary, you may
>> // set constraints to precisely control the invocation order of the
>> contributed filter
>> // within the pipeline.
>>
>> ///
>> //  ADD the custom nocache HTTP header(s)
>>
>>configuration.add("NoCache", nocache);
>>
>>//
>>   //
>>
>>
>> configuration.add("Timing", filter);
>> }
>>
>> Step 3:   Run Jetty to verify/examine headers - I am using Google Chrome -
>> which has a free HTTP Headers extension.
>> http://localhost:8080/yourArtifactId/[yourPage]
>>
>> Name   Extension
>> Content-Encodinggzip
>> Exprires   Sun, 07 Dec 1941  07:55:00 GMT
>> Transfer-Encoding  chunked
>> ServerJetty(6.1.26)
>> Content-Type   text/html; charset=utf-8
>> Cache-Control  no-cache, no-store, must-revalidate
>>
>>
>>
>>
>>
>> --
>> View this message in context: 
>> http://tapestry.1045711.n5.nabble.com/t5-adding-http-header-tp3369097p5716459.html
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>
>> -
>> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
>> For additional commands, e-mail: users-h...@tapestry.apache.org
>>

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



Re: t5: adding http header

2012-09-23 Thread Bob Harner
If the compiler complained about @Override, you are problem using a
1.5 JDK and Wulf (I assume) was using 1.6.

On Sun, Sep 23, 2012 at 3:25 PM, netdawg  wrote:
> Wulf:  Why (rather how) the @Override annotation ?  I actually had to remove
> it for it work.
>
> Anyhooo...here is the complete working example (right or wrong, not
> sure)...comments welcome...
>
> Step 1.  Created a class in your src/main/java -- SERVICES package - where
> you will find AppModule.java already installed by Tapestry.  In my case, I
> created a class called RevalidateHTTPHeader
>
> package org.yourGroupId.yourArtifactId.services;
>
> import java.io.IOException;
>
> import org.apache.tapestry5.services.Request;
> import org.apache.tapestry5.services.RequestFilter;
> import org.apache.tapestry5.services.RequestHandler;
> import org.apache.tapestry5.services.Response;
>
>
> public class RevalidateHTTPHeader implements RequestFilter
> {
>
>   private static final String CACHE_CTRL = "Cache-Control";
>   private static final String EXPIRE_DATE = "Exprires";
>
>   public boolean service(Request request, Response response,  RequestHandler
> handler) throws IOException
>   {
> response.setHeader(CACHE_CTRL, "no-cache, no-store, must-revalidate");
> response.setHeader(EXPIRE_DATE, "Sun, 07 Dec 1941  07:55:00 GMT");
> return handler.service(request, response);
>   }
> }
>
>
> Step 2.  Within AppModule.java, do two things -
>
> a.  declare the following member variable
>
> RevalidateHTTPHeader nocache = new RevalidateHTTPHeader();
>
> b.  add the following within contributeRequestHandler method:
>
> public void contributeRequestHandler(OrderedConfiguration
> configuration,
>  @Local
>  RequestFilter filter)
> {
> // Each contribution to an ordered configuration has a name, When
> necessary, you may
> // set constraints to precisely control the invocation order of the
> contributed filter
> // within the pipeline.
>
> ///
> //  ADD the custom nocache HTTP header(s)
>
>configuration.add("NoCache", nocache);
>
>//
>   //
>
>
> configuration.add("Timing", filter);
> }
>
> Step 3:   Run Jetty to verify/examine headers - I am using Google Chrome -
> which has a free HTTP Headers extension.
> http://localhost:8080/yourArtifactId/[yourPage]
>
> Name   Extension
> Content-Encodinggzip
> Exprires   Sun, 07 Dec 1941  07:55:00 GMT
> Transfer-Encoding  chunked
> ServerJetty(6.1.26)
> Content-Type   text/html; charset=utf-8
> Cache-Control  no-cache, no-store, must-revalidate
>
>
>
>
>
> --
> View this message in context: 
> http://tapestry.1045711.n5.nabble.com/t5-adding-http-header-tp3369097p5716459.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> -
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>

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



RE: t5: adding http header

2012-09-23 Thread netdawg
Wulf:  Why (rather how) the @Override annotation ?  I actually had to remove
it for it work.   

Anyhooo...here is the complete working example (right or wrong, not
sure)...comments welcome...

Step 1.  Created a class in your src/main/java -- SERVICES package - where
you will find AppModule.java already installed by Tapestry.  In my case, I
created a class called RevalidateHTTPHeader 

package org.yourGroupId.yourArtifactId.services;

import java.io.IOException;

import org.apache.tapestry5.services.Request;
import org.apache.tapestry5.services.RequestFilter;
import org.apache.tapestry5.services.RequestHandler;
import org.apache.tapestry5.services.Response;


public class RevalidateHTTPHeader implements RequestFilter 
{

  private static final String CACHE_CTRL = "Cache-Control";
  private static final String EXPIRE_DATE = "Exprires";
 
  public boolean service(Request request, Response response,  RequestHandler
handler) throws IOException 
  { 
response.setHeader(CACHE_CTRL, "no-cache, no-store, must-revalidate"); 
response.setHeader(EXPIRE_DATE, "Sun, 07 Dec 1941  07:55:00 GMT"); 
return handler.service(request, response);   
  }
}


Step 2.  Within AppModule.java, do two things - 

a.  declare the following member variable

RevalidateHTTPHeader nocache = new RevalidateHTTPHeader();

b.  add the following within contributeRequestHandler method:

public void contributeRequestHandler(OrderedConfiguration
configuration,
 @Local
 RequestFilter filter)
{
// Each contribution to an ordered configuration has a name, When
necessary, you may
// set constraints to precisely control the invocation order of the
contributed filter
// within the pipeline.

///
//  ADD the custom nocache HTTP header(s)  
 
   configuration.add("NoCache", nocache);  

   //
  //


configuration.add("Timing", filter);
}

Step 3:   Run Jetty to verify/examine headers - I am using Google Chrome -
which has a free HTTP Headers extension.  
http://localhost:8080/yourArtifactId/[yourPage]

Name   Extension
Content-Encodinggzip
Exprires   Sun, 07 Dec 1941  07:55:00 GMT
Transfer-Encoding  chunked
ServerJetty(6.1.26)
Content-Type   text/html; charset=utf-8
Cache-Control  no-cache, no-store, must-revalidate





--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/t5-adding-http-header-tp3369097p5716459.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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



Re: Advisin Tapestry Session

2012-09-23 Thread Bob Harner
I can't answer your specific question, but as an alternative approach
(and not tied to Tapestry) you could implement an HttpSessionListener,
like this (and configure it in your web.xml):

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import org.apache.log4j.Logger;

public class SessionListener implements HttpSessionListener
{
private static final Logger logger =
Logger.getLogger(SessionListener.class);
private static int currentSessions = 0;
private static int totalSessions  = 0;

public void sessionCreated(HttpSessionEvent httpSessionEvent) {
currentSessions++;
totalSessions++;
logger.info("Session created: current sessions = " +
currentSessions + "; sessions since app started = " + totalSessions);
}
public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
currentSessions--;
logger.info("Session destroyed: current sessions = " +
currentSessions + "; sessions since app started = " + totalSessions);
}
}

Your sessionDestroyed() method is called just *before* the session is
invalidated (e.g. from a timeout).


On Sun, Sep 23, 2012 at 9:58 AM, Matías Blasi  wrote:
> Hi all,
>
> I'm trying to implement a mechanism to track each user session, at least
> the login and logout events.
> The login is easy, because it occurs in a defined place, but the logout can
> occurs explicitly or because of a timeout, so I thought in advising the
> Tapestry Session.invalidate() method:
>
> @SuppressWarnings("unchecked")
> @Advise(serviceInterface=org.apache.tapestry5.services.Session.class)
> public static void adviseUserActivity(final UserService userService,
> final MethodAdviceReceiver receiver)
> throws SecurityException, NoSuchMethodException {
> MethodAdvice advise = new MethodAdvice() {
> @Override
> public void advise(MethodInvocation invocation) {
> userService.endSession(userService.getCurrentUser().getUserName());
> }
> };
>
>
>   receiver.adviseMethod(receiver.getInterface().getMethod("invalidate"),
> advise);
> }
>
> But oddly, I'm getting the following error when starting up the application:
>
> Caused by: java.lang.RuntimeException: Error invoking method public static
> void
> com.app.services.AppModule.adviseUserActivity(com.app.core.services.UserService,org.apache.tapestry5.ioc.MethodAdviceReceiver)
> throws java.lang.SecurityException,java.lang.NoSuchMethodException:
> org.hibernate.Session.invalidate()
> at
> org.apache.tapestry5.ioc.internal.util.MethodInvoker.invoke(MethodInvoker.java:61)
> at
> org.apache.tapestry5.ioc.internal.util.LoggingInvokableWrapper.invoke(LoggingInvokableWrapper.java:42)
> at
> org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:74)
> ... 79 more
> Caused by: java.lang.NoSuchMethodException:
> org.hibernate.Session.invalidate()
> at java.lang.Class.getMethod(Class.java:1622)
> at com.app.services.AppModule.adviseUserActivity(AppModule.java:198)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:616)
> at
> org.apache.tapestry5.ioc.internal.util.MethodInvoker.invoke(MethodInvoker.java:50)
> ... 81 more
> 2012-09-23 10:50:11.134::INFO:  Started SelectChannelConnector@0.0.0.0:8080
> [INFO] Started Jetty Server
>
> Why is it trying to advise the org.hibernate.Sesssion.invalidate() method
> if I explicitly
> annotated: 
> @Advise(serviceInterface=org.apache.tapestry5.services.Session.class),
> is it a bug?
>
> Anyway, do you think this is the best way of doing this, or is there any
> other better mechanism to intercept a finished session?
>
> Best regards,
> Matias.

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



Advisin Tapestry Session

2012-09-23 Thread Matías Blasi
Hi all,

I'm trying to implement a mechanism to track each user session, at least
the login and logout events.
The login is easy, because it occurs in a defined place, but the logout can
occurs explicitly or because of a timeout, so I thought in advising the
Tapestry Session.invalidate() method:

@SuppressWarnings("unchecked")
@Advise(serviceInterface=org.apache.tapestry5.services.Session.class)
public static void adviseUserActivity(final UserService userService,
final MethodAdviceReceiver receiver)
throws SecurityException, NoSuchMethodException {
MethodAdvice advise = new MethodAdvice() {
@Override
public void advise(MethodInvocation invocation) {
userService.endSession(userService.getCurrentUser().getUserName());
}
};


  receiver.adviseMethod(receiver.getInterface().getMethod("invalidate"),
advise);
}

But oddly, I'm getting the following error when starting up the application:

Caused by: java.lang.RuntimeException: Error invoking method public static
void
com.app.services.AppModule.adviseUserActivity(com.app.core.services.UserService,org.apache.tapestry5.ioc.MethodAdviceReceiver)
throws java.lang.SecurityException,java.lang.NoSuchMethodException:
org.hibernate.Session.invalidate()
at
org.apache.tapestry5.ioc.internal.util.MethodInvoker.invoke(MethodInvoker.java:61)
at
org.apache.tapestry5.ioc.internal.util.LoggingInvokableWrapper.invoke(LoggingInvokableWrapper.java:42)
at
org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:74)
... 79 more
Caused by: java.lang.NoSuchMethodException:
org.hibernate.Session.invalidate()
at java.lang.Class.getMethod(Class.java:1622)
at com.app.services.AppModule.adviseUserActivity(AppModule.java:198)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at
org.apache.tapestry5.ioc.internal.util.MethodInvoker.invoke(MethodInvoker.java:50)
... 81 more
2012-09-23 10:50:11.134::INFO:  Started SelectChannelConnector@0.0.0.0:8080
[INFO] Started Jetty Server

Why is it trying to advise the org.hibernate.Sesssion.invalidate() method
if I explicitly
annotated: 
@Advise(serviceInterface=org.apache.tapestry5.services.Session.class),
is it a bug?

Anyway, do you think this is the best way of doing this, or is there any
other better mechanism to intercept a finished session?

Best regards,
Matias.