Making a Spring bean Applicationcontext aware

Suppose we have a webapplication with spring,
and we are initializing spring’s WebApplicationContext by configuring ContextLoaderListener in web.xml.
How can we get an instance of spring’s applicationContext object?
Possible solutions:
While configuring spring through web.xml the spring ApplicationContext object is set in the ServletContext.
To get ApplicationContext we say

ApplicationContext applicationContext = (ApplicationContext)servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);

So we can get spring ApplicationContext only where ServletContext is avaliable i.e. in Servlet,ServletFilter or any implementation class of ServletContextListener.
What if we dont want to write a servletFilter or ServletContextListener .
What if we need to access a spring bean before a servletFilter or servlet is called(for authentication)and we dont want to write a ServletContextListener.
How can we obtain spring’s applicationContext in this case?
One way to achieve this would be to use the ApplicationContextAware interface provided by Spring.
Create a class which implements ApplicationContextAware. The method, “setApplicationContext(…)” gets called during the creation of this bean, providing the reference to the context. Our program should store this for a later interaction with the context.

package com.abc; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; public class ApplicationContextProvider implements ApplicationContextAware { private static ApplicationContext applicationContext = null; public static ApplicationContext getApplicationContext() { return applicationContext; } public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { / / Assign the ApplicationContext into a static variable this.applicationContext = applicationContext; } }

Initialize the new bean in applicationContext.xml

Now we can call the static method, ApplicationContextProvider.getApplicationContext(), from any class in our application, to get assess to the Spring ApplicationContext.

http://blog.imaginea.com/making-a-spring-bean-applicationcontext-aware/

Intertech – Complete RESTful Web Services Training

http://www/Intertech.com This is an Intertech presentation on Complete RESTful Web Services Training. For more information on Intertech’s Complete RESTful Web Services Training, visit us at: http://www.intertech.com/Courses/Course.aspx?CourseID=99162

For more videos, articles, and white papers, check out Intertech’s blog at http://www.Intertech.com/Blog

http://www.youtube.com/watch?v=CHxvgp3vsMY&feature=colike
http://www.youtube.com/watch?v=MxPW_kXV3hU
http://www.youtube.com/watch?v=NTcdSldyH6M
http://www.youtube.com/watch?v=5Aqo2BO9kmA
http://www.youtube.com/watch?v=glzmZ5U6w48&feature=colike
http://www.youtube.com/watch?v=2syOgviey5w&feature=colike

Resources
http://www.intertech.com/downloads/JAXRS-OxyBlast.pdf
http://www.intertech.com/downloads/JAXRS-OxyBlast.zip

Increasing VDI file size on VirtualBox

This little tutorial explains how to increase size of existing .vdi virtual hard drive file once the guest OS is already installed on it. I’ve taken a KISS approach describing each end every single step.

http://www.llakomy.com/articles/increasing-vdi-file-size-on-virtualbox-part-1-using-hdclone
http://www.llakomy.com/articles/increasing-vdi-file-size-on-virtualbox-part-2-merging-partitions-with-gparted

what are Agile and Scrum development methodology?

In software development Agile is a set of values and principles formulated by a group of the industry leading figures in 2001.
Scrum is a concrete software development methodology that can be traced back to 1995 and was created by two of the original signatories of Agile Manifesto. Scrum supports Agile values.
The early approach to software project management usually referred to as “waterfall model” implies a sequence of clearly defined steps necessary to complete any project: define, plan, organise, execute and then close.
This represents a very neat, simple and above all convenient abstraction from the project management theorist point of view. When one stage follows another it is possible to define clear inputs and outputs for each stage, isolate and identify techniques and tools that are most useful at every phase. This is a clear example of reductionism in tackling project management complexity: keep splitting the whole into smaller bits until you get to understand each bit in isolation and then hopefully you will master the mechanics of their totality.
But as soon as the waterfall abstraction was presented it started to leak. Firstly it turned out that real-life process can not be clearly cut into stages, often definition is still changed on what it seems to be planning, organisation or even execution stage. So, in theory, the stages were allowed to overlap and theoreticians started drawing all sorts of diagrams there it’s possible to see how the definition stage gradually runs out as execution starts picking up during the organisation stage. Then, again only in theory, it is possible to accurately estimate during the planning stage how long it is going to take to develop a piece of software. Obviously, in actual practise, the estimates and other plans have to be tweaked right through the execution phase which gave birth to a string of complex yet not very meaningful methods as Earned Value Management.
The chronic problems with the waterfall abstraction gave birth to a number of “agile” project management methods (Agile, Scrum, XP Programming etc) that despite many differences at the more detailed level use the same fundamental principles to tackle product development complexity:

  • The project is organised as a number of small iterations through the classic project stages (definition, planning, organisation, execution and closure).
  • Each iteration aims at a relatively small yet semantically complete increment in product functionality or non-functional characteristics.
  • Strong end-user involvement throughout the project.

Since every iteration goes through a separate definition and planning stage the time horizon for various estimation and planning activities is greatly reduced. It helps achieve greater accuracy, hence make it easier to access feasibility, measure value and costs etc.
Small increments help controlling the scope, evaluate utility of the changes and keep users involved since there is always a fresh version of fully functioning product. It is also much easier to organise a number of teams working on a large project simultaneously when increments are kept small, this really helps tackling task dependencies.
The user feedback is key to iterative methods, since it helps the product evolve gradually in a right direction providing greater utility at the end as opposed to the uncertainly of user reaction that is natural to punctuated equilibrium driven by the waterfall “big-bang” approach.

http://stackoverflow.com/questions/677778/what-are-agile-and-scrum-development-methodology

Error: “\Java\jre6\lib\ext\QTJava.zip was unexpected at this time.”

After installation of Weblogic Server if you get an error: “\Java\jre6\lib\ext\QTJava.zip was unexpected at this time.” This can be solved as under,

Check if QTJava.zip is set in %CLASSPATH% environment variable CLASSPATH=.;C:\Program Files (x86)\QuickTime\QTSystem\QTJava.zip

Remove C:\Program Files (x86)\QuickTime\QTSystem\QTJava.zip from %CLASSPATH% environment variable and restart the computer.

http://ora-soa.blogspot.com/2011/06/error-javajre6libextqtjavazip-was.html

tablesorter

tablesorter is a jQuery plugin for turning a standard HTML table with THEAD and TBODY tags into a sortable table without page refreshes. tablesorter can successfully parse and sort many types of data including linked data in a cell. It has many useful features including:

  • Multi-column sorting
  • Parsers for sorting text, URIs, integers, currency, floats, IP addresses, dates (ISO, long and short formats), time. Add your own easily
  • Support secondary “hidden” sorting (e.g., maintain alphabetical sort when sorting on other criteria)
  • Extensibility via widget system
  • Cross-browser: IE 6.0+, FF 2+, Safari 2.0+, Opera 9.0+
  • Small code size

http://tablesorter.com/docs/

Checked vs Unchecked exception

Unchecked exceptions are those that extend RuntimeException class. Compiler will never force you to catch such exception or force you to declare it in the method using throws keyword. All other exception types (that do not extend RuntimeException) are checked and therefore must be declared to be thrown and/or catched.
Checked exceptions are used when you want the caller of your method (i.e the user of your API) to explicitly handle the exceptional case in your API. Checked exceptions are declared when you believe the call will be able to do something meaningful with that exceptional case, like retrying the call, rolling changes back or converting it into some user-readable error message.
If you believe that there is nothing useful the call can do about the exception (especially when it represents a bug, or a wrong usage of your API), then the exception should be unchecked. Also, an API with too many checked exceptions can be annoying to program with (e.g. try using java reflection API=)

http://stackoverflow.com/questions/4639432/checked-vs-unchecked-exception

Why do we use Interface? Is it only for Standardization?

Purposes of Interfaces

  • create loosely coupled software
  • support design by contract (an implementor must provide the entire interface)
  • allow for pluggable software
  • allow different objects to interact easily
  • hide implementation details of classes from each other
  • facilitate reuse of software

Analogy 1: Much like the US space shuttle, Russian Soyuz spacecraft and Chinese Shenzhou 5 can all dock to the International Space Station, because they implement the same docking interface. (This is the just an example – I don’t know if it’s true in real life however let’s suspend our disbelief for the sake of an example)
Analogy 2: Like you can plug various computer monitors into your home computer. You can plug a wall-size TV into it, an old CRT (the thick kind), a 20″ flat screen, or a braille machine for the blind to “see” by touch. There’s compatibility among these various/different devices and your computer because they all agree on interface standards.
Details of C# interfaces — With C#/OOP interfaces you’re doing the same kind of thing but in the unseen/virtual world.
You’re correct about standardization, but also flexibility, scalability, extensibility, maintainability, reusability, testability and power.
(The more you use software interfaces the more these “buzz words” will be understood. And always consider interfaces in the real world because they have done us equally well.)

http://stackoverflow.com/questions/2026054/why-do-we-use-interface-is-it-only-for-standardization

Strategy Pattern

In computer programming, the strategy pattern (also known as the policy pattern) is a particular software design pattern, whereby algorithms can be selected at runtime. Formally speaking, the strategy pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it. package org.wikipedia.strategy; // The classes that implement a concrete strategy should implement this // The context class uses this to call the concrete strategy interface Strategy { int execute(int a, int b); } // Implements the algorithm using the strategy interface class ConcreteStrategyAdd implements Strategy { public int execute(int a, int b) { System.out.println(“Called ConcreteStrategyAdd’s execute()”); return a + b; // Do an addition with a and b } } class ConcreteStrategySubtract implements Strategy { public int execute(int a, int b) { System.out.println(“Called ConcreteStrategySubtract’s execute()”); return a – b; // Do a subtraction with a and b } } class ConcreteStrategyMultiply implements Strategy { public int execute(int a, int b) { System.out.println(“Called ConcreteStrategyMultiply’s execute()”); return a * b; // Do a multiplication with a and b } } // Configured with a ConcreteStrategy object and maintains a reference to a // Strategy object class Context { private Strategy strategy; // Constructor public Context(Strategy strategy) { this.strategy = strategy; } public int executeStrategy(int a, int b) { return strategy.execute(a, b); } } // StrategyExample test application class StrategyExample { public static void main(String[] args) { Context context; // Three contexts following different strategies context = new Context(new ConcreteStrategyAdd()); int resultA = context.executeStrategy(3, 4); context = new Context(new ConcreteStrategySubtract()); int resultB = context.executeStrategy(3, 4); context = new Context(new ConcreteStrategyMultiply()); int resultC = context.executeStrategy(3, 4); } }


Called ConcreteStrategyAdd's execute()
Called ConcreteStrategySubtract's execute()
Called ConcreteStrategyMultiply's execute()

http://en.wikipedia.org/wiki/Strategy_pattern