Thursday, February 16, 2012

Disable session saving in tomcat

When starting Tomcat you may have such an error:



Feb 16, 2012 10:24:15 AM org.apache.catalina.session.StandardManager doLoad
SEVERE: IOException while loading persisted sessions:
java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException:


If you are developing and changing your code regularly, it is most annoying. The easiest is to convince tomcat not to persist sessions across Tomcat restarts.

1. Got to file: context.xml (in eclipse, you find it under Serves->tomcat v7.0 at localhost. or something equivalent)
2. Uncomment

That's it.

Friday, February 3, 2012

Execution plan with Derby

I don't know for you, but I do have sometimes the problem to find out how a database works.
I usually have SQuirreL SQL for connecting the db, but I don't know how to retrieve the execution plan.

I went through the documentation for Derby and finally got the answer. I still will have to find out how to interpret the stuff !


CALL SYSCS_UTIL.SYSCS_SET_RUNTIMESTATISTICS(1);
select * from EDW_BPM_OBJECT;
call SYSCS_UTIL.SYSCS_SET_RUNTIMESTATISTICS(0);
VALUES SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS();

Friday, December 2, 2011

Adding user data to a timer thread

I had the quite usual requirement to add user info to a timer.
Some code was retrieving user date from the request scope in order to log the data with each change in the database.
Unfortunately, the timer has no request scope associated with it. And of course no user object attached to the request scope.

With Spring you can user the RunAs mechanism to add rights to a user. This is exactly what I did.

1. First I use the thread scope found www.springbyexample.org/examples/custom-thread-scope-module.html which I configure as
  
      
          
              
                  
              
          
      
  


Now the authentication itself gets configured:
    
    
        
        
    


The third element of configuration is the proxy configuration after the timer.
    
        
        
        
            
                threadScopeAfterAdvice
                threadAuthenticationInterceptor
            
        
    


the threadScopeAfterAdvice only cleans the scope after the thread execution is done.

the threadAuthenticationInterceptor is a org.aopalliance.intercept.MethodInterceptor

public Object invoke(MethodInvocation invocation) throws Throwable {
        UserDetails userDetail = userDetailService.loadUserByUsername(userId);
        RunAsUserToken runAsUserToken = new RunAsUserToken("mykey", userDetail, USER_CREDENTIALS,
                userDetail.getAuthorities(), null);

        Authentication authentication = authenticationManager.authenticate(runAsUserToken);
        if (authentication.isAuthenticated()) {
            SecurityContext sc = new SecurityContextImpl();
            sc.setAuthentication(authentication);
            SecurityContextHolder.setContext(sc);
        }

        try {
            return invocation.proceed();
        } finally {
            SecurityContextHolder.clearContext();

        }
    }

Thursday, October 20, 2011

Step filtering in eclipse

With the Mockito framework it may be annoying to step through the internal Mockito code instead of your code.

With eclipse there is a way to prevent this. Step filtering.

Tuesday, July 19, 2011

Setting language in gimp

I regularly have the problem that my Windows machine is set for German! Some times I'm not even allowed to set it to English, but when I can, it doesn't work as it should. It is only half in English.

Changing the language of The Gimp. Well the problem is that gtk+ has the wrong language.
So control panel -> system -> advanced system setting.
Add a new environment varialbe named "lang" with a value of "c"
Restart The Gimp
et voila


thanks to Syko

Friday, July 1, 2011

JSF2 state saving and event phase shifting

An annoying aspect of valueChangeListener in JSF2 is that it is not handled in the phase I expected.







The method selectAllChangeListener is in the validation phase and not in the invoke application phase as you may need it.
The good news is you can re-throw the event.

public void selectAllChangeListener(ValueChangeEvent e) {
if (!e.getPhaseId().equals(PhaseId.INVOKE_APPLICATION)) {
e.setPhaseId(PhaseId.INVOKE_APPLICATION);
e.queue();
} else {
boolean selectAll = (Boolean) e.getNewValue();
boolean lastSelectAllStateSet = (Boolean) getStateHelper().get(LAST_SELECTED_ALL_SET);
if (lastSelectAllStateSet != selectAll) {
getTableModel().setSelectAll(selectAll);
getStateHelper().put(LAST_SELECTED_ALL_SET, selectAll);
}
}
}

It is important to queue the event on the same component. Which is what e.queue() does. It is equivalent to

e.getComponent().queueEvent(e);


Another important point is the call to getStateHelper.
You cannot keep states in a JSF component. You will loose the reference to the component after a refresh of your page (F5 on Firefox). You must keep them with the getStateHelper method.

Friday, June 24, 2011

Setting attributes in JSF2's commandLinks

One of the recurrent problem with JSF is how can I pass argument from my xhtml facelet page to my backing bean. I've seen various possibilities, but the simplest is probably this one.

<h:commandlink value="click me">
<f:setpropertyactionlistener target="#{myBean.mySetterMethod}" value="myNewValue" />
</h:commandlink>

The example is of course minimalist.