Posts

Showing posts from October, 2013

Building Webservices using Spring

In this post, I'm going to explain how to write a contract first webservice using Spring.

We are going to create a service for creating a person record. We are going to call the service as 'CreatePersonService'. It will accept first name, middle name and last name as parameters and return a id parameter back as a response.

We need to first define the XSD representing the person record. Also, we need an XSD to represent the request to create the Person record. 

Let us first start with the maven dependencies required:

pom.xml:We will be using jaxb for generating classes from xsd.
<dependency> <groupId>org.springframework.ws</groupId> <artifactId>spring-ws-core</artifactId> <version>2.1.3.RELEASE</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>org.dom4j</groupId> <artifactId>dom4j</artifactId> <ve…

Popups using Javascript and CSS

Image
In this post, I'm writing about an interesting way of displaying popups using javascript and css.

These popups do not show up in a new window, but rather in the same page as a different box. You might have seen these kind of popups while logging in or during display of your profile details in various social networking sites or email websites like gmail.

The idea here is to use css and div to display a box which embeds a separate html form of its own.
Lets first create a the form elements for login:

<div id="popupbox"> <form name="login" action="" method="post"> <div id="centertag">Username:</div> <div id="centertag"><input name="username" size="14" /></div> <div id="centertag">Password:</div> <div id="centertag"><input name="password" type="password" size="14" /></div> <a href="…

Site Map

Spring Beans Autowiring

In this post I'm going to write about Autowiring feature in Spring.


Overview:Generally, in Spring, you will define the beans and inject other beans into their properties by configuring them in xml. For eg, if we have a DAO, UserDAO and a service class UserService, which has a property reference for the DAO, then, the bean configuration would look like this: <bean id="userDAO" class="com.myorg.service.dao.UserDAO"> </bean> <bean id="userSvc" class="com.myorg.service.UserService"> <propertyname="userDAO" ref="userDAO"/> </bean>
Spring provides a feature called Autowiring, wherein the decision to wire the bean properties could be left to the Spring framework and this saves us a lot of configuration hassle.

There are four types of autowiring:
byNamebyTypeconstructorautodetect1. Autowiring - byName:In this type of wiring, Spring attempts to find the beans which has the same name/id as that of t…

Spring AOP - Part III

For part I, refer to: Spring AOP - Part I
For part II, refer to: Spring AOP - Part II

Continuing further on AOP examples, in this post, we will see how can we pass arguments to the Aspect classes.


Passing parameters to Aspect classes:In this example, we will write a very basic auditing service, which will store audit details of who accessed a particular service.
The audit details could be stored in database. But that part is not shown here to keep the details simple.

Let us say we have an Account service, which offers CRUD on the account. The username parameter which is the first parameter for all the methods, indicates the user who will perform a CRUD on the account.
public interface AccountService { public long createAccount(String username, Account account); public void updateAccount(String username, Account account); public void deleteAccount(String username, Account account); }
Define a corresponding AccountServiceImpl which will actually perform the CRUD. (not shown here).