How to create your own custom annotations in java and how to use it..PART-II

Hi in my previous post i have explained how to approach and understand over custom annotations using java, taking the support of meta annotations already given by java. Now i explain you how to code your own annotations. In my example i would like to explain how to inject object based on annotation.

Now i write a custom annotation “@AutoInject”, this annotation should be annotated on methods which will inject the object of particular class type as shown below

private EmployeeDTO employeeDTO;

public EmployeeDTO getEmployeeDTO() {
return employeeDTO;
}

@AutoInject
public void setEmployeeDTO(EmployeeDTO employeeDTO) {
this.employeeDTO = employeeDTO;
}

Now this code to get executed first we need to design our annotation i.e. @AutoInject as shown below:

/**
*
*/
package com.spark.custom.annotations;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* @author Mantha Pavan Kumar
* injects the object to a getter method
*/
@Documented
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface AutoInject {

}

Now to process the annotation we have to write a class which will actually give the annotation behavior as below.

/**
*
*/
package com.spark.custom.annotations;

import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.io.File;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

/**
* @author Mantha Pavan Kumar
*
*/
public class GenericAnnotations {
/**
* @param obj
* @return
*/
public static <T> T injectDependencies(final T obj) {
try {
Class clazz = obj.getClass();
BeanInfo beanInfo = Introspector.getBeanInfo(clazz);

for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
Method writeMethod = pd.getWriteMethod();

if (writeMethod == null) {
continue;
}

Object existingVal = pd.getReadMethod().invoke(obj);
if (existingVal == null) {
for (Annotation annotation : writeMethod.getAnnotations()) {
if (annotation instanceof AutoInject) {
Class propertyType = pd.getPropertyType();
writeMethod.invoke(obj, propertyType.newInstance());
}
}
}
}
} catch (Exception e) {
// do something intelligent :)
}
return obj;
}

}

in this way you can code your own functional behavior of annotations, Happy Coding 🙂 please find the below file for the entire code.
CustomAnnotations

Advertisements

creating a installer using IzPack..Great Tool

please find the below files to use them directly.

shortcutSpec_xml install_xml

Hi, I am here to describe about Izpack, in past to create installers for my java apps i went with a licensed version of Advanced installer, still that is a complex tool to create installers.IzPack is a open source tool which is smooth than Advanced installer below are the Features of the tool.

Features and Drawbacks of Using IzPack
Because of the following reasons I chose IzPack to create the installer for my application, from all other free and open source installer software. The reasons which helped me to make my decision are as follows,

IzPack is Open Source
It has attractive GUI
Great Customizability
It is a Cross-Platform Installer
Automatic Uninstaller Creation

The drawback of using IzPack is, it doesn’t contain enough documentation or working examples for a beginner to use it and get the job done easily. Science it has less documentation and Samples i am here to share my experience to guide you all.

How IzPack Installer Operates
All what we have to do to make the installer is write an xml file stating all the necessary configuration information and compile it using the compiler provided by the IzPack. Then according to our xml, an installer file named install.jar will be created by the IzPack. It will wrap all the files and folder structure from the end user.

creating your install.xml file:

<?xml version="1.0" encoding="iso-8859-1" standalone="yes" ?>
<!--
Install.xml of Project [AppName] using IzPack Installer
-->
<installation version="1.0">

<info>
<appname>[AppName]</appname>
<appversion>1.0</appversion>
<authors>
<author name="Mr. M K Pavan Kumar" email=""/>
</authors>
<javaversion>1.6</javaversion>
<requiresjdk>no</requiresjdk>
<url>http://www.[AppName].com</url>
<uninstaller name="uninstall.jar" path="${INSTALL_PATH}/uninstaller" write="yes"/>
<summarylogfilepath>$INSTALL_PATH/InstallationSummary.htm</summarylogfilepath>
<writeinstallationinformation>yes</writeinstallationinformation>
</info>

<guiprefs width="600" height="480" resizable="no">
<modifier key="layoutAnchor" value="CENTER"/>
<modifier key="useHeadingPanel" value="yes"/>
<modifier key="useHeadingForSummary" value="yes"/>
<modifier key="headingImageOnLeft" value="yes"/>
<modifier key="headingLineCount" value="2"/>
<modifier key="headingFontSize" value="1.5"/>
<modifier key="headingBackgroundColor" value="0x00ffffff"/>
<modifier key="headingPanelCounter" value="text"/>
<modifier key="headingPanelCounterPos" value="inHeading"/>
</guiprefs>

<variables>
<variable name="DesktopShortcutCheckboxEnabled" value="true"/>
<variable name="ApplicationShortcutPath" value="ApplicationShortcuts"/>
</variables>

<locale>
<langpack iso3="eng"/>
</locale>

<resources>
<res src="shortcutSpec.xml" id="shortcutSpec.xml"/>
<res id="HTMLInfoPanel.readme" src="Readme.html"/>
<res id="HTMLLicencePanel.licence" src="Licence.html"/>
<res id="Heading.image" src="images/heading-image.jpg"/>
<res id="Installer.image" src="images/side-image.jpg" />
</resources>

<panels>
<panel classname="HelloPanel"/>
<panel classname="HTMLInfoPanel" id="readme"/>
<panel classname="HTMLLicencePanel" id="licence"/>
<panel classname="TargetPanel"/>
<panel classname="TreePacksPanel"/>
<panel classname="SummaryPanel"/>
<panel classname="InstallPanel"/>
<panel classname="ShortcutPanel"/>
<panel classname="FinishPanel"/>
</panels>

<packs>
<pack name="core" required="yes">
<description>This will include the necessary processing of SwiftUI framework and other core files used in the SwiftUI.</description>
<file src="Readme.html" targetdir="$INSTALL_PATH"/>
<file src="Licence.html" targetdir="$INSTALL_PATH"/>
<fileset dir="images" targetdir="$INSTALL_PATH\images">
<include name="**"/>
</fileset>
<file src="apache-tomcat-7.0.16.zip" targetdir="$INSTALL_PATH\core" unpack="true"/>
<executable targetfile="$INSTALL_PATH/core/apache-tomcat-7.0.16/bin/startup.bat" stage="never" />
<executable targetfile="$INSTALL_PATH/core/apache-tomcat-7.0.16/bin/shutdown.bat" stage="never" />
</pack>

<pack name="Documentation" required="no">
<description>This is official [AppName] documentation.</description>
<fileset dir="doc" targetdir="$INSTALL_PATH\doc">
<include name="**"/>
</fileset>
</pack>

</packs>

<listeners>
<listener installer="SummaryLoggerInstallerListener">
<os family="windows"/>
</listener>
</listeners>

<native type="izpack" name="ShellLink.dll"/>
<native type="izpack" name="ShellLink_x64.dll"/>
<native type="3rdparty" name="COIOSHelper.dll" stage="both">
<os family="windows"/>
</native>

</installation>

creating shortcutsSpec.xml file:

<?xml version="1.0" encoding="iso-8859-1" standalone="yes" ?>

<!--
shortcutSpec.xml of Project Jefe using IzPack Installer to create windows shortcuts
-->

<shortcuts>

<skipIfNotSupported/>

<programGroup defaultName="[AppName]" location="applications"/>

<shortcut
name="[AppName] - Startup"
programGroup="yes"
desktop="yes"
applications="no"
startMenu="yes"
startup="no"
target="$INSTALL_PATH\core\apache-tomcat-7.0.16\bin\startup.bat"
commandLine=""
description="[AppName] tomcat Server Startup"
iconFile="$INSTALL_PATH\images\startup.jpeg"
iconIndex="0"
initialState="noShow">

<createForPack name="core"/>

</shortcut>

<shortcut
name="[AppName] - Shutdown"
programGroup="yes"
desktop="no"
applications="no"
startMenu="no"
startup="no"
target="$INSTALL_PATH\core\apache-tomcat-7.0.16\bin\shutdown.bat"
commandLine=""
iconFile="$INSTALL_PATH\images\shutdown.jpeg"
iconIndex="0"
description="Shutdown [AppName] tomcat Server">

<createForPack name="core"/>
</shortcut>

<shortcut
name="[AppName] - Uninstaller"
programGroup="yes"
desktop="no"
applications="no"
startMenu="no"
startup="no"
target="$INSTALL_PATH\uninstaller\uninstall.jar"
commandLine=""
iconFile="$INSTALL_PATH\images\uninstall.jpeg"
iconIndex="31"
description="[AppName] Uninstaller">

<createForPack name="core"/>
</shortcut>

</shortcuts>

Finally,
Go to the IzPack installation folder and then to IzPack bin using command prompt with Administration privileges and type the following command
D:\IzPack\bin>compile D:\appInst\install.xml -b D:\appInst
This will create install.jar file now to run the jar file run java -jar install.jar that open up the installer.
Happy Coding 🙂

How to create your own custom annotations in java and how to use it..PART-I

Hi All
Recently i have a thought why cant i create a custom annotations and use it, and below is the solution for it.

Lets look at what are annotations:

Annotations provide data about a program that is not part of the program itself. They have no direct effect on the operation of the code they annotate.Annotations have a number of uses, among them:

Information for the compiler — Annotations can be used by the compiler to detect errors or suppress warnings.
Compiler-time and deployment-time processing — Software tools can process annotation information to generate code, XML files, and so forth.
Runtime processing — Some annotations are available to be examined at runtime.

Annotations can be applied to a program’s declarations of classes, fields, methods, and other program elements.

Annotation Structure

There are two main components in annotations. First is annotation type and the next is the annotation itself which we use in the code to add meaning. Every annotation belongs to a annotation type.

Annotation Type:

public @interface {
method declaration;
}
eg: public @interface AutoInject{
public injectObject() default "";
}

Annotation type is very similar to an interface with little difference.

We attach ‘@’ just before interface keyword.
Methods will not have parameters.
Methods will not have throws clause.
Method return types are restricted to primitives, String, Class, enums, annotations, and arrays of the preceding types.
We can assign a default value to method.

There are specific annotations which can only be used in the context of annotations. The annotations are target, retention, documented and inherited.

Meta Annotations

Annotations itself is meta information then what is meta annotations? As you have rightly guessed, it is information about annotation. When we annotate a annotation type then it is called meta annotation. For example, we say that this annotation can be used only for methods.

@Target(ElementType.METHOD)
public @interface MethodInfo { }

Annotation Types:
Documented: When a annotation type is annotated with @Documented then wherever this annotation is used those elements should be documented using Javadoc tool.

Inherited: This meta annotation denotes that the annotation type can be inherited from super class. When a class is annotated with annotation of type that is annotated with Inherited, then its super class will be queried till a matching annotation is found.

Retention: This meta annotation denotes the level till which this annotation will be carried. When an annotation type is annotated with meta annotation Retention, RetentionPolicy has three possible values:

@Retention(RetentionPolicy.RUNTIME)
public @interface Developer {
String value();
}

a.Class: When the annotation value is given as ‘class’ then this annotation will be compiled and included in the class file.
b.Runtime: The value name itself says, when the retention value is ‘Runtime’ this annotation will be available in JVM at runtime. We can write custom code using reflection package and parse the annotation. I have give an example below.
c.Source: This annotation will be removed at compile time and will not be available at compiled class.

Target:This meta annotation says that this annotation type is applicable for only the element (ElementType) listed. Possible values for ElementType are, CONSTRUCTOR, FIELD, LOCAL_VARIABLE, METHOD, PACKAGE, PARAMETER, TYPE.

in my next post i will explain how to code custom annotations and use them
Happy Coding 🙂

Converting a color Image to a grayscale image programatically using Java

Hi in the last couple of days i was working with one of my friend to create a website.We had a requirement in which, we should put lot of images that need to be converted as gray scale images from color, Then we had lot of work with photoshop to make every image into gray scale and then port into server which is little tedious job, then i have made this program which will work perfectly to make colored images into gray scale images and i looped it in the image list to get all images as gray scale on the fly. Thanks to Java API 🙂

The below code is self explanatory.

/**
*
*/
package com.spark.image.converter;

import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

/**
* @author Mantha Pavan Kumar
*
*/
public class Color2Grayscale {

/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// Save the image file as a BufferedImage object
BufferedImage cat = ImageIO.read(new File("image.JPG"));

// Loop through all the pixels in the image (w = width, h = height)
for (int w = 0; w < cat.getWidth(); w++) {
for (int h = 0; h < cat.getHeight(); h++) {
// BufferedImage.getRGB() saves the colour of the pixel as a
// single integer.
// use Color(int) to grab the RGB values individually.
Color color = new Color(cat.getRGB(w, h));

// use the RGB values to get their average.
int averageColor = ((color.getRed() + color.getGreen() + color
.getBlue()) / 3);

// create a new Color object using the average colour as the
// red, green and blue
// colour values
Color avg = new Color(averageColor, averageColor, averageColor);

// set the pixel at that position to the new Color object using
// Color.getRGB().
cat.setRGB(w, h, avg.getRGB());
}
}

// save the newly created image in a new file.
ImageIO.write(cat, "jpg", new File("image_greyscale.jpg"));
}

}

Happy Coding.

Database Change Management using Liquibase and Maven

Hi Guys, this is my recent research

We never develop code without version control, why should we develop database without it?

Liquibase is an open source (Apache 2.0 Licensed), database-independent library for tracking, managing and applying database changes. It is built on a simple premise: All database changes are stored in a human readable yet trackable form.

Simple configuration of liquibase project is projected here.

Step1: Create a Maven Project using your IDE(in my case Eclipse3.7)

Step2: Place the liquibase Maven Plugin in the POM.xml

as shown below:


<project>

..........

<build>
 <plugins>
 <plugin>
 <groupId>org.liquibase</groupId>
 <artifactId>liquibase-maven-plugin</artifactId>
 <version>2.0.1</version>
 <dependencies>
 <dependency>
 <groupId>mysql</groupId>
 <artifactId>mysql-connector-java</artifactId>
 <version>5.1.21</version>
 </dependency>
 </dependencies>
 <executions>
 <execution>
 <configuration>
 <propertyFile>src/main/resources/liquibase.properties</propertyFile>
 </configuration>
 <phase>process-resources</phase>
 <goals>
 <goal>update</goal>
 </goals>
 </execution>
 </executions>
 </plugin>
 </plugins>
 </build>

</project>

Step3: Place the liquibase.properties file in src/main/resources/ folder  – and a sample is here:


#liquibase.properties

changeLogFile=src/main/resources/changelogs/change_log.xml
 driver=com.mysql.jdbc.Driver
 url=jdbc:mysql://localhost:3306/testdbbkp
 username=user
 password=pwd

Note: the schema should exist before you run the project

Step4: Now create a change_log.xml to create all tables and even modifications to those tables as shown below


<databaseChangeLog
 xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
 xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd
 http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">

<changeSet id="1" author="pavan">
 <createTable tableName="department">
 <column name="id" type="int">
 <constraints primaryKey="true" nullable="false"/>
 </column>
 <column name="name" type="varchar(50)">
 <constraints nullable="false"/>
 </column>
 <column name="active" type="boolean" defaultValueBoolean="true"/>
 </createTable>
 </changeSet>

<changeSet id="2" author="Mantha Pavan Kumar">
 <comment>
 changeSet 2 with modifications to existing table;
 </comment>

<renameColumn tableName="department" oldColumnName="id" newColumnName="dept_id" columnDataType="int"/>
 <renameColumn tableName="department" oldColumnName="name" newColumnName="dept_name" columnDataType="varchar(50)"/>
 </changeSet>

<changeSet id="3" author="Mantha Pavan Kumar">
 <comment>
 changeSet 2 with modifications to existing table;
 </comment>

<loadData tableName="department" file="src/main/resources/csv/Book1.csv">
 <column name="dept_id" type="numeric"/>
 <column name="dept_name" type="string"/>
 </loadData>
 </changeSet>

<changeSet id="4" author="Mantha Pavan Kumar">
 <comment>
 creating table using sql commands with liqibase;
 </comment>

<sql>
 create table employee(id int,first_name varchar(50),last_name varchar(50));
 </sql>
 </changeSet>

<changeSet id="5" author="Mantha Pavan Kumar">
 <comment>
 creating complete database with data using sql backup file;
 </comment>

<sqlFile path="src/main/resources/sql/database.sql"/>
 </changeSet>

<changeSet id="6" author="Mantha Pavan Kumar">
 <comment>
 creating a lookuptable
 </comment>
 <createTable tableName="lookup">
 <column name="lookup_id" type="int">
 <constraints primaryKey="true" nullable="false"/>
 </column>
 <column name="lookup_name" type="varchar(50)">
 <constraints nullable="false"/>
 </column>
 <column name="active" type="boolean" defaultValueBoolean="true"/>
 </createTable>
 </changeSet>

</databaseChangeLog>

The above file shows you the different configurations that can be made. once the project is ran liquibase will create two tables databasechangelog and databasechangeloglock. now the liquibase will store all the modifications we do in databasechangelog table according to the <changeSet> defined in “change_log.xml”

to run the project issue the command : mvn clean install package

all your tables gets installed and track will be maintained

Happy coding 🙂

Maven+Freemarker to generate Java Pojos Dynamically

Hi guys, from past couple of months i was working on lot many plugin development and reporting plugins which i was asked to make the data populate dynamically, So i started using “Freemarker” templates to render data dynamically from java. While i was doing this i got an idea where i can specify my database schema and the code should generate “Java Pojo” classes on the fly, yes there are some tools available but we can make our own custom tool with “Freemarker” and below is my solution to it.

CodeGenerator.java

/**
*
*/
package com.spark.code.generator;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.spark.code.generator.freemarker.engine.FreemarkerEngine;
import com.spark.code.generator.model.ColumnMetaData;

/**
* @author Mantha Pavan Kumar
*
*/
public class CodeGenerator {

/**
* @param args
*/
public static void main(String[] args) {

Connection connection = getConnection();
List&lt;String&gt; list = new ArrayList&lt;String&gt;();
PreparedStatement preparedStatement = null;
Map&lt;String, List&lt;ColumnMetaData&gt;&gt; map = new HashMap&lt;String, List&lt;ColumnMetaData&gt;&gt;();
List&lt;ColumnMetaData&gt; columnMetaDataList = null;
ColumnMetaData columnMetaData = null;

try {
DatabaseMetaData databaseMetaData = connection.getMetaData();
ResultSet resultSet = databaseMetaData.getTables(
connection.getCatalog(), null, null,
new String[] { "TABLE" });
while (resultSet.next()) {
list.add(resultSet.getString("TABLE_NAME"));
}
resultSet.close();
for (int i = 0; i &lt; list.size(); i++) {
columnMetaDataList = new ArrayList&lt;ColumnMetaData&gt;();
String sql = "select * from " + list.get(i) + " where 1=2";
preparedStatement = connection.prepareStatement(sql);
resultSet = preparedStatement.executeQuery();

ResultSetMetaData metaData = resultSet.getMetaData();
int colCount = metaData.getColumnCount();
for (int j = 0; j &lt; colCount; j++) {
columnMetaData = new ColumnMetaData();
columnMetaData.setColumnName(metaData.getColumnName(j + 1));
columnMetaData.setColumnType(metaData
.getColumnTypeName(j + 1));
columnMetaDataList.add(columnMetaData);
}
map.put(list.get(i), columnMetaDataList);
}

} catch (SQLException e) {
e.printStackTrace();
}

Map&lt;String, Object&gt; templateMap = new HashMap&lt;String, Object&gt;();
templateMap.put("data", map);
System.out.println(FreemarkerEngine.getInstance().getTemplate(
"src/ftl/PojoGen.tmpl", templateMap));

}

private static String toProperCase(String inputString) {
StringBuilder ff = new StringBuilder();

for (String f : inputString.split("_")) {
/*
* if (ff.length() &gt; 0) { ff.append(" "); }
*/
ff.append(f.substring(0, 1).toUpperCase()).append(
f.substring(1, f.length()).toLowerCase());
}

return ff.toString();
}

public static Connection getConnection() {

Connection connection = null;

try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/test", "root", "root");

} catch (Exception e) {
e.printStackTrace();
}
return connection;
}

}

The above class gets the meta data of database schema(schema:test in my case) and populates into a map object. Its time to push this map object to Freemarker so that it generates POJO classes. below is the freemarker template which generates the pojo classes

PojoGen.tmpl

/**
*    &lt;p&gt;Generated by Spark Code Generation Tool
*    @author Mantha Pavan Kumar
*    @version 1.0&lt;/p&gt;
**/

import java.io.Serializable;
import java.util.Date;

&lt;#list data?keys as key&gt;
public class ${key?cap_first} implements Serializable{

&lt;#list data[key] as value&gt;
/**
*  Attribute ${value.columnName}
**/
private &lt;#if value.columnType == 'INT UNSIGNED' || value.columnType == 'INT' || value.columnType == 'BIGINT UNSIGNED'&gt;int&lt;#elseif value.columnType == 'VARCHAR'&gt;String&lt;#elseif value.columnType == 'DATE' || value.columnType == 'DATETIME'&gt;Date&lt;#elseif value.columnType == 'DOUBLE'&gt;double&lt;/#if&gt; ${value.columnName};
&lt;/#list&gt;

&lt;#list data[key] as value&gt;
/**
*  @param ${value.columnName}
**/
public void set${value.columnName}(&lt;#if value.columnType == 'INT UNSIGNED' || value.columnType == 'INT' || value.columnType == 'BIGINT UNSIGNED'&gt;int&lt;#elseif value.columnType == 'VARCHAR'&gt;String&lt;#elseif value.columnType == 'DATE' || value.columnType == 'DATETIME'&gt;Date&lt;#elseif value.columnType == 'DOUBLE'&gt;double&lt;/#if&gt; ${value.columnName}){
this.${value.columnName} = ${value.columnName};
}
/**
*  @return
**/
public &lt;#if value.columnType == 'INT UNSIGNED' || value.columnType == 'INT' || value.columnType == 'BIGINT UNSIGNED'&gt;int&lt;#elseif value.columnType == 'VARCHAR'&gt;String&lt;#elseif value.columnType == 'DATE' || value.columnType == 'DATETIME'&gt;Date&lt;#elseif value.columnType == 'DOUBLE'&gt;double&lt;/#if&gt; get${value.columnName}(){
return ${value.columnName};
}
&lt;/#list&gt;
}
&lt;/#list&gt;

for this logic to work we have a helper class which will invoke the Freemarker engine and the code is as below

FreemarkerEngine.java

/**
*
*/
package com.spark.code.generator.freemarker.engine;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Map;

import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;

/**
* @author Mantha Pavan Kumar
*
*/
public class FreemarkerEngine {

Configuration configuration ;

public FreemarkerEngine() {
configuration = new Configuration();
}

public static FreemarkerEngine getInstance(){

FreemarkerEngine engine = new FreemarkerEngine();
return engine;
}

public String getTemplate(String tempalte,Map params){
ByteArrayOutputStream bos = new ByteArrayOutputStream();
OutputStreamWriter output = new OutputStreamWriter(bos);
Template template = null;
try {
template = configuration.getTemplate(tempalte);
template.process(params, output);
} catch (IOException e) {
e.printStackTrace();
} catch (TemplateException e) {
e.printStackTrace();
}

return bos.toString();
}

}