Showing posts with label JAVA. Show all posts
Showing posts with label JAVA. Show all posts

Thursday, 5 December 2013

HttpSessionListener , HttpSessionAttributeListener , ServletContextListener in java example


1. HttpSessionListener :- This interface may are notified of changes to the list of active sessions in a web application. To receive notification events, implementation class must be configured in the deployment descriptor (web.xml) for the web application. HttpSessionListener is used to keep track the the active session. When a new user login session created & add 1 in counter when invalidate logout minus 1 in counter.



create a web application with user login & user logout feature where you can see how this will be work.

implementing HttpSessionListener interface invoked at two method:-

1. public void sessionCreated(HttpSessionEvent httpSessionEvent)
    //Receives notification that a session has been created. LOGIN
    //Parameters: httpSessionEvent- containing the session.

2. public void sessionDestroyed(HttpSessionEvent httpSessionEvent)
   //Receives notification that a session is invalidated. LOGOUT
   //Parameters:httpSessionEvent - containing the session.

Sample Code :-

package com.javastoreroom.listener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import org.apache.log4j.Logger;

public class SessionListener implements HttpSessionListener {
 private static final Logger LOGGER = Logger.getLogger(SessionListener.class);
 private static int  activeSessionCounter;
 
 public static int getActiveSessionCounter() {
  return activeSessionCounter;
 }

 public static void setActiveSessionCounter(int activeSessionCounter) {
  SessionListener.activeSessionCounter = activeSessionCounter;
 }

 public void sessionCreated(HttpSessionEvent arg0) {
  activeSessionCounter++;
  LOGGER.info("session created ------ one add into counter -------> :"+activeSessionCounter);

 }

 public void sessionDestroyed(HttpSessionEvent arg0) {
  activeSessionCounter--;
  LOGGER.info("session destroy ----- remove one into counter -----> :"+activeSessionCounter);

 }

}

As we write above "implementation class must be configured in the deployment descriptor (web.xml)"


  com.javastoreroom.listener.SessionListener
 

now when you run your web application you can see in log :-
while user login :-session created ------ one add into counter -------> :1
While user Logout:-session destroy ----- remove one into counter -----> :0

2. HttpSessionAttributeListener:- This interface receiving notification events about HttpSession attribute changes.To receive these notification events, the implementation class must be either declared in the deployment descriptor or annotated with WebListener.HttpSessionAttributeListener is used to keep monitor session attribute. When a new user login session created & put username , id some other attribute in session to access globally in application. Using this interface we can check when attribute add , update and remove from session.

implementing HttpSessionAttributeListener interface invoked at three method:-

1. public void attributeAdded(HttpSessionBindingEvent bindingEvent)
    //Receives notification that an attribute has been added to a session. LOGIN & set USERNAME IN SESSION
    //Parameters:bindingEvent- containing the session and the name and value of the attribute that was added

2. public void attributeRemoved(HttpSessionBindingEvent bindingEvent)
    //Receives notification that an attribute has been removed from a session.
    //Parameters:bindingEvent-containing the session and the name and value of the attribute that was removed

3. public void attributeReplaced(HttpSessionBindingEvent bindingEvent)
    //Receives notification that an attribute has been replaced in a session.
    //Parameters:bindingEvent- containing the session and the name and (old) value of replaced with new one.

Sample Code:-
package com.javastoreroom.listener;

import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;
import org.apache.log4j.Logger;

public class SessionAttributeListener implements HttpSessionAttributeListener {
 public static final Logger LOGGER = Logger.getLogger(SessionAttributeListener.class);

 public void attributeAdded(HttpSessionBindingEvent bindingEvent) {
  String attributeName = bindingEvent.getName();
  Object object = bindingEvent.getValue();
              LOGGER.info("attribute added in session -->" + attributeName + "&"+ object);
 }

 public void attributeRemoved(HttpSessionBindingEvent bindingEvent) {
  String attributeName=bindingEvent.getName();
  Object object=bindingEvent.getValue();
  LOGGER.info("attribute removed in session -->" + attributeName + "&"+ object);

 }

 public void attributeReplaced(HttpSessionBindingEvent bindingEvent) {
  String attributeName=bindingEvent.getName();
  Object object=bindingEvent.getValue();
  LOGGER.info("attribute replace in session -->" + attributeName + "&"+ object);
 }
}

"implementation class must be configured in the deployment descriptor (web.xml)"


  com.javastoreroom.listener.SessionAttributeListener
 

3.ServletContextListener:-This interface receive notifications about changes to the servlet context of the web application they are part of. To receive notification events, the implementation class must be configured in the deployment descriptor for the web application.If you want to run your code before the web application is start.Here you want to start sending notification when application start either user login or not.

implementing ServletContextListenerinterface invoked at two method:-

1. public void contextInitialized(ServletContextEvent servletContextEvent)
    //Notification that the web application initialization process is starting. All ServletContextListeners are notified of context initialization before any filter or servlet in the web application is initialized.

2. public void contextDestroyed(ServletContextEvent servletContextEvent)
    //Notification that the servlet context is about to be shut down. All servlets and filters have been destroy()ed before any //ServletContextListeners are notified of context destruction. 

Sample Code:-

package com.javastoreroom.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;

import org.apache.log4j.Logger;

public class applicationListener implements ServletContextListener {
 public static final Logger LOGGER = Logger.getLogger(SessionAttributeListener.class);

 @Override
 public void contextDestroyed(ServletContextEvent arg0) {
  LOGGER.info("context destory when stop ");
  
 }

 @Override
 public void contextInitialized(ServletContextEvent arg0) {
  LOGGER.info("context started before aplication started ");
  
 }
}

When you start a tomcat server see log "context started before aplication started" line will be shown before application start.

:) Enjoy JAVA Love it

Tuesday, 26 November 2013

extract war file using terminal

WAR file ( Web application ARchive) is a JAR file used to distribute a collection of JavaServer Pages, Java Servlets, Java classes, XML files, tag libraries, static web pages and other application resources that together create a web application.

The /WEB-INF directory in the WAR file contains web.xml which defines the structure of the web application. The /WEB-INF/classes directory is on the Class Loader's class path. This is where .class files are loaded from when the web application is executing. Any JAR files placed in the /WEB-INF/lib directory will also be placed on the Class Loader's class path.

extract a war file open your terminal and type following command :-

Last login: Wed Nov 27 10:46:12 
APP-66:~Arun$ jar -xvf DisplayTag.war

And hit enter .war file extracted and inside a war folder structure created in directory where you extract. Here i am create a .war of this project Struts2 pagination while extracting DisplayTag.war following war file structure are shown :-





Friday, 25 October 2013

serialization , deserialization in java example


Serialization is the process of translating object state into a format that can be stored in a file , memory buffer, or transmitted across a network connection .
This process of serializing an object is also called marshalling an object.Opposite extracting a data structure from a series of bytes, is deserialization known as unmarshalling. Mainly you see in Hibernate , Jpa etc. We can serialize our Model classes using Serializable interface.


Here we have create a Simple Java bean class Employee and its variables having some values. We can save this object into a file or into a database table.
i m saving these object into a file :-


Employee.java
package com.javastoreroom.thread;

import java.io.Serializable;

public class Employee  implements Serializable{     // serialization interface has no methods , fields and serves only to identify the semantics
                                                    // of being serializable. 
 /**
  * 
  */
 private static final long serialVersionUID = 1L; //JVM use this value to assign this version serialized objects
 
 
 private String userName;
 private String section;
 private String rollNumber;
 
 
 public Employee(String name , String section , String number){
  
  this.userName = name;
  this.section =  section;
  this.rollNumber = number;
 }
 

 public String getUserName() {
  return userName;
 }

 public void setUserName(String userName) {
  this.userName = userName;
 }

 public String getSection() {
  return section;
 }

 public void setSection(String section) {
  this.section = section;
 }

 public String getRollNumber() {
  return rollNumber;
 }

 public void setRollNumber(String rollNumber) {
  this.rollNumber = rollNumber;
 }

}


ObjectOutputStream Class writes primitive data types and Java objects to an OutputStream. The objects can be read using an ObjectInputStream. Persistent storage of objects can be accomplished by using a file for the stream.objects that support the java.io.Serializable interface can be written to streams.

writeObject method is used to write an object to the stream. Any object, including Strings and arrays, is written with writeObject. Multiple objects or primitives can be written to the stream.ObjectOutputStream. The class of the object, the signature of the class, and the values of the non-transient and non-static fields of the class and all of its supertypes are written using writeObject method.

public final void writeObject(Object obj)throws IOException


ObjectInputStream Class deserializes primitive data and objects previously written using an ObjectOutputStream. ObjectInputStream is used to recover those objects previously serialized.

readObject is used to read an object from the stream.
public final Object readObject() throws IOException,ClassNotFoundException
ObjectInputStream. The class of the object, the signature of the class, and the values of the non-transient and non-static fields of the class and all of its supertypes are read.


SerilazationDeserlization.java

package com.javastoreroom.thread;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class SerilazationDeserlization {

 public static void main(String[] args) {
  serializeObject();
  deserializeObject();
 }

 private static void serializeObject() {
  Employee employee = new Employee("Arun", "A", "8095");
  FileOutputStream fileOutputStream = null;
  ObjectOutputStream objectOutputStream = null;
  try {
   fileOutputStream = new FileOutputStream("Arun.txt");
   objectOutputStream = new ObjectOutputStream(fileOutputStream);
   objectOutputStream.writeObject(employee);
  } catch (FileNotFoundException e) {
   e.printStackTrace();
  } catch (IOException e) {
   e.printStackTrace();
  } finally {
   try {
    objectOutputStream.flush();
    objectOutputStream.close();
   } catch (IOException e) {
    e.printStackTrace();
   }
  }
 }

 private static void deserializeObject() {
  FileInputStream fileInputStream;
  try {
   fileInputStream = new FileInputStream("Arun.txt");
   ObjectInputStream inputStream = new ObjectInputStream(fileInputStream);
   Employee employee2 = (Employee) inputStream.readObject();
   System.out.println(employee2.getUserName());
   System.out.println(employee2.getRollNumber());
   System.out.println(employee2.getSection());
  } catch (FileNotFoundException e) {
   e.printStackTrace();
  } catch (IOException e) {
   e.printStackTrace();
  } catch (ClassNotFoundException e) {
   e.printStackTrace();
  }

 }

}



when execute above code arun.txt created contain serialize object :-
¨Ì  sr !com.javastoreroom.thread.Employee           L 
rollNumbert  Ljava/lang/String;L  sectionq ~  L  userNameq ~  xpt  8095t  At  Arun 

when you deserialize arun.txt you will get following output :-
Arun
8095
A

Done :)

Sunday, 20 October 2013

java.lang.IllegalThreadStateException



package com.javastoreroom.thread;

import java.sql.Timestamp;
import java.util.Date;

public class ThreadSleeping extends Thread {

 public void run() {
       Date date = new Timestamp(System.currentTimeMillis());
       
  for (int i = 0; i < 10; i++) {
   try {
    Thread.sleep(1000);
   } catch (Exception e) {
    e.printStackTrace();
   }
   System.out.print(i +",\t");
  }
 }

 public static void main(String[] args) {
  ThreadSleeping sleeping = new ThreadSleeping();
  sleeping.start();
 }

}
if you run above example following output shown :-
if you change the main block code to this :-
public static void main(String[] args) {
  ThreadSleeping sleeping = new ThreadSleeping();
  sleeping.start();
  sleeping.start();
 }

