<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7397436882433825691</id><updated>2012-01-10T21:57:04.036-08:00</updated><category term='gammu on ubuntu'/><category term='tata photon on linux'/><category term='Difference between web server and application server'/><category term='Web Services'/><category term='Web Server and Application server'/><title type='text'>Fire Cracks</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://firecracks.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7397436882433825691/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://firecracks.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Biju</name><uri>http://www.blogger.com/profile/10765353064992372034</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>13</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7397436882433825691.post-7925710129738109976</id><published>2011-09-12T12:27:00.000-07:00</published><updated>2011-09-12T12:31:11.110-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='gammu on ubuntu'/><title type='text'>Installing and Configuring GAMMU on Ubuntu</title><content type='html'>1. apt-get install gammu&lt;br /&gt;&lt;br /&gt;2. Detecting mobile&lt;br /&gt;&lt;br /&gt;Unplug the mobile from usb and run 'lsusb'. You would get something like this&lt;br /&gt;&lt;br /&gt;Bus 002 Device 006: ID 413c:8162 Dell Computer Corp.&lt;br /&gt;Bus 002 Device 005: ID 413c:8161 Dell Computer Corp.&lt;br /&gt;Bus 002 Device 004: ID 0a5c:4500 Broadcom Corp. BCM2046B1 USB 2.0 Hub (part of BCM2046 Bluetooth)&lt;br /&gt;Bus 002 Device 003: ID 12d1:140b Huawei Technologies Co., Ltd. EC1260 Wireless Data Modem HSD USB Card&lt;br /&gt;Bus 002 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub&lt;br /&gt;Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub&lt;br /&gt;Bus 001 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub&lt;br /&gt;Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub&lt;br /&gt;&lt;br /&gt;3. Plugin the mobile on USB and run again  'lsusb'&lt;br /&gt;&lt;br /&gt;Bus 002 Device 006: ID 413c:8162 Dell Computer Corp.&lt;br /&gt;Bus 002 Device 005: ID 413c:8161 Dell Computer Corp.&lt;br /&gt;Bus 002 Device 004: ID 0a5c:4500 Broadcom Corp. BCM2046B1 USB 2.0 Hub (part of BCM2046 Bluetooth)&lt;br /&gt;Bus 002 Device 003: ID 12d1:140b Huawei Technologies Co., Ltd. EC1260 Wireless Data Modem HSD USB Card&lt;br /&gt;Bus 002 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub&lt;br /&gt;Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub&lt;br /&gt;&lt;font style="font-weight: bold;"&gt;Bus 001 Device 024: ID 0fce:d053 Sony Ericsson Mobile Communications AB &lt;/font&gt;&lt;br /&gt;Bus 001 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub&lt;br /&gt;Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub&lt;br /&gt;&lt;br /&gt;Load the driver&lt;br /&gt;&amp;gt;modprobe usbserial vendor=0x0fce product=0xd053&lt;br /&gt;&lt;br /&gt;&amp;gt;dmesg&lt;br /&gt;&lt;br /&gt;[ 4670.288435] usb 1-1.2: new full speed USB device using ehci_hcd and address 24&lt;br /&gt;[ 4670.389320] cdc_acm 1-1.2:1.1: ttyACM0: USB ACM device&lt;br /&gt;[ 4670.391582] cdc_acm 1-1.2:1.3: ttyACM1: USB ACM device&lt;br /&gt;[ 4670.395248] cdc_wdm 1-1.2:1.7: cdc-wdm0: USB WDM device&lt;br /&gt;&lt;br /&gt;ttyACM0 would be the connected port&lt;br /&gt;&lt;br /&gt;4. Configure gammu&lt;br /&gt;&amp;gt;gammu-config&lt;br /&gt;Port : /dev/ACM0&lt;br /&gt;Connection : at19200&lt;br /&gt;LogFile : gammulog&lt;br /&gt;&lt;br /&gt;Save it&lt;br /&gt;&lt;br /&gt;5. Check it&lt;br /&gt;&amp;gt;gammu --identify&lt;br /&gt;You should get som&lt;br /&gt;Device               : /dev/ttyACM0&lt;br /&gt;Manufacturer         : Sony Ericsson&lt;br /&gt;Model                : W300i/W300c (AAF-1052031-BV)&lt;br /&gt;Firmware             : xxxxxxxxx&lt;br /&gt;IMEI                 : xxxxxxxxxx&lt;br /&gt;Product code         : xxxxxxxxxxxx&lt;br /&gt;SIM IMSI             : xxxxxxxxxx&lt;br /&gt;&lt;br /&gt;6. Send your first message&lt;br /&gt;&amp;gt;gammu sendsms TEXT 9995960189 -text "Thanks Biju"&lt;br /&gt;If you want break, press Ctrl+C...&lt;br /&gt;Sending SMS 1/1....waiting for network answer..OK, message reference=0&lt;br /&gt;&lt;br /&gt;Enjoy!!!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7397436882433825691-7925710129738109976?l=firecracks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://firecracks.blogspot.com/feeds/7925710129738109976/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7397436882433825691&amp;postID=7925710129738109976' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7397436882433825691/posts/default/7925710129738109976'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7397436882433825691/posts/default/7925710129738109976'/><link rel='alternate' type='text/html' href='http://firecracks.blogspot.com/2011/09/installing-and-configuring-gammu-on.html' title='Installing and Configuring GAMMU on Ubuntu'/><author><name>Biju</name><uri>http://www.blogger.com/profile/10765353064992372034</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7397436882433825691.post-3756813400520549658</id><published>2011-09-12T12:26:00.000-07:00</published><updated>2011-09-12T12:38:08.927-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='tata photon on linux'/><title type='text'>Configuring Tata photon on Linux</title><content type='html'>On the usb device you can find the linux installer. Run it as root user.  Photon connector will be in Applications-&amp;gt;Internet-&amp;gt;Tata  Photon+&lt;br /&gt;&lt;br /&gt;Run and connect it. I got problem in connecting to net if the browser not as root user.&lt;br /&gt;Its works fine for me if a take the browser as root user&lt;br /&gt;Take browser as root user &amp;gt;sudo firefox. It works fine then.&lt;br /&gt;&lt;br /&gt;If anyone knows better idea please let me know.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7397436882433825691-3756813400520549658?l=firecracks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://firecracks.blogspot.com/feeds/3756813400520549658/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7397436882433825691&amp;postID=3756813400520549658' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7397436882433825691/posts/default/3756813400520549658'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7397436882433825691/posts/default/3756813400520549658'/><link rel='alternate' type='text/html' href='http://firecracks.blogspot.com/2011/09/configuring-tata-photon-on-linux.html' title='Configuring Tata photon on Linux'/><author><name>Biju</name><uri>http://www.blogger.com/profile/10765353064992372034</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7397436882433825691.post-7044021596769287441</id><published>2009-07-03T07:26:00.001-07:00</published><updated>2009-07-03T07:26:24.465-07:00</updated><title type='text'>Aspect Oriented Programming in Spring</title><content type='html'>&lt;div class="titlepage"&gt;&lt;div&gt;&lt;div&gt;&lt;br /&gt;&lt;div style="text-align: left;"&gt;AOP is an acronym for Aspect Oriented Programming. AOP provides the ability to implement crosscutting logic—that is, logic that applies to many parts of your application—in a single place and to have that logic applied across your application automatically. There are two main kinds of AOP implementation. Static AOP, such as AspectJ (&lt;a href="http://www.aspectj.org/" title="www.aspectj.org"&gt;www.aspectj.org&lt;/a&gt;), provides a compile-time solution for building AOP-based logic and adding it to an application. Dynamic AOP, such as that in Spring, allows crosscutting logic to be applied arbitrarily to any other code at runtime. Wthin the Spring framework itself, AOP is used for many purposes, particularly in transaction management. You can think of Spring's AOP implementation as coming in two logical parts. The first part is the AOP core, which provides fully decoupled, purely programmatic AOP functionality. The second part of the AOP implementation is the set of framework services that make AOP easier to use in your applications. Spring AOP is really a subset of the full AOP feature set, implementing only a handful of the constructs available in implementations like AspectJ. The core architecture of Spring AOP is based around proxies. When you want to create an advised instance of a class, you must use the ProxyFactory class to create a proxy of an instance of that class, first providing the ProxyFactory with all the aspects that you want to be woven into the proxy. Internally, Spring has two proxy implementations: JDK dynamic proxy and CGLIB proxy. In previous releases of Spring, there was not much difference between the two proxy types, and CGLIB proxies were only used when you wanted to proxy classes rather than interfaces, or when you explicitly specified them. As of the 1.1 release of Spring, the CGLIB proxy is noticeably faster than JDK dynamic proxies in most cases. The ProxyFactory class controls the weaving and proxy creation process in Spring AOP&lt;br /&gt;&lt;/div&gt;&lt;h2 class="title"&gt;Chapter 6. Aspect Oriented Programming with Spring&lt;/h2&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="section"&gt;&lt;div class="titlepage"&gt;&lt;div&gt;&lt;div&gt;&lt;h2 class="title"&gt;&lt;a name="aop-introduction"&gt;&lt;/a&gt;6.1. Introduction&lt;/h2&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;span class="emphasis"&gt;&lt;i&gt;Aspect-Oriented Programming&lt;/i&gt;&lt;/span&gt; (AOP) complements     Object-Oriented Programming (OOP) by providing another way of thinking     about program structure. The key unit of modularity in OOP is the class,     whereas in AOP the unit of modularity is the &lt;span class="emphasis"&gt;&lt;i&gt;aspect&lt;/i&gt;&lt;/span&gt;.     Aspects enable the modularization of concerns such as transaction     management that cut across multiple types and objects. (Such concerns are     often termed &lt;span class="emphasis"&gt;&lt;i&gt;crosscutting&lt;/i&gt;&lt;/span&gt; concerns in AOP     literature.)&lt;/p&gt;&lt;p&gt;One of the key components of Spring is the &lt;span class="emphasis"&gt;&lt;i&gt;AOP     framework&lt;/i&gt;&lt;/span&gt;. While the Spring IoC container does not depend on     AOP, meaning you do not need to use AOP if you don't want to, AOP     complements Spring IoC to provide a very capable middleware     solution.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7397436882433825691-7044021596769287441?l=firecracks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://firecracks.blogspot.com/feeds/7044021596769287441/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7397436882433825691&amp;postID=7044021596769287441' title='9 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7397436882433825691/posts/default/7044021596769287441'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7397436882433825691/posts/default/7044021596769287441'/><link rel='alternate' type='text/html' href='http://firecracks.blogspot.com/2009/07/aspect-oriented-programming-in-spring.html' title='Aspect Oriented Programming in Spring'/><author><name>Biju</name><uri>http://www.blogger.com/profile/10765353064992372034</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>9</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7397436882433825691.post-8875854453696640927</id><published>2009-07-03T07:23:00.000-07:00</published><updated>2009-07-03T07:24:43.116-07:00</updated><title type='text'>Spring Annotations</title><content type='html'>&lt;span style="font-weight: bold;"&gt;Annotation-based configuration&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;As mentioned in the section entitled Section 3.7.1.2, “Example: The RequiredAnnotationBeanPostProcessor”, using a BeanPostProcessor in conjunction with annotations is a common means of extending the Spring IoC container. For example, Spring 2.0 introduced the possibility of enforcing required properties with the @Required annotation. As of Spring 2.5, it is now possible to follow that same general approach to drive Spring's dependency injection. Essentially, the @Autowired annotation provides the same capabilities as described in Section 3.3.5, “Autowiring collaborators” but with more fine-grained control and wider applicability. Spring 2.5 also adds support for JSR-250 annotations such as @Resource, @PostConstruct, and @PreDestroy. Of course, these options are only available if you are using at least Java 5 (Tiger) and thus have access to source level annotations. Use of these annotations also requires that certain BeanPostProcessors be registered within the Spring container. As always, these can be registered as individual bean definitions, but they can also be implicitly registered by including the following tag in an XML-based Spring configuration (notice the inclusion of the 'context' namespace):&lt;br /&gt;&lt;br /&gt;&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;br /&gt;&lt;beans xmlns="http://www.springframework.org/schema/beans"&lt;br /&gt;       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&lt;br /&gt;       xmlns:context="http://www.springframework.org/schema/context"&lt;br /&gt;       xsi:schemaLocation="http://www.springframework.org/schema/beans&lt;br /&gt;           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd&lt;br /&gt;           http://www.springframework.org/schema/context&lt;br /&gt;           http://www.springframework.org/schema/context/spring-context-2.5.xsd"&gt;&lt;br /&gt;              &lt;br /&gt;     &lt;context:annotation-config/&gt;&lt;br /&gt;    &lt;br /&gt;&lt;br /&gt;&lt;/beans&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;3.11.1. @Required&lt;br /&gt;&lt;br /&gt;The @Required annotation applies to bean property setter methods, as in the following example:&lt;br /&gt;&lt;br /&gt;public class SimpleMovieLister {&lt;br /&gt;&lt;br /&gt;    private MovieFinder movieFinder;&lt;br /&gt;&lt;br /&gt;    @Required&lt;br /&gt;    public void setMovieFinder(MovieFinder movieFinder) {&lt;br /&gt;        this.movieFinder = movieFinder;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    // ...&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;This annotation simply indicates that the affected bean property must be populated at configuration time: either through an explicit property value in a bean definition or through autowiring.&lt;br /&gt;&lt;br /&gt;3.11.2. @Autowired&lt;br /&gt;&lt;br /&gt;As expected, the @Autowired annotation may be applied to "traditional" setter methods:&lt;br /&gt;&lt;br /&gt;public class SimpleMovieLister {&lt;br /&gt;&lt;br /&gt;    private MovieFinder movieFinder;&lt;br /&gt;&lt;br /&gt;    @Autowired&lt;br /&gt;    public void setMovieFinder(MovieFinder movieFinder) {&lt;br /&gt;        this.movieFinder = movieFinder;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    // ...&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;The annotation may also be applied to methods with arbitrary names and/or multiple arguments:&lt;br /&gt;&lt;br /&gt;public class MovieRecommender {&lt;br /&gt;&lt;br /&gt;    private MovieCatalog movieCatalog;&lt;br /&gt;   &lt;br /&gt;    private CustomerPreferenceDao customerPreferenceDao;&lt;br /&gt;&lt;br /&gt;    @Autowired&lt;br /&gt;    public void prepare(MovieCatalog movieCatalog, CustomerPreferenceDao customerPreferenceDao) {&lt;br /&gt;        this.movieCatalog = movieCatalog;&lt;br /&gt;        this.customerPreferenceDao = customerPreferenceDao;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    // ...&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;The @Autowired annotation may even be applied on constructors and fields:&lt;br /&gt;&lt;br /&gt;public class MovieRecommender {&lt;br /&gt;&lt;br /&gt;    @Autowired&lt;br /&gt;    private MovieCatalog movieCatalog;&lt;br /&gt;   &lt;br /&gt;    private CustomerPreferenceDao customerPreferenceDao;&lt;br /&gt;&lt;br /&gt;    @Autowired&lt;br /&gt;    public MovieRecommender(CustomerPreferenceDao customerPreferenceDao) {&lt;br /&gt;        this.customerPreferenceDao = customerPreferenceDao;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    // ...&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;By default, the autowiring will fail whenever zero candidate beans are available; the default behavior is to treat annotated methods, constructors, and fields as indicating required dependencies. This behavior can be changed as demonstrated below.&lt;br /&gt;&lt;br /&gt;public class SimpleMovieLister {&lt;br /&gt;&lt;br /&gt;    private MovieFinder movieFinder;&lt;br /&gt;&lt;br /&gt;    @Autowired(required=false)&lt;br /&gt;    public void setMovieFinder(MovieFinder movieFinder) {&lt;br /&gt;        this.movieFinder = movieFinder;&lt;br /&gt;    }&lt;br /&gt;    // ...&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;@Autowired may also be used for well-known "resolvable dependencies": the BeanFactory interface, the ApplicationContext interface, the ResourceLoader interface, the ApplicationEventPublisher interface and the MessageSource interface. These interfaces (and their extended interfaces such as ConfigurableApplicationContext or ResourcePatternResolver) will be automatically resolved, with no special setup necessary.&lt;br /&gt;&lt;br /&gt;public class MovieRecommender {&lt;br /&gt;&lt;br /&gt;    @Autowired&lt;br /&gt;    private ApplicationContext context;&lt;br /&gt;&lt;br /&gt;    public MovieRecommender() {&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    // ...&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;3.11.5. @Resource&lt;br /&gt;&lt;br /&gt;Spring also supports injection using the JSR-250 @Resource annotation on fields or bean property setter methods. This is a common pattern found in Java EE 5 and Java 6 (e.g. in JSF 1.2 managed beans or JAX-WS 2.0 endpoints), which Spring supports for Spring-managed objects as well.&lt;br /&gt;&lt;br /&gt;@Resource takes a 'name' attribute, and by default Spring will interpret that value as the bean name to be injected. In other words, it follows by-name semantics as demonstrated in this example:&lt;br /&gt;&lt;br /&gt;public class SimpleMovieLister {&lt;br /&gt;&lt;br /&gt;    private MovieFinder movieFinder;&lt;br /&gt;&lt;br /&gt;    @Resource(name="myMovieFinder")&lt;br /&gt;    public void setMovieFinder(MovieFinder movieFinder) {&lt;br /&gt;        this.movieFinder = movieFinder;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;If no name is specified explicitly, then the default name will be derived from the name of the field or setter method: In case of a field, it will simply be equivalent to the field name; in case of a setter method, it will be equivalent to the bean property name. So the following example is going to have the bean with name "movieFinder" injected into its setter method:&lt;br /&gt;&lt;br /&gt;public class SimpleMovieLister {&lt;br /&gt;&lt;br /&gt;    private MovieFinder movieFinder;&lt;br /&gt;&lt;br /&gt;    @Resource&lt;br /&gt;    public void setMovieFinder(MovieFinder movieFinder) {&lt;br /&gt;        this.movieFinder = movieFinder;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;3.11.6. @PostConstruct and @PreDestroy&lt;br /&gt;&lt;br /&gt;The CommonAnnotationBeanPostProcessor not only recognizes the @Resource annotation but also the JSR-250 lifecycle annotations. Introduced in Spring 2.5, the support for these annotations offers yet another alternative to those described in the sections on initialization callbacks and destruction callbacks. Provided that the CommonAnnotationBeanPostProcessor is registered within the Spring ApplicationContext, a method carrying one of these annotations will be invoked at the same point in the lifecycle as the corresponding Spring lifecycle interface's method or explicitly declared callback method. In the example below, the cache will be pre-populated upon initialization and cleared upon destruction.&lt;br /&gt;&lt;br /&gt;public class CachingMovieLister {&lt;br /&gt;&lt;br /&gt;    @PostConstruct&lt;br /&gt;    public void populateMovieCache() {&lt;br /&gt;        // populates the movie cache upon initialization...&lt;br /&gt;    }&lt;br /&gt;   &lt;br /&gt;    @PreDestroy&lt;br /&gt;    public void clearMovieCache() {&lt;br /&gt;        // clears the movie cache upon destruction...&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;4.7. Application contexts and Resource paths&lt;br /&gt;4.7.1. Constructing application contexts&lt;br /&gt;&lt;br /&gt;An application context constructor (for a specific application context type) generally takes a string or array of strings as the location path(s) of the resource(s) such as XML files that make up the definition of the context.&lt;br /&gt;&lt;br /&gt;When such a location path doesn't have a prefix, the specific Resource type built from that path and used to load the bean definitions, depends on and is appropriate to the specific application context. For example, if you create a ClassPathXmlApplicationContext as follows:&lt;br /&gt;&lt;br /&gt;ApplicationContext ctx = new ClassPathXmlApplicationContext("conf/appContext.xml");&lt;br /&gt;&lt;br /&gt;The bean definitions will be loaded from the classpath, as a ClassPathResource will be used. But if you create a FileSystemXmlApplicationContext as follows:&lt;br /&gt;&lt;br /&gt;ApplicationContext ctx =&lt;br /&gt;    new FileSystemXmlApplicationContext("conf/appContext.xml");&lt;br /&gt;&lt;br /&gt;The bean definition will be loaded from a filesystem location, in this case relative to the current working directory.&lt;br /&gt;&lt;br /&gt;Note that the use of the special classpath prefix or a standard URL prefix on the location path will override the default type of Resource created to load the definition. So this FileSystemXmlApplicationContext...&lt;br /&gt;&lt;br /&gt;ApplicationContext ctx =&lt;br /&gt;&lt;br /&gt;    new FileSystemXmlApplicationContext("classpath:conf/appContext.xml");&lt;br /&gt;&lt;br /&gt;... will actually load its bean definitions from the classpath. However, it is still a FileSystemXmlApplicationContext. If it is subsequently used as a ResourceLoader, any unprefixed paths will still be treated as filesystem paths.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7397436882433825691-8875854453696640927?l=firecracks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://firecracks.blogspot.com/feeds/8875854453696640927/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7397436882433825691&amp;postID=8875854453696640927' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7397436882433825691/posts/default/8875854453696640927'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7397436882433825691/posts/default/8875854453696640927'/><link rel='alternate' type='text/html' href='http://firecracks.blogspot.com/2009/07/spring-annotations.html' title='Spring Annotations'/><author><name>Biju</name><uri>http://www.blogger.com/profile/10765353064992372034</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7397436882433825691.post-3618819262258602599</id><published>2009-07-03T07:06:00.000-07:00</published><updated>2009-07-03T07:23:10.922-07:00</updated><title type='text'>Spring</title><content type='html'>&lt;span style="font-weight: bold;"&gt;IoC container&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;3.1. Introduction&lt;br /&gt;&lt;br /&gt;This chapter covers the Spring Framework's implementation of the Inversion of Control (IoC) [1] principle.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The org.springframework.beans and org.springframework.context packages provide the basis for the Spring Framework's IoC container. The BeanFactory interface provides an advanced configuration mechanism capable of managing objects of any nature. The ApplicationContext interface builds on top of the BeanFactory (it is a sub-interface) and adds other functionality such as easier integration with Spring's AOP features, message resource handling (for use in internationalization), event propagation, and application-layer specific contexts such as the WebApplicationContext for use in web applications.&lt;br /&gt;&lt;br /&gt;In short, the BeanFactory provides the configuration framework and basic functionality, while the ApplicationContext adds more enterprise-centric functionality to it. The ApplicationContext is a complete superset of the BeanFactory, and any description of BeanFactory capabilities and behavior is to be considered to apply to the ApplicationContext as well.&lt;br /&gt;&lt;br /&gt;This chapter is divided into two parts, with the first part covering the basic principles that apply to both the BeanFactory and ApplicationContext, and with the second part covering those features that apply only to the ApplicationContext interface.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;3.2.1. The container&lt;br /&gt;&lt;br /&gt;The org.springframework.beans.factory.BeanFactory is the actual representation of the Spring IoC container that is responsible for containing and otherwise managing the aforementioned beans.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Find below an example of the basic structure of XML-based configuration metadata.&lt;br /&gt;&lt;br /&gt;&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;br /&gt;&lt;beans xmlns="http://www.springframework.org/schema/beans"&lt;br /&gt;       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&lt;br /&gt;       xsi:schemaLocation="http://www.springframework.org/schema/beans&lt;br /&gt;           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"&gt;&lt;br /&gt;&lt;br /&gt;  &lt;bean id="..." class="..."&gt;&lt;br /&gt;    &lt;!-- collaborators and configuration for this bean go here --&gt;&lt;br /&gt;  &lt;/bean&gt;&lt;br /&gt;&lt;br /&gt;  &lt;bean id="..." class="..."&gt;&lt;br /&gt;    &lt;!-- collaborators and configuration for this bean go here --&gt;&lt;br /&gt;  &lt;/bean&gt;&lt;br /&gt;&lt;br /&gt;  &lt;!-- more bean definitions go here --&gt;&lt;br /&gt;&lt;br /&gt;&lt;/beans&gt;&lt;br /&gt;&lt;br /&gt;3.2.2. Instantiating a container&lt;br /&gt;&lt;br /&gt;Instantiating a Spring IoC container is straightforward.&lt;br /&gt;ApplicationContext context = new ClassPathXmlApplicationContext( new String[] {"services.xml", "daos.xml"}); // an ApplicationContext is also a BeanFactory (via inheritance) BeanFactory factory = context;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;3.2.3.2.2. Instantiation using a static factory method&lt;br /&gt;&lt;br /&gt;&lt;bean id="exampleBean"&lt;br /&gt;      class="examples.ExampleBean2"&lt;br /&gt;      factory-method="createInstance"/&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;3.2.3.2.3. Instantiation using an instance factory method&lt;br /&gt;&lt;br /&gt;&lt;!-- the factory bean, which contains a method called createInstance() --&gt;&lt;br /&gt;&lt;bean id="serviceLocator" class="com.foo.DefaultServiceLocator"&gt;&lt;br /&gt;  &lt;!-- inject any dependencies required by this locator bean --&gt;&lt;br /&gt;&lt;/bean&gt;&lt;br /&gt;&lt;br /&gt;&lt;!-- the bean to be created via the factory bean --&gt;&lt;br /&gt;&lt;bean id="exampleBean"&lt;br /&gt;      factory-bean="serviceLocator"&lt;br /&gt;      factory-method="createInstance"/&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;3.3. Dependencies&lt;br /&gt;The basic principle behind Dependency Injection (DI) is that objects define their dependencies (that is to say the other objects they work with) only through constructor arguments, arguments to a factory method, or properties which are set on the object instance after it has been constructed or returned from a factory method.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Then, it is the job of the container to actually inject those dependencies when it creates the bean. This is fundamentally the inverse, hence the name Inversion of Control (IoC), of the bean itself being in control of instantiating or locating its dependencies on its own using direct construction of classes, or something like the Service Locator pattern.&lt;br /&gt;&lt;br /&gt;3.3.1.1. Constructor Injection&lt;br /&gt;&lt;br /&gt;Constructor-based DI is effected by invoking a constructor with a number of arguments, each representing a dependency. Additionally, calling a static factory method with specific arguments to construct the bean, can be considered almost equivalent, and the rest of this text will consider arguments to a constructor and arguments to a static factory method similarly. Find below an example of a class that could only be dependency injected using constructor injection.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;3.3.1.1.1. Constructor Argument Resolution&lt;br /&gt;&lt;br /&gt;Constructor argument resolution matching occurs using the argument's type. If there is no potential for ambiguity in the constructor arguments of a bean definition, then the order in which the constructor arguments are defined in a bean definition is the order in which those arguments will be supplied to the appropriate constructor when it is being instantiated. Consider the following class:&lt;br /&gt;&lt;br /&gt;package x.y;&lt;br /&gt;&lt;br /&gt;public class Foo {&lt;br /&gt;&lt;br /&gt;    public Foo(Bar bar, Baz baz) {&lt;br /&gt;        // ...&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;beans&gt;&lt;br /&gt;    &lt;bean name="foo" class="x.y.Foo"&gt;&lt;br /&gt;        &lt;constructor-arg&gt;&lt;br /&gt;            &lt;bean class="x.y.Bar"&gt;&lt;br /&gt;        &lt;/constructor-arg&gt;&lt;br /&gt;        &lt;constructor-arg&gt;&lt;br /&gt;            &lt;bean class="x.y.Baz"&gt;&lt;br /&gt;        &lt;/constructor-arg&gt;&lt;br /&gt;    &lt;/bean&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/beans&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;When another bean is referenced, the type is known, and matching can occur (as was the case with the preceding example). When a simple type is used, such as &lt;value&gt;true&lt;value&gt;, Spring cannot determine the type of the value, and so cannot match by type without help. Consider the following class:&lt;br /&gt;&lt;br /&gt;package examples;&lt;br /&gt;&lt;br /&gt;public class ExampleBean {&lt;br /&gt;&lt;br /&gt;    // No. of years to the calculate the Ultimate Answer&lt;br /&gt;    private int years;&lt;br /&gt;&lt;br /&gt;    // The Answer to Life, the Universe, and Everything&lt;br /&gt;    private String ultimateAnswer;&lt;br /&gt;&lt;br /&gt;    public ExampleBean(int years, String ultimateAnswer) {&lt;br /&gt;        this.years = years;&lt;br /&gt;        this.ultimateAnswer = ultimateAnswer;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;bean id="exampleBean" class="examples.ExampleBean"&gt;&lt;br /&gt;  &lt;constructor-arg type="int" value="7500000"&gt;&lt;br /&gt;  &lt;constructor-arg type="java.lang.String" value="42"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/bean&gt;&lt;br /&gt;&lt;br /&gt;3.3.1.1.1.2. Constructor Argument Index&lt;br /&gt;&lt;br /&gt;Constructor arguments can have their index specified explicitly by use of the index attribute. For example:&lt;br /&gt;&lt;bean id="exampleBean" class="examples.ExampleBean"&gt; &lt;constructor-arg index="0" value="7500000"&gt; &lt;constructor-arg index="1" value="42"&gt; &lt;/bean&gt;&lt;br /&gt;&lt;br /&gt;As well as solving the ambiguity problem of multiple simple values, specifying an index also solves the problem of ambiguity where a constructor may have two arguments of the same type. Note that the index is 0 based.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;3.3.1.2. Setter Injection&lt;br /&gt;&lt;br /&gt;Setter-based DI is realized by calling setter methods on your beans after invoking a no-argument constructor or no-argument static factory method to instantiate your bean.&lt;br /&gt;&lt;br /&gt;Find below an example of a class that can only be dependency injected using pure setter injection. Note that there is nothing special about this class... it is plain old Java.&lt;br /&gt;public class SimpleMovieLister { // the SimpleMovieLister has a dependency on the MovieFinder private MovieFinder movieFinder; // a setter method so that the Spring container can 'inject' a MovieFinder public void setMovieFinder(MovieFinder movieFinder) { this.movieFinder = movieFinder; } // business logic that actually 'uses' the injected MovieFinder is omitted... }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Bean dependency resolution generally happens as follows:&lt;br /&gt;&lt;br /&gt;   1.&lt;br /&gt;&lt;br /&gt;      The BeanFactory is created and initialized with a configuration which describes all the beans. (Most Spring users use a BeanFactory or ApplicationContext implementation that supports XML format configuration files.)&lt;br /&gt;   2.&lt;br /&gt;&lt;br /&gt;      Each bean has dependencies expressed in the form of properties, constructor arguments, or arguments to the static-factory method when that is used instead of a normal constructor. These dependencies will be provided to the bean, when the bean is actually created.&lt;br /&gt;   3.&lt;br /&gt;&lt;br /&gt;      Each property or constructor argument is either an actual definition of the value to set, or a reference to another bean in the container.&lt;br /&gt;   4.&lt;br /&gt;&lt;br /&gt;      Each property or constructor argument which is a value must be able to be converted from whatever format it was specified in, to the actual type of that property or constructor argument. By default Spring can convert a value supplied in string format to all built-in types, such as int, long, String, boolean, etc.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The Spring container validates the configuration of each bean as the container is created, including the validation that properties which are bean references are actually referring to valid beans. However, the bean properties themselves are not set until the bean is actually created. For those beans that are singleton-scoped and set to be pre-instantiated (such as singleton beans in an ApplicationContext), creation happens at the time that the container is created, but otherwise this is only when the bean is requested.&lt;br /&gt;&lt;br /&gt;3.3.1.3. Some examples&lt;br /&gt;&lt;br /&gt;First, an example of using XML-based configuration metadata for setter-based DI. Find below a small part of a Spring XML configuration file specifying some bean definitions.&lt;br /&gt;&lt;br /&gt;&lt;bean id="exampleBean" class="examples.ExampleBean"&gt;&lt;br /&gt;&lt;br /&gt;  &lt;!-- setter injection using the nested &lt;ref/&gt; element --&gt;&lt;br /&gt;  &lt;property name="beanOne"&gt;&lt;ref bean="anotherExampleBean"&gt;&lt;/property&gt;&lt;br /&gt;&lt;br /&gt;  &lt;!-- setter injection using the neater 'ref' attribute --&gt;&lt;br /&gt;  &lt;property name="beanTwo" ref="yetAnotherBean"&gt;&lt;br /&gt;  &lt;property name="integerProperty" value="1"&gt;&lt;br /&gt;&lt;/bean&gt;&lt;br /&gt;&lt;br /&gt;&lt;bean id="anotherExampleBean" class="examples.AnotherBean"&gt;&lt;br /&gt;&lt;bean id="yetAnotherBean" class="examples.YetAnotherBean"&gt;&lt;br /&gt;&lt;br /&gt;public class ExampleBean {&lt;br /&gt;&lt;br /&gt;    private AnotherBean beanOne;&lt;br /&gt;    private YetAnotherBean beanTwo;&lt;br /&gt;    private int i;&lt;br /&gt;&lt;br /&gt;    public void setBeanOne(AnotherBean beanOne) {&lt;br /&gt;        this.beanOne = beanOne;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public void setBeanTwo(YetAnotherBean beanTwo) {&lt;br /&gt;        this.beanTwo = beanTwo;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public void setIntegerProperty(int i) {&lt;br /&gt;        this.i = i;&lt;br /&gt;    }   &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;As you can see, setters have been declared to match against the properties specified in the XML file. Find below an example of using constructor-based DI.&lt;br /&gt;&lt;br /&gt;&lt;bean id="exampleBean" class="examples.ExampleBean"&gt;&lt;br /&gt;&lt;br /&gt;  &lt;!-- constructor injection using the nested &lt;ref/&gt; element --&gt;&lt;br /&gt;  &lt;constructor-arg&gt;&lt;br /&gt;    &lt;ref bean="anotherExampleBean"&gt;&lt;br /&gt;  &lt;/constructor-arg&gt;&lt;br /&gt; &lt;br /&gt;  &lt;!-- constructor injection using the neater 'ref' attribute --&gt;&lt;br /&gt;  &lt;constructor-arg ref="yetAnotherBean"&gt;&lt;br /&gt; &lt;br /&gt;  &lt;constructor-arg type="int" value="1"&gt;&lt;br /&gt;&lt;/bean&gt;&lt;br /&gt;&lt;br /&gt;&lt;bean id="anotherExampleBean" class="examples.AnotherBean"&gt;&lt;br /&gt;&lt;bean id="yetAnotherBean" class="examples.YetAnotherBean"&gt;&lt;br /&gt;&lt;br /&gt;public class ExampleBean {&lt;br /&gt;&lt;br /&gt;    private AnotherBean beanOne;&lt;br /&gt;    private YetAnotherBean beanTwo;&lt;br /&gt;    private int i;&lt;br /&gt;   &lt;br /&gt;    public ExampleBean(&lt;br /&gt;        AnotherBean anotherBean, YetAnotherBean yetAnotherBean, int i) {&lt;br /&gt;        this.beanOne = anotherBean;&lt;br /&gt;        this.beanTwo = yetAnotherBean;&lt;br /&gt;        this.i = i;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;As you can see, the constructor arguments specified in the bean definition will be used to pass in as arguments to the constructor of the ExampleBean.&lt;br /&gt;&lt;br /&gt;Now consider a variant of this where instead of using a constructor, Spring is told to call a static factory method to return an instance of the object:&lt;br /&gt;&lt;br /&gt;&lt;bean id="exampleBean" class="examples.ExampleBean"&lt;br /&gt;      factory-method="createInstance"&gt;&lt;br /&gt;  &lt;constructor-arg ref="anotherExampleBean"&gt;&lt;br /&gt;  &lt;constructor-arg ref="yetAnotherBean"&gt;&lt;br /&gt;  &lt;constructor-arg value="1"&gt;&lt;br /&gt;&lt;/bean&gt;&lt;br /&gt;&lt;br /&gt;&lt;bean id="anotherExampleBean" class="examples.AnotherBean"&gt;&lt;br /&gt;&lt;bean id="yetAnotherBean" class="examples.YetAnotherBean"&gt;&lt;br /&gt;&lt;br /&gt;public class ExampleBean {&lt;br /&gt;&lt;br /&gt;    // a private constructor&lt;br /&gt;    private ExampleBean(...) {&lt;br /&gt;      ...&lt;br /&gt;    }&lt;br /&gt;   &lt;br /&gt;    // a static factory method; the arguments to this method can be&lt;br /&gt;    // considered the dependencies of the bean that is returned,&lt;br /&gt;    // regardless of how those arguments are actually used.&lt;br /&gt;    public static ExampleBean createInstance (&lt;br /&gt;            AnotherBean anotherBean, YetAnotherBean yetAnotherBean, int i) {&lt;br /&gt;&lt;br /&gt;        ExampleBean eb = new ExampleBean (...);&lt;br /&gt;        // some other operations...&lt;br /&gt;        return eb;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Note that arguments to the static factory method are supplied via &lt;constructor-arg/&gt; elements, exactly the same as if a constructor had actually been used. Also, it is important to realize that the type of the class being returned by the factory method does not have to be of the same type as the class which contains the static factory method, although in this example it is. An instance (non-static) factory method would be used in an essentially identical fashion (aside from the use of the factory-bean attribute instead of the class attribute), so details will not be discussed here.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;3.3.4. Lazily-instantiated beans&lt;br /&gt;&lt;br /&gt;&lt;bean id="lazy" class="com.foo.ExpensiveToCreateBean" init="true"&gt;&lt;br /&gt;&lt;br /&gt;&lt;bean name="not.lazy" class="com.foo.AnotherBean"&gt;&lt;br /&gt;&lt;br /&gt;3.3.7.1. Lookup method injection&lt;br /&gt;&lt;br /&gt;3.3.7.1. Lookup method injection&lt;br /&gt;&lt;br /&gt;Lookup method injection refers to the ability of the container to override methods on container managed beans, to return the result of looking up another named bean in the container. The lookup will typically be of a prototype bean as in the scenario described above. The Spring Framework implements this method injection by dynamically generating a subclass overriding the method, using bytecode generation via the CGLIB library.&lt;br /&gt;&lt;br /&gt;So if you look at the code from previous code snippet (the CommandManager class), the Spring container is going to dynamically override the implementation of the createCommand() method. Your CommandManager class is not going to have any Spring dependencies, as can be seen in this reworked example below:&lt;br /&gt;&lt;br /&gt;package fiona.apple;&lt;br /&gt;&lt;br /&gt;// no more Spring imports!&lt;br /&gt;&lt;br /&gt;public abstract class CommandManager {&lt;br /&gt;&lt;br /&gt;   public Object process(Object commandState) {&lt;br /&gt;      // grab a new instance of the appropriate Command interface&lt;br /&gt;      Command command = createCommand();&lt;br /&gt;      // set the state on the (hopefully brand new) Command instance&lt;br /&gt;      command.setState(commandState);&lt;br /&gt;      return command.execute();&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;    // okay... but where is the implementation of this method?&lt;br /&gt;   protected abstract Command createCommand();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;In the client class containing the method to be injected (the CommandManager in this case), the method that is to be 'injected' must have a signature of the following form:&lt;br /&gt;&lt;br /&gt;&lt;public|protected&gt; [abstract] &lt;return-type&gt; theMethodName(no-arguments);&lt;br /&gt;&lt;br /&gt;If the method is abstract, the dynamically-generated subclass will implement the method. Otherwise, the dynamically-generated subclass will override the concrete method defined in the original class. Let's look at an example:&lt;br /&gt;&lt;br /&gt;&lt;!-- a stateful bean deployed as a prototype (non-singleton) --&gt;&lt;br /&gt;&lt;bean id="command" class="fiona.apple.AsyncCommand" scope="prototype"&gt;&lt;br /&gt;  &lt;!-- inject dependencies here as required --&gt;&lt;br /&gt;&lt;/bean&gt;&lt;br /&gt;&lt;br /&gt;&lt;!-- commandProcessor uses statefulCommandHelper --&gt;&lt;br /&gt;&lt;bean id="commandManager" class="fiona.apple.CommandManager"&gt;&lt;br /&gt;  &lt;lookup-method name="createCommand" bean="command"&gt;&lt;br /&gt;&lt;/bean&gt;&lt;br /&gt;&lt;br /&gt;The bean identified as commandManager will call its own method createCommand() whenever it needs a new instance of the command bean. It is important to note that the person deploying the beans must be careful to deploy the command bean as a prototype (if that is actually what is needed). If it is deployed as a singleton, the same instance of the command bean will be returned each time!&lt;br /&gt;&lt;br /&gt;Please be aware that in order for this dynamic subclassing to work, you will need to have the CGLIB jar(s) on your classpath. Additionally, the class that the Spring container is going to subclass cannot be final, and the method that is being overridden cannot be final either. Also, testing a class that has an abstract method can be somewhat odd in that you will have to subclass the class yourself and supply a stub implementation of the abstract method. Finally, objects that have been the target of method injection cannot be serialized.&lt;br /&gt;&lt;br /&gt;3.4. Bean scopes&lt;br /&gt;&lt;br /&gt;singleton&lt;br /&gt;&lt;br /&gt;Scopes a single bean definition to a single object instance per Spring IoC container.&lt;br /&gt;&lt;br /&gt;prototype&lt;br /&gt;&lt;br /&gt;Scopes a single bean definition to any number of object instances.&lt;br /&gt;&lt;br /&gt;request&lt;br /&gt;&lt;br /&gt;Scopes a single bean definition to the lifecycle of a single HTTP request; that is each and every HTTP request will have its own instance of a bean created off the back of a single bean definition. Only valid in the context of a web-aware Spring ApplicationContext.&lt;br /&gt;&lt;br /&gt;session&lt;br /&gt;&lt;br /&gt;Scopes a single bean definition to the lifecycle of a HTTP Session. Only valid in the context of a web-aware Spring ApplicationContext.&lt;br /&gt;&lt;br /&gt;global session&lt;br /&gt;&lt;br /&gt;Scopes a single bean definition to the lifecycle of a global HTTP Session. Typically only valid when used in a portlet context. Only valid in the context of a web-aware Spring ApplicationContext.&lt;br /&gt;&lt;br /&gt;3.4.4.1. Initial web configuration&lt;br /&gt;In order to support the scoping of beans at the request, session, and global session levels (web-scoped beans), some minor initial configuration is required before you can set about defining your bean definitions. Please note that this extra setup is not required if you just want to use the 'standard' scopes (namely singleton and prototype).&lt;br /&gt;&lt;br /&gt;&lt;web-app&gt;&lt;br /&gt;  ...&lt;br /&gt;  &lt;listener&gt;&lt;br /&gt;    &lt;listener-class&gt;org.springframework.web.context.request.RequestContextListener&lt;/listener-class&gt;&lt;br /&gt;  &lt;/listener&gt;&lt;br /&gt;  ...&lt;br /&gt;&lt;/web-app&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If you are using an older web container (Servlet 2.3), you will need to use the provided javax.servlet.Filter implementation. Find below a snippet of XML configuration that has to be included in the 'web.xml' file of your web application if you want to have access to web-scoped beans in requests outside of Spring's DispatcherServlet on a Servlet 2.3 container. (The filter mapping depends on the surrounding web application configuration and so you will have to change it as appropriate.)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;web-app&gt;&lt;br /&gt;  ..&lt;br /&gt;  &lt;filter&gt;&lt;br /&gt;    &lt;filter-name&gt;requestContextFilter&lt;/filter-name&gt;&lt;br /&gt;    &lt;filter-class&gt;org.springframework.web.filter.RequestContextFilter&lt;/filter-class&gt;&lt;br /&gt;  &lt;/filter&gt;&lt;br /&gt;  &lt;filter-mapping&gt;&lt;br /&gt;    &lt;filter-name&gt;requestContextFilter&lt;/filter-name&gt;&lt;br /&gt;    &lt;url-pattern&gt;/*&lt;/url-pattern&gt;&lt;br /&gt;  &lt;/filter-mapping&gt;&lt;br /&gt;  ...&lt;br /&gt;&lt;/web-app&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;3.4.4.5. Scoped beans as dependencies&lt;br /&gt;Being able to define a bean scoped to a HTTP request or Session (or indeed a custom scope of your own devising) is all very well, but one of the main value-adds of the Spring IoC container is that it manages not only the instantiation of your objects (beans), but also the wiring up of collaborators (or dependencies). If you want to inject a (for example) HTTP request scoped bean into another bean, you will need to inject an AOP proxy in place of the scoped bean. That is, you need to inject a proxy object that exposes the same public interface as the scoped object, but that is smart enough to be able to retrieve the real, target object from the relevant scope (for example a HTTP request) and delegate method calls onto the real object.&lt;br /&gt;&lt;br /&gt;Let's look at the configuration that is required to effect this; the configuration is not hugely complex (it takes just one line), but it is important to understand the “why” as well as the “how” behind it.&lt;br /&gt;&lt;br /&gt;&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;br /&gt;&lt;beans xmlns="http://www.springframework.org/schema/beans"&lt;br /&gt;       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&lt;br /&gt;       xmlns:aop="http://www.springframework.org/schema/aop"&lt;br /&gt;       xsi:schemaLocation="&lt;br /&gt;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd&lt;br /&gt;http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"&gt;&lt;br /&gt;&lt;br /&gt;    &lt;!-- a HTTP Session-scoped bean exposed as a proxy --&gt;&lt;br /&gt;    &lt;bean id="userPreferences" class="com.foo.UserPreferences" scope="session"&gt;&lt;br /&gt;         &lt;br /&gt;          &lt;!-- this next element effects the proxying of the surrounding bean --&gt;&lt;br /&gt;          &lt;aop:scoped-proxy/&gt;&lt;br /&gt;    &lt;/bean&gt;&lt;br /&gt;   &lt;br /&gt;    &lt;!-- a singleton-scoped bean injected with a proxy to the above bean --&gt;&lt;br /&gt;    &lt;bean id="userService" class="com.foo.SimpleUserService"&gt;&lt;br /&gt;   &lt;br /&gt;        &lt;!-- a reference to the proxied 'userPreferences' bean --&gt;&lt;br /&gt;        &lt;property name="userPreferences" ref="userPreferences"&gt;&lt;br /&gt;&lt;br /&gt;    &lt;/bean&gt;&lt;br /&gt;&lt;/beans&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;3.5.1. Lifecycle callbacks&lt;br /&gt;3.5.1.1. Initialization callbacks&lt;br /&gt;&lt;br /&gt;Implementing the org.springframework.beans.factory.InitializingBean interface allows a bean to perform initialization work after all necessary properties on the bean have been set by the container. The InitializingBean interface specifies exactly one method:&lt;br /&gt;&lt;br /&gt;void afterPropertiesSet() throws Exception;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Implementing the org.springframework.beans.factory.InitializingBean interface allows a bean to perform initialization work after all necessary properties on the bean have been set by the container. The InitializingBean interface specifies exactly one method:&lt;br /&gt;&lt;br /&gt;void afterPropertiesSet() throws Exception;&lt;br /&gt;&lt;br /&gt;Generally, the use of the InitializingBean interface can be avoided and is actually discouraged since it unnecessarily couples the code to Spring. As an alternative, bean definitions provide support for a generic initialization method to be specified. In the case of XML-based configuration metadata, this is done using the 'init-method' attribute. For example, the following definition:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;bean id="exampleInitBean" class="examples.ExampleBean" method="init"&gt;&lt;br /&gt;&lt;br /&gt;public class ExampleBean {&lt;br /&gt;   &lt;br /&gt;    public void init() {&lt;br /&gt;        // do some initialization work&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;...is exactly the same as...&lt;br /&gt;&lt;br /&gt;&lt;bean id="exampleInitBean" class="examples.AnotherExampleBean"&gt;&lt;br /&gt;&lt;br /&gt;public class AnotherExampleBean implements InitializingBean {&lt;br /&gt;   &lt;br /&gt;    public void afterPropertiesSet() {&lt;br /&gt;        // do some initialization work&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;... but does not couple the code to Spring.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;3.5.1.2. Destruction callbacks&lt;br /&gt;&lt;br /&gt;Implementing the org.springframework.beans.factory.DisposableBean interface allows a bean to get a callback when the container containing it is destroyed. The DisposableBean interface specifies a single method:&lt;br /&gt;&lt;br /&gt;void destroy() throws Exception;&lt;br /&gt;&lt;br /&gt;Generally, the use of the DisposableBean callback interface can be avoided and is actually discouraged since it unnecessarily couples the code to Spring. As an alternative, bean definitions provide support for a generic destroy method to be specified. When using XML-based configuration metadata this is done via the 'destroy-method' attribute on the &lt;bean/&gt;. For example, the following definition:&lt;br /&gt;&lt;br /&gt;&lt;bean id="exampleInitBean" class="examples.ExampleBean" method="cleanup"&gt;&lt;br /&gt;&lt;br /&gt;public class ExampleBean {&lt;br /&gt;&lt;br /&gt;    public void cleanup() {&lt;br /&gt;        // do some destruction work (like releasing pooled connections)&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;...is exactly the same as...&lt;br /&gt;&lt;br /&gt;&lt;bean id="exampleInitBean" class="examples.AnotherExampleBean"&gt;&lt;br /&gt;&lt;br /&gt;public class AnotherExampleBean implements DisposableBean {&lt;br /&gt;&lt;br /&gt;    public void destroy() {&lt;br /&gt;        // do some destruction work (like releasing pooled connections)&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;... but does not couple the code to Spring.&lt;br /&gt;&lt;br /&gt;3.8.5. Convenient ApplicationContext instantiation for web applications&lt;br /&gt;&lt;br /&gt;As opposed to the BeanFactory, which will often be created programmatically, ApplicationContext instances can be created declaratively using for example a ContextLoader. Of course you can also create ApplicationContext instances programmatically using one of the ApplicationContext implementations. First, let's examine the ContextLoader mechanism and its implementations.&lt;br /&gt;&lt;br /&gt;The ContextLoader mechanism comes in two flavors: the ContextLoaderListener and the ContextLoaderServlet. They both have the same functionality but differ in that the listener version cannot be reliably used in Servlet 2.3 containers. Since the Servlet 2.4 specification, servlet context listeners are required to execute immediately after the servlet context for the web application has been created and is available to service the first request (and also when the servlet context is about to be shut down): as such a servlet context listener is an ideal place to initialize the Spring ApplicationContext. It is up to you as to which one you use, but all things being equal you should probably prefer ContextLoaderListener; for more information on compatibility, have a look at the Javadoc for the ContextLoaderServlet.&lt;br /&gt;&lt;br /&gt;You can register an ApplicationContext using the ContextLoaderListener as follows:&lt;br /&gt;&lt;br /&gt;&lt;context-param&gt;&lt;br /&gt;  &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;&lt;br /&gt;  &lt;param-value&gt;/WEB-INF/daoContext.xml /WEB-INF/applicationContext.xml&lt;/param-value&gt;&lt;br /&gt;&lt;/context-param&gt;&lt;br /&gt;&lt;br /&gt;&lt;listener&gt;&lt;br /&gt;  &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;&lt;br /&gt;&lt;/listener&gt;&lt;br /&gt;&lt;br /&gt;&lt;!-- or use the ContextLoaderServlet instead of the above listener&lt;br /&gt;&lt;servlet&gt;&lt;br /&gt;  &lt;servlet-name&gt;context&lt;/servlet-name&gt;&lt;br /&gt;  &lt;servlet-class&gt;org.springframework.web.context.ContextLoaderServlet&lt;/servlet-class&gt;&lt;br /&gt;  &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;&lt;br /&gt;&lt;/servlet&gt;&lt;br /&gt;--&gt;&lt;br /&gt;&lt;br /&gt;The listener inspects the 'contextConfigLocation' parameter. If the parameter does not exist, the listener will use /WEB-INF/applicationContext.xml as a default. When it does exist, it will separate the String using predefined delimiters (comma, semicolon and whitespace) and use the values as locations where application contexts will be searched for. Ant-style path patterns are supported as well: e.g. /WEB-INF/*Context.xml (for all files whose name ends with "Context.xml", residing in the "WEB-INF" directory) or /WEB-INF/**/*Context.xml (for all such files in any subdirectory of "WEB-INF").&lt;br /&gt;&lt;br /&gt;The ContextLoaderServlet can be used instead of the ContextLoaderListener. The servlet will use the 'contextConfigLocation' parameter just as the listener does.&lt;br /&gt;&lt;br /&gt;3.3.5. Autowiring collaborators&lt;br /&gt;&lt;br /&gt;The Spring container is able to autowire relationships between collaborating beans. This means that it is possible to automatically let Spring resolve collaborators (other beans) for your bean by inspecting the contents of the BeanFactory. The autowiring functionality has five modes. Autowiring is specified per bean and can thus be enabled for some beans, while other beans will not be autowired. Using autowiring, it is possible to reduce or eliminate the need to specify properties or constructor arguments, thus saving a significant amount of typing. [2] When using XML-based configuration metadata, the autowire mode for a bean definition is specified by using the autowire attribute of the &lt;bean/&gt; element. The following values are allowed:&lt;br /&gt;&lt;br /&gt;Table 3.2. Autowiring modes&lt;br /&gt;Mode    Explanation&lt;br /&gt;no   &lt;br /&gt;&lt;br /&gt;No autowiring at all. Bean references must be defined via a ref element. This is the default, and changing this is discouraged for larger deployments, since explicitly specifying collaborators gives greater control and clarity. To some extent, it is a form of documentation about the structure of a system.&lt;br /&gt;byName   &lt;br /&gt;&lt;br /&gt;Autowiring by property name. This option will inspect the container and look for a bean named exactly the same as the property which needs to be autowired. For example, if you have a bean definition which is set to autowire by name, and it contains a master property (that is, it has a setMaster(..) method), Spring will look for a bean definition named master, and use it to set the property.&lt;br /&gt;byType   &lt;br /&gt;&lt;br /&gt;Allows a property to be autowired if there is exactly one bean of the property type in the container. If there is more than one, a fatal exception is thrown, and this indicates that you may not use byType autowiring for that bean. If there are no matching beans, nothing happens; the property is not set. If this is not desirable, setting the dependency-check="objects" attribute value specifies that an error should be thrown in this case.&lt;br /&gt;constructor   &lt;br /&gt;&lt;br /&gt;This is analogous to byType, but applies to constructor arguments. If there isn't exactly one bean of the constructor argument type in the container, a fatal error is raised.&lt;br /&gt;autodetect   &lt;br /&gt;&lt;br /&gt;Chooses constructor or byType through introspection of the bean class. If a default constructor is found, the byType mode will be applied.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;3.7.2. Customizing configuration metadata with BeanFactoryPostProcessors&lt;br /&gt;&lt;br /&gt;The next extension point that we will look at is the org.springframework.beans.factory.config.BeanFactoryPostProcessor. The semantics of this interface are similar to the BeanPostProcessor, with one major difference: BeanFactoryPostProcessors operate on the bean configuration metadata; that is, the Spring IoC container will allow BeanFactoryPostProcessors to read the configuration metadata and potentially change it before the container has actually instantiated any other beans.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;A bean factory post-processor is executed manually (in the case of a BeanFactory) or automatically (in the case of an ApplicationContext) to apply changes of some sort to the configuration metadata that defines a container. Spring includes a number of pre-existing bean factory post-processors, such as PropertyOverrideConfigurer and PropertyPlaceholderConfigurer, both described below. A custom BeanFactoryPostProcessor can also be used to register custom property editors, for example.&lt;br /&gt;&lt;br /&gt;In a BeanFactory, the process of applying a BeanFactoryPostProcessor is manual, and will be similar to this:&lt;br /&gt;&lt;br /&gt;XmlBeanFactory factory = new XmlBeanFactory(new FileSystemResource("beans.xml"));&lt;br /&gt;&lt;br /&gt;// bring in some property values from a Properties file&lt;br /&gt;PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();&lt;br /&gt;cfg.setLocation(new FileSystemResource("jdbc.properties"));&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;// now actually do the replacement&lt;br /&gt;cfg.postProcessBeanFactory(factory);&lt;br /&gt;&lt;br /&gt;This explicit registration step is not convenient, and this is one of the reasons why the various ApplicationContext implementations are preferred above plain BeanFactory implementations in the vast majority of Spring-backed applications, especially when using BeanFactoryPostProcessors.&lt;br /&gt;&lt;br /&gt;An ApplicationContext will detect any beans which are deployed into it which implement the BeanFactoryPostProcessor interface, and automatically use them as bean factory post-processors, at the appropriate time. Nothing else needs to be done other than deploying these post-processor in a similar fashion to any other bean.&lt;br /&gt;&lt;br /&gt;3.7.2.1. Example: the PropertyPlaceholderConfigurer&lt;br /&gt;&lt;br /&gt;The PropertyPlaceholderConfigurer is used to externalize property values from a BeanFactory definition, into another separate file in the standard Java Properties format. This is useful to allow the person deploying an application to customize environment-specific properties (for example database URLs, usernames and passwords), without the complexity or risk of modifying the main XML definition file or files for the container.&lt;br /&gt;&lt;br /&gt;Consider the following XML-based configuration metadata fragment, where a DataSource with placeholder values is defined. We will configure some properties from an external Properties file, and at runtime, we will apply a PropertyPlaceholderConfigurer to the metadata which will replace some properties of the DataSource:&lt;br /&gt;&lt;br /&gt;&lt;bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;&lt;br /&gt;    &lt;property name="locations"&gt;&lt;br /&gt;        &lt;value&gt;classpath:com/foo/jdbc.properties&lt;/value&gt;&lt;br /&gt;    &lt;/property&gt;&lt;br /&gt;&lt;/bean&gt;&lt;br /&gt;&lt;br /&gt;&lt;bean id="dataSource" destroy-method="close"&lt;br /&gt;      class="org.apache.commons.dbcp.BasicDataSource"&gt;&lt;br /&gt;    &lt;property name="driverClassName" value="${jdbc.driverClassName}"&gt;&lt;br /&gt;    &lt;property name="url" value="${jdbc.url}"&gt;&lt;br /&gt;    &lt;property name="username" value="${jdbc.username}"&gt;&lt;br /&gt;    &lt;property name="password" value="${jdbc.password}"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/bean&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7397436882433825691-3618819262258602599?l=firecracks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://firecracks.blogspot.com/feeds/3618819262258602599/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7397436882433825691&amp;postID=3618819262258602599' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7397436882433825691/posts/default/3618819262258602599'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7397436882433825691/posts/default/3618819262258602599'/><link rel='alternate' type='text/html' href='http://firecracks.blogspot.com/2009/07/spring.html' title='Spring'/><author><name>Biju</name><uri>http://www.blogger.com/profile/10765353064992372034</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7397436882433825691.post-4050464099005852023</id><published>2009-07-03T07:04:00.000-07:00</published><updated>2009-07-03T07:05:49.234-07:00</updated><title type='text'>Annotations</title><content type='html'>&lt;h2&gt;1) Introduction&lt;/h2&gt;  &lt;p align="justify"&gt; &lt;span class="IL_SPAN"&gt;Annotations&lt;/span&gt; in &lt;span style="color: rgb(0, 153, 0); font-weight: 400; font-style: normal; font-family: Verdana;" class="IL_LINK_STYLE"&gt;&lt;/span&gt;Java is all about adding meta-data facility to the Java &lt;span class="IL_SPAN"&gt;Elements&lt;/span&gt;. Like Classes, Interfaces or Enums, &lt;span class="IL_SPAN"&gt;Annotations&lt;/span&gt; define a type in Java and they can be applied to several Java &lt;span class="IL_SPAN"&gt;Elements&lt;/span&gt;. Tools which will read and interpret the Annotaions &lt;span style="color: rgb(0, 153, 0); font-weight: 400; font-style: normal; font-family: Verdana;" class="IL_LINK_STYLE"&gt;&lt;/span&gt; will implement a lot of functionalities from the meta-information obtained. For example, they can ensure the consistency between classes, can check the validity of the paramters passed by the clients at run-time and can generate lot of base code for a project. This article provides you a complete guide detailing the various aspects of &lt;span class="IL_SPAN"&gt;Annotations&lt;/span&gt;. The topics covered in this article are as follows,&lt;br /&gt;&lt;/p&gt;&lt;b&gt;TestAnnotation.java&lt;/b&gt;&lt;p&gt; &lt;/p&gt;&lt;pre bgcolor="#E7E7E7"&gt;&lt;br /&gt; public @interface TestAnnotation&lt;br /&gt; {&lt;br /&gt;  // Property &lt;span class="IL_SPAN"&gt;Definition&lt;/span&gt; here.&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;    &lt;p align="justify"&gt; Don't get confused with the &lt;span class="IL_SPAN"&gt;interface&lt;/span&gt; keyword. It has nothing to do with &lt;span class="IL_SPAN"&gt;annotations&lt;/span&gt;. '@' along with &lt;span class="IL_SPAN"&gt;interface&lt;/span&gt; is the start of the annotation &lt;span class="IL_SPAN"&gt;definition&lt;/span&gt; and TestAnnotation in the above case is the name of the Annotation. Whether &lt;span class="IL_SPAN"&gt;annotations&lt;/span&gt; can be applied to class (a class-level annotation), or a method (method-level annotation) or a field (field-level annotation) is specified in the declaration of the annotation itself. This is referred to as &lt;i&gt;&lt;b&gt;Annotating an Annotation&lt;/b&gt;&lt;/i&gt; itself.&lt;/p&gt;&lt;br /&gt;2.2) Target Annotation  &lt;p align="justify"&gt; For example, if the case is that @TestAnnotation annotation can only be applied to methods, then there is a Meta-Annotation (meta-data about meta-data) which tells for which element type this annotation is applicable. For example, the following is the declaration of the @TestAnnotation annotation along with some meta-data that states the &lt;span class="IL_SPAN"&gt;elements&lt;/span&gt; that this annotation can be applied to. &lt;/p&gt;  &lt;p&gt; &lt;b&gt;TestAnnotation.java&lt;/b&gt; &lt;/p&gt;&lt;pre bgcolor="#E7E7E7"&gt;&lt;br /&gt; @Target(ElementType.METHOD)&lt;br /&gt; public @interface TestAnnotation&lt;br /&gt; {&lt;br /&gt;  // Property Definitions here.&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;   &lt;p align="justify"&gt; From the above, we can see that the Annotation @TestAnnotation is annotated with @Target. This kind of Annotation Chaining is always possible. The target element tells that the @TestAnnotation annotation can be applied only to methods and not to any other element types. The argument to @Target Annotation can be one from the possible set of values of any Java Element, which is defined in a well-defined Enum called ElementType. Here are the possible values taken by this Enum, &lt;/p&gt;  &lt;p align="justify"&gt; &lt;/p&gt;&lt;ul&gt;&lt;li&gt;TYPE – Applied only to Type. A Type can be a Java class or &lt;span class="IL_SPAN"&gt;interface&lt;/span&gt; or an Enum or even an Annotation.&lt;/li&gt;&lt;li&gt;FIELD – Applied only to Java Fields (Objects, Instance or Static, declared at class level).&lt;/li&gt;&lt;li&gt;METHOD – Applied only to methods.&lt;/li&gt;&lt;li&gt;PARAMETER – Applied only to method parameters in a method &lt;span class="IL_SPAN"&gt;definition&lt;/span&gt;.&lt;/li&gt;&lt;li&gt;CONSTRUCTOR – Can be applicable only to a constructor of a class.&lt;/li&gt;&lt;li&gt;LOCAL_VARIABLE – Can be applicable only to Local variables. (Variables that are declared within a method or a block of code).&lt;/li&gt;&lt;li&gt;ANNOTATION_TYPE – Applied only to Annotation Types.&lt;/li&gt;&lt;li&gt;PACKAGE – Applicable only to a Package.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;h3&gt;2.3) Retention Annotation&lt;/h3&gt;  &lt;p align="justify"&gt; Another commonly used Meta-data for an Annotation is the &lt;i&gt;&lt;b&gt;Retention Policy&lt;/b&gt;&lt;/i&gt;. Assume that we have some &lt;span class="IL_SPAN"&gt;Annotations&lt;/span&gt; defined in the source code. We have a mechanism through which we can say that to what extent the &lt;span class="IL_SPAN"&gt;Annotations&lt;/span&gt; should be retained. The three possible ways of telling this are, &lt;/p&gt;  &lt;p align="justify"&gt; &lt;/p&gt;&lt;ul&gt;&lt;li&gt;Retain the Annotation in the Source Code only&lt;/li&gt;&lt;li&gt;Retain the Annotation in &lt;span class="IL_SPAN"&gt;the Class&lt;/span&gt; file also.&lt;/li&gt;&lt;li&gt;Retain the Annotation &lt;span class="IL_SPAN"&gt;Definition&lt;/span&gt; during the Run-time so that JVM can make use of it.&lt;/li&gt;&lt;/ul&gt;   &lt;p align="justify"&gt;The Annotation that is used to achieve this is @Retention and it takes a possible values of SOURCE, CLASS and RUNTIME defined in RetentionPolicy Enumeration. For example, if we want to retain the @TestAnnotation information till &lt;span class="IL_SPAN"&gt;the class&lt;/span&gt; file, we can define something like this, &lt;/p&gt;  &lt;p&gt; &lt;b&gt;TestAnnotation.java&lt;/b&gt; &lt;/p&gt;&lt;pre bgcolor="#E7E7E7"&gt;&lt;br /&gt; @Target(ElementType.METHOD)&lt;br /&gt; @Retention(RetentionPolicy.CLASS)&lt;br /&gt; public @interface TestAnnotation&lt;br /&gt; {&lt;br /&gt;  // Property Definitions here.&lt;br /&gt; }&lt;br /&gt;.&lt;br /&gt;&lt;/pre&gt;&lt;h2 id="Built-in Annotations in Java"&gt;3) Built-in Annotations in Java&lt;/h2&gt;  &lt;p align="justify"&gt; There are some pre-defined annotations available in the Java They are, &lt;/p&gt;&lt;p align="justify"&gt; &lt;/p&gt;&lt;ul&gt;&lt;li&gt;Override&lt;/li&gt;&lt;li&gt;Deprecated&lt;/li&gt;&lt;li&gt;SuppressWarnings&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;http://www.javabeat.net/articles/30-annotations-in-java-50-2.html&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7397436882433825691-4050464099005852023?l=firecracks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://firecracks.blogspot.com/feeds/4050464099005852023/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7397436882433825691&amp;postID=4050464099005852023' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7397436882433825691/posts/default/4050464099005852023'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7397436882433825691/posts/default/4050464099005852023'/><link rel='alternate' type='text/html' href='http://firecracks.blogspot.com/2009/07/annotations.html' title='Annotations'/><author><name>Biju</name><uri>http://www.blogger.com/profile/10765353064992372034</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7397436882433825691.post-3007928420521121900</id><published>2009-07-03T07:03:00.001-07:00</published><updated>2009-07-03T07:04:13.423-07:00</updated><title type='text'>Java and Web Services</title><content type='html'>&lt;span style="font-size:100%;"&gt;Web Services have at their core XML as a mechanism for communication. Ultimately, Web Services are based on three specific technologies: a mechanism to register a service, a mechanism to find a service, and a mechanism for two parties to communicate. Today, developers can use the Java 2 Enterprise Edition APIs and XML to provide Web Services. Such developments leverage existing Web sites and provide simple methods to extend, interconnect and publish existing J2EE-based applications in new and exciting ways.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;a Web Service is three specific things:&lt;/span&gt; &lt;ul&gt;&lt;li&gt;     &lt;span style="font-size:100%;"&gt;A way to find and register interest in a service.&lt;/span&gt;   &lt;/li&gt;&lt;li&gt;     &lt;span style="font-size:100%;"&gt;A transport mechanism to access a service.&lt;/span&gt;   &lt;/li&gt;&lt;li&gt;     &lt;span style="font-size:100%;"&gt;A way to define what the input and output parameters are for such a service.&lt;/span&gt;   &lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;   &lt;span style="font-size:100%;"&gt;Defining a Service, Web Services Description Language&lt;/span&gt; &lt;/h3&gt;&lt;br /&gt;&lt;p&gt;   &lt;span style="font-size:100%;"&gt;Specifically WSDL provides a number of key pieces of information:&lt;/span&gt; &lt;/p&gt; &lt;ul&gt;&lt;li&gt;     &lt;span style="font-size:100%;"&gt;A definition of the format of the messages that are passed between two endpoints using its &lt;types&gt; and &lt;message&gt; elements and appropriate schema definitions.&lt;/message&gt;&lt;/types&gt;&lt;/span&gt;   &lt;/li&gt;&lt;li&gt;     &lt;span style="font-size:100%;"&gt; The semantics of the service: how it might be called to make a synchronous request/reply, synchronous reply-only or asynchronously communicate.&lt;/span&gt;   &lt;/li&gt;&lt;li&gt;     &lt;span style="font-size:100%;"&gt; The end point and transport of the service via the &lt;service&gt; element: that is, who provides the service.&lt;/service&gt;&lt;/span&gt;   &lt;/li&gt;&lt;li&gt;     &lt;span style="font-size:100%;"&gt;An encoding via the &lt;binding&gt; element, that is how the service is accessed.&lt;/binding&gt;&lt;/span&gt;   &lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;h3&gt;   &lt;span style="font-size:100%;"&gt;Universal Discovery and Description Integration (UDDI)&lt;/span&gt; &lt;/h3&gt; &lt;p&gt; &lt;br /&gt;  &lt;/p&gt; &lt;span style="font-size:100%;"&gt;In order to actually use a service, a client must first find that service, retrieve information about how to use the service, and understand who might provide the service. The Universal Discover and Description and Integration specification, or UDDI, defines a number of lookup services aimed at allowing clients to look up and retrieve the required information to access a Web Service.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;h3&gt;   &lt;span style="font-size:100%;"&gt;Connecting It All Together With the Simple Object Access Protocol&lt;/span&gt; &lt;/h3&gt; &lt;p&gt;   &lt;span style="font-size:100%;"&gt;We now understand three things: how a Web Service is defined, and where it can be published and accessed. But we've left out one crucial aspect of the puzzle: how do we actually access the service once we've found it? Web Services become accessible using a protocol known as the Simple Object Access Protocol, or SOAP. In fact, you normally access a UDDI registry using well-defined SOAP calls! But what is SOAP? SOAP, at its simplest, is a protocol for encapsulating a request as an XML payload using standard communications protocols such as HTTP. The power of SOAP comes from the fact that is simple, easy to implement, and well supported in the industry.&lt;/span&gt; &lt;/p&gt; &lt;p&gt;   &lt;span style="font-size:100%;"&gt;Typically, a SOAP call is packaged as the body of an HTTP request. The listing below, from the W3C SOAP specification, shows an example of a SOAP call to access a service known as GetLastTradePrice as an HTTP server might receive it.&lt;/span&gt; &lt;/p&gt;&lt;br /&gt;&lt;p&gt; &lt;br /&gt;&lt;/p&gt; &lt;p&gt; &lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7397436882433825691-3007928420521121900?l=firecracks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://firecracks.blogspot.com/feeds/3007928420521121900/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7397436882433825691&amp;postID=3007928420521121900' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7397436882433825691/posts/default/3007928420521121900'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7397436882433825691/posts/default/3007928420521121900'/><link rel='alternate' type='text/html' href='http://firecracks.blogspot.com/2009/07/ava-and-web-services.html' title='Java and Web Services'/><author><name>Biju</name><uri>http://www.blogger.com/profile/10765353064992372034</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7397436882433825691.post-7738192989413624492</id><published>2007-12-27T06:28:00.000-08:00</published><updated>2007-12-27T06:29:16.616-08:00</updated><title type='text'>Guruji Oru Vakku (1985) - Penninte chenchundil</title><content type='html'>Movie : Guruji Oru Vakku&lt;br /&gt;Singer: Yesudas,Chithra&lt;br /&gt;Music : Jerry Amaldas&lt;br /&gt;Lyrics: Bichu Thirumala&lt;br /&gt;Director: Rajan Sankaradi&lt;br /&gt;*******************************************************&lt;br /&gt;&lt;br /&gt;Penninte chenchundil punjiri poothu&lt;br /&gt;Hayya kannaadi puzhayil viriyana kulirala pole&lt;br /&gt;Kandille kinnaaram parayanoraale&lt;br /&gt;Hayya illikkad adimudi ulayana kalapila pole&lt;br /&gt;(penninte)&lt;br /&gt;&lt;br /&gt;Kari vandina kannukalil oliyambukal eyyanatho&lt;br /&gt;Thein kudikkanatho kandu....&lt;br /&gt;Vira kollana chundukalil uriyadana thanthramo&lt;br /&gt;Maara manthramo kettoo&lt;br /&gt;Hoyyaaram payyaaram thudi kottana sringaaram&lt;br /&gt;Oh..hoy hoy manassinu kulirane (penninte)&lt;br /&gt;&lt;br /&gt;Azhakaarnnoru chandirano mazhavillezhum indirano&lt;br /&gt;Aaru neeyariyaararo&lt;br /&gt;Kulirekanorambiliyo kuliraatana kambiliyo&lt;br /&gt;Mangayaanival aararo...&lt;br /&gt;Annaaram Punnaaram mozhi muttana kinnaaram&lt;br /&gt;Oh..hoy hoy adimudi thalirane (kandille)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7397436882433825691-7738192989413624492?l=firecracks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://firecracks.blogspot.com/feeds/7738192989413624492/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7397436882433825691&amp;postID=7738192989413624492' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7397436882433825691/posts/default/7738192989413624492'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7397436882433825691/posts/default/7738192989413624492'/><link rel='alternate' type='text/html' href='http://firecracks.blogspot.com/2007/12/guruji-oru-vakku-1985-penninte.html' title='Guruji Oru Vakku (1985) - Penninte chenchundil'/><author><name>Biju</name><uri>http://www.blogger.com/profile/10765353064992372034</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7397436882433825691.post-1603562152011373352</id><published>2007-12-12T04:13:00.000-08:00</published><updated>2007-12-12T06:07:37.888-08:00</updated><title type='text'>Java Beans</title><content type='html'>JavaBeans™ is a portable, platform-independent component model written in the Java programming language. The JavaBeans architecture was built through a collaborative industry effort and enables developers to write reusable components in the Java programming language.&lt;br /&gt;&lt;br /&gt;With the JavaBeans API you can create reuseable, platform-independent components. Using JavaBeans-compliant application builder tools, you can combine these components into applets, applications, or composite components.&lt;br /&gt;&lt;br /&gt;JavaBean components are known as beans. Beans are dynamic in that they can be changed or customized. Through the design mode of a builder tool, you use the property sheet or bean customizer to customize the bean and then save (persist) your customized beans.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7397436882433825691-1603562152011373352?l=firecracks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://java.sun.com/docs/books/tutorial/javabeans/index.html' title='Java Beans'/><link rel='replies' type='application/atom+xml' href='http://firecracks.blogspot.com/feeds/1603562152011373352/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7397436882433825691&amp;postID=1603562152011373352' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7397436882433825691/posts/default/1603562152011373352'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7397436882433825691/posts/default/1603562152011373352'/><link rel='alternate' type='text/html' href='http://firecracks.blogspot.com/2007/12/java-beans.html' title='Java Beans'/><author><name>Biju</name><uri>http://www.blogger.com/profile/10765353064992372034</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7397436882433825691.post-6336429315437188322</id><published>2007-12-06T10:21:00.000-08:00</published><updated>2007-12-06T10:25:30.473-08:00</updated><title type='text'>Bob Parsons 16 rules</title><content type='html'>A serial entrepreneur, Parsons' first endeavor was Parsons Technology, a software company he started in his basement in 1984, after teaching himself how to write computer programs. After creating the company’s initial software, MoneyCounts and Personal Tax Edge, Parsons used direct mail marketing to sell these and subsequent products.&lt;br /&gt;&lt;br /&gt;When Parsons Technology was sold to Intuit, Inc. in 1994 for $64 million dollars, the company had nearly 1,000 employees, $100 million in annual revenue and three million customers. At the time, Parsons Technology sold more than 100 products, was releasing a new product or significant product upgrade every six days, and was sending more than six million pieces of direct marketing mail each month.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;1. Get and stay out of your comfort zone.&lt;/span&gt;&lt;br /&gt;I believe that not much happens of any significance when we're in our comfort zone. I hear people say, "But I'm concerned about security." My response to that is simple: "Security is for cadavers."&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;2. Never give up.&lt;/span&gt;&lt;br /&gt;Almost nothing works the first time it's attempted. Just because what you're doing does not seem to be working, doesn't mean it won't work. It just means that it might not work the way you're doing it. If it was easy, everyone would be doing it, and you wouldn't have an opportunity.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;3. When you’re ready to quit, you’re closer than you think.&lt;/span&gt;&lt;br /&gt;There's an old Chinese saying that I just love, and I believe it is so true. It goes like this: "The temptation to quit will be greatest just before you are about to succeed."&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;4. With regard to whatever worries you, not only accept the worst thing that could happen, but make it a point to quantify what the worst thing could be.&lt;/span&gt;&lt;br /&gt;Very seldom will the worst consequence be anywhere near as bad as a cloud of "undefined consequences." My father would tell me early on, when I was struggling and losing my shirt trying to get Parsons Technology going, "Well, Robert, if it doesn't work, they can't eat you."&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;5. Focus on what you want to have happen.&lt;/span&gt;&lt;br /&gt;Remember that old saying, "As you think, so shall you be."&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;6. Take things a day at a time.&lt;/span&gt;&lt;br /&gt;No matter how difficult your situation is, you can get through it if you don't look too far into the future, and focus on the present moment. You can get through anything one day at a time.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;7. Always be moving forward.&lt;/span&gt;&lt;br /&gt;Never stop investing. Never stop improving. Never stop doing something new. The moment you stop improving your organization, it starts to die. Make it your goal to be better each and every day, in some small way. Remember the Japanese concept of Kaizen. Small daily improvements eventually result in huge advantages.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;8. Be quick to decide.&lt;/span&gt;&lt;br /&gt;Remember what General George S. Patton said: "A good plan violently executed today is far and away better than a perfect plan tomorrow."&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;9. Measure everything of significance.&lt;/span&gt;&lt;br /&gt;I swear this is true. Anything that is measured and watched, improves.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;10. Anything that is not managed will deteriorate.&lt;/span&gt;&lt;br /&gt;If you want to uncover problems you don't know about, take a few moments and look closely at the areas you haven't examined for a while. I guarantee you problems will be there.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;11. Pay attention to your competitors, but pay more attention to what you’re doing.&lt;/span&gt;&lt;br /&gt;When you look at your competitors, remember that everything looks perfect at a distance. Even the planet Earth, if you get far enough into space, looks like a peaceful place.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;12. Never let anybody push you around.&lt;/span&gt;&lt;br /&gt;In our society, with our laws and even playing field, you have just as much right to what you're doing as anyone else, provided that what you're doing is legal.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;13. Never expect life to be fair.&lt;/span&gt;&lt;br /&gt;Life isn't fair. You make your own breaks. You'll be doing good if the only meaning fair has to you, is something that you pay when you get on a bus (i.e., fare).&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;&lt;br /&gt;14. Solve your own problems.&lt;/span&gt;&lt;br /&gt;You'll find that by coming up with your own solutions, you'll develop a competitive edge. Masura Ibuka, the co-founder of SONY, said it best: "You never succeed in technology, business, or anything by following the others." There's also an old Asian saying that I remind myself of frequently. It goes like this: "A wise man keeps his own counsel."&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;15. Don’t take yourself too seriously.&lt;/span&gt;&lt;br /&gt;Lighten up. Often, at least half of what we accomplish is due to luck. None of us are in control as much as we like to think we are.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;16. There’s always a reason to smile.&lt;/span&gt;&lt;br /&gt;Find it. After all, you're really lucky just to be alive. Life is short. More and more, I agree with my little brother. He always reminds me: “We’re not here for a long time, we’re here for a good time!”&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7397436882433825691-6336429315437188322?l=firecracks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://firecracks.blogspot.com/feeds/6336429315437188322/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7397436882433825691&amp;postID=6336429315437188322' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7397436882433825691/posts/default/6336429315437188322'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7397436882433825691/posts/default/6336429315437188322'/><link rel='alternate' type='text/html' href='http://firecracks.blogspot.com/2007/12/bob-parsons-16-rules.html' title='Bob Parsons 16 rules'/><author><name>Biju</name><uri>http://www.blogger.com/profile/10765353064992372034</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7397436882433825691.post-8617012714700742011</id><published>2007-11-29T07:01:00.000-08:00</published><updated>2007-11-29T07:10:49.989-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Difference between web server and application server'/><category scheme='http://www.blogger.com/atom/ns#' term='Web Server and Application server'/><title type='text'>Web Server and Application server</title><content type='html'>What is the difference between an application server and a Web server?&lt;br /&gt;Taking a big step back, a Web server serves pages for viewing in a Web browser, while an application server provides methods that client applications can call. A little more precisely, you can say that: &lt;br /&gt;A Web server exclusively handles HTTP requests, whereas an application server serves business logic to application programs through any number of protocols. &lt;br /&gt;&lt;br /&gt;Let's examine each in more detail.&lt;br /&gt;The Web server&lt;br /&gt;A Web server handles the HTTP protocol. When the Web server receives an HTTP request, it responds with an HTTP response, such as sending back an HTML page. To process a request, a Web server may respond with a static HTML page or image, send a redirect, or delegate the dynamic response generation to some other program such as CGI scripts, JSPs (JavaServer Pages), servlets, ASPs (Active Server Pages), server-side JavaScripts, or some other server-side technology. Whatever their purpose, such server-side programs generate a response, most often in HTML, for viewing in a Web browser. &lt;br /&gt;Understand that a Web server's delegation model is fairly simple. When a request comes into the Web server, the Web server simply passes the request to the program best able to handle it. The Web server doesn't provide any functionality beyond simply providing an environment in which the server-side program can execute and pass back the generated responses. The server-side program usually provides for itself such functions as transaction processing, database connectivity, and messaging. &lt;br /&gt;While a Web server may not itself support transactions or database connection pooling, it may employ various strategies for fault tolerance and scalability such as load balancing, caching, and clustering—features oftentimes erroneously assigned as features reserved only for application servers. &lt;br /&gt;The application server&lt;br /&gt;As for the application server, according to our definition, an application server exposes business logic to client applications through various protocols, possibly including HTTP. While a Web server mainly deals with sending HTML for display in a Web browser, an application server provides access to business logic for use by client application programs. The application program can use this logic just as it would call a method on an object (or a function in the procedural world). &lt;br /&gt;Such application server clients can include GUIs (graphical user interface) running on a PC, a Web server, or even other application servers. The information traveling back and forth between an application server and its client is not restricted to simple display markup. Instead, the information is program logic. Since the logic takes the form of data and method calls and not static HTML, the client can employ the exposed business logic however it wants. &lt;br /&gt;In most cases, the server exposes this business logic through a component API, such as the EJB (Enterprise JavaBean) component model found on J2EE (Java 2 Platform, Enterprise Edition) application servers. Moreover, the application server manages its own resources. Such gate-keeping duties include security, transaction processing, resource pooling, and messaging. Like a Web server, an application server may also employ various scalability and fault-tolerance techniques.   Continued &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;An example&lt;br /&gt;As an example, consider an online store that provides real-time pricing and availability information. Most likely, the site will provide a form with which you can choose a product. When you submit your query, the site performs a lookup and returns the results embedded within an HTML page. The site may implement this functionality in numerous ways. I'll show you one scenario that doesn't use an application server and another that does. Seeing how these scenarios differ will help you to see the application server's function. &lt;br /&gt;Scenario 1: Web server without an application server&lt;br /&gt;In the first scenario, a Web server alone provides the online store's functionality. The Web server takes your request, then passes it to a server-side program able to handle the request. The server-side program looks up the pricing information from a database or a flat file. Once retrieved, the server-side program uses the information to formulate the HTML response, then the Web server sends it back to your Web browser. &lt;br /&gt;To summarize, a Web server simply processes HTTP requests by responding with HTML pages.&lt;br /&gt;Scenario 2: Web server with an application server&lt;br /&gt;Scenario 2 resembles Scenario 1 in that the Web server still delegates the response generation to a script. However, you can now put the business logic for the pricing lookup onto an application server. With that change, instead of the script knowing how to look up the data and formulate a response, the script can simply call the application server's lookup service. The script can then use the service's result when the script generates its HTML response. &lt;br /&gt;In this scenario, the application server serves the business logic for looking up a product's pricing information. That functionality doesn't say anything about display or how the client must use the information. Instead, the client and application server send data back and forth. When a client calls the application server's lookup service, the service simply looks up the information and returns it to the client. &lt;br /&gt;By separating the pricing logic from the HTML response-generating code, the pricing logic becomes far more reusable between applications. A second client, such as a cash register, could also call the same service as a clerk checks out a customer. In contrast, in Scenario 1 the pricing lookup service is not reusable because the information is embedded within the HTML page. To summarize, in Scenario 2's model, the Web server handles HTTP requests by replying with an HTML page while the application server serves application logic by processing pricing and availability requests. &lt;br /&gt;Caveats&lt;br /&gt;Recently, XML Web services have blurred the line between application servers and Web servers. By passing an XML payload to a Web server, the Web server can now process the data and respond much as application servers have in the past. &lt;br /&gt;Additionally, most application servers also contain a Web server, meaning you can consider a Web server a subset of an application server. While application servers contain Web server functionality, developers rarely deploy application servers in that capacity. Instead, when needed, they often deploy standalone Web servers in tandem with application servers. Such a separation of functionality aids performance (simple Web requests won't impact application server performance), deployment configuration (dedicated Web servers, clustering, and so on), and allows for best-of-breed product selection.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7397436882433825691-8617012714700742011?l=firecracks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://firecracks.blogspot.com/feeds/8617012714700742011/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7397436882433825691&amp;postID=8617012714700742011' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7397436882433825691/posts/default/8617012714700742011'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7397436882433825691/posts/default/8617012714700742011'/><link rel='alternate' type='text/html' href='http://firecracks.blogspot.com/2007/11/web-server-and-application-server.html' title='Web Server and Application server'/><author><name>Biju</name><uri>http://www.blogger.com/profile/10765353064992372034</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7397436882433825691.post-6277896911439245168</id><published>2007-11-29T06:57:00.000-08:00</published><updated>2007-11-29T06:58:14.747-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Web Services'/><title type='text'>Web Services</title><content type='html'>&lt;style&gt;  &lt;!--   @page { size: 8.5in 11in; margin: 0.79in }   P { margin-bottom: 0.08in }   TD P { margin-bottom: 0in }   H3 { margin-bottom: 0.08in }  --&gt;  &lt;/style&gt;  &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="color:#000080;"&gt;&lt;b&gt;Web Services Concept: &lt;/b&gt;&lt;/span&gt; &lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;span style="color:#000080;"&gt;Web services are the mechanism to develop a Service-Oriented-Architecture (SOA). SOA is an architectural approach for designing large scale distributed systems to integrate heterogeneous application on the service interfaces. Web services technologies support to the Service-Oriented-Architecture in various ways. Some of them are illustrated below:&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;span style="color:#000080;"&gt;A service requestor uses the selection  criteria to the query registry for finding the services description.&lt;/span&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style="color:#000080;"&gt;A service requestor can bind and use  the service if it finds a suitable descriptor.&lt;/span&gt;&lt;/p&gt; &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;span style="color:#000080;"&gt;Web services are used in various fields such converting a temperature value from Fahrenheit to Celsius. More realistic examples built using the web services are heterogeneous applications such as billing application and report generator, interconnected in-house architectures. A service interface is just like an object interface with a slight difference that the contract between the interface and the client is more flexible and the implementation of client and the service is not much tightly coupled as compared to EJB or other distributed platform. Looser coupling allows the client and service implementation to run on various platforms, independently such as Microsoft .NET is capable of using a Java EE application server to access a service running on it. From the client's point of view, web services's life cycle is more static as compared to average objects because web services stay around rather than pop-up and go away, even if the services are implemented using the object technology.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="color:#000080;"&gt;&lt;b&gt;Web Services Standards: &lt;/b&gt;The de facto standardized set of  web services can be summarized by using an equation.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="color:#000080;"&gt;Web Services = WSDL + SOAP + UDDI &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="color:#000080;"&gt;Lets take a quick look over WSDL and UDDI, but we are not going to cover these topics here because these are less useful. The requestor does not necessarily have the registry to know the services and its end point address. Registry not only supports a simple naming service but also queries for the services that follow the given predicate.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="color:#000080;"&gt;&lt;b&gt;WSDL: &lt;/b&gt;There is no need to write down the xml file. The tool you are using automatically creates an xml file. A number of things are worth nothing while using WSDL.&lt;/span&gt;&lt;/p&gt; &lt;ul&gt;&lt;li&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="color:#000080;"&gt;&lt;b&gt;The  service description includes an endpoint address: &lt;/b&gt;WSDL is  similar to java interface and an object reference joined together or  in other words, we can say web services don't have distinct  identities. Since they are not objects therefore they must be viewed  like objects. It does not have any client visible state therefore  your are not able to compare the two references for equality. &lt;/span&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="color:#000080;"&gt;&lt;b&gt;It uses  larger number of concepts than in java: &lt;/b&gt;Service provides one or  more ports at an address. Ports are the representation of the  service interfaces that binds to protocols.&lt;/span&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="color:#000080;"&gt;&lt;b&gt;Operations  result in terms of input and output messages rather than parameters  and return values: &lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style="color:#000080;"&gt;&lt;b&gt;Services are bind using SOAP  binding: &lt;/b&gt; &lt;/span&gt;  &lt;/p&gt; &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;span style="color:#000080;"&gt;&lt;b&gt;Building a Web Service with JEE: &lt;/b&gt;The creation of the portable and interoperable distributed components from the web services is not a trivial task. Either regular Java classes or stateless EJBs can be easily deployed as web services. Package the Java regular classes in a web module and EJB web services in normal ejb-jar modules.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="color:#000080;"&gt;Two options are there to deploy an application, you can use one of the two deployment options given below:&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="color:#000080;"&gt;&lt;b&gt;Java Class versus Stateless EJB: &lt;/b&gt;It depends upon you whether you should have a regular Java class or EJBs as your technology to build a Web Service. We can easily develop java classes than EJBs. Java classes are pure java objects and do not have the extra baggage that the EJBs do. One benefit of using EJB is that it supports the features such as declarative transaction and security. EJB leaves free to the developer just to concentrate only on applying the business logic without worrying about the infrastructure services.  &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="color:#000080;"&gt;&lt;b&gt;Packaging Requirement: &lt;/b&gt;Whatever you are using either a regular Java class or EJB, in both the conditions you need to package several artifacts into your WAR or ejb-jar accordingly, to expose components as a Java Web Service. Web Services use the following two packaging structures based on either regular Java classes or EJBs. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="color:#000080;"&gt;&lt;b&gt;Web app &lt;/b&gt;(.war) for a regular Java web service:&lt;/span&gt;&lt;/p&gt; &lt;table bg border="0" cellpadding="0" cellspacing="0" width="34%" style="color:#ffffcc;"&gt;  &lt;col width="256*"&gt;  &lt;tbody&gt;&lt;tr&gt;   &lt;td width="100%"&gt;    &lt;p&gt;&lt;span style="color:#000080;"&gt;/WEB-INF/&lt;br /&gt;             web.xml&lt;br /&gt;             webservices.xml&lt;br /&gt;             oracle-webservices.xml&lt;br /&gt;             mapping-file.xml&lt;br /&gt;             wsdl/                  it is wsdl file&lt;br /&gt;             /classes/(includes endpoint and bean classes)&lt;br /&gt;            /lib/&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;&lt;span style="color:#000080;"&gt;&lt;b&gt;ejb-jar &lt;/b&gt;for an EJB-based web service: &lt;/span&gt;&lt;/p&gt; &lt;table bg border="0" cellpadding="0" cellspacing="0" width="39%" style="color:#ffffcc;"&gt;  &lt;col width="256*"&gt;  &lt;tbody&gt;&lt;tr&gt;   &lt;td width="100%"&gt;    &lt;p&gt;&lt;span style="color:#000080;"&gt;/META-INF/&lt;br /&gt;                ejb-jar.xml&lt;br /&gt;                webservices.xml&lt;br /&gt;                            oracle-webservices.xml&lt;br /&gt;                mapping-file.xml&lt;br /&gt;                            wsdl/   the wsdl file&lt;br /&gt;                ejb classes   (includes endpoint and bean classes)&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;&lt;span style="color:#000080;"&gt;Lets discuss each of the descriptors and the deployment-time artifacts one-by-one.&lt;/span&gt;&lt;/p&gt; &lt;ul&gt;&lt;li&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="color:#000080;"&gt;&lt;b&gt;WSDL: &lt;/b&gt;We  are not going to discuss about the WSDL any more as we have already  discuss it in the previous section. &lt;/span&gt;  &lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="color:#000080;"&gt;&lt;b&gt;Web  Services deployment descriptor: &lt;/b&gt;webservices.xml is the standard  deployment descriptor that a JEE plateform requires. This descriptor  specifies the description for deployment about the set of web  services into the JEE application server and also their dependencies  on the container resources and services. The mapping.xml file that  contains Java-to-WSDL mapping and the service endpoint interface for  the HelloWorld web service is also specified by this deployment  descriptor.   &lt;/span&gt;  &lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style="color:#000080;"&gt;&lt;b&gt;Endpoint interface: &lt;/b&gt;The Web  Service endpoint implements the java.rmi.Remote interface therefore  every method of web service endpoint interface must throw the  java.rmi.RemoteException. The deployment descriptor registers to the  end point for the module (ejb-jar.xml) or web.xml. The deployment  descriptor (e.g. ejb-jar.xml) should have the following entry.   &lt;/span&gt;  &lt;/p&gt; &lt;/li&gt;&lt;/ul&gt; &lt;table bg border="0" cellpadding="0" cellspacing="0" width="21%" style="color:#ffffcc;"&gt;  &lt;col width="256*"&gt;  &lt;tbody&gt;&lt;tr&gt;   &lt;td width="100%"&gt;    &lt;p&gt;&lt;span style="color:#000080;"&gt;&lt;service-endpoint&gt;&lt;br /&gt;oracle.ejb21.ws.HelloServiceInf&lt;br /&gt;&lt;/service-endpoint&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;&lt;span style="color:#000080;"&gt;Following is the code for the Web Service endpoint for a HelloWorld web service:&lt;/span&gt;&lt;/p&gt; &lt;table bgcolor="#ffffcc" border="0" cellpadding="0" cellspacing="0" width="37%"&gt;  &lt;col width="256*"&gt;  &lt;tbody&gt;&lt;tr&gt;   &lt;td width="100%"&gt;    &lt;p&gt;public interface HelloServiceInf extends java.rmi.Remote    {&lt;br /&gt;java.lang.String sayHello(java.lang.String name)&lt;br /&gt;throws    java.rmi.RemoteException;&lt;br /&gt;}&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;ul&gt;&lt;li&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="color:#000080;"&gt;&lt;b&gt;Vendor-specific  deployment descriptors: &lt;/b&gt;We can not specify several  implementation-specific reference, such as endpoint addresses,  context root in the Web Services deployment descriptor but we can  rather specify the vendor-specific deployment descriptor. For  example if you are using OC4J then an oracle-webservices.xml file is  required to package in WAR or ejb-jar to define the properties.&lt;/span&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style="color:#000080;"&gt;&lt;b&gt;Java-WSDL mapping: &lt;/b&gt;Mapping  between the WSDL and Java types is defined in this file. Mapping  file does not have any standard name, web services deployment  descriptor defines its name. &lt;/span&gt;  &lt;/p&gt; &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;span style="color:#000080;"&gt;Before deploying your component as a web service, first you must package all these artifacts in the ejb-jar module or in the WAR. Most of the development tools like Oracle JDeveloper simplifies the development task of web services simply by mapping files, generating the deployment descriptor etc. Moreover most of the application servers provide Web Services assembly tools that fulfill the JEE web service packaging requirements.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="color:#000080;"&gt;Before understanding the components required to make up a Web Service and the associated packaging requirements, first you must deal with the architectural issues when developing a web service. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="color:#000080;"&gt;&lt;b&gt;Approaches to Construct Services: &lt;/b&gt;The main thing about building a Web Service is to identify the service along with its right granularity. Its depends upon you  either you can expose an existing component that is built as a Java class or EJB and expose it as a service or build the new service. You can use either top-down or bottom-up approach while building a new service.&lt;/span&gt;&lt;/p&gt; &lt;ul&gt;&lt;li&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="color:#000080;"&gt;&lt;b&gt;Top-down  approach: &lt;/b&gt;While building the services from scratch, this is the  most appropriate approach. With this approach start describing the  service with WSDL instead of jumping right into the implementation.  This is the most preferable approach since services become  maintainable, more usable and interoperable due to the control over  the WSDL while deploying your web service, careful consideration of  the operations and message exposed. Several JEE vendors provide  tools to make the approach easier such as Oracle Application  Server's web services assembler generates deployment descriptors,  interfaces and skeleton implementation classes which can be used to  build your application.&lt;/span&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style="color:#000080;"&gt;&lt;b&gt;Bottom-up approach: &lt;/b&gt;This  approach is used whenever an existing Java class or EJB is to be  exposed as a Web Service. The reason behind the populalrity of this  approach is that, this approach allows to reuse the existing  business logic without rewriting the applications. While using this  approach, you have to create a WSDL to describe the Web Service  along with other deployment descriptors and add a web service  end-point interface for the implementation to which you want to  expose as a Web Service. Tools provided by application servers (such  as Oracle Application Server's web services assembler tool) are used  to make the life simpler by generating the descriptors such as  webservices.xml, WSDL and mapping files for Web Services components  free up the developer from manually creating these files. &lt;/span&gt;  &lt;/p&gt; &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;span style="color:#000080;"&gt;&lt;b&gt;Tips for developing Web Services: &lt;/b&gt;Here are the some points that must follow while developing Web Services.&lt;/span&gt;&lt;/p&gt; &lt;ul&gt;&lt;li&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="color:#000080;"&gt;Most of the  conventional best practices are for JEE applications that are  relevant to Web Services. for example, avoid exposing a component  involve in the long-run transaction as a Web Service.  &lt;/span&gt;  &lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="color:#000080;"&gt;Confirm  design of your Web Service so that it can create minimum network  traffic. &lt;/span&gt;  &lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="color:#000080;"&gt;Do not  overuse Web Services in your applications. Check the necessity to  expose your application as a Web Service. &lt;/span&gt;  &lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a name="intelliTxt"&gt;&lt;/a&gt;&lt;span style="color:#000080;"&gt;Compare your  security requirements with the performance of your application as  security comes with the higher cost. Performance of end-to-end  security for web services are quite costly. &lt;/span&gt;  &lt;/p&gt; &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;span style="color:#000080;"&gt;To build java based web services, J2EE Blueprint Application ( Java Adventure Builder) provides a nice blueprint application.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="color:#000080;"&gt;After designing, developing and deploying, we generally create the associated components to interact with the given service.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="color:#000080;"&gt;&lt;b&gt;Invoking Web Services: &lt;/b&gt;Web Service can have the client of any of the following type: Dynamic Invocation Interface (DII) or dynamic proxy, static stub.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="color:#000080;"&gt;Building a Web Service client may be complex similar to build a simple web service. But JEE 1.4 makes it simple to use the web services for JEE developers from any type of JEE component such as EJB components or web clients.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="color:#000080;"&gt;Invoking a Web Service is similar to invoking any other resource using JNDI via the following:&lt;/span&gt;&lt;/p&gt; &lt;ul&gt;&lt;li&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="color:#000080;"&gt;First define  your component by using a "&lt;b&gt;service-ref"&lt;/b&gt; element in  the deployment descriptor. For example, if you are accessing the  HelloWorldService web service by using web module then the module's  web.xml file may contain the following:&lt;/span&gt;&lt;/p&gt; &lt;/li&gt;&lt;/ul&gt; &lt;dl&gt;&lt;dd&gt;  &lt;table bgcolor="#ffffcc" border="0" cellpadding="0" cellspacing="0" width="44%"&gt;   &lt;col width="256*"&gt;   &lt;tbody&gt;&lt;tr&gt;    &lt;td width="100%"&gt;     &lt;p&gt;&lt;a name="intelliTxt0"&gt;&lt;/a&gt;&lt;service-ref&gt;&lt;br /&gt;&lt;service-ref-name&gt;service/HelloWorldService&lt;/service-ref-name&gt;&lt;br /&gt;&lt;service-interface&gt;oracle.ws.HelloWorldService&lt;/service-interface&gt;&lt;br /&gt;&lt;wsdl-file&gt;META-INF/HelloWorldService.wsdl&lt;/wsdl-file&gt;&lt;br /&gt;&lt;service-qname&gt;urn:oracle-ws&lt;/service-qname&gt;&lt;br /&gt;&lt;/service-ref&gt;&lt;/p&gt;    &lt;/td&gt;   &lt;/tr&gt;  &lt;/tbody&gt;&lt;/table&gt; &lt;/dd&gt;&lt;/dl&gt; &lt;ul&gt;&lt;li&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="color:#000080;"&gt;Allow your  application to find Web Service just by specifying the location of  the Web Service in the vendor-specific deployment descriptor. &lt;/span&gt;&lt;/p&gt;  &lt;table bgcolor="#ffffcc" border="0" cellpadding="0" cellspacing="0" width="255"&gt;   &lt;col width="255"&gt;   &lt;tbody&gt;&lt;tr&gt;    &lt;td width="255"&gt;     &lt;p&gt;&lt;service-ref-mapping name="service/HelloWorldService"&gt;&lt;br /&gt;&lt;port-info&gt;&lt;br /&gt;&lt;wsdl-port     namespaceURI="urn:     HelloWorldService"&lt;br /&gt;localpart="HelloWorldServicePort"/&gt;&lt;br /&gt;&lt;stub-property&gt;&lt;br /&gt;&lt;name&gt;javax.xml.rpc.service.endpoint.address&lt;/name&gt;&lt;br /&gt;&lt;value&gt;http://localhost:8888/hello/HelloWorldInf&lt;/value&gt;&lt;br /&gt;&lt;/stub-property&gt;&lt;br /&gt;&lt;/port-info&gt;&lt;br /&gt;&lt;/service-ref-mapping&gt;&lt;/p&gt;    &lt;/td&gt;   &lt;/tr&gt;  &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&lt;span style="color:#000080;"&gt;  &lt;/span&gt;  &lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p style="margin-bottom: 0in;"&gt;&lt;span style="color:#000080;"&gt;Package type  classes and end-point interface with your application before  deploying it to the server. Make the JNDI lookup to use a Web  Service.&lt;/span&gt;&lt;/p&gt; &lt;/li&gt;&lt;/ul&gt; &lt;dl&gt;&lt;dd&gt;  &lt;table bgcolor="#ffffcc" border="0" cellpadding="0" cellspacing="0" width="36%"&gt;   &lt;col width="256*"&gt;   &lt;tbody&gt;&lt;tr&gt;    &lt;td width="100%"&gt;     &lt;p&gt;InitialContext ctx= new InitialContext();&lt;br /&gt;HelloServiceInf     hs =     (HelloServiceInf)&lt;br /&gt;ctx.lookup("java:comp/env/service/HelloWorldService");&lt;br /&gt;HelloWorld     hello= hs.getHelloWorldServicePort();&lt;br /&gt;String myhello =     hs.sayHello("Zulfiqar") ;&lt;/p&gt;    &lt;/td&gt;   &lt;/tr&gt;  &lt;/tbody&gt;&lt;/table&gt; &lt;/dd&gt;&lt;/dl&gt; &lt;p&gt;&lt;span style="color:#000080;"&gt;&lt;b&gt;Simplifying SOA Development with JEE 5.0: &lt;/b&gt;Building service-oriented applications are rather difficult with JEE, JEE 5.0 is designed to simplify the development by using Web Services Metadata annotations defined by JSR 181. Web Services Metadata and EJB 3.0 both are used to provide friendly environment to the developer. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="color:#000080;"&gt;To develop a simple Java Web Service in JEE 1.4, several Web Service artifacts such as mapping files, WSDL, proprietary web services deployment descriptor and several verbose standard are designed in JEE 5.0. Web Services Metadata specification receives a by default configuration approach similar to EJB 3.0 for simplifying the development process. Web Services Metadata annotation process generates these files for you so just concentrate on the implementation class.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="color:#000080;"&gt;Following is the Java Web Service developed using Web Services Metadata:&lt;/span&gt;&lt;/p&gt; &lt;table bgcolor="#ffffcc" border="0" cellpadding="0" cellspacing="0" width="36%"&gt;  &lt;col width="256*"&gt;  &lt;tbody&gt;&lt;tr&gt;   &lt;td width="100%"&gt;    &lt;p&gt;package oracle.jr181.demo;&lt;br /&gt;import    javax.jws.WebMethod;&lt;br /&gt;import    javax.jws.WebService;&lt;br /&gt;@WebService(name =    "HelloWorldService",&lt;br /&gt;targetNamespace =    "http://hello/targetNamespace" )&lt;br /&gt;public class    HelloWorldService {&lt;br /&gt;@WebMethod public String    sayhello(String name ) {&lt;br /&gt;return "Hello” +name+ “    from jws";&lt;br /&gt;}&lt;br /&gt;}&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;&lt;span style="color:#000080;"&gt;EJB 3.0 uses regular Java classes to simplify the development process. EJB-based Web Services developed using EJB 3.0 and Web Services Metadata, are much simpler. HelloWorld EJB is the example given below developed by using EJB 3.0 and Web Services Metadata. Don't worry while creating WSDL, deployment descriptors, etc., since the application server generates these artifacts during deployment.&lt;/span&gt;&lt;/p&gt; &lt;table bgcolor="#ffffcc" border="0" cellpadding="0" cellspacing="0" width="41%"&gt;  &lt;col width="256*"&gt;  &lt;tbody&gt;&lt;tr&gt;   &lt;td width="100%"&gt;    &lt;p&gt;package oracle.ejb30.ws;&lt;br /&gt;import javax.ejb.Remote;&lt;br /&gt;import    javax.jws.WebService;&lt;br /&gt;@WebService&lt;br /&gt;public interface    HelloServiceInf extends java.rmi.Remote{&lt;br /&gt;@WebMethod    java.lang.String sayHello(java.lang.String name)&lt;br /&gt;throws    java.rmi.RemoteException;&lt;br /&gt;}&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;&lt;span style="color:#000080;"&gt;Implementation of HelloWorld EJB using EJB 3.0 is given below: &lt;/span&gt; &lt;/p&gt; &lt;table bgcolor="#ffffcc" border="0" cellpadding="0" cellspacing="0" width="40%"&gt;  &lt;col width="256*"&gt;  &lt;tbody&gt;&lt;tr&gt;   &lt;td width="100%"&gt;    &lt;p&gt;package oracle.ejb30.ws;&lt;br /&gt;import    java.rmi.RemoteException;&lt;br /&gt;import    javax.ejb.Stateless;&lt;br /&gt;@Stateless(name="HelloServiceEJB")&lt;br /&gt;public    class HelloServiceBean implements HelloServiceInf {&lt;br /&gt;public    String sayHello(String name) {&lt;br /&gt;return("Hello "+name    +" from first EJB3.0 Web Service");&lt;br /&gt;}&lt;br /&gt;}&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;&lt;span style="color:#000080;"&gt;The above example demonstrates the simplification of service development while simplifying by using Web Services Metadata and EJB 3.0.&lt;/span&gt;&lt;/p&gt; &lt;h3&gt;&lt;span style="color:#000080;"&gt;Conclusion&lt;/span&gt;&lt;/h3&gt; &lt;p&gt;&lt;span style="color:#000080;"&gt;This articles gives you the understanding about the basics of building Web Services using the J2EE platform. You can build and deploy your Web Services in J2EE-compliant application servers such as Sun Java System Application Sever, Oracle Application Server 10g, etc.&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7397436882433825691-6277896911439245168?l=firecracks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://firecracks.blogspot.com/feeds/6277896911439245168/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7397436882433825691&amp;postID=6277896911439245168' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7397436882433825691/posts/default/6277896911439245168'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7397436882433825691/posts/default/6277896911439245168'/><link rel='alternate' type='text/html' href='http://firecracks.blogspot.com/2007/11/web-services.html' title='Web Services'/><author><name>Biju</name><uri>http://www.blogger.com/profile/10765353064992372034</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7397436882433825691.post-8920520311200690675</id><published>2007-11-29T06:28:00.000-08:00</published><updated>2007-11-29T06:55:52.746-08:00</updated><title type='text'>EJB</title><content type='html'>&lt;style&gt;  &lt;!--   @page { size: 8.5in 11in; margin: 0.79in }   P { margin-bottom: 0.08in }  --&gt;  &lt;/style&gt;  &lt;p align="left"&gt;&lt;span style="color: rgb(25, 25, 112);"&gt;The J2EE Architecture allows the programmers to divide their work into two major categories:&lt;/span&gt;  &lt;/p&gt; &lt;ul&gt;&lt;li&gt;&lt;p align="left"&gt;&lt;span style="color: rgb(25, 25, 112);"&gt;Business Logic&lt;/span&gt;   &lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;p align="left"&gt;&lt;span style="color: rgb(25, 25, 112);"&gt;Presentation Logic &lt;/span&gt;  &lt;/p&gt; &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Presentation Logic:&lt;/span&gt;&lt;/span&gt; &lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;Presentation Logic consists of all the program (JSP and Servlets), images and html files that are used to interact with the client. These files are archived into .war file. These files are installed on the web server and these interacts with the users.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;&lt;span style="font-size:130%;"&gt;&lt;b&gt;Business Logic:&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;These are EJB applications which implements the business logic of the system and are archived into .jar file. Business logic runs on the application server.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;These two types of archives are bundled into complete J2EE applications, and delivered as Enterprise Archive (EAR) file.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;Let's took an example of form processing. In this example J2EE application could have and HTML form, which prompts the user to input the data, a servlet to receive the data from the form and process it, and also an Enterprise Bean to store the data in a database. In this example the HTML form and servlet are archived in a WAR file, and the Enterprise Java Bean is archived into JAR file. These two archive files (WAR and JAR) both are added to the EAR file, which is finally deployed on the server.&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p align="center"&gt;&lt;span style="color: rgb(25, 25, 112);"&gt;&lt;span style="font-size:180%;"&gt;&lt;b&gt;Enterprise Java Beans (EJB) - An Introduction&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;One of Java's most important features is platform independence. Since its arrival, Java has been depicted as "write once, run anywhere". But Enterprise JavaBeans (EJBs) go one step further. They are not only platform independent but also implementation independent. That is, EJBs can run in any application server that implements the EJB specifications. In this overview, I discuss about the background, necessity and motivations for the emergence of EJBs in the enterprise distributed computing arena and a short EJB architectural overview.&lt;/span&gt;  &lt;/p&gt; &lt;p align="left"&gt;&lt;b&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;Enterprise Distributed Object Computing (EDOC)&lt;/span&gt;&lt;/b&gt;  &lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;Distributed computing allows a business system to be more accessible. Distributed systems allow parts of the system to be located on separate computers located in different locations, where they make the most sense. That is, distributed computing allows business logic and data to be reached from remote locations at any time from anywhere by any one. The most recent development in distributed computing is distributed object computing. The technologies such as Java RMI, CORBA and Microsoft's DCOM help to accomplish distributed object computing paradigm by allowing objects running on one computer to be accessed for servicing the clients in other computers.&lt;/span&gt;  &lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;Object-oriented (OO) programming languages, such as Java, C++ and Smalltalk, are used to code software that fulfills the goals such as flexibility, extensibility and reusability, of OO technology. In business systems, OO languages are being used to improve development of GUIs, to simplify access to data and above all, to encapsulate the business logic into business objects. As a business's products, processes,and objectives evolve over time, the software that models the business has to be flexible, extensible, adaptable and reusable. The OO programming methodologies, namely encapsulation, polymorphism and inheritance, play a very important share in accomplishing the above mentioned goals. As today's enterprises are being shaped to comprise a number of business objects fulfilling various tasks, distributed computing is all set to take a very significant role in developing and deploying enterprise-class software in the days ahead. In the following sections, I discuss some of the earlier computing paradigms and the context in which EJB architecture came out and promises to shape the future requirements.&lt;/span&gt;  &lt;/p&gt; &lt;p align="left"&gt;&lt;b&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;Transaction Processing (TP) Monitors&lt;/span&gt;&lt;/b&gt;  &lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;TP monitors have been evolving for about 30 years and have become powerful, high-speed server platforms for mission-critical applications. TP monitors are operating systems for business systems whose applications are written in languages like COBOL. TP monitors automatically manage the entire environment that a business system runs in, including transactions, resource management, and fault tolerance and thus are eligible to be called operating systems. The business logic in TP monitors is made up of procedural applications that are often accessed through network messaging or remote procedural calls (RPC). RPC is a distributed mechanism that allows clients to invoke procedures on applications in a TP monitor as if the procedure was executed locally.&lt;/span&gt;  &lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;The downside for TP monitors is as follows: TP monitors are not object oriented and they work with procedural code that can perform complex and mission-critical tasks but no sense of identity. Accessing a TP monitors through RPC is like executing static methods; there is no such thing as a unique and distinct object. Also the business logic, which is procedural, is not as flexible, extensible, or reusable as business logic, which is object-oriented.&lt;/span&gt;  &lt;/p&gt; &lt;p align="left"&gt;&lt;b&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;Object Request Brokers (ORBs)&lt;/span&gt;&lt;/b&gt; &lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;Distributed objects allow unique objects that have state and identity to be distributed across a network so that they can be accessed by other systems. Distributed object computing technologies like CORBA and Java RMI grew out of RPC with one significant and necessary difference that the invoking method is on an object instance, not an application procedure. Distributed objects are usually deployed on some kind of ORB, which is responsible for helping client applications find distributed objects in a transparent manner. The down side for an ORB is as follows: ORBs do not define an operating system for distributed objects. That is, all the responsibility for concurrency, transactions, resource management and fault tolerance rests on the application developers. These services may be available from the ORB vendors or can be purchased from third party vendors and can be implemented in an ORB, but the developer has to write the glue code to incorporate them into the business objects.&lt;/span&gt;  &lt;/p&gt; &lt;p align="left"&gt;&lt;b&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;Component Transaction Monitor (CTM)&lt;/span&gt;&lt;/b&gt;  &lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;As the advantages of distributed objects became visible, the number of systems deployed using ORBs gets increased. But as indicated above, there happened to be a number of deficiencies on server side due to the poor server-side component model, which ORB architecture has been blessed with. The vital and relevant server-side services according to the ORB architecture specifications have been made to be explicitly accessed through APIs by the distributed object, resulting in more complexity. Also, the resource management strategies such as instance swapping, resource pooling, and activation may not be supported at all in this component model. These strategies are mainly responsible for distributed object systems to scale, improving performance and throughput and reducing latency. Without automatic support for resource management, application developers must implement home-grown resource management solutions, which requires a very sophisticated understanding of distributed object systems. Further on, ORBs fail to address the complexities of managing a component in a high-volume, mission-critical environment, an area where TP monitors have always excelled.&lt;/span&gt;  &lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;Having realized that combining these two revolutionary technologies will do wonders for enterprises, companies like IBM and BEA started to design a hybrid of ORBs and TP monitor systems, which is referred to as component transaction monitors (CTMs) or application servers. These types of application servers combine the flexibility and accessibility of distributed object systems based on ORBs with the robust operating system of a TP monitor. CTMs provide a comprehensive environment for server-side components by managing concurrency, transactions, object distribution, load balancing, security and resource management automatically.&lt;/span&gt;  &lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;CTMs have started to come out of several different industries including the relational database industry, the application server industry, the web server industry, the CORBA ORB industry, and the TP monitor industry. Each vendor offers products that reflect their particular area of expertise. But a CTM that supports the Enterprise JavaBeans standard server-side component model from Sun Microsystems seems to be a more elegant and productive choice. There are a number of reasons for this fine architectural decision. Sun Microsystems has framed a number of excellent standard server-side specifications for several technologies and made the Java implementation an open standard quite successfully. The Java Database Connectivity API (JDBC) was one of the shining examples.&lt;/span&gt;  &lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;Consequently, a critical mass of enterprise computing vendors - developers of application servers, transaction process monitors, object request brokers, database management systems, and others - are rolling out precise, robust and powerful implementations of the EJB technology specifications. Component-based, multi-tier applications are the future of enterprise computing. EJB is poised to realize the benefits of these components: portability, scalability to a wide range of enterprise servers, simplified development, deployment, and maintenance. With this brief background information on EJBs, let us enter a very brief discussion on EJB's robust architecture.&lt;/span&gt;  &lt;/p&gt; &lt;p align="left"&gt;&lt;b&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;Enterprise JavaBeans - An Introduction&lt;/span&gt;&lt;/b&gt;  &lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;Enterprise JavaBeans (EJB) is a comprehensive technology that provides the infrastructure for building enterprise-level server-side distributed Java components. The EJB technology provides a distributed component architecture that integrates several enterprise-level requirements such as distribution, transactions, security, messaging, persistence, and connectivity to mainframes and Enterprise Resource Planning (ERP) systems. When compared with other distributed component technologies such as Java RMI and CORBA, the EJB architecture hides most the underlying system-level semantics that are typical of distributed component applications, such as instance management, object pooling, multiple threading, and connection pooling. Secondly, unlike other component models, EJB technology provides us with different types of components for business logic, persistence, and enterprise messages.&lt;/span&gt; &lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;Thus, an Enterprise Java Bean is a remote object with semantics specified for creation, invocation and deletion. The EJB container is assigned the system-level tasks mentioned above. What a web container does for Java servlets and JSPs in a web server, the EJB container is for EJBs.&lt;/span&gt;  &lt;/p&gt; &lt;p align="left"&gt;&lt;b&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;EJB Architecture&lt;/span&gt;&lt;/b&gt;  &lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;Any distributed component technology should have the following requirements:&lt;/span&gt;  &lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;1. There should be a mechanism to create the client-side and server-side proxy objects. A client-side proxy represents the server-side object on the client-side. As far as the client is concerned, the client-side proxy is equivalent to the server-side object. On the other hand, the purpose of the server-side proxy is to provide the basic infrastructure to receive client requests and delegate these request to the actual implementation object&lt;/span&gt;  &lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;2. We need to obtain a reference to client-side proxy object. In order to communicate with the server-side object, the client needs to obtain a reference to the proxy.&lt;/span&gt;  &lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;3. There should be a way to inform the distributed component system that a specific component is no longer in use by the client.&lt;/span&gt;  &lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;In order to meet these requirements, the EJB architecture specifies two kinds of interfaces for each bean. They are home interface and remote interface. These interfaces specify the bean contract to the clients. However, a bean developer need not provide implementation for these interfaces. The home interface will contain methods to be used for creating remote objects. The remote interface should include business methods that a bean is able to serve to clients. One can consider using the home interface to specify a remote object capable of creating objects conforming to the remote interface. That is, a home interface is analogous to a factory of remote objects. These are regular Java interfaces extending the javax.ejb.EJBHome and javax.ejb.EJBObject interfaces respectively.&lt;/span&gt; &lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;As discussed below, the EJB architecture specifies three types of beans - session beans, entity beans, and message-driven beans. A bean developer has to specify the home and remote interfaces and also he has to implement one of these bean interfaces depending upon the type of the bean. For instance, for session beans, he has to implement the javax.ejb.SessionBean interface. The EJB architecture expects him to implement the methods specified in the bean interface and the methods specified in the home and remote interfaces. During the deployment time, he should specify the home and remote interfaces and bean implementation class to define a bean. The EJB container relies on specific method names and uses delegation for invoking methods on bean instances.&lt;/span&gt;  &lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;Thus regarding the first requirement, the EJB container generates the proxy objects for all beans. For the second one, the EJB container for each bean implement a proxy object to the home interface and publishes in the JNDI implementation of the J2EE platform. One can use JNDI to look for this and obtain a reference. As this object implements the home interface only, he can use one of the creation methods of the home object to get a proxy to the remote interface of the bean. When one invokes a creation method on the home proxy object, the container makes sure that a bean instance is created on the EJB container runtime and its proxy is returned to the client. Once the client gets hold of the proxy for the remote interface, it can directly access the services of the bean.&lt;/span&gt;  &lt;/p&gt; &lt;p align="left"&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;Finally, once the client decides to stop accessing the services of the bean, it can inform the EJB container by calling a remote method on the bean. This signals the EJB container to disassociate the bean instance from the proxy and that bean instance is ready to service any other clients.&lt;/span&gt;  &lt;/p&gt; &lt;p align="left"&gt;&lt;b&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;Types of EJBs&lt;/span&gt;&lt;/b&gt;  &lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;The EJB architecture is based on the concept that in an enterprise computing system, database persistence-related logic should be independent of the business logic that relies on the data. This happens to be a very useful technique for separating business logic concerns from database concerns. This makes that business logic can deal with the business data without worrying about how the data is stored in a relational database.&lt;/span&gt;  &lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;Enterprise JavaBeans server-side components come in two fundamentally different types: entity beans and session beans.&lt;/span&gt;  &lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;Basically entity beans model business concepts that can be expressed as nouns. For example, an entity bean might represent a customer, a piece of equipment, an item in inventory. Thus entity beans model real-world objects. These objects are usually persistent records in some kind of database.&lt;/span&gt;  &lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;Session beans are for managing processes or tasks. A session bean is mainly for coordinating particular kinds of activities. That is, session beans are plain remote objects meant for abstracting business logic. The activity that a session bean represents is fundamentally transient. A session bean does not represent anything in a database, but it can access the database.&lt;/span&gt; &lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;Thus an entity bean has persistent state whereas a session bean models interactions but does not have persistent state.&lt;/span&gt;  &lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;Session beans are transaction-aware. In a distributed component environment, managing transactions across several components mandates distributed transaction processing. The EJB architecture allows the container to manage transactions declaratively. This mechanism lets a bean developer to specify transactions across bean methods. Session beans are client-specific. That is, session bean instances on the server side are specific to the client that created them on the client side. This eliminates the need for the developer to deal with multiple threading and concurrency.&lt;/span&gt;  &lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;Unlike session beans, entity beans have a client-independent identity. This is because an entity bean encapsulates persistent data. The EJB architecture lets a developer to register a primary key class to encapsulate the minimal set of attributes required to represent the identity of an entity bean. Clients can use these primary key objects to accomplish the database operations, such as create, locate, or delete entity beans. Since entity beans represent persistent state, entity beans can be shared across different clients. Similar to session beans, entity beans are also transactional, except for the fact that bean instances are not allowed to programmatically control transactions.&lt;/span&gt;  &lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;These two types of beans are meant for synchronous invocation. That is, when a client invokes a method on one of the above types, the client thread will be blocked till the EJB container completes executing the method on the bean instance. Also these beans are unable to service the messages which comes asynchronously over a messaging service such as JMS. To overcome this deficiency, the EJB architecture has introduced a third type of bean called message-driven bean. A message-driven bean is a bean instance that can listen to messages from the JMS.&lt;/span&gt;  &lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;Unlike other types of beans, a message-driven bean is a local object without home and remote interfaces. In a J2EE platform, message-driven beans are registered against JMS destinations. When a JMS message receives a destination, the EJB container invokes the associated message-driven bean. Thus message-driven beans do not require home and remote interfaces as instances of these beans are created based on receipt of JMS messages. This is an asynchronous activity and does not involve clients directly. The main purpose of message-driven beans is to implement business logic in response to JMS messages. For instance, take a B2B e-commerce application receiving a purchase order via a JMS message as an XML document. On receipt of such a message in order to persist this data and perform any business logic, one can implement a message-driven bean and associate it with the corresponding JMS destination. Also these beans are completely decoupled from the clients that send messages.&lt;/span&gt;  &lt;/p&gt; &lt;p&gt;&lt;b&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;Session Beans: Stateful and Stateless&lt;/span&gt;&lt;/b&gt; &lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;Session beans can be either stateful or stateless. Stateful session beans maintain conversational state when used by a client. Conversational state is not written to a database but can store some state in private variables during one method call and a subsequent method call can rely on this state. Maintaining a conversational state allows a client to carry on a conversation with a bean. As each method on the bean is invoked, the state of the session bean may change and that change can affect subsequent method calls.&lt;/span&gt;  &lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;Stateless session beans do not maintain any conversational state. Each method is completely independent and uses only data passed in its parameters. One can specify whether a bean is stateful or not in the bean's deployment descriptor.&lt;/span&gt;  &lt;/p&gt; &lt;p&gt;&lt;b&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;Entity Beans: Container and Bean Managed Persistence&lt;/span&gt;&lt;/b&gt;  &lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;An example entity bean in a B2B application is given as follows. A purchase order is a business identity and requires persistence store such as a relational database. The various purchase order attributes can be defined as the attributes of an entity bean. Since database operations involve create, update, load, delete, and find operations, the EJB architecture requires entity beans to implement these operations. Entity beans should implement the javax.ejb.EntityBean interface that specifies the load and delete operations among others. In addition, the bean developer should specify the appropriate create and find methods on the home interface, and provide their implementation in an entity bean.&lt;/span&gt; &lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;There are two types of entity beans and they are distinguished by how they manage persistence. Container-managed beans have their persistence automatically managed by the EJB container. This is a more sophisticated approach and here the bean developer does not implement the persistence logic. The developer relies on the deployment descriptor to specify attributes whose persistence should be managed by the container. The container knows how a bean instance's fields map to the database and automatically takes care of inserting, updating, and deleting the data associated with entities in the database.&lt;/span&gt;  &lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;Beans using bean-managed persistence do all this work explicitly: the bean developer has to write the code to manipulate the database. The EJB container tells the bean instance when it is safe to insert, update, and delete its data from the database, but it provides no other help. The bean instance has to do the persistence work itself.&lt;/span&gt;  &lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;&lt;b&gt;EJB Container: &lt;/b&gt;The environment that surrounds the beans on the EJB server is often referred to as the container. The container acts as an intermediary between the bean class and the EJB server. The container manages the EJB objects and EJB homes for a particular type of bean and helps these constructs to manage bean resources and apply the primary services relevant to distributed systems to bean instances at run time. An EJB server can have more than one container and each container in turn can accommodate more than one enterprise bean.&lt;/span&gt;  &lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;&lt;b&gt;Remote Interface: &lt;/b&gt;This interface for an enterprise bean defines the enterprise bean's business methods that clients for this bean can access. The remote interface extends javax.ejb.EJBObject, which in turn extends java.rmi.Remote.&lt;/span&gt;  &lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;&lt;b&gt;Home interface: &lt;/b&gt;This interface defines the bean's life cycle methods such as creation of new beans, removal of beans, and locating beans. The home interface extends javax.ejb.EJBHome, which in turn extends java.rmi.Remote.&lt;/span&gt;  &lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;&lt;b&gt;Bean Class: &lt;/b&gt;This class has to implement the bean's business methods in the remote interface apart from some other callback methods. An entity bean must implement javax.ejb.EntityBean and a session bean must implement javax.ejb.SessionBean. Both EntityBean and Session Bean extend javax.ejb.EnterpriseBean.&lt;/span&gt;  &lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;&lt;b&gt;Primary Key: &lt;/b&gt;This is a very simple class that provides a reference into the database. This class has to implement java.io.Serializable. Only entity beans need a primary key.&lt;/span&gt; &lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;&lt;b&gt;Deployment Descriptors:&lt;/b&gt; Much of the information about how beans are managed at runtime is not supplied in the interfaces and classes mentioned above. There are some common primary services related with distributed systems apart from some specific services such as security, transactions, naming that are being handled automatically by EJB server. But still EJB server needs to know beforehand how to apply the primary services to each bean class at runtime. Deployment descriptors exactly do this all important task.&lt;/span&gt;  &lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;&lt;b&gt;JAR Files:&lt;/b&gt; Jar files are ZIP files that are used specifically for packaging Java classes that are ready to be used in some type of application. A Jar file containing one or more enterprise beans includes the bean classes, remote interfaces, home interfaces, and primary keys for each bean. It also contains one deployment descriptor.&lt;/span&gt;  &lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;Deployment is the process of reading the bean's JAR file, changing or adding properties to the deployment descriptor, mapping the bean to the database, defining access control in the security domain, and generating vendor-specific classes needed to support the bean in the EJB environment. Every EJB server product comes with its own deployment tools containing a graphical user interface and a set of command-line programs.&lt;/span&gt;  &lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;For clients like enterprise bean itself, Java RMI or CORBA client, to locate enterprise beans on the net, Java EJB specifications specify the clients to use Java Naming and Directory Interface (JNDI). JNDI is a standard Java extension that provides a uniform Application Programming Interface (API) for accessing a wide range of naming and directory services. The communication protocol may be Java RMI-IIOP or CORBA's IIOP&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(0, 0, 128);"&gt;There are some special integrated application development tools such as Inprise's JBuilder, Sun's Forte and IBM's VisualAge, for designing EJBs in the market.&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7397436882433825691-8920520311200690675?l=firecracks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://firecracks.blogspot.com/feeds/8920520311200690675/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7397436882433825691&amp;postID=8920520311200690675' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7397436882433825691/posts/default/8920520311200690675'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7397436882433825691/posts/default/8920520311200690675'/><link rel='alternate' type='text/html' href='http://firecracks.blogspot.com/2007/11/ejb.html' title='EJB'/><author><name>Biju</name><uri>http://www.blogger.com/profile/10765353064992372034</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
