Wednesday, December 7, 2011

Hibernate Cache Configuration

Hibernate Cache Configuration
  • Controlling the second-level cache - hibernate.cache.use_second_level_cache is used to enable/disable second-level cache globally by setting true/false.
  • Setting up a local cache provider - hibernate.cache.provider_class is used to define cache provider.  
          Hibernate supports the following open-source cache implementations:
                 EHCache (org.hibernate.cache.EhCacheProvider)
                 OSCache (org.hibernate.cache.OSCacheProvider)
                 SwarmCache (org.hibernate.cache.SwarmCacheProvider)
                 JBoss TreeCache (org.hibernate.cache.TreeCacheProvider)
  • Activating second-level caching classes in one of the following ways:
          1) Activate it on class-by-class basis in the *.hbm.xml file, using the cache attribute:
                 <hibernate-mapping package="com.javawhat.test">
                            <class name="State" table="STATE" dynamic-update="true">
                                       <cache usage="read-only"/>
                                       .................................................
                           </class>
                 </hibernate-mapping>

          2) Activate all cache classes in hibernate.cfg.xml file (recommended), using class-cache attribute:
                 <hibernate-configuration>
                            <session-factory>
                                       ..................................
                                       <property name="hibernate.cache.provider_class">
                                                   org.hibernate.cache.EHCacheProvider
                                       </property>
                                      .........................................
                                       <class-cache   class="com.javawhat.test.State" usage="read-only" />
                           </session-factory>
                </hibernate-configuration>
  • Configure cache provider using configuration file. Here is using EHCache as example:
               <ehcache>
                      <diskStore path="java.io.tmpdir"/>
                      <defaultCache maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="120"
                         timeToLiveSeconds="120" overflowToDisk="true" diskPersistent="false"
                         diskExpiryThreadIntervalSeconds="120" memoryStoreEvictionPolicy="LRU" />
                      <cache name="com.javawhat.test.State" maxElementsInMemory="55"
                         eternal="true" overflowToDisk="false" />
             </ehcache>

how you maintain session if your browser is not support session?

You need to append the jsessionid to all the URL's involved in your webapplication which are supposed to be invoked by the client. This includes the redirect URL's and the links in the JSP page.

In case of a redirect URL, you need to use HttpServletResponse#encodeRedirectURL() first:
             response.sendRedirect(response.encodeRedirectURL("page.jsp"));

In case of links in a JSP page, you basically need to pass those URL's through HttpServletResponse#encodeURL() first. You can do this with help of JSTL's (just drop jstl-1.2.jar in /WEB-INF) <c:url> tag, it will behind the scenes pass the URL through the aforementioned method:

             <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
             ..............................................
             <a href="<c:url value="page1.jsp" />">link1</a>
             <a href="<c:url value="page2.jsp" />">link2</a>
             ..............................................
             <form action="<c:url value="servlet" />" method="post">
             ..............................................
            </form>

Answer:

We know that session tracking uses cookies by default to associate a session identifier with a unique user. If the browser does not support cookies, or if cookies are disabled, you can still enable session tracking using URL rewriting.

URL rewriting essentially includes the session ID within the link itself as a name/value pair. However, for this to be effective, you need to append the session ID for each and every link that is part of your servlet response.

Adding the session ID to a link is greatly simplified by means of of a couple of methods: response.encodeURL() associates a session ID with a given URL, and if you are using redirection, response.encodeRedirectURL() can be used by giving the redirected URL as input.

Both encodeURL() and encodeRedirectedURL() first determine whether cookies are supported by the browser; if so, the input URL is returned unchanged since the session ID will be persisted as a cookie.

Consider the following example, in which two JSP files, say hello1.jsp and hello2.jsp, interact with each other. Basically, we create a new session within hello1.jsp and place an object within this session. The user can then traverse to hello2.jsp by clicking on the link present within the page.Within hello2.jsp, we simply extract the object that was earlier placed in the session and display its contents. Notice that we invoke the encodeURL() within hello1.jsp on the link used to invoke hello2.jsp; if cookies are disabled, the session ID is automatically appended to the URL, allowing hello2.jsp to still retrieve the session object.

Try this example first with cookies enabled. Then disable cookie support, restart the brower, and try again. Each time you should see the maintenance of the session across pages.

Do note that to get this example to work with cookies disabled at the browser, your JSP engine has to support URL rewriting.

hello1.jsp
           <%@ page session="true" %>
           <%
                      Integer num = new Integer(100);
                      session.putValue("num",num);
                      String url =response.encodeURL("hello2.jsp");
           %>
          <a href='<%=url%>'>hello2.jsp</a>

hello2.jsp
          <%@ page session="true" %>
         <%
                    Integer i= (Integer )session.getValue("num");
                    out.println("Num value in session is "+i.intValue());
         %>

Cookies

Using cookies is the simplest and most common way to track HTTP sessions, because it requires no special programming to track sessions. When session management is enabled and a client makes a request, the HttpSession object is created and a unique session ID is generated for the client and sent to the browser as a cookie. On subsequent requests to the same hostname, the browser continues to send the same session ID back as a cookie and the Session Manager uses the cookie to find the HttpSession associated with the client.

URL rewriting

There are situations in which cookies do not work. Some browsers do not support cookies. Other browsers allow the user to disable cookie support. In such cases, the Session Manager must resort to a second method, URL rewriting, to manage the user session.

With URL rewriting, links returned to the browser or redirect have the session ID appended to them. For example, the following link in a Web page:
             <a href="/store/catalog">
is rewritten as:
             <a href="store/catalog;jsessionid=DA32242SSGE2">

When the user clicks the link, the rewritten form of the URL is sent to the server as part of the client's request. The Web container recognizes ;jsessionid=DA32242SSGE2 as the session ID and saves it for obtaining the proper HttpSession object for this user.

Note: Do not make assumptions about the length or exact content of the ID that follows the equals sign (=). In fact, the IDs are often longer than what this example shows.

An application that uses URL rewriting to track sessions must adhere to certain programming guidelines. The application developer needs to:
          • Program session servlets to encode URLs
          • Supply a servlet or JSP file as an entry point to the application
          • Avoid using plain HTML files in the application

Program session servlets to encode URLs

Depending on whether the servlet is returning URLs to the browser or redirecting them, include either the encodeURL() or encodeRedirectURL() method in the servlet code. Here are examples demonstrating what to replace in your current servlet code.

Rewrite URLs to return to the browser

Suppose you currently have this statement:
           out.println("<a href=\"/store/catalog\">catalog<a>");

Change the servlet to call the encodeURL method before sending the URL to the output stream:
           out.println("<a href=\"");
           out.println(response.encodeURL ("/store/catalog"));
           out.println("\">catalog</a>");

Rewrite URLs to redirect

Suppose you currently have the following statement:
           response.sendRedirect (http://myhost/store/catalog);

Change the servlet to call the encodeRedirectURL method before sending the URL to the output stream:
           response.sendRedirect (response.encodeRedirectURL (http://myhost/store/catalog));


encodeURL() and encodeRedirectURL():
The encodeURL() and encodeRedirectURL() methods are part of the HttpServletResponse object. These calls check to see if URL rewriting is configured before encoding the URL. If it is not configured, they return the original URL.

If both cookies and URL rewriting are enabled and response.encodeURL() or encodeRedirectURL() is called, the URL is encoded, even if the browser making the HTTP request processed the session cookie.

You can also configure session support to enable protocol switch rewriting. When this option is enabled, the product encodes the URL with the session ID for switching between HTTP and HTTPS protocols.

Supply a servlet or JSP file as an entry point
The entry point to an application (such as the initial screen presented) may not require the use of sessions. However, if the application in general requires session support (meaning some part of it, such as a servlet, requires session support) then after a session is created, all URLs must be encoded in order to perpetuate the session ID for the servlet (or other application component) requiring the session support.

The following example shows how Java code can be embedded within a JSP file:
            <% response.encodeURL ("/store/catalog"); %>


Question: Difference between forward and sendRedirect?
Answer:
When you invoke a forward request, the request is sent to another resource on the server, without the client being informed that a different resource is going to process the request. This process occurs completely with in the web container.

When a sendRedirtect method is invoked, it causes the web container to return to the browser indicating that a new URL should be requested. Because the browser issues a completely new request any object that are stored as request attributes before the redirect occurs will be lost. This extra round trip a redirect is slower than forward.



 

Friday, December 2, 2011

Multiple Database Connection in Hibernate

Multiple Database Connection in Hibernate
=========================================

Introduction

Hibernate is designed to be used with a large set of databases. The details of those databases are configured in an XML file called hibernate.cfg.xml. This configuration files could be given any name and is usually placed in the root of your application class path. There are many configuration parameters available that makes the mapping of domain model to relational model easier. The same configurations can be done from your Java class uning org.hibernate.cfg.Configuration class. If you are beginner in Hibernate, please read our article on Introduction to Hibernate ORM Framework.

Sample Application

             

The sample we discuss here shows how an Employee object can be configured to store in both Oracle Data base and Derby Database. Here we create a POJO class called Employee and store and retrieve its objects from both Oracle and Derby database.

Software Requirements

For this example I have used the following tools.
         NetBeans IDE ( may use Eclipse also)
         Hibernate 3.0
         Oracle 9i , Derby
         Sample Project Structure
         Employee.java

Employee .java
package hibernatepack.samples;
public class Employee {
        private int empid;
        private String empname;
        private double salary;

        public int getEmpid() {
                   return empid;
        }

        public void setEmpid(int empid) {
                   this.empid = empid;
        }

        public String getEmpname() {
                   return empname;
        }

        public void setEmpname(String empname) {
                   this.empname = empname;
        }

        public double getSalary() {
                   return salary;
        }

        public void setSalary(double salary) {
                   this.salary = salary;
        }
}


The mapping details of the Employee class are available in the Employee.hbm.xml file:

 Employee.hbm.xml 
        <?xml version="1.0" encoding="UTF-8"?>
        <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
                 "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
        <hibernate-mapping>
                <class name="hibernatepack.samples.Employee" table="HBEmployeeDetails" >
                         <id name= "empid" column="EmpNo" />
                         <property name= "empname" column = "EmpName" />
                         <property name="salary" column="Salary" />
                </class>
        </hibernate-mapping>


Since we need to persist the Employee object both in Oracle and in Derby, we need to create 2 configuration files - one for Oracle, another one for Derby.


oracleconfig.cfg.xml
        <?xml version="1.0" encoding="UTF-8"?>
        <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
                 "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
        <hibernate-configuration>
                   <session-factory>
                              <property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
                              <property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property>
                              <property name="hibernate.connection.url">
                                       jdbc:oracle:thin:@10.154.117.76:1521:oracle
                              </property>
                              <property name="hibernate.connection.username">user</property>
                              <property name="hibernate.connection.password">password</property>
                              <property name="hibernate.hbm2ddl.auto">create</property>
                              <property name="hibernate.show_sql">true</property>
                              <mapping resource="Employee.hbm.xml" />
                   </session-factory>
        </hibernate-configuration>

derbiconfig.cfg.xml
        <?xml version="1.0" encoding="UTF-8"?>
        <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
                 "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
        <hibernate-configuration>
                    <session-factory>
                               <property name="hibernate.dialect">org.hibernate.dialect.DerbyDialect</property>
                               <property name="hibernate.connection.driver_class">
                                               org.apache.derby.jdbc.ClientDriver
                               </property>
                               <property name="hibernate.connection.url">jdbc:derby://localhost:1527/HibernateDB</property>
                               <property name="hibernate.connection.username">user</property>
                               <property name="hibernate.connection.password">pwd</property>
                               <property name="hibernate.show_sql">true</property>
                               <property name="hibernate.hbm2ddl.auto">create</property>
                               <mapping resource="Employee.hbm.xml"/>
                     </session-factory>
        </hibernate-configuration>

The IEmployeeDAO.java lists the operations on the Employee object.

IEmployeeDAO.java
package hibernatepack.samples;
import java.util.List;
public interface IEmployeeDAO {
           public void findAllEmployees();
           public void insertEmployee(Employee e);
}

Let us Implement the above interface using a class :
EmloyeeDaoImpl.java
public class EmployeeDaoImpl implements IEmployeeDAO {
           SessionFactory sessionFactory1 = new Configuration().configure("oracleconfig.cfg.xml").buildSessionFactory();
           SessionFactory sessionFactory2 = new Configuration().configure("derbyconfig.cfg.xml").buildSessionFactory();

           Session session = null;
           Transaction transaction = null;

           public void findAllEmployees() {
                      ArrayList empList = new ArrayList();
                      try {
                              session = sessionFactory1.openSession();
                              transaction = session.beginTransaction();
                              transaction.begin();
                              Criteria crit = session.createCriteria(Employee.class);
                              empList = (ArrayList) crit.list();
                              System.out.println("Records from Oracle Database");
                              for (Employee emp : empList) {
                                          System.out.println(emp.getEmpid() + " " + emp.getEmpname() + " " + emp.getSalary());
                              }
                              session.close();

                              session = sessionFactory2.openSession();
                              Criteria crit1 = session.createCriteria(Employee.class);
                              empList = (ArrayList) crit1.list();
                              System.out.println("Records from Derby Database");
                              for (Employee emp : empList) {
                                          System.out.println(emp.getEmpid() + " " + emp.getEmpname() + " " + emp.getSalary());
                              }

                              session.close();

                      } catch (Exception he) {
                                  he.printStackTrace();
                      }
           }

           public void insertEmployee(Employee e) {
                      try {
                              session = sessionFactory1.openSession();
                              transaction = session.beginTransaction();
                              transaction.begin();
                              session.save(e);
                              transaction.commit();
                              session.close();
                      
                              session = sessionFactory2.openSession();
                              transaction = session.beginTransaction();
                              transaction.begin();
                              session.save(e);
                              transaction.commit();
                              session.close();

                       } catch (HibernateException he) {
                                   he.printStackTrace();
                       }
            }
}

Creating Session Factory object in Hibernate

Each database has its own SessionFactory object.
                 SessionFactory sessionFactory1 =
                             new Configuration().configure("oracleconfig.cfg.xml").buildSessionFactory();
                 SessionFactory sessionFactory2 =
                             new Configuration().configure("derbyconfig.cfg.xml").buildSessionFactory();


Specify the name of the configuration file as an argument to the configure() method when building the session factory object. Let us create the test application.

EmployeeTest.java
package hibernatepack.samples;
import java.awt.Choice;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class EmployeeTest {
            private static int choice; public static void main(String[] args) {
                        EmployeeDaoImpl empOperations = new EmployeeDaoImpl();
                        Employee e1 = new Employee();

                        do {
                                System.out.println("1. Insert ");
                                System.out.println("2. List ");
                                System.out.println("3. Exit ");
                                System.out.println("Enter your choice ");
                                Scanner sc = new Scanner(System.in);
                               
                                choice = sc.nextInt();
                                switch (choice) {
                                            case 1:
                                                        System.out.println("Enter the employee Number ");
                                                        Scanner sc1 = new Scanner(System.in);

                                                        int empid = sc1.nextInt();
                                                        System.out.println("Enter the employee Name ");

                                                        Scanner sc2 = new Scanner(System.in);
                                                        String empname = sc2.nextLine();
                                                        System.out.println("Enter the Salary ");
                                                        Scanner sc3 = new Scanner(System.in);

                                                        double empsal = sc3.nextDouble();
                                                        e1.setEmpid(empid);
                                                        e1.setEmpname(empname);
                                                        e1.setSalary(empsal);
                                                        empOperations.insertEmployee(e1);
                                                        break;
                                            case 2:
                                                        empOperations.findAllEmployees();
                                                        break;
                                 }
                         } while (choice != 3);
             }
}


When you execute the insert method, table named “HBEMPLOYEEDETAILS” is created both in Oracle and in Derby. Find below the sample output screen.

                 

              

                


Conclusion

This is very simple example on how to configure the multiple databases using Hibernate configuration files. In the next weeks I will be writing few more examples on configuring the databases and fetching the data. In the following section you can find the interesting articles related to Hibernate framework.


Multiple Database Connection in Hibernate with Spring

figured this one out on my own. Basically, you need an applicationContext.xml for each Hibernate connection you're going to make. Here are fragments of mine applicationContext.xml

applicationContext.xml
         <beans>
                   <bean id="hibernateSession"      
                      class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
                              <property name="configLocation">   
                                          <value>file:src/hibernate.cfg.xml</value>
                              </property>
                  </bean>
                  <bean id="persistenceLayer" class="com.monitor.hibernatespring.PersistenceLayer"
                     abstract="false" singleton="true" lazy-init="default" autowire="default"
                     dependency-check="default">
                              <property name="monitorScheduleDAO">
                                          <ref bean="MonitorScheduleDAO" />
                             </property>
                 </bean>
                 <bean id="MonitorScheduleDAO"
                    class="com.monitor.hibernatespring.MonitorScheduleDAO">
                             <property name="sessionFactory">
                                          <ref bean="hibernateSession" />
                             </property>
                 </bean>
         </beans>

horseContext.xml
         <?xml version="1.0" encoding="UTF-8"?>
         <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
               "http://www.springframework.org/dtd/spring-beans.dtd">
         <beans>
                     <bean id="hibernateSession"
                            class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
                                  <property name="configLocation">
                                              <value>file:src/horse.cfg.xml</value>
                                  </property>
                     </bean>
                    <bean id="horseLayer" class="com.monitor.hibernatespring.HorseLayer"
                           abstract="false" singleton="true" lazy-init="default" autowire="default"
                           dependency-check="default">
                                  <property name="chartEntryDAO">
                                              <ref bean="ChartEntryDAO" />
                                  </property>
                    </bean>
                    <bean id="ChartEntryDAO"
                           class="com.monitor.hibernatespring.ChartEntryDAO">
                                  <property name="sessionFactory">
                                              <ref bean="hibernateSession" />
                                  </property>
                    </bean>
         </beans>

hibernate.cfg.xml
         <?xml version='1.0' encoding='UTF-8'?>
         <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
               "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
         <!-- Generated by MyEclipse Hibernate Tools. -->
         <hibernate-configuration>
                    <session-factory>
                               <property name="connection.username"> netgohur_root</property>
                               <property name="connection.url">jdbc:mysql://localhost:3306/monitor_test</property>
                               <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
                               <property name="myeclipse.connection.profile">MONITOR_CHASSIS</property>
                               <property name="connection.password">mysql9tdf</property>
                               <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
                               <mapping resource="com/monitor/hibernatespring/MonitorSchedule.hbm.xml" />
                   </session-factory>
         </hibernate-configuration>

horse.cfg.xml
         <?xml version='1.0' encoding='UTF-8'?>
         <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
               "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
         <!-- Generated by MyEclipse Hibernate Tools. -->
         <hibernate-configuration>
                     <session-factory>
                                <property name="connection.username">netgohur_root</property>
                                <property name="connection.url">jdbc:mysql://localhost:3306/chart_entry</property>
                                <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
                                <property name="myeclipse.connection.profile">horse_race</property>
                                <property name="connection.password">mysql9tdf</property>
                                <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
                                <mapping resource="com/monitor/hibernatespring/MonitorSchedule.hbm.xml" />
                    </session-factory>
         </hibernate-configuration>


In my main class ...
                // Load the Spring 2 bean configuration and create a bean factory
               beanFactory = new XmlBeanFactory(new ClassPathResource("applicationContext.xml"));

               // Load the Spring 2 bean configuration and create a bean factory
               horseFactory = new XmlBeanFactory(new ClassPathResource("horseContext.xml"));

              // Create instance of PersistenceLayer (Spring 2)
              PersistenceLayer persistenceLayer = (PersistenceLayer) beanFactory.getBean("persistenceLayer");

             // Create instance of HorseLayer (Spring 2)
             HorseLayer horseLayer = (HorseLayer) horseFactory.getBean("horseLayer");

I guess my point is, when you right-click on
            <project> - >MyEclipse->

Add Hibernate Capability, you're only getting the possibility of connecting to a single JDBC database generated. It seems there might be some way to add the capability "Add an additional Hibernate connection."

           <?xml version="1.0"?>
           <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" 
                  "http://www.springframework.org/dtd/spring-beans.dtd">
           <beans>
                       <bean id="propertyConfigurer"
                                   class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
                                  <property name="location">
                                             <value>junit.properties</value>
                                  </property>
                      </bean>
                      <bean name="smsdDataSource" class="org.apache.commons.dbcp.BasicDataSource">
                                  <property name="driverClassName" value="${oracle.database.driver}"/>
                                  <property name="url" value="${oracle.smsd.database.url}" />
                                  <property name="username" value="${oracle.smsd.database.username}" />
                                  <property name="password" value="${oracle.smsd.database.password}" />
                      </bean>
                      <bean name="sm10DataSource" class="org.apache.commons.dbcp.BasicDataSource">
                                  <property name="driverClassName" value="${oracle.database.driver}"/>
                                  <property name="url" value="${oracle.sm10.database.url}" />
                                  <property name="username" value="${oracle.sm10.database.username}" />
                                  <property name="password" value="${oracle.sm10.database.password}" />
                      </bean>
                      <bean name="dtiDataSource"
                                  class="org.apache.commons.dbcp.BasicDataSource">
                                  <property name="driverClassName" value="${sybase.database.driver}"/>
                                  <property name="url" value="${sybase.dti.database.url}" />
                                  <property name="username" value="${sybase.dti.database.username}" />
                                  <property name="password" value="${sybase.dti.database.password}" />
                      </bean>
                      <bean id="dtiDatabaseSessionFactory"
                                  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
                                  <property name="mappingDirectoryLocations">
                                              <list>
                                                         <value>classpath:/com/sm/hibernatemaps/dti</value>
                                              </list>
                                 </property>
                                 <property name="hibernateProperties">
                                              <props>
                                                         <prop key="hibernate.dialect">${sybase.database.hibernate.dialect}</prop>
                                                         <prop key="hibernate.show_sql">${database.hibernate.showsql}</prop>
                                              </props>
                                </property>
                                <property name="dataSource" ref="dtiDataSource"/>
                      </bean>
                      <bean id="dtiTransactionManager"
                                class="org.springframework.orm.hibernate3.HibernateTransactionManager">
                                <property name="sessionFactory">
                                              <ref bean="dtiDatabaseSessionFactory" />
                                </property>
                      </bean>
                      <bean id="acctTypesManagerService" class="com.sm.dti.accttypes.AcctTypesManagerImpl">
                                <property name="sessionFactory">
                                              <ref bean="dtiDatabaseSessionFactory"/>
                                </property>
                      </bean>
           </beans>


Clieck here to download in docx format


Hibernate Articles

Interceptors in Hibernate
Integrating Spring Framework with Hibernate
Introduction to Hibernate Caching
Book Hibernate in Action



 

Ant build XML file

Ant build XML file ---------------------
<?xml version="1.0" encoding="UTF-8"?>
<project name="ApplicationService Build File" default="install">
<description>Builds Activation</description>

<!-- Project directories -->
<property name="root" value="E://Dev/CLP_4_0_0/4.0.0/AAServer/Samples/JAVA/ApplicationService"/>
<property file="${root}/build.properties"/>
<property name="temp.lib" value="${root}/lib"/>
<property name="axis.lib" value="${war.axis.lib}"/>
<property name="src" value="${root}/src"/>
<property name="classes" value="${root}/classes"/>
<property name="axis2.classes" value="${war.axis2.classes}"/>
<property name="war.proj.home" value="${war.file.home}/webapps" />
<property name="war.proj.loc1" value="${war.file.loc1}" />
<property name="war.proj.loc2" value="${war.file.loc2}" />
<property name="war.proj.loc3" value="${war.file.loc3}" />
<property name="war.proj.loc4" value="${war.file.loc4}" />
<property name="war.proj.TestServer" value="${war.file.TestServer}" />

<!-- project-specific variables -->
<!--Time stam added for war file creation
<tstamp />
<property name="webapp.name" value="ApplicationService-${DSTAMP}-${TSTAMP}" />-->
<property name="webapp.name" value="ApplicationService" />
<property name="package.name" value="${webapp.name}.war" />
<property name="dest.dir" value="target" />
<property name="package.file" value="${dest.dir}/${package.name}" />

<!-- put everything in a temp folder with the right structure during the build -->
<property name="temp.dir" value="temp" />
<property name="temp.dir.web-inf" value="${temp.dir}/WEB-INF" />
<property name="temp.dir.lib" value="${temp.dir.web-inf}/lib" />
<property name="temp.dir.classes" value="${temp.dir.web-inf}/classes" />
<property name="temp.dir.modules" value="${temp.dir.web-inf}/modules" />
<property name="temp.dir.meta-inf" value="${temp.dir}/META-INF" />
<property name="temp.dir.classes.axis2" value="${temp.dir.web-inf}/classes/org/apache/axis2/webapp" />
<property name="webroot" value="${root}/WebContent" />
<property name="jsp.dir" value="${webroot}" />

<!-- Classpath -->
<path id="classpath.build">
<fileset dir="${temp.lib}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${axis.lib}">
<include name="**/*.jar"/>
</fileset>

</path>


<target name="create_web_service_stubs"
description="Compiles all test files.">

<java classname="org.apache.axis.wsdl.WSDL2Java"
fork="true"
dir="${src}">
<classpath refid="classpath.build" />
<arg line=" -f ../NStoPkg.properties -w ../schema-public/UserOrgHierarchyService.wsdl"/>
</java>
</target>

<target name="clean">
<delete>
<fileset dir="${dest.dir}" includes="**/*"/>
</delete>
<delete dir="${temp.dir}" />
<delete dir="${temp.dir.classes}" />
<delete dir="${temp.dir.modules}" />
<delete dir="${temp.dir.meta-inf}" />
<delete dir="${temp.dir.web-inf}" />
<delete dir="${temp.dir.classes.axis2}" />

</target>

<target name="prepare" depends="clean">
<mkdir dir="${dest.dir}" />
<mkdir dir="${temp.dir}" />
<mkdir dir="${temp.dir.lib}" />
<mkdir dir="${temp.dir.meta-inf}" />
<mkdir dir="${temp.dir.web-inf}" />
<mkdir dir="${temp.dir.classes}" />
<mkdir dir="${temp.dir.modules}" />
<mkdir dir="${temp.dir.classes.axis2}" />
</target>

<!-- COMPILE -->
<target name="compile" depends="prepare">
<echo>=== COMPILING SOURCE ===</echo>
<echo>Compiling ${src} files ...</echo>
<javac debug="on" srcdir="${src}" destdir="${temp.dir.classes}" includes="**/*">
<classpath refid="classpath.build" />
</javac>
</target>

<!-- PACKAGE -->
<target name="package" depends="compile">
<echo>=== CREATING ARCHIVE ===</echo>

<!-- copy the config files -->
<copy file="${webroot}/META-INF/MANIFEST.MF" tofile="${temp.dir.meta-inf}/MANIFEST.MF" overwrite="true" />
<copy file="ErrorDictionary.properties" tofile="${temp.dir.classes}/ErrorDictionary.properties" overwrite="true" />

<copy todir="${temp.dir.web-inf}" overwrite="true">
<fileset dir="${webroot}/WEB-INF">
<include name="**/*.xml"/>
<include name="**/*.tld"/>
<include name="**/*.list"/>
<include name="**/*.aar"/>
<include name="**/*.class"/>
<include name="**/*.wsdl"/>
</fileset>
</copy>

<copy todir="${temp.dir.classes}" overwrite="true">
<fileset dir="${src}">
<include name="**/*.properties"/>
<include name="**/*.xml"/>
<include name="**/*.dtd"/>
</fileset>
</copy>

<copy todir="${temp.dir.classes.axis2}" overwrite="true">
<fileset dir="${axis2.classes}">
<include name="**/*.class"/>
</fileset>
</copy>

<copy todir="${temp.dir.modules}" overwrite="true">
<fileset dir="${webroot}/WEB-INF/modules">
<include name="**/*.mar"/>
</fileset>
</copy>

<echo>=== CREATING war ===</echo>
<!-- with all resources in place, create the war file -->
<war destfile="${package.file}" webxml="${temp.dir.web-inf}/web.xml" basedir="${temp.dir}">
<fileset dir="${jsp.dir}">
<include name="**/*.jsp"/>
<include name="**/*.inc"/>
<include name="**/*.css"/>
<include name="**/*.html"/>
<include name="**/*.gif"/>
<include name="**/*.jpg"/>
<include name="**/*.jar"/>
<include name="**/*.txt"/>
</fileset>
<lib dir="${temp.lib}" />
<classes dir="${temp.dir.classes}" />
</war>
<echo>=== complete ARCHIVE ===</echo>
</target>



<!-- INSTALL -->
<target name="install" depends="package">
<!--
<echo>=== STOPPING SERVER ===</echo>
<java jar="${tomcat.home}/bin/bootstrap.jar" fork="true">
<jvmarg value="-Dcatalina.home=${tomcat.home}"/>
<arg line="stop"/>
</java>
<sleep seconds="2"/>

<echo>=== DELETING APP ===</echo>
<delete dir="${war.proj.home}/${webapp.name}" />-->

<echo>=== COPYING ARCHIVE ===</echo>
<tstamp>
<format property="Time_Stamp" pattern="ddMMyyyyHHmmss"/>
</tstamp>
<copy file="${package.file}" tofile="${war.proj.loc2}/${Time_Stamp}/${package.name}" overwrite="true" />
<!--<copy file="${package.file}" tofile="${war.proj.loc2}/${Time_Stamp}/${package.name}" overwrite="true" />
<copy file="${package.file}" tofile="${war.proj.loc3}/${Time_Stamp}/${package.name}" overwrite="true" />
<copy file="${package.file}" tofile="${war.proj.loc4}/${Time_Stamp}/${package.name}" overwrite="true" />
<copy file="${package.file}" tofile="${war.proj.TestServer}/${Time_Stamp}/${package.name}" overwrite="true" />-->
</target>
<!--<echo>=== DELETING APP FROM TOMCAT===</echo>
<delete dir="${tomcat.home}/wtpwebapps/${webapp.name}" />
<echo>=== COPYING ARCHIVE IN TOMCAT===</echo>
<copy file="${package.file}" tofile="${tomcat.home}/wtpwebapps/${package.name}" overwrite="true" />
<echo>=== START TOMCAT SERVER ===</echo>
<java jar="${tomcat.home}/bin/bootstrap.jar" fork="true">
<jvmarg value="-Dcatalina.home=${tomcat.home}"/>
</java>

<tstamp>
<format property="Time_Stamp" pattern="yyyyMMddHHmmss"/>
</tstamp>
<copy file="${package.file}" tofile="${test.retomte.path}/${Time_Stamp}/${package.name}" overwrite="true" />-->

<delete dir="${temp.dir}" />
</project>


build.properties---------------------
#tomcat.home=C\:/Program Files/Apache Software Foundation/Tomcat 6.0

tomcat.home=C\:/apache-tomcat-6.0.29
war.file.home=E\:/Dev/CLP_4_0_0/4.0.0/AAServer/Samples/JAVA/ApplicationService/conf_build
war.axis.lib=E\:/axis2-1.5.1/lib
war.axis2.classes=E:/axis2-1.5.1/webapp/WEB-INF/classes/org/apache/axis2/webapp
war.file.loc1=//10.25.22.116/e$/WarFileLoc/ApplicationService
war.file.loc2=//10.25.22.117/e$/WarFileLoc/ApplicationService
war.file.loc3=//10.25.22.118/e$/WarFileLoc/ApplicationService
war.file.loc4=//10.25.22.119/e$/WarFileLoc/ApplicationService
war.file.TestServer=//10.25.57.140/e$/TestDeployer/ApplicationService
test.retomte.path=//10.25.17.153/SLAA_Build
#tomcat.home=C\:/apache-tomcat-6.0.29/webapps

Benche Thakar Gan

Benche Thakar Gan -> Rupam Ishlam -> Autograph (Bengali)
=================================================
Jodi kede nite bole, kobita thasa khata, jeno kadte debo na
Jodi phele jete bole, shahure kato katha, jeno ami phelte debo na
Ami ami jani jani, chora bali kato khani, kede nite chai amader roj
Ami ami jani jani, prati rate hoirani, kato harano swapnor khonj

Ar oi narom balise, tomar oi chokher nalise,
benche thak raat porider snann, mukhe niye benche thakar gan
Ar oi tomar mukher chadore, porichito hater aadore,
sukhe thak raat porider snann, mukhe niye banchiye rakhar gan

Jodi harai nimese, jibane paripati, jeno ami harate debo na
Jodi beche dite bole, sekade bandha mati, jeno ami bechte debona
Ami ami jani jani, chora bali kato khani, kede nite chai amader roj
Ami ami jani jani, prati rate hoirani, kato harano swapnor khonj

Ar oi narom balise, tomar oi chokher nalise,
benche thak raat porider snann, mukhe niye benche thakar gan
Ar oi tomar mukher chadore, porichito hater aadore,
sukhe thak raat porider snann, mukhe niye banchiye rakhar gan


Benche Thakar Gan -> Rupam Ishlam -> Autograph (Translated)
=================================================
If want to snatch, that poetry note book, don’t allow to snatch
If want to molest, city life straggle and pain, I won’t allow to molest
I know I know, how slavering sand, want to snatch our penny
I know I know, every harassing those nights, search for faded dreams

And with soft pillow, with complain in your eyes
Lets’ alive night birds, with living hope and song
And in your face cover, with those loving touch
Lets’ be happy night birds, with living hope and song

If miss immediately, everything your life, I won’t allow to miss
If told to sell, feeling love of life, I don’t allow to sale
I know I know, how slavering sand, want to snatch our penny
I know I know, every harassing those nights, search for faded dreams

And with soft pillow, with complain in your eyes
Lets’ alive night birds, with living hope and song
And in your face cover, with those loving touch
Lets’ be happy night birds, with living hope and song

Java Mail Send Code

This summary is not available. Please click here to view the post.