Thursday, December 13, 2012

Negative seek offset error / Checksum validation fails

No comments:
Negative seek offset error / Checksum validation fails

If you face any of these issue , while using nexus with tomcat. Do not doubt the nexus, whose all versions are stable and works fine.

This is the issue with Tomcat. I faced this issue when i use tomcat apache-tomcat-7.0.28 with nexus.

I changed the nexus version from 1.9.2 to 2.3 and tried. Faced similar issue. and changed the tomcat to apache-tomcat-7.0.23 in which it works fine.

apache-tomcat-7.0.28 might have implemented new security mechanism. I didn't care about tomcat versions .  I go with tomcat-7.0.23. If you know the reason , update it. It might help others.


--
Thank you.


Regards,
Kaleeswaran.S

Read More

Thursday, November 29, 2012

Plist File Parsing Using Java

No comments:
Plist File Parsing Using Java

Below example illustrates , how to iterate over a plist file Nodes using apache's   XMLPropertyListConfiguration

  public void infoPlistConversion(String plistPath) throws Exception {
        XMLPropertyListConfiguration conf = new XMLPropertyListConfiguration(plistPath);
        System.out.println("root node children size => "+ conf.getRootNode().getChildrenCount());
        System.out.println("conf root => " + conf.getRootNode().getChild(0).getName());
        System.out.println("conf.getRoot().getChild(0).getValue() => " + conf.getRootNode().getChild(0).getValue());
        List children = conf.getRoot().getChildren();
        printChildrenValue(children);
    }
   
    private void printChildrenValue(List children) {
        if (children instanceof List) {
            List<PListNode> configs = (List<PListNode>) children;
            for (PListNode pListNode : configs) {
                // sub nodes
                if (pListNode.getValue() == null && pListNode.getChildrenCount() > 1) {
                    List pListNodeChildren = pListNode.getChildren();
                    System.out.println("-------------------------------------------------");
                    System.out.println("plist Name root => "+ pListNode.getName());
                    printChildrenValue(pListNodeChildren);
                // just print values
                } else {
                    // if it is ConfigParam and elements are not null
                    System.out.println("plist Name => "+ pListNode.getName());
                    System.out.println("plist Value => "+ pListNode.getValue());
                }
            }
        }
    }

--
Thank you.


Regards,
Kaleeswaran.S

Read More

Monday, October 29, 2012

Tomcat Maven Plugin Remote Debugging using Eclipse

No comments:
I am developing a maven based web application. i am running the application with tomcat maven plugin like

mvn tomcat:run

I want to debug the application from eclipse.

Step 1:
export MAVEN_OPTS="-Xmx512M -XX:MaxPermSize=512m" which allocates 512 MB of memory.

Step 2:
export MAVEN_OPTS="-agentlib:jdwp=transport=dt_socket,address=2480,server=y,suspend=n"
Step 3:

run the application like mvn tomcat:run

step 4:

connect to port 2480 in eclipse remote debugging.

Enjoy. Happy Debugging.
--
Thank you.


Regards,
Kaleeswaran.S

Read More

Thursday, August 16, 2012

Jdom CRUD Operations

No comments:
Hi,

Jdom CRUD Operations

Here is sample code to do some operations like
   