You will get java.lang.IllegalThreadStateException exception reason behind the exception is you are trying to start the thread twice. you are trying to start something which is already started, so you getting IllegalThreadStateException. Another reason behind the exception if you mark user thread as a daemon thread . it not be started and throw IllegalThreadStateException .
ThreadSleeping sleeping = new ThreadSleeping();
  sleeping.start();
  sleeping.setDaemon(true); // throw exception
 
Exception in thread "main" java.lang.IllegalThreadStateException
 at java.lang.Thread.start(Thread.java:656)
 at com.javastoreroom.thread.ThreadSleeping.main(ThreadSleeping.java:24)
:)

Tuesday, 8 October 2013

date difference in mysql , date difference between two date in java


Here we calculate date difference by mysql or java in both way :-



MYSQL

DATEDIFF() Functions returns expr1 – expr2 expressed as a value in days from one date to the other. expr1 and expr2 are date or date-and-time expressions. Only the date parts of the values are used in the calculation.

SELECT DATEDIFF('2013-10-30','2013-09-11') from dual; --  will return 49 days 
SELECT DATEDIFF('2013-09-30','2013-10-11') from dual; --   will return -11 days 

Java

package com.javastoreroom.date;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateDiffrence {

 public static void main(String[] args) {

  SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  String dateStart = "2013-09-05";
  String dateStop = "2013-10-08";

  try {
   Date date = format.parse(dateStart);
   Date date1 = format.parse(dateStop);

   long time = date1.getTime() - date.getTime();
   long day = time / (24 * 60 * 60 * 1000);
   System.out.println("count total day ------- :"+day); // line print number of day between these two date count total day ------- :33

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

 }

}

DONE :)

Wednesday, 2 October 2013

decompile class file using javap , java class file disassembler


javap command disassembles java class files. Its output depends on the options used. If no options are used, javap prints out the package, protected, and public fields and methods of the classes passed to it. javap prints its output to stdout.


here is the class we test compile the following class:-

package com.javastoreroom.net;

public class Add  {

 public static void main(String[] args) {
  new Add().totalValue(5 , 6);
 }

 private void totalValue(int i, int j) {
   System.out.println("Add two value");
   System.out.println("[-------Sum of two value ----------"+(i+j)+"------]");

 }
}


run javap Add following attribute , method shown:-

C:Desktop Arun> javap Add
Compiled from "Add.java"
public class com.javastoreroom.net.Add extends java.lang.Object{
    public com.javastoreroom.net.Add();
    public static void main(java.lang.String[]);
}


run javap -c Add command following byte-code are shown :-

Compiled from "Add.java"
public class com.javastoreroom.net.Add extends java.lang.Object{
public com.javastoreroom.net.Add();
  Code:
   0: aload_0
   1: invokespecial #8; //Method java/lang/Object."":()V
   4: return

public static void main(java.lang.String[]);
  Code:
   0: new #1; //class com/javastoreroom/net/Add
   3: dup
   4: invokespecial #16; //Method "":()V
   7: iconst_5
   8: bipush 6
   10: invokespecial #17; //Method totalValue:(II)V
   13: return

}

Try another option just type command javap -help following command shown :-
Usage: javap  ...

where options include:
-c                        Disassemble the code
-classpath      Specify where to find user class files
-extdirs            Override location of installed extensions
-help                     Print this usage message
-J                  Pass  directly to the runtime system
-l                        Print line number and local variable tables
-public                   Show only public classes and members
-protected                Show protected/public classes and members
-package                  Show package/protected/public classes
and members (default)
-private                  Show all classes and members
-s                        Print internal type signatures
-bootclasspath  Override location of class files loaded
by the bootstrap class loader
-verbose                  Print stack size, number of locals and args for methods
If verifying, print reasons for failure


Thursday, 19 September 2013

Compare 2 Dates , Convert String into Date , Convert Date into String - in java SimpleDateFormat


Here i m discuss SimpleDateFormat class SimpleDateFormat is a concrete class for formatting and parsing dates in a locale-sensitive manner. It allows for formatting (date -> String), parsing (String -> date). It allows you to choosing any user-defined date-time formatting patterns.

Letter Date or Time Component Presentation Examples
G Era designator Text AD
y Year Year 1996; 96
M Month in year Month July; Jul; 07
w Week in year Number 27
W Week in month Number 2
D Day in year Number 189
d Day in month Number 10
F Day of week in month Number 2
E Day in week Text Tuesday; Tue
a Am/pm marker Text PM
H Hour in day (0-23) Number 0
k Hour in day (1-24) Number 24
K Hour in am/pm (0-11) Number 0
h Hour in am/pm (1-12) Number 12
m Minute in hour Number 30
s Second in minute Number 55
S Millisecond Number 978
z Time zone General time zone Pacific Standard Time; PST; GMT-08:00
Z Time zone RFC 822 time zone -0800

refer this link know to more...
public class SimpleDateFormat extends DateFormat



SimpleDateFormatPattern .Java Sample Code


public static void main(String[] args) throws ParseException {

  SimpleDateFormat format = null;
  String startDate = "2013-01-08 12:10:56";
  String endDate = "2013-12-09 10:10:56";
  
  System.out.println("<<<<<<<<<<<<<<--------Compare 2 Dates------------>>>>>>>>>>>>>>>>>>>>"); 
  new SimpleDateFormatPattern().compareTwoDate( format , startDate , endDate);
  
         System.out.println("<<<<<<<<<<<<<<--------Convert String into Date------->>>>>>>>>>>>>>>>>"); 
  new SimpleDateFormatPattern().convertStringToDate(format , startDate , endDate);
  
         System.out.println("<<<<<<<<<<<<<<--------Convert Date into String------>>>>>>>>>>>>>>>>>>"); 
         new SimpleDateFormatPattern().convertDateToString(format);
 }

Compare 2 Dates
private void compareTwoDate(SimpleDateFormat format, String startDate, String endDate) {
  Date date1 , date2;
  format = new SimpleDateFormat("yyyy-MM-dd");
  try {
   date1 = format.parse(startDate);
   date2 = format.parse(endDate);
   
   if (date1.compareTo(date2) < 0) 
    System.out.println("Start Date is before than End Date");
   
   else if(date1.compareTo(date2) >0)
    System.out.println("Start Date is after than End Date");
   
   else
    System.out.println("Start Date and End Date both are equal");
  } catch (ParseException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }
Convert String into Date
private void convertStringToDate(SimpleDateFormat format, String startDate, String endDate) {
  format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
  try {
   Date startDates =  format.parse(startDate);
   Date endDates = format.parse(endDate);
   
   System.out.println("String to date    :"+startDates);
   System.out.println("String to date    :"+endDates);
   
  } catch (ParseException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }
Convert Date into String
private void convertDateToString(SimpleDateFormat format) {
  format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); 
   Date date = new Date();
   String todayDate = format.format(date);
   System.out.println("Date to String    :" +todayDate);
 }

after executing SimpleDateFormatPattern.java following result shown :-

Friday, 13 September 2013

add number using jstl , add two number in jstl

Adding 2 or more number via jstl :-


addNumber.jsp:-

Number
Total : ${total}
after executing addNumber.jsp you get following output :-

Saturday, 7 September 2013

org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0x13) , (Unicode: 0x9) was found in the element content of the document.


While read a xml getting org.xml.sax.SAXParseException the parser exception when parsing the xml. i check text that create this Exception nothing special character found there. but while dBuilder.parse() method parse xml throw exception .


log4j:WARN File option not set for appender [file].
log4j:WARN Are you using FileAppender instead of ConsoleAppender?
[Fatal Error] employeeInfo.xml:45:35: An invalid XML character (Unicode: 0x13) was found in the element content of the document.
Exception in thread "main" org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0x13) was found in the element content of the document.
 at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:246)
 at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284)
 at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:180)
 at javastoreroom.ReadXML.main(ReadXMLFile.java:33)


Spending a lots of hour while (open xml in OpenOffice find the reason like Name :Arun but when check in OpenOffice it's look like Aru#n content some junk character) finally get solution first read all xml content using BufferedReader and do this :-
String lineReader =" ";
while((lineReader = bufferedReader.readLine()) != null){
  lineReader = lineReader.replaceAll("[^\\x20-\\x7e]", "");
  buffer.append(l);
  }

Now create a temporary xml file and write buffer all content. Then read temp.xml now everything goes very well.Check it here valid or invalid character in xml

Hope this will help you :)


java.net.MalformedURLException: no protocol: /Users/Arun/Documents/employeeInfo.xml


Getting this exception while read xml file using SmbJcifs :-


java.net.MalformedURLException: no protocol: /Users/Arun/Documents/employeeInfo.xml
 at java.net.URL.(URL.java:567)
 at jcifs.smb.SmbFile.(SmbFile.java:437)
 at test.ReadXMLFile.readxmldata(ReadXMLFile.java:78)
 at test.ReadXMLFile.main(ReadXMLFile.java:29)
Exception in thread "main" java.lang.IllegalArgumentException: File cannot be null
 at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:201)
 at test.ReadXMLFile.main(ReadXMLFile.java:33)


Reason for This url or path string looks like it's invalid. in smb it's not supposed to be '/Users/Arun/Documents/employeeInfo.xml' directory.
Url pattern of smb (smb://IPADDRESS/Volume/Folder/) where file located. when i change to this (smb:// URL syntax) every thing goes very well.

:) :)

Monday, 2 September 2013

com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 1 of 1-byte UTF-8 sequence.


while reading another xml file using smb jcifs. Here i am refer this example read .xml file using smb jcifs . Xml contain some UTF-8 characters inside a XML file, and parser is not configure to parse the UTF-8 properly, characters like copyright , reserve etc. Throw an exception :-


com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 1 of 1-byte UTF-8 sequence.
 at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.invalidByte(UTF8Reader.java:684)
 at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(UTF8Reader.java:554)
 at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(XMLEntityScanner.java:1742)
 at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.skipChar(XMLEntityScanner.java:1416)
 at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2793)
 at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:647)
 at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
 at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
 at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
 at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
 at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:232)
 at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284)
 at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:124)
 at com.gwtech.source.XmlReader.readAllXML(XmlReader.java:61)
 at com.gwtech.source.XmlReader.execute(XmlReader.java:343)
 at org.quartz.core.JobRunShell.run(JobRunShell.java:191)
 at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:516)


To read content in UTF-8 format modify input source :-

SmbConnect.java class found Here Do some modification :-

Change this code :-
InputStream inputStream = sFile.getInputStream();
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
    Document doc = dBuilder.parse(inputStream);
to This
InputStream stream = new SmbFileInputStream(fXmlFile);
  Reader reader = new InputStreamReader(stream);
  InputSource inputSource = new InputSource(reader);
  inputSource.setEncoding("UTF-8"); // set UTF-8 character encoding 

  DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
  DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
  Document doc = dBuilder.parse(inputSource);

Now Everything is working fine hope this help you :)

Monday, 19 August 2013

copy folder using smb , copy folder from smb share to local drive using jcifs in Java

We are already discuss about JCIFS SMB client library to know check it older post now here discuss about jcifs copyTo method :-


public void copyTo(SmbFile dest)throws SmbException

This method will copy the file or directory represented by this SmbFile and it's sub-contents to the location specified by the dest parameter. This file and the destination file do not need to be on the same host. This operation does not copy extended file attibutes such as ACLs but it does copy regular attributes as well as create and last write times. This method is almost twice as efficient as manually copying as it employs an additional write thread to read and write data concurrently.

Sample Code :-
package com.javastoreroom.myapp;

import java.net.MalformedURLException;

