Archive: ‘Spring’ Category

Spring Interview Questions Part: 2

No comments August 14th, 2009

  • What are important ApplicationContext implementations in spring framework?
  1. ClassPathXmlApplicationContext – This context loads a context definition from an XML file located in the class path, treating context definition files as class path resources.
  2. FileSystemXmlApplicationContext – This context loads a context definition from an XML file in the filesystem.
  3. XmlWebApplicationContext – This context loads the context definitions from an XML file contained within a web application.

  • What is an Aspect?

An aspect is the cross-cutting functionality that you are implementing. It is the aspect of your application you are modularizing. An example of an aspect is logging. Logging is something that is required throughout an application. However, because applications tend to be broken down into layers based on functionality, reusing a logging module through inheritance does not make sense. However, you can create a logging aspect and apply it throughout your application using AOP.

  • What is a Jointpoint?

A joinpoint is a point in the execution of the application where an aspect can be plugged in. This point could be a method being called, an exception being thrown, or even a field being modified. These are the points where your aspect’s code can be inserted into the normal flow of your application to add new behavior.

  • Explain Bean lifecycle in Spring framework?
  1. The spring container finds the bean’s definition from the XML file and instantiates the bean.
  2. Using the dependency injection, spring populates all of the properties as specified in the bean definition.
  3. If the bean implements the BeanNameAware interface, the factory calls setBeanName() passing the bean’s ID.
  4. If the bean implements the BeanFactoryAware interface, the factory calls setBeanFactory(), passing an instance of itself.
  5. If there are any BeanPostProcessors associated with the bean, their post- ProcessBeforeInitialization()methods will be called.
  6. If an init-method is specified for the bean, it will be called.
  7. Finally, if there are any BeanPostProcessors associated with the bean, theirpostProcessAfterInitialization() methods will be called.
  • What are the types of injection supported by Spring ?

Setter Injection and constructor injection

  • What is mean by Bean-Wiring?

The act of creating associations between application components(beans) within Spring container is refered to as Bean Wiring.

  • What do you mean by Advice?

Action taken by an aspect at a particular join point. Different types of advice include “around,” “before” and “after” advice. Many AOP frameworks, including Spring, model an advice as an interceptor, maintaining a chain of interceptors “around” the join point.

  • What are the types of Advice?

Types of advice:

Before advice: Advice that executes before a join point, but which does not have the ability to prevent execution flow proceeding to the join point (unless it throws an exception).

After returning advice: Advice to be executed after a join point completes normally: for example, if a method returns without throwing an exception.

After throwing advice: Advice to be executed if a method exits by throwing an exception.

After (finally) advice: Advice to be executed regardless of the means by which a join point exits (normal or exceptional return).

Around advice: Advice that surrounds a join point such as a method invocation. This is the most powerful kind of advice. Around advice can perform custom behavior before and after the method invocation. It is also responsible for choosing whether to proceed to the join point or to shortcut the advised method execution by returning its own return value or throwing an exception

  • What are the types of the transaction management Spring supports ?

Spring Framework supports:

Programmatic transaction management.

Declarative transaction management.

  • Why most users of the Spring Framework choose declarative transaction management ?

Most users of the Spring Framework choose declarative transaction management because it is the option with the least impact on application code, and hence is most consistent with the ideals of a non-invasive lightweight container.

  • What is RowCallbackHandler ?

The RowCallbackHandler interface extracts values from each row of a ResultSet.

Has one method – processRow(ResultSet)

Called for each row in ResultSet.

Typically stateful.

What is mean by Bean-Wiring?
The act of creating associations between application components(beans) within Spring container is refered to as Bean Wiring.
Book Mark it-> del.icio.us | Reddit | Slashdot | Digg | Facebook | Technorati | Google | StumbleUpon | Window Live | Tailrank | Furl | Netscape | Yahoo | BlinkList

Popularity: 15% [?]

Bookmark this on BuzzURLBookmark this on BuzzURL Post to TwitterTweets for this web page Bookmark this on FC2 Bookmark newsing it! Choix it! Add to Google Bookmark Bookmark this on Delicious Digg This