//Adding elements
    public void addElementAtXpath() {
        try {
            XPath xpath = XPath.newInstance("publishers");
            xpath.addNamespace(root_.getNamespace());
            Element publisherNode = (Element) xpath.selectSingleNode(root_);
            org.jdom.Element element = new Element("kalees");
            element.addContent(createElement(CI_FILE_RELEASE_OVERRIDE_AUTH_NODE, TRUE));
            publisherNode.addContent(element);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
   
// Changing attributes
    public void changeAttributeValue() {
        try {
            XPath xpath = XPath.newInstance("scm");
            xpath.addNamespace(root_.getNamespace());
            Element scmNode = (Element) xpath.selectSingleNode(root_);
            scmNode.setAttribute("class", "Kalees");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
   
//Deleting Elements
    public void deleteElementAtXpath() {
        //deleting a node...
        // deleting content of a node
        //triggerNode.removeContent();
        try {
            String childName = "hudson.plugins.emailext.ExtendedEmailPublisher";
            XPath xpath = XPath.newInstance("publishers");
            xpath.addNamespace(root_.getNamespace());
            Element triggerNode = (Element) xpath.selectSingleNode(root_); // if it is null then element is not present
            triggerNode.removeChild(childName);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static Element createElement(String nodeName, String NodeValue) {
        org.jdom.Element element = new Element(nodeName);
        if (NodeValue != null) {
            element.addContent(NodeValue);
        }
        return element;
    }
--
Thank you.


Regards,
Kaleeswaran.S

Read More

Wednesday, August 8, 2012

Eclisep Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at java.util.Arrays.copyOf

No comments:
Eclisep Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at java.util.Arrays.copyOf

If you face this issue in eclipse while running a standalone java application. Eclipse will allocate only 384 MB of Java heap memory. based on the type of JRE you are using and eclipse plugin and application size, this issue occurs. we have to increase heap memory size. To increase the available heap memory, right click your java progrram click "run as -> run configurations" . click argument tab and type -Xms1024M -Xmx1024M in VM arguments field. This increases VM size while running from eclipse.





--
Thank you.


Regards,
Kaleeswaran.S

Read More

Thursday, August 2, 2012

JDOM - How to insert an element, after another

No comments:

JDOM - How to insert an element, after another

    private Document document_ = null;
    private Element root_ = null;

    @Test
    public void generateXml() {
        //Url path of the file
        String filePath = "http://172.................. .xml";
        testXmlGeneration(filePath);
    }
   
    private void testXmlGeneration(String url) {
        try {
            SAXBuilder builder = new SAXBuilder();
            // giving xml file url to jdom for parsing
            document_ = builder.build(url);
            root_ = document_.getRootElement();

            // creating necessary elements which is to be appended at a particular point of the location in xml
            org.jdom.Element element = new Element("release");
            element.addContent(createElement("override", "true"));
            element.addContent(createElement("url", "http://outside.out.coml"));
            element.addContent(createElement("username", "kaleeswaran"));
            element.addContent(createElement("password", "xm0QczqM6k9x10Os1z0k="));
            element.addContent(createElement("rpackage", "PackageRed"));
            element.addContent(createElement("release", "release"));
            element.addContent(createElement("file__patterns", null).addContent(createElement("hudson.plugins.collabnet.documentuploader.FilePattern", "*.zip")));
           
            // i want to add the generated elements after the publish tag in the xml
            XPath xpath = XPath.newInstance("publish");
            xpath.addNamespace(root_.getNamespace());
            Element pullisherNode = (Element) xpath.selectSingleNode(root_);
            // here specify the index value where the element should be added and pass the element
            pullisherNode.getContent().add(3, element);

           
           
            File dest = new File("/Users/kaleeswaran/Desktop/gonfig.xml");
            InputStream configAsStream = getConfigAsStream();
            ciManager.streamToFile(dest, configAsStream) ;
            System.out.println("new value added =======> " + url);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
   
    public static Element createElement(String nodeName, String NodeValue) {
        org.jdom.Element element = new Element(nodeName);
        if (NodeValue != null) {
            element.addContent(NodeValue);
        }
        return element;
    }
   
    public InputStream getConfigAsStream() throws IOException {
        XMLOutputter xmlOutput = new XMLOutputter();
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        xmlOutput.output(document_, outputStream);
       
        return new ByteArrayInputStream(outputStream.toByteArray());
    }
--
Thank you.


Regards,
Kaleeswaran.S

Read More

Wednesday, June 27, 2012

Convert Java Objects to / from JSON using Gson

No comments:
Here is the example code which will give you the overview of gson

package com.file;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

public class gsonObjectTry {

    Gson gson = new Gson();
   
    public static void main(String[] args) {
        List<Student> students = new ArrayList<Student>();
        students.add(new Student("kalees", "24", "e3084"));
        students.add(new Student("muthu", "25", "e3085"));
        new gsonObjectTry().createStudents(students);
//        new gsonObjectTry().addStudent(new Student("newStudent", "25", "e3085"));
//        new gsonObjectTry().deleteStudent(Arrays.asList(new Student("muthu", "25", "e3085")));
        new gsonObjectTry().updateStudent(Arrays.asList(new Student("muthu", "25", "e9999")));
       
//        new gsonObjectTry().addNewStudent(new Student("new Student", "25", "e1111"));
    }
   
    public void createStudents(List<Student> students) {
        try {
            //write converted json data to a file named "file.json"
            File gsonFile = new File("/Users/kaleeswaran/Tried/gsonExample.json");
            FileWriter writer = new FileWriter(gsonFile);
             Gson gson = new Gson();
             String jobJson = gson.toJson(students);
             writer = new FileWriter(gsonFile);
             writer.write(jobJson);
             writer.flush();
             System.out.println("Students created successfully");
        } catch (IOException e) {
            System.out.println("createStudents failed");
            e.printStackTrace();
        }
    }
   
    // normally added newly
    public void addStudent(Student student) {
        try {
            //write converted json data to a file named "file.json"
            File gsonFile = new File("/Users/kaleeswaran/Tried/gsonExample.json");
            FileWriter writer = new FileWriter(gsonFile);
             Gson gson = new Gson();
             String jobJson = gson.toJson(student);
             writer = new FileWriter(gsonFile);
             writer.write(jobJson);
             writer.flush();
             System.out.println("Student created successfully");
        } catch (IOException e) {
            System.out.println("createStudents failed");
            e.printStackTrace();
        }
    }
   
    public void addNewStudent(Student student) {
        try {
            List<Student> students = null;
             BufferedReader bufferedReader = new BufferedReader(new FileReader("/Users/kaleeswaran/Tried/gsonExample.json"));
             Gson gson = new Gson();
             Type type = new TypeToken<List<Student>>(){}.getType();

             students = gson.fromJson(bufferedReader, type);
             bufferedReader.close();
            //write converted json data to a file named "file.json"
            File gsonFile = new File("/Users/kaleeswaran/Tried/gsonExample.json");
            FileWriter writer = new FileWriter(gsonFile);
           
            students.add(student);
             String jobJson = gson.toJson(students);
             writer = new FileWriter(gsonFile);
             writer.write(jobJson);
             writer.flush();
             System.out.println("Student created successfully");
        } catch (IOException e) {
            System.out.println("createStudents failed");
            e.printStackTrace();
        }
    }
   
    //build
    public void deleteStudent(List<Student> deleteStudent) {
        List<Student> students = null;
        try {
             BufferedReader bufferedReader = new BufferedReader(new FileReader("/Users/kaleeswaran/Tried/gsonExample.json"));
             Gson gson = new Gson();
             Type type = new TypeToken<List<Student>>(){}.getType();

             students = gson.fromJson(bufferedReader, type);
             bufferedReader.close();
           
            //all values
             Iterator<Student> iterator = students.iterator();
            //deleteable values
             for (Student selectedInfo : deleteStudent) {
                 while (iterator.hasNext()) {
                     Student itrStudent = iterator.next();
                     System.out.println("itrStudent.getName() ======> " + itrStudent.getName());
                     System.out.println("selectedInfo.getName() ======> " + selectedInfo.getName());
                     if (itrStudent.getName().equals(selectedInfo.getName())) {
                         iterator.remove();
                         break;
                     }
                 }
             }
        } catch (Exception e) {
            System.out.println("Student removing failed");
        }
       
         //write back to file
        try {
            //write converted json data to a file named "file.json"
            File gsonFile = new File("/Users/kaleeswaran/Tried/gsonExample.json");
            FileWriter writer = new FileWriter(gsonFile);
             String studentsJson = gson.toJson(students);
             writer = new FileWriter(gsonFile);
             writer.write(studentsJson);
             writer.flush();
             System.out.println("Student deleted successfully");
        } catch (IOException e) {
            System.out.println("delete Student failed");
            e.printStackTrace();
        }
    }
   
    public void updateStudent(List<Student> updateStudent) {
        List<Student> students = null;
        try {
             BufferedReader bufferedReader = new BufferedReader(new FileReader("/Users/kaleeswaran/Tried/gsonExample.json"));
             Gson gson = new Gson();
             Type type = new TypeToken<List<Student>>(){}.getType();

             students = gson.fromJson(bufferedReader, type);
             bufferedReader.close();
           
            //all values
             Iterator<Student> iterator = students.iterator();
            //deleteable values
             for (Student selectedInfo : updateStudent) {
                 while (iterator.hasNext()) {
                     Student itrStudent = iterator.next();
                     System.out.println("itrStudent.getName() ======> " + itrStudent.getName());
                     System.out.println("selectedInfo.getName() ======> " + selectedInfo.getName());
                     if (itrStudent.getName().equals(selectedInfo.getName())) {
                         iterator.remove();
                         break;
                     }
                 }
             }
             students.addAll(updateStudent);
        } catch (Exception e) {
            System.out.println("Student updating failed");
        }
       
         //write back to file
//         String studentsInfoJson = gson.toJson(students);
        try {
            //write converted json data to a file named "file.json"
            File gsonFile = new File("/Users/kaleeswaran/Tried/gsonExample.json");
            FileWriter writer = new FileWriter(gsonFile);
             String studentsJson = gson.toJson(students);
             writer = new FileWriter(gsonFile);
             writer.write(studentsJson);
             writer.flush();
             System.out.println("Student updated successfully");
        } catch (IOException e) {
            System.out.println("delete updated failed");
            e.printStackTrace();
        }
    }

}

class Student {
    private String name;
    private String age;
    private String empNo;
   
    public Student(String name, String age, String empNo) {
        this.name = name;
        this.age = age;
        this.empNo = empNo;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getAge() {
        return age;
    }
    public void setAge(String age) {
        this.age = age;
    }
    public String getEmpNo() {
        return empNo;
    }
    public void setEmpNo(String empNo) {
        this.empNo = empNo;
    }
   
}


--
Thank you.


Regards,
Kaleeswaran.S

Read More

Thursday, May 24, 2012

Compile Jasper reports with Maven Plugin

2 comments:
jasperreports-maven-plugin is a plugin which is used to convert all the jrxml files(Designed templtes) to .jasper files.
  
 <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jasperreports-maven-plugin</artifactId>
                <version>1.0-beta-2</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile-reports</goal>
                        </goals>
                        <configuration>
                            <!--  jrxml file  directory-->
                            <sourceDirectory>src\\main\\resources\\reports\\template</sourceDirectory>
                            <sourceFileExt>.jrxml</sourceFileExt>
                            <compiler>net.sf.jasperreports.engine.design.JRJavacCompiler</compiler>
                            <!--  Destination for jasper file -->
                            <outputDirectory>src\\main\\resources\\reports\\jasper</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
                <dependencies>
                    <!-- These plugins are used to specify correct version for jrxml xml validation -->
                    <dependency>
                        <groupId>net.sf.jasperreports</groupId>
                        <artifactId>jasperreports</artifactId>
                        <version>4.5.0</version>
                    </dependency>
                   
                    <dependency>
                        <groupId>log4j</groupId>
                        <artifactId>log4j</artifactId>
                        <version>1.2.16</version>
                    </dependency>

       
                </dependencies>
            </plugin>

        </plugins>
    </build>

Add it in pom.xml. This is will do the compilation.

Regards,
Kaleeswaran.S

Read More

Friday, January 20, 2012

JMeter Calculation

3 comments:


Throughput Calculation In JMeter

  1. select a label name in result.xml which is generated by jmeter
  2. search the min (timestamp(ts)) for corresponding labels
  3. search the max (timestamp (ts)  + elapsed time (t)) for  corresponding labels.
  4. calculate the difference between max and min 
  5. calculate Throughput= (number of samples/ difference between max and min) * 1000  



  1. select a label name(Register) in result.xml which is generated by jmeter
  2. search the min (timestamp(ts)) 1327038233281 in result.xml
  3. search the max (timestamp (ts)  + elapsed time (t)) 1327038233781 + 47.
  4. calculate the difference between max and min (1327038233828 -  1327038233281  )..  Diff ===> 547
  5. calculate Throughput= (number of samples/ difference between max and min) * 1000 (2/547) ... Result is.. 3.656307129798903107861060329067
  6. Round the Final throughput value.
ThroughPut  = (No of sample / (max(ts + t) - min(ts)) )
Standard Deviation Calculation in JMeter

standard devaiation(SD) =
x = particular label's t(Time)
x_(x bar) = some of all time(T) of specific label / no of samples

No of samples specifies = number of occurrence of a label in xml file(No of hits of a label)

KB/SEC Calculation in JMeter

kb/sec = (avg bytes /1024) * through put

Avg bytes = avg bytes of specific label bytes (by).

Total Calculation in JMeter

When calculating total row values for jmeter we should not consider labels. Instead of that we have consider the whole xml file as data and we have to use the above formula to calculate it. Don't consider labels. In whole xml take max ts value and min ts and proceed and no of samples
(Total occurrence of all labels). for throughput.


For Standard deviation don't consider labels. Take whole xml.

xBar(x_) = sumOfTime(t) / totalNoOfSamples;
for (Integer time(t) : allTimes) {
    // for each time we have to find this value
    sumOfMean += Math.pow(time(t) - xBar(x_), 2);
}


Final calculation : 

 sqrt(sumOfMean / getNoOfSamples());

For KB/SEC calculation  , don't consider labels , take all by values in xml file.

For Total row calculation formula is same but the only difference is , don't consider labels. Otherwise same.

Happy Coding :).

--
Thanks.
Chelladurai.

Regards,
Kaleeswaran.S

Read More