import jcifs.smb.NtlmPasswordAuthentication;
import jcifs.smb.SmbException;
import jcifs.smb.SmbFile;

import org.apache.log4j.Logger;

public class MoveFolder {
 
 private static final Logger LOGGER = Logger.getLogger(MoveFolder.class);
 public static void main(String[] args) {
  
  NtlmPasswordAuthentication  ntlmPasswordAuthentication = new NtlmPasswordAuthentication(null, "Arun", "********"); 

  try {
   SmbFile source = new SmbFile("smb://192.168.1.170/C_Volume/EmployeeInfo/" ,ntlmPasswordAuthentication);
   LOGGER.info("************* Source Location Authenticate *****************");

   SmbFile destination = new SmbFile("smb://192.168.1.170/D_Volume/AllBackUp" , ntlmPasswordAuthentication);
   LOGGER.info("************* Destination Location  Authenticate ************");

   //--------- final process to move folder
   source.copyTo(destination);
            LOGGER.info("**** Content have been Move from one directory to another ****");
  } catch (MalformedURLException e) {
   e.printStackTrace();
  } catch (SmbException e) {
   e.printStackTrace();
  }

 }

}

After executing application all file, folder are copy to destination directory.


Sunday, 18 August 2013

if else if in jstl , if else


JSTL is the Java Server Pages Standard Tag Library. JSTL encapsulates, as simple tags, core functionality common to many JSP applications.


JSTL includes core tags to support iteration, conditionals, and expression-language support. It also supports EL functions for string manipulation. how these tags work, you should read the JSTL specification

Iteration
The core iteration tag is , which iterates over most collections and similar objects you'd think to iterate over. lets you iterate over tokens in a String object; it lets you specify the String and the delimiters.

Conditionals
JSTL supports a simple conditional tag along with a collection of tags -- , , and -- that support mutually exclusive conditionals. These latter three tags let you implement a typical if/else if/else if/else structure.

Expression language
JSTL provides a few tags to facilitate use of the expression language. prints out the value of a particular expression in the current EL, similar to the way that the scriptlet expression (<%= ... %>) syntax prints out the value of a expression in the scripting language (typically Java). lets you set a scoped attribute (e.g., a value in the request, page, session, or application scopes) with the value of an expression.

Text inclusion
JSP supports the jsp:include tag, but this standard action is limited in that it only supports relative URLs. JSTL introduces the c:import tag, which lets you retrieve absolute URLs. For instance, you can use c:import to retrieve information from the web using HTTP URLs, or from a file server using an FTP URL. The tag also has some advanced support for performance optimizations, avoiding unnecessary buffering of data that's retrieved.

I18N-capable text formatting
Formatting data is one of the key tasks in many JSP pages. JSTL introduces tags to support data formatting and parsing. These tags rely on convenient machinery to support internationalized applications.

XML manipulation
You can't look anywhere these days without seeing XML, and JSTL gives you convenient support for manipulating it from your JSP pages. Parse documents, use XPath to select content, and perform XSLT transformations from within your JSP pages.

Database access
Easily access relational databases using the SQL actions. You can perform database queries, easily access results, perform updates, and group several operations into a transaction.

Functions
String manipulations can be performed using the functions provided in JSTL.


Iterator Tags

The forEach tag allows you to iterate over a collection of objects.


The forTokens tag is used to iterate over a collection of tokens separated by a delimiter.


Conditionals if else if ladder in jstl :-











After executing jstlview.jsp you we get following output :-



Tuesday, 13 August 2013

javax.el.PropertyNotFoundException


Getting below error while iterator a list using jstl :-


javax.el.PropertyNotFoundException: Property 'source' not found on type java.lang.String
 at javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:237)
 at javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:214)
 at javax.el.BeanELResolver.property(BeanELResolver.java:325)
 at javax.el.BeanELResolver.getValue(BeanELResolver.java:85)
 at org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:104)
 at org.apache.el.parser.AstValue.getValue(AstValue.java:183)
 at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:185)
 at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:1026)
 at org.apache.jsp.WEB_002dINF.jsp.dashboard.misdetails_jsp._jspx_meth_c_005fforEach_005f0(misdetails_jsp.java:514)
 at org.apache.jsp.WEB_002dINF.jsp.dashboard.misdetails_jsp._jspx_meth_s_005fif_005f0(misdetails_jsp.java:407)
 at org.apache.jsp.WEB_002dINF.jsp.dashboard.misdetails_jsp._jspService(misdetails_jsp.java:131)
 at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
 at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
 at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
 at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
 at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:413)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
 at com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:39)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
 at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
 at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:487)
 at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412)
 at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)
 at org.apache.struts2.dispatcher.ServletDispatcherResult.doExecute(ServletDispatcherResult.java:139)
 at org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:178)
 at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:348)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:253)
 at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:221)
 at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
 at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
 at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:88)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
 at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
 at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:123)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
 at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
 at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:184)
 at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
 at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
 at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:105)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
 at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
 at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:115)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
 at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
 at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:143)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
 at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
 at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:123)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
 at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
 at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:170)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
 at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
 at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:207)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
 at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
 at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
 at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
 at com.gwtech.crm.interceptor.SessionInterceptor.intercept(SessionInterceptor.java:31)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
 at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
 at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:221)
 at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
 at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
 at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:150)
 at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:48)
 at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
 at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
 at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:123)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
 at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
 at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:184)
 at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
 at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
 at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:105)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
 at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
 at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:83)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
 at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
 at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:207)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
 at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
 at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:74)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
 at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
 at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:127)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
 at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
 at org.apache.struts2.interceptor.ProfilingActivationInterceptor.intercept(ProfilingActivationInterceptor.java:107)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
 at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
 at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:206)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
 at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
 at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:115)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
 at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
 at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:143)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
 at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
 at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:121)
 at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
 at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
 at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:170)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
 at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
 at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:123)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
 at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
 at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
 at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
 at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:50)
 at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:504)
 at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
 at com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.java:119)
 at com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:55)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
 at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
 at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
 at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1008)
 at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
 at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
 at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
 at java.lang.Thread.run(Thread.java:680)
Aug 13, 2013 5:20:54 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [default] in context with path [/ProjectName] threw exception [java.lang.NullPointerException] with root cause
java.lang.NullPointerException
 at org.apache.struts2.dispatcher.ServletDispatcherResult.doExecute(ServletDispatcherResult.java:123)
 at org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:178)
 at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:348)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:253)
 at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:50)
 at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:504)
 at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
 at com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.java:119)
 at com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:55)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
 at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
 at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
 at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1008)
 at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
 at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
 at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
 at java.lang.Thread.run(Thread.java:680)

When i check my jstl syntax for iterating a list it's wrong like this :-



         ${txt.name}
         ${txt.class}
     


when i change to this :-



         ${txt.name}
         ${txt.class}
    


Everything is working fine :)

Compare value using Struts 2 If, ElseIf, Else tag


Struts 2 If, ElseIf, Else perform basic condition flow. 'If' tag could be used by itself or with 'Else If' Tag and/or single/multiple 'Else' Tag.


Parameters
1. test :- Expression to determine if body of tag is to be displayed.

Action Class :- containing a nameList of name
package com.struts2;

import java.util.ArrayList;
import java.util.List;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class RetrieveAction extends ActionSupport{
 
 /**
  * @author Arun
  */
 
 private List nameList = null;
   
 public String fetchName(){
  nameList =  new ArrayList();
  {
   nameList.add("Arun");
   nameList.add("Anu");
   nameList.add("Aryan");
   nameList.add("Anu");
   nameList.add("Aranv");
   nameList.add("Arun");
   nameList.add("Aryan");
   nameList.add("Aryan");
   nameList.add("Aarus");
   nameList.add("Aranv");
   nameList.add("Aryan");
   nameList.add("Anu");
  }
  return SUCCESS;
 }

 public List getNameList() {
  return nameList;
 }

 public void setNameList(List nameList) {
  this.nameList = nameList;
 }
 
}


Result.jsp


Struts2


Spring3


Hibernate3


Core Java


While running project you will following output :-

Hope This Help You :)

Monday, 12 August 2013

javax.servlet.jsp.jstl.fmt.request.charset&UTF-8


i am getting these log when use jstl in jsp to replace struts tag info to jstl some conversion or arithmetic operation.


Reason for this :- JSPs will often create a session if one doesn't already exist. This allows JSPs to use the implicit session variable.

2013-08-13 10:42:44 INFO  SessionAttributeListener:29 - attribute replace in session -->javax.servlet.jsp.jstl.fmt.request.charset&UTF-8
2013-08-13 10:42:44 INFO  SessionAttributeListener:29 - attribute replace in session -->javax.servlet.jsp.jstl.fmt.request.charset&UTF-8
2013-08-13 10:42:44 INFO  SessionAttributeListener:29 - attribute replace in session -->javax.servlet.jsp.jstl.fmt.request.charset&UTF-8
2013-08-13 10:42:44 INFO  SessionAttributeListener:29 - attribute replace in session -->javax.servlet.jsp.jstl.fmt.request.charset&UTF-8
2013-08-13 10:42:44 INFO  SessionAttributeListener:29 - attribute replace in session -->javax.servlet.jsp.jstl.fmt.request.charset&UTF-8
2013-08-13 10:42:44 INFO  SessionAttributeListener:29 - attribute replace in session -->javax.servlet.jsp.jstl.fmt.request.charset&UTF-8
2013-08-13 10:42:44 INFO  SessionAttributeListener:29 - attribute replace in session -->javax.servlet.jsp.jstl.fmt.request.charset&UTF-8
2013-08-13 10:42:44 INFO  SessionAttributeListener:29 - attribute replace in session -->javax.servlet.jsp.jstl.fmt.request.charset&UTF-8
2013-08-13 10:42:44 INFO  SessionAttributeListener:29 - attribute replace in session -->javax.servlet.jsp.jstl.fmt.request.charset&UTF-8
2013-08-13 10:42:44 INFO  SessionAttributeListener:29 - attribute replace in session -->javax.servlet.jsp.jstl.fmt.request.charset&UTF-8
2013-08-13 10:42:44 INFO  SessionAttributeListener:29 - attribute replace in session -->javax.servlet.jsp.jstl.fmt.request.charset&UTF-8
2013-08-13 10:42:44 INFO  SessionAttributeListener:29 - attribute replace in session -->javax.servlet.jsp.jstl.fmt.request.charset&UTF-8
2013-08-13 10:42:44 INFO  SessionAttributeListener:29 - attribute replace in session -->javax.servlet.jsp.jstl.fmt.request.charset&UTF-8
2013-08-13 10:42:44 INFO  SessionAttributeListener:29 - attribute replace in session -->javax.servlet.jsp.jstl.fmt.request.charset&UTF-8
2013-08-13 10:42:44 INFO  SessionAttributeListener:29 - attribute replace in session -->javax.servlet.jsp.jstl.fmt.request.charset&UTF-8
2013-08-13 10:42:44 INFO  SessionAttributeListener:29 - attribute replace in session -->javax.servlet.jsp.jstl.fmt.request.charset&UTF-8
2013-08-13 10:42:44 INFO  SessionAttributeListener:29 - attribute replace in session -->javax.servlet.jsp.jstl.fmt.request.charset&UTF-8
2013-08-13 10:42:44 INFO  SessionAttributeListener:29 - attribute replace in session -->javax.servlet.jsp.jstl.fmt.request.charset&UTF-8
2013-08-13 10:42:44 INFO  SessionAttributeListener:29 - attribute replace in session -->javax.servlet.jsp.jstl.fmt.request.charset&UTF-8
2013-08-13 10:42:44 INFO  SessionAttributeListener:29 - attribute replace in session -->javax.servlet.jsp.jstl.fmt.request.charset&UTF-8
2013-08-13 10:42:44 INFO  SessionAttributeListener:29 - attribute replace in session -->javax.servlet.jsp.jstl.fmt.request.charset&UTF-8
2013-08-13 10:42:44 INFO  SessionAttributeListener:29 - attribute replace in session -->javax.servlet.jsp.jstl.fmt.request.charset&UTF-8
2013-08-13 10:42:44 INFO  SessionAttributeListener:29 - attribute replace in session -->javax.servlet.jsp.jstl.fmt.request.charset&UTF-8
2013-08-13 10:42:44 INFO  SessionAttributeListener:29 - attribute replace in session -->javax.servlet.jsp.jstl.fmt.request.charset&UTF-8
2013-08-13 10:42:44 INFO  SessionAttributeListener:29 - attribute replace in session -->javax.servlet.jsp.jstl.fmt.request.charset&UTF-8
2013-08-13 10:42:44 INFO  SessionAttributeListener:29 - attribute replace in session -->javax.servlet.jsp.jstl.fmt.request.charset&UTF-8
2013-08-13 10:42:44 INFO  SessionAttributeListener:29 - attribute replace in session -->javax.servlet.jsp.jstl.fmt.request.charset&UTF-8
2013-08-13 10:42:44 INFO  SessionAttributeListener:29 - attribute replace in session -->javax.servlet.jsp.jstl.fmt.request.charset&UTF-8
2013-08-13 10:42:44 INFO  SessionAttributeListener:29 - attribute replace in session -->javax.servlet.jsp.jstl.fmt.request.charset&UTF-8
2013-08-13 10:42:44 INFO  SessionAttributeListener:29 - attribute replace in session -->javax.servlet.jsp.jstl.fmt.request.charset&UTF-8
2013-08-13 10:42:44 INFO  SessionAttributeListener:29 - attribute replace in session -->javax.servlet.jsp.jstl.fmt.request.charset&UTF-8
2013-08-13 10:42:44 INFO  SessionAttributeListener:29 - attribute replace in session -->javax.servlet.jsp.jstl.fmt.request.charset&UTF-8
2013-08-13 10:42:44 INFO  SessionAttributeListener:29 - attribute replace in session -->javax.servlet.jsp.jstl.fmt.request.charset&UTF-8
2013-08-13 10:42:44 INFO  SessionAttributeListener:29 - attribute replace in session -->javax.servlet.jsp.jstl.fmt.request.charset&UTF-8
2013-08-13 10:42:44 INFO  SessionAttributeListener:29 - attribute replace in session -->javax.servlet.jsp.jstl.fmt.request.charset&UTF-8
2013-08-13 10:42:44 INFO  SessionAttributeListener:29 - attribute replace in session -->javax.servlet.jsp.jstl.fmt.request.charset&UTF-8
2013-08-13 10:42:44 INFO  SessionAttributeListener:29 - attribute replace in session -->javax.servlet.jsp.jstl.fmt.request.charset&UTF-8
2013-08-13 10:42:44 INFO  SessionAttributeListener:29 - attribute replace in session -->javax.servlet.jsp.jstl.fmt.request.charset&UTF-8
2013-08-13 10:42:44 INFO  SessionAttributeListener:29 - attribute replace in session -->javax.servlet.jsp.jstl.fmt.request.charset&UTF-8
2013-08-13 10:42:44 INFO  SessionAttributeListener:29 - attribute replace in session -->javax.servlet.jsp.jstl.fmt.request.charset&UTF-8
2013-08-13 10:42:44 INFO  SessionAttributeListener:29 - attribute replace in session -->javax.servlet.jsp.jstl.fmt.request.charset&UTF-8
2013-08-13 10:42:44 INFO  SessionAttributeListener:29 - attribute replace in session -->javax.servlet.jsp.jstl.fmt.request.charset&UTF-8

if want to hide these , do default behavior is turned off using the page directive
<%@ page session="false" %> 

Hope This Help You :)

Thursday, 8 August 2013

remove duplicate values in a list java

if list contain duplicated object you want to remove them useing set. A Set is a Collection that cannot contain duplicate elements.
It models the mathematical set abstraction.Set adds the restriction that duplicate elements are prohibited. To Know More Visit Set Interface

Sample Code :-RemoveDuplicate.java

package com.javastoreroom.mytestapp;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

public class RemoveDuplicate {

 public static void main(String[] args) {
  List list = new ArrayList();

  list.add("jan");
  list.add("feb");
  list.add("jan");
  list.add("march");
  list.add("April");
  list.add("jan");
  list.add("feb");
  list.add("may");
  list.add("may");

  System.out.println("======== List Details ==========================");
  for (String string : list) {
   System.out.print(string + ",");
  }

  // -- Use LinkedHashSet if you remain the order

  Set set2 = new LinkedHashSet();
  set2.addAll(list);
  list.clear();
  list.addAll(set2);

  System.out.println();
  System.out.println("======== LinkedHashSet Details =================");

  for (String string2 : list) {
   System.out.print(string2 + ",");
  }

  // -- HashSet does not retain the order

  Set set = new HashSet();
  set.addAll(list);
  list.clear();
  list.addAll(set);

  System.out.println();
  System.out.println("======== HashSet Details =======================");
  for (String string : list) {
   System.out.print(string + ",");
  }

 }

}


After executing output shown like this :-

Done :)

Sunday, 4 August 2013

read .xml file using smb jcifs , jcifs


We are already discuss Java CIFS Client Library here.


Now reading .xml file using smb Requirement:-
1. PersonDetails.xml reside in server or another machine


     
         Arun
         2009-08-21T08:43:02
         Kumar
       
      
         15000
         5000
      

2. Download jcifs-1.1.11.jar add in your lib folder

Constant.java
package com.javastoreroom.mytestapp;
 
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
 
    public class Constant {
  
    public static final String USER_NAME = "domain\\username";
    public static final String PASSWORD = "domain\\password";
    public static final String FILE_SOURCE_PATH = "smb://IP-Address/folderName/PersonDetails.xml"; // The local network's broadcast address of  target file or directory. SmbFile URLs
     
 
}

SmbConnect.java

package com.javastoreroom.mytestapp;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import java.io.InputStream;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import jcifs.smb.NtlmPasswordAuthentication;
import jcifs.smb.SmbFile;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class SmbConnect {

 private static final org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(SmbConnect.class);

 public static void main(String... args) {
  new SmbConnect().readXMLFiles();
 }

 public void readXMLFiles() {
  try {
   NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null, Constant.USER_NAME, Constant.PASSWORD); //This class stores and encrypts NTLM user credentials.
   
   SmbFile sFile = new SmbFile(Constant.FILE_SOURCE_PATH , auth); //This class represents a resource on an SMB network.
          try {
       
           if(sFile.getName().endsWith(".xml")){
            
     InputStream inputStream = sFile.getInputStream();
     DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
     DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
     Document doc = dBuilder.parse(inputStream);
     doc.getDocumentElement().normalize();
     NodeList nList = doc.getElementsByTagName("person");            
            
     for (int temp = 0; temp < nList.getLength(); temp++) {
      Node nNode = nList.item(temp);
      if (nNode.getNodeType() == Node.ELEMENT_NODE) {
       Element eElement = (Element) nNode;
       
       log.info("|===================Here is person details===================|");
       
       log.info(" name -- >" + eElement.getElementsByTagName("name").item(0).getTextContent());
       log.info(" joining date -- > " + eElement.getElementsByTagName("join-date").item(0).getTextContent());
       log.info(" last name -- > " + eElement.getElementsByTagName("last-name").item(0).getTextContent());
       log.info(" basic salary -- > " + eElement.getElementsByTagName("basic").item(0).getTextContent());
       log.info(" hra allowance -- > " + eElement.getElementsByTagName("HRA").item(0).getTextContent());
       
       log.info("|===========================EOF=============================|");
       
      }
            
               }
              }
    } catch (Exception exception) {
    exception.printStackTrace();
   }
  }
  catch (Exception e) {
   e.printStackTrace();
  }
 }
 
}


after executing SmbConnect.java following output are shown :-


DONE :)

Saturday, 3 August 2013

Quartz Scheduler , scheduler example in java


Quartz-Scheduler is a open source job scheduling service that can be integrated with, or used along side virtually any Java application - from the smallest stand-alone application to the largest e-commerce system.


Quartz is in use by many tens of thousands of entities, many of whom have directly embedded Quartz in their own custom applications, and others who are using products that already have Quartz embedded within them.

To know more visit :- Quartz Scheduler Enterprise Job Scheduler

if you need to implement Scheduler in your application Quartz can be downloaded here:- quartz.jar
add in java build path or lib folder.

Here is sample of Quartz process :-

Services.java
package com.javastoreroom.mytestapp;

import org.apache.log4j.Logger;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

public class Services implements Job {
 
 /**
  * @see Job interface to be implemented by classes which represent  'job' to be performed. 
  */

 private static final Logger LOGGER =  Logger.getLogger(Services.class);
 public static void main(String args[]) {
  try {
   new ServiceThread();
  } catch (Exception e) {
  }
 }

 /**
  * @see execute Called by the Scheduler when a Trigger fires that is associated with the Job. 
  */
 
 @Override
 public void execute(JobExecutionContext arg0) throws JobExecutionException {
  new Services().add();
 }

 private void add() {
  int a = (int) (Math.random() * 50 ) , b = 10 , c = 0;
  c = a + b;
  LOGGER.info(" inside checking sum of two number ----->>> " + c);
 }
}


ServiceThread.java

package com.javastoreroom.mytestapp;

import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.impl.StdSchedulerFactory;


public class ServiceThread {


 public ServiceThread() throws Exception {

  SchedulerFactory sf = new StdSchedulerFactory(); // Before you can use the scheduler, it needs to be instantiated using  SchedulerFactory.
 
  Scheduler sched = sf.getScheduler(); // Scheduler interface can be used add, remove, and list Jobs and Triggers, and perform other scheduling- related operations.
  
  JobDetail jd = new JobDetail("job1", "group1", Services.class); // JobDetail object is created by the Quartz client (program) at the time the Job is added to the scheduler
  
  CronTrigger ct = new CronTrigger("cronTrigger", "group2","0 0/1 * * * ?"); // Cron Triggers -> firing job schedule that recurs based on calendar-like notions (HH:mm :ss . yyyy-MM-dd etc ... )
  
  sched.scheduleJob(jd, ct);
  sched.start(); 
 }


}


After running Services.java following result shown . CronTrigger expression (0 0/1 * * * ?) create a trigger that simply fires every 1 minutes -


Done :)

org.xml.sax.SAXParseException: Premature end of file



[Fatal Error] :1:1: Premature end of file.
org.xml.sax.SAXParseException: Premature end of file.
 at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:246)
 at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284)
 at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:124)
 at com.javastoreroom.source.XmlReader.readAllXML(XmlReader.java:60)
 at com.javastoreroom.source.XmlReader.execute(XmlReader.java:342)
 at org.quartz.core.JobRunShell.run(JobRunShell.java:191)
 at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:516)

When i am reading a hundred of .xml file using a thread , getting this error ([Fatal Error] :1:1: Premature end of file.)
i am google to known try few other correction (like close InputStream , Reset ) but getting again & again .When i try to
know the reason check my first test.xml file it's empty & create error here i am check file size (fXmlFile.length()>0) everything
works fine.

Hope this help you and save your some time :)