Skip to main content

Posts

Showing posts with the label Spring

Unity Transaction Handler

This post is going to explain how to write a custom Entity Framework Transaction Handler using Microsoft Unity Container. Unity is a light weight dependency injection framework created by the Microsoft Enterprise Best Practices group that also allows optional type and instance interception. You can find all about Unity here . The idea behind a Transaction Handler is to allow application developers to use consistent programming model of transaction management regardless of the underlying technology. As a long time Java programmer, I have seen the benefits of using Spring Framework's transaction management, and I wanted to apply the same programming model and approach to my recent .NET project. Microsoft Unity version 2.0 at the time of this writing did not have an out of the box transaction handler that could easily integrate with Entity Framework unlike its Spring Framework counter part. This post is going to go into detail on how to configure Unity to declare a custom transact...

How to CAS enable JasperServer in 5 Minutes

At work we recently decided to integrate our reports server, JasperServer 4.5, with our single sign on server, CAS. Here is how to CAS enable JasperServer in 5 Minutes: List of Assumptions: CAS is already installed, configured and in production. JasperServer is already installed. CAS Apache WebServer client mod_auth_cas is installed and configured. List of Steps: Add CAS configuration to applicationContext-security.xml Add LDAP configuration to applicationContext-security.xml Modify authenticationManager bean in applicationContext-security.xml Modify filterChainProxy bean settings in applicationConfiguration-security-web.xml Modify mod_auth_cas configuration Adding CAS configuration to applicationContext-security.xml Since mod_auth_cas client is configured at the web server level, we will be modifying the application security context of JasperServer to work with pre-authentication. Mod_auth_cas is a supported client of CAS and more information can be found at https://wiki....

Spring MVC and Reflection

Annotation based Spring MVC controllers and annotations in general provide flexibility for rapid application development in today's JAVA development environment. When you combine annotations with reflection you get quick, neat and powerful solutions. Here is an example that combines a simple annotated Spring MVC form with reflection. @RequestMapping(method = RequestMethod.POST) public String processSubmit(@ModelAttribute TestPlan testPlan, BindingResult result) { if (result.hasErrors()) { return "test/form"; } else { try { prepareTestPlan(testPlan); // find the right method and execute it Method[] methods = WebServiceTestForm.class.getMethods(); for (Method m : methods) { TestDesc t = m.getAnnotation(TestDesc.class); if (t != null && t.name() != null && t.name().equals(testPlan.getTestName())) { ...

How to control Date formatting when Jackson JSON Processor is used with Spring 3.0

If you have not already checked out Spring 3.0, I highly recommend that you do. They have introduced lots of new features in this release. Rest support in Spring MVC and being able to output XML and JSON formatted strings out of the box are few new features of this release. I recently set up a simple web application to try out few of these features. This web application had a simple controller that was being exposed as a REST service. I configured Spring 3.0 to use ContentNegotiatingViewResolver (more to come on this on later posts). With this and the built in support for JSON, this simple controller was able output JSON string in no time. Spring 3 by default uses Jackson JSON from http://jackson.codehaus.org/ with a MappingJacksonJsonView. One of the data fields that was getting outputted was java.util.Date. Jackson uses default strategy to determine date formatting in serialization. If you go to Jackson's website, you will see that there are few different ways to change the f...

Spring.NET exception handling through AOP

Spring has few custom handlers that help application developers with exception handling. Recently, on one of the projects I was working on I had a requirement where I was to log user exception, capture the exception detail, and email the exception details to a set up email address. The first thing I looked at was Spring.Net's ExceptionHandlerAdvice in Spring.Aspects.Exceptions namespace. You can use this predefined advice to handle your exceptions. You can take a look at chapter 14 of Spring.NET documentation to get more details about what this advice does for you. Looking at ExceptionHandlerAdvice, I knew that I had to set up the exceptionHandlers property. I used the following value to set this property. on exception (#e is T(System.Exception)) execute @(customExceptionHandlingAdvice).Handle(#e) The above value using Spring.NET SPeL (Expression Language). You can find out more about the Spring's expression language in the Spring.NET documentation. Exception handler...

Using Spring AOP to create a quick/simple auditing mechanism

These days I have been working in .NET. The project I am on uses Spring.NET and NHibernate for data access. One of the requirements of the project was to capture user activity and log them. There are certainly many different approaches to achieve this goal. There are solutions that you could deploy to your database (triggers etc.) or create application level services that would capture and log user activity. Since the project was already utilizing Spring, I wanted to utilize Spring's AOP features. The first thing I did was to create two database tables that would hold audit data. The first table I called history_log and the second table I called history_log_param . The history_log table has the following columns. CREATE TABLE [dbo].[history_log]( [id] [int] IDENTITY(1,1) NOT NULL, [table_name] [varchar](50) NOT NULL, [method_name] [varchar](50) NOT NULL, [argument_count] [int] NOT NULL, [message] [varchar](500) NOT NULL, [user_name] [varchar](50) NOT NULL, [date] [datetime...