At Cake Solutions, we have been using Java for quite a few years. Recently, I had to formulate why our customers should chose Java over other languages. It was easy to come up with geeky reasons, but purely technical reasons on their own are not enough. It turns out that modern Java EE applications are successful, interesting and exciting because of all the tools we have in the Java world–it boils down to the fact that I believe that a lot of the innovation we see in contemporary computing runs on the JVM and with JDK 1.7, we should see even more exciting developments.
In the meantime, download the Why Java PDF, where I try to explain why you should use JVM-based platform over anything else.
Posts Tagged ‘java’
Why Java
Monday, August 23rd, 2010October North West Spring User Group Meeting
Monday, October 19th, 2009Last Tuesday was the North West Spring User Group. I was asked to deliver my jQuery talk that I gave to the South Spring User Group back in September last year.
It’s always good talking about jQuery as it’s relatively straight forward for the audience to read and has a shallow learning curve (if you know CSS already). One of the other pleasures talking about jQuery, and other front end tech, is that you can always show interactive demos to “wow” the audience…
Here are my slides followed by a link to my demo code:
I brought some of my demo code up to date showing examples using the live, event delegation functionality with jQuery. You can view my demo here or download it zipped here.
If you have any queries about the above or want assist you in a jQuery, Javascript and AJAX project contact us.
Spring Integration
Jonas Partner from OpenCredo also gave a presentation on the evening on Spring Integration. His slides are below:
That’s what I call performance
Thursday, August 27th, 2009We are completing work on caching and routing tier we added to a lived-in system. The performance increase is very substantial and I will write a lot more about how we achieved this next week.
For now, I’ll wet your appetite with a screenshot that says it all
P.S. Yes, we’re talking about the
RDTSC and System.nanoTime()!
Introducing AsyncWorker
Tuesday, June 23rd, 2009I have another project for the Open Source Central: AsyncWorker. I am tired of writing similar asynchronous call infrastructure from scratch in every project. This is why I am going to write the AsyncWorker. At the highest level, there will be an interface (class?) AsyncWorker defined as
interface AsyncWorker {
<T> T invoke(T t);
<T> T invoke(T t, int maxWait);
<T> InvocationIdentity execute(T t, AsyncCallback callback);
}
The implementation of the AsyncWorker will be flexible enough to use simple heap, JMS or database queues to store the invocations and the API is very easy to start using in your existing projects. For example, if you wanted to turn a synchronous call into asynchronous one with as little coding as possible, you’d write
@Controller
class ExistingController {
private SomeService someService;
private AsyncWorker asyncWorker;
@RequestMapping(...)
public void index() {
// this.someService.doWork(1, 2, "hello"); #A
this.asyncWorker.invoke(this.someService). #B
doWork(1, 2, "hello");
}
}
That should be it! Instead of synchronous call on line #A, you will use the AsyncWorker on line #B. The AsyncWorker will queue the invocation of the doWork method of SomeService and will return immediately. Because of the asynchronous nature of the call, the value returned from the method call will be default for the return type (0 for int, long, 0.0 for double, float, null for object reference, etc.).
The alternatives, as you can guess, are using the invoke(T, int) method, which will also invoke any method of T asynchronously, but will wait up to the specified timespan before returning. If the invoked method completes within the specified timespan, the returned value will be valid, otherwise it will be the default value.
Finally, you can use the execute method to schedule the asynchronous call — this gives you the highest degree of control and you will get an InvocationIdentity object back. You will be able to use the returned InvocationIdentity to monitor the progress of the call.
Call for comments
If you think this is a good idea, please comment and add any features you’d find useful. We will be releasing this project under the Open Source Central under Apache Licence.
Acegi Concurrent Login
Thursday, May 8th, 2008It is a security requirement for most web sites to disable concurrent logins, so users cannot login from different machines using same login details.
Let’s see how to enable this functionality with Acegi Security.
Firstly, add org.acegisecurity.concurrent.SessionRegistry implementation bean to your security context:
<bean id="sessionRegistry" class="org.acegisecurity.concurrent.SessionRegistryImpl" />
We are using default Acegi implementation org.acegisecurity.concurrent.SessionRegistryImpl.
Next, define the org.acegisecurity.concurrent.SessionController bean:
<bean id="sessionController" class="org.acegisecurity.
concurrent.ConcurrentSessionControllerImpl">
<property name="exceptionIfMaximumExceeded" value="true"/>
<property name="maximumSessions" value="1" />
<property name="sessionRegistry" ref="sessionRegistry"/>
</bean>
As you can see, it takes sessionRegistry property, as well as two additional properties maximumSessions and exceptionIfMAximumExceeded.
maximumSessions says how meny concurrent login sessions are allowed (in our case just one)
if exceptionIfMAximumExceeded property is set to true, exception will be thrown every time the user tries to login concurrently. You can check this exception in your login controller and display user with a message.
Otherwise, if exceptionIfMAximumExceeded property is set to false, exception will NOT be thrown. If user tries to login concurrently, he will be allowed, but his last login session (before the concurrent one) will be invalidated.
Last step is to add sessionController property to your ProviderManager bean:
<bean id="authenticationManager" class="org.acegisecurity.providers.ProviderManager">
<property name="providers">
<list>
<ref local="daoAuthenticationProvider"/>
</list>
</property>
<property name="sessionController" ref="sessionController"/>
</bean>
And you’re ready to run.
Some users have encountered problems with concurrent logins: If a user logs out, and then tries to log in again, the ConcurrentLoginException is thrown, so user cannot log in again. This happens when Acegi logout does not remove the session data for the user that has been logout out (before his login session has expired)
In order to fix this, you can manually clear the authentication session for the user that’s logged out:
public void logout() {
SecurityContext context = SecurityContextHolder.getContext();
if (context == null) return;
Authentication authentication = context.getAuthentication();
if (authentication == null) return;
String sessionId = SessionRegistryUtils.obtainSessionIdFromAuthentication(authentication);
this.sessionRegistry.removeSessionInformation(sessionId);
}
You will also need this code to be run when Acegi session gets unpublished.
For this implement org.acegisecurity.ui.session.HttpSessionEventPublisher, and configure listener for it in your web.xml:
public class MyHttpSessionEventPublisher extends HttpSessionEventPublisher {
private static final Log logger = LogFactory.getLog(MyHttpSessionEventPublisher.class);
private UserContext userContext;
public void sessionDestroyed(HttpSessionEvent event) {
logger.info("unpublishing session");
if (userContext == null) {
this.userContext = lookupBean(
WebApplicationContextUtils.
getWebApplicationContext(
event.getSession().getServletContext()),
"userContext",
UserContext.class);
}
this.userContext.invalidate();
super.sessionDestroyed(event);
}
private T lookupBean(final ApplicationContext applicationContext, final String beanName, final Class c) {
//noinspection unchecked
return (T) applicationContext.getBean(beanName, c);
}
}
In web.xml you will have:
<listener>
<listener-class>net.cakesolutions.service.security.acegi.BimHttpSessionEventPublisher</listener-class>
</listener>
And you’re ready to go.
Hope this article has helped anyone in configuring concurrent logins with Acegi Security.