Creating Web Services using CXF (Contract first Approach) Part 2 : WSDL Creation.

5 comments June 15th, 2009

What is WSDL and what its Structure?

A WSDL document defines services as collections of network endpoints, or ports. In WSDL, the abstract definition of endpoints and messages is separated from their concrete network deployment or data format bindings. This allows the reuse of abstract definitions: messages, which are abstract descriptions of the data being exchanged, and port types which are abstract collections of operations.

The concrete protocol and data format specifications for a particular port type constitutes a reusable binding. A port is defined by associating a network address with a reusable binding, and a collection of ports define a service. Hence, a WSDL document uses the following elements in the definition of network services:

WSDL document describes a web service using these major elements:

Element Defines
<types> The data types used by the web service
<message> The messages used by the web service
<portType> The operations performed by the web service
<binding> The communication protocols used by the web service
<port> A single endpoint defined as a combination of a binding and a network address.
<service> A collection of related endpoints.

The main structure of a WSDL document looks like this:

<definitions>
<types>
definition of types……..
</types>

<message>
definition of a message….
</message>
<portType>
definition of a port…….
</portType>
<binding>
definition of a binding….
</binding>

<service>
definition of services….
</service>

</definitions>

A WSDL document can also contain other elements, like extension elements and a service element that makes it possible to group together the definitions of several web services in one single WSDL document.

Creating WSDL for our Example

<types>:In the Types we are defining or configuring the Datatypes which we are using for the entire application. Here we are importing the XSD files here.

<message>:In our example we need to configure our input and our parameters/ the message which we are passing through Webservice. We are configuring request and response objects here.

<portType>: We have one operation which is called getProduct. So here we need to declare this getProduct operation.

<binding> : Here we will be providing our protocol types and we are using SOAP protocol.

<service> : Defining the Service End point. And for the ProductService we are defining it as “http://localhost:8080/ContractFirst/services/ProductService

   1: <?xml version="1.0" encoding="UTF-8" standalone="no"?>
   2: <wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
   3:     xmlns:tns="http://com/your/company/service/ProductService/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
   4:     xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ProductService"
   5:     targetNamespace="http://com/your/company/service/ProductService/"
   6:     xmlns:prd="http://com/your/company/service/Product/">
   7:     <wsdl:types>
   8:         <xsd:schema targetNamespace="http://com/your/company/service/ProductService/"
   9:             xmlns:prd="http://com/your/company/service/Product/">
  10:             <xsd:import namespace="http://com/your/company/service/Product/"
  11:                 schemaLocation="../Product.xsd" />
  12:             <xsd:element name="getProductRequest">
  13:                 <xsd:complexType>
  14:                     <xsd:sequence>
  15:                         <xsd:element name="productRequest" type="prd:ProductRequest" />
  16:                     </xsd:sequence>
  17:                 </xsd:complexType>
  18:             </xsd:element>
  19:             <xsd:element name="getProductResponse">
  20:                 <xsd:complexType>
  21:                     <xsd:sequence>
  22:                         <xsd:element name="productResponse" type="prd:ProductResponse" />
  23:                     </xsd:sequence>
  24:                 </xsd:complexType>
  25:             </xsd:element>
  26:         </xsd:schema>
  27:     </wsdl:types>
  28:     <wsdl:message name="ProductRequest">
  29:         <wsdl:part element="tns:getProductRequest" name="parameters" />
  30:     </wsdl:message>
  31:     <wsdl:message name="ProductResponse">
  32:         <wsdl:part element="tns:getProductResponse" name="parameters" />
  33:     </wsdl:message>
  34:     <wsdl:portType name="ProductService">
  35:         <wsdl:operation name="getProduct">
  36:             <wsdl:input message="tns:ProductRequest" />
  37:             <wsdl:output message="tns:ProductResponse" />
  38:         </wsdl:operation>
  39:     </wsdl:portType>
  40:     <wsdl:binding name="ProductServiceSOAP" type="tns:ProductService">
  41:         <soap:binding style="document"
  42:             transport="http://schemas.xmlsoap.org/soap/http" />
  43:         <wsdl:operation name="getProduct">
  44:             <soap:operation
  45:                 soapAction="http://com/your/company/service/ProductService/getProduct" />
  46:             <wsdl:input>
  47:                 <soap:body use="literal" />
  48:             </wsdl:input>
  49:             <wsdl:output>
  50:                 <soap:body use="literal" />
  51:             </wsdl:output>
  52:         </wsdl:operation>
  53:     </wsdl:binding>
  54:     <wsdl:service name="ProductService">
  55:         <wsdl:port binding="tns:ProductServiceSOAP" name="ProductServiceSOAP">
  56:             <soap:address
  57:                 location="http://localhost:8080/ContractFirst/services/ProductService" />
  58:         </wsdl:port>
  59:     </wsdl:service>
  60: </wsdl:definitions>

In our next part we will go through Skelton creation using WSDL to Java tool which is giving by CXF.

Book Mark it-> del.icio.us | Reddit | Slashdot | Digg | Facebook | Technorati | Google | StumbleUpon | Window Live | Tailrank | Furl | Netscape | Yahoo | BlinkList

Popularity: 12% [?]

Bookmark this on BuzzURLBookmark this on BuzzURL Post to TwitterTweets for this web page Bookmark this on FC2 Bookmark newsing it! Choix it! Add to Google Bookmark Bookmark this on Delicious Digg This

Creating Web services using Apache CXF (Part 1) : The Basics.

16 comments June 10th, 2009

As we discussed in the previous post, CXF is the combination of two projects: Celtix developed by IONA and XFire developed by Codehaus working together at the Apache Software Foundation.

If you want an Enterprise support  for CXF then please find the following links.

Open Source FUSE Services Framework – based on CXF

FUSE open source community

FUSE Forums

CXF Developer Advantages

  • If you know Spring then CXF is too easy for you. All its configurations are in a Spring xml file. Internally CXF is reading this Spring XML as its Configuration file.JAX-WS encompasses many different areas:
    • Generating WSDL from Java classes and generating Java classes from WSDL
    • Provider API which allows you to create simple messaging receiving server endpoints
    • Dispatch API which allows you to send raw XML messages to server endpoints
  • CXF implements the JAX-WS APIs which make building web services easy.
  • Aegis Databinding (2.0.x) is a databinding library that makes development of code-first web services incredibly easy.
  • CXF enables the development of RESTful services via annotations using the HTTP Binding.

It has a lot many features more to say. Once you got your project requirements and clear with the approach which you want to follow then please have a look on this feature list. I think you definitely will choose CXF without any doubt. [I am exerting some of the features from its own site]

General
  • High Performance
  • Extensible
  • Intuitive & Easy to Use
Support for Standards
  • JAX-WS, JAX-WSA, JSR-181, and SAAJ
  • SOAP 1.1, 1.2, WS-I Basic Profile, WS-Security, WS-Addressing, WS-RM and WS-Policy
  • WSDL 1.1 and 2.0
  • MTOM
Multiple Transports, Bindings, Data Bindings, and Formats
  • Bindings: SOAP, REST/HTTP
  • Data bindings: JAXB 2.0, Aegis, XMLBeans. (Castor and JiBX will be supported in a later version of CXF)
  • Formats: XML, JSON
  • Transports: HTTP, Servlet, JMS, and Jabber transports
  • Extensibility API allows additional bindings for CXF, enabling additional message format support such as CSV and fixed record length
Flexible Deployment
  • Lightweight containers: deploy services in Tomcat or Spring-based containers
  • JBI integration: deploy as a service engine in a JBI container such as ServiceMix, OpenESB or Petals
  • SCA integration: deploy in an SCA container such as Tuscany
  • J2EE integration: deploy services in J2EE application servers such as Geronimo, JOnAS, JBoss, WebLogic, and WebSphere
  • Standalone Java client/server
Support for Multiple Programming Languages
  • Full support for JAX-WS 2.0 client/server programming model
  • JAX-WS 2.0 synchronous, asynchronous and one-way API’s
  • JAX-WS 2.0 Dynamic Invocation Interface (DII) API
  • Support for wrapped and non-wrapped styles
  • XML messaging API
  • Support for JavaScript and ECMAScript 4 XML (E4X) – both client and server
  • Support for CORBA with Yoko
  • Support for SCA withTuscany
  • Support for JBI with ServiceMix
Code Generation
  • Java to WSDL
  • WSDL to Java
  • XSD to WSDL
  • WSDL to XML
  • WSDL to SOAP
  • WSDL to service

Other related posts:

1. Creating Web services using Apache CXF (Part 1) : The Basics.

2. Creating Web services using Apache CXF (Part 2) : Development.

3. Creating Web services using Apache CXF (Part 3) : Configuration.

4. Creating Web services using Apache CXF (Part 4): Testing.

Book Mark it-> del.icio.us | Reddit | Slashdot | Digg | Facebook | Technorati | Google | StumbleUpon | Window Live | Tailrank | Furl | Netscape | Yahoo | BlinkList

Popularity: 35% [?]

Bookmark this on BuzzURLBookmark this on BuzzURL Post to TwitterTweets for this web page Bookmark this on FC2 Bookmark newsing it! Choix it! Add to Google Bookmark Bookmark this on Delicious Digg This

Apache CXF- An ultimate web service open source framework : Lets start learning…

7 comments June 10th, 2009

Apache CXF is an open source services framework which is a result of the merge between the XFire and Celtix projects. CXF helps us build and develop services using JAX-WS. These services can speak a variety of protocols such as SOAP, XML/HTTP, RESTful HTTP, or CORBA and work over a variety of transports such as HTTP, JMS or JBI.

If you want to know more about XFire and Celtix then please do visit following links.

Codehaus XFire is a next-generation java SOAP framework. Codehaus XFire makes service oriented development approachable through its easy to use API and support for standards. It is also highly performant since it is built on a low memory StAX based model.

Celtix is a web service framework with support for legacy integration. It primarily focuses on providing JAX-WS and WS-* support.

Lets come back to CXF. Some of the main advantages of this framework are,

  • JAX-WS Specification compliance
  • Improved HTTP and JMS Transports
  • Spring XML support
  • RESTful services support
  • Great WS-* support: WS-Addressing, WS-Policy, WS-ReliableMessaging, and WS-Security are all supported
  • Support for JSON
  • SOAP Attachments support
  • Improved APIs and extension points
  • A larger community, which means faster development, and better support

Through this series of posts I would like to go through CXF from bottom to top. Want to go through from basics – development of a sample – deployment – advantages etc.

I would like to do it in TWO Different ways. Code-First and Contract-First.

Code-First Approach

1. Creating Web services using Apache CXF (Part 1) : The Basics.

2. Creating Web services using Apache CXF (Part 2) : Development.

3. Creating Web services using Apache CXF (Part 3) : Configuration.

4. Creating Web services using Apache CXF (Part 4): Testing.

Contract-First Approach [Under preparation]

  1. Creating Web Services using CXF (Contract first Approach) Part 1: Creating XSDs.
  2. Creating Web Services using CXF (Contract first Approach) Part 2 : WSDL Creation.
  3. Creating Web Services using CXF (Contract first Approach) Part 3: Creating Stubs.
  4. Creating Web Services using CXF (Contract first Approach) Part 4 : Writing the Implementation.
  5. Creating Web Services using CXF (Contract first Approach) Part 5 : Configuration and Deployment.
  6. Creating Web Services using CXF (Contract first Approach) Part 6: Testing.
Book Mark it-> del.icio.us | Reddit | Slashdot | Digg | Facebook | Technorati | Google | StumbleUpon | Window Live | Tailrank | Furl | Netscape | Yahoo | BlinkList

Popularity: 20% [?]

Bookmark this on BuzzURLBookmark this on BuzzURL Post to TwitterTweets for this web page Bookmark this on FC2 Bookmark newsing it! Choix it! Add to Google Bookmark Bookmark this on Delicious Digg This

Spring Interview Questions Part: 1

No comments June 9th, 2009
  • What is mean by Dependency Injection? Or What do you mean by Inversion of Control?

Dependency injection (DI) is a programming design pattern and architectural model, sometimes also referred to as inversion of control or IOC, although technically speaking, dependency injection specifically refers to an implementation of a particular form of IOC.

Dependancy Injection describes the situation where one object uses a second object to provide a particular capacity. For example, being passed a database connection as an argument to the constructor instead of creating one internally. The term "Dependency injection" is a misnomer, since it is not a dependency that is injected, rather it is a provider of some capability or resource that is injected. There are three common forms of dependency injection: setter-, constructor- and interface-based injection.

Dependency injection is a way to achieve loose coupling. Inversion of control (IOC) relates to the way in which an object obtains references to its dependencies. This is often done by a lookup method. The advantage of inversion of control is that it decouples objects from specific lookup mechanisms and implementations of the objects it depends on. As a result, more flexibility is obtained for production applications as well as for testing.

  • What are the modules in Spring?
  1. The core container:

    The core container provides the fundamental functionality of the Spring framework. In this module primary component is the BeanFactory, an implementation of the Factory pattern. The BeanFactoryapplies the Inversion of Control (IOC) pattern to separate an application’s configuration and dependency specification from the actual application code.

  2. Spring context module :

    TThe Spring context is a configuration file that provides context information to the Spring framework. The Spring context includes enterprise services such as e-mail, JNDI, EJB, internalization, validation, scheduling and applications lifecycle events. Also included is support for the integration with templating frameworks such as velocity.

  3. Spring AOP module:

    The Spring AOP module allows a software component to be decorated with additional behavior, through its configuration management feature. As a result you can easily AOP-enable any object managed by the Spring framework. The Spring AOP module provides transaction management services for objects in any Spring-based application. With Spring AOP you can incorporate declarative transaction management into your applications without relying on EJB components.

  4. Spring DAO module:

    The Spring DAO module provides a JDBC-abstraction layer that reduces the need to do tedious JDBC coding and parsing of database-vendor specific error codes. Also, the JDBC package provides a way to do programmatic as well as declarative transaction management, not only for classes implementing special interfaces, but for all your POJOs (plain old Java objects).

  5. Spring ORM module:

    : Spring provides integration with OR mapping tools like Hibernate, JDO and iBATIS. Spring transaction management supports each of these ORM frameworks as well as JDBC.

  6. Spring Web module:

    The Web context module provides basic web-oriented integration features builds on top of the application context module, providing contexts for Web-based applications. As a result, the Spring framework supports integration with Jakarta Struts. The Web module also eases the tasks of handling multi-part requests and binding request parameters to domain objects.

  7. Spring MVC framework module:

    Spring provides a pluggable MVC architecture. The users have a choice to use the web framework or continue to use their existing web framework. Spring separates the roles of the controller; the model object, the dispatcher and the handler object which makes it easier to customize them. Spring web framework is view agnostic and does not push the user to use only JSPs for the view. The user has the flexibility to use JSPs, XSLT, velocity templates etc to provide the view.

  • What is a BeanFactory and XMLBeanFactory?

Bean factory is a container. It configures, instantiates and manages a set of beans. These beans are collaborated with one another and have dependencies among themselves. The reflection of these dependencies are used in configuring data that is used by BeanFactory.

XMLBeanFactory is a bean factory that is loaded its beans from an XML file.

  • What are Inner Beans?

A bean inside another bean is known as Inner Bean. They are created and used on the fly, and can not be used outside the enclosing beans. The Id and scope attributes for inner beans are of no use.

  • What is DataAccessException?

DataAccessException is an unchecked RuntimeException. These type of exceptions are unforced by users to handle. This exception is used to handle the errors occurring when the details of the database access API in use, such as JDBC.

Book Mark it-> del.icio.us | Reddit | Slashdot | Digg | Facebook | Technorati | Google | StumbleUpon | Window Live | Tailrank | Furl | Netscape | Yahoo | BlinkList

Popularity: 22% [?]

Bookmark this on BuzzURLBookmark this on BuzzURL Post to TwitterTweets for this web page Bookmark this on FC2 Bookmark newsing it! Choix it! Add to Google Bookmark Bookmark this on Delicious Digg This