Posts

Showing posts with the label Java

JMeter SSH Sampler

https://github.com/linkeshkanna/Jmeter.SSH.FTP.Request Jmeter Custom Sampler to make SFTP Request To Create SSH FTP Requests in JMeter, we need this custom Sampler. This contains two jar files. 1. jmeter-ssh-sampler-1.0.2-SNAPSHOT.jar 2. jsch-0.1.53.jar We can generate this by downloading the source and building it using Maven. I just built it using maven and checked in the jar files here. To install this in Jmeter, 1. Copy the jmeter-ssh-sampler-1.0.2-SNAPSHOT.jar to the "Jmeter/Lib/ext" directory. 2. Copy the "jsch-0.1.53.jar" to the "Jmeter/Lib" directory 3. Restart Jmeter. I have also added a sample test to list of the directory contents in a Public SFTP Server.

XML To JSON Converter

Have the following jars in the classpath,  commons-beanutils-1.6.1.jar  commons-collections-3.2.jar  commons-lang-2.1.jar  commons-logging-1.1.jar  ezmorph-1.0.4.jar  json-lib-2.3-jdk15.jar  xom-1.0.jar import net.sf.json.JSON; import net.sf.json.xml.XMLSerializer; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; public class XML2JSONConverter {     public String convertXMLTOJSON(String inputXML) {         String jsonString = "";         try {             JSON objJson = new XMLSerializer().read(inputXML);             jsonString = objJson.toString();         } catch (Exception e) {             e.printStackTrace();         }         return jsonString;     }     static String co...

Java InputStream to String Covertion

Found this small method to convert InputStream to String, This will help to avoid using Apache IOUtils etc.,  static String convertStreamToString(java.io.InputStream is) {         java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");         return s.hasNext() ? s.next() : "";     }

java.lang.Out OfMemoryError

Unveiling the java.lang.Out OfMemoryError — When we encounter a java.lang.OutOfMemoryError, we often find that Java heap dumps, along with other artifacts, are generated by the Java Virtual Machine. If you feel like jumping right into a Java heap dump when you get a java.lang.OutOfMemoryError, don’t worry, it’s a normal thought. You may be able to discover something serendipitously, but it’s not always the best idea to analyze Java heap dumps, depending on the situation you are facing. We first need to investigate the root cause of the java.lang.OutOfMemoryError. http://java.sys-con.com/node/1229281

XPath Builder Tool

A cool XPath builder tool, I liked it, http://www.bubasoft.net/Product/XpathBuilder

Offset for given Time Zone

import java.util.TimeZone; public String getTimeZoneOffSet(String timeZoneID) {         TimeZone tz = TimeZone.getTimeZone(timeZoneID);         int rawOffset = tz.getRawOffset();         int hour = rawOffset / (60 * 60 * 1000);         int minute = Math.abs(rawOffset / (60 * 1000)) % 60;         return hour + ":" + minute;     } Test:  tc.getTimeZoneOffSet("America/New_York")); This returns Offset for NY -->-5:0 Using Calendar Class import java.util.Calendar ; public int getOffsetForTimeZone(String timeZoneId) {         int a;         Calendar calendar = new GregorianCalendar();         TimeZone timeZ = calendar.getTimeZone();         ti...

opencsv - Flat File Parser

I was looking for a open source flat file parser in java and found opencsv http://opencsv.sourceforge.net/ . A very clean and easy to use java utility. Would recommend this for any one who looking for flat file parser.

Wiring Your Web Application with Open Source Java - O'Reilly Media

Wiring Your Web Application with Open Source Java - O'Reilly Media

Tomcat Clustering

http://www.easywayserver.com/implementation-tomcat-clustering.htm

Open Source Load Balancing Softwares

Nice post about LB softwares and I found this on a good blog http://linuxpoison.blogspot. com/  Linux Virtual Server The Linux Virtual Server Project is a project to cluster many real servers together into a highly available, high- performance virtual server. The LVS load balancer handles connections from clients and passes them on the the real servers (so-called Layer 4 switching) and can virtualize almost any TCP or UDP service, like HTTP, HTTPS, NNTP, FTP, DNS, ssh, POP3, IMAP4, SMTP, etc. It is fully transparent to the client accessing the virtual service. Homepage: http://www.LinuxVirtualServer.org/ BalanceNG BalanceNG is a modern software IP load balancing solution. It is small, fast, and easy to use and setup. It offers session persistence, different distribution methods (Round Robin, Random, Weighted Random, Least Session, Least Bandwidth, Hash, Agent, and Randomized Agent) and a customizable UDP health check agent in source code. It supports VRRP to set up hi...

Hibernate Connection Fails if there is Database inconsistency or DB fail-over (Oracle RAC)

        /**      * A static method with returns Hibernate Sessoin Object.      *      * @return {@link Session}      */     public static Session getSession() throws HibernateException {         Session appSession = sessionFactory .openSession();         try         {                 if (appSession.connection().isClosed()||!appSession.isConnected()||!appSession.isOpen()){                         System. out .println( "Session Closed, Creating Session again..." );                  ...

Modifying the JVM heap size Formula

  The total value of all server JVM heap sizes within the dynamic cluster for a specific node must be less than half of the total RAM of that computer. To determine the maximum heap size setting for a single server instance, use the following equation: total_RAM / 2 / number_of_servers = maximum_heap_size For example, to support three servers on a machine with 1.5 GB of RAM: 1.5 GB / 2 = 750 MB 750 MB / 3 = 250 MB The maximum heap size is 250 MB for each server instance.

Applets are not running on Internet Explorer 7.0

I think there was an issue with applets on Internet Explorer 7.0. When I tried to run some applets on my windows 2003 server (SP2) box with IE 7.0 and JDK 1.5 version I could not able to load applets on my browser. I tried in almost all known ways by enabling applets through browser setting Tools -->Advanced and from java console (control panel --> java console --> Advanced) but no luck finally I thought to uninstall the java and reinstall it again and did the same but still no luck so finally I have installed lower version of Internet Explorer version 6.0 and it started working... I think IE 7.0 has some issues still. But IE 7.0 has got some pros and cons as per my limited usage experience... Pros: Rich look and feel Tabbed browsing Implemented Add-on concept as Mozilla Firefox had. Cons: Though you enable Add-ons still browser through you message that you have not enabled add-on facility which really frustrates. As I told Applet issue. When we say Add-on user will easily se...

Error Reporting through E-Mail using Log4j (SMTPAppender Class)

This could be one of the cool thing if you get an intimation through an email when ever your application is facing the problem in production or test environments apart from this you get log file as well so we can decrees the turn around time some what in fixing and issue and making your environment up. A few months back I have implemented the same thing for one of our production application and I have used log4j for logging and emailing the log file when ever log file get populated with error level messages. In log4j api we have one class called SMTPAppender which will email us our log file when ever log file is populated with error level message. Just needs to configure log4j properties file with all SMTP server details. Note: Make sure that you should have mail.jar and activation.jar files in your class path. log4j.properties: log4j.rootLogger=INFO, filer ,SMTPTest log4j.appender.filer=org.apache.log4j.RollingFileAppender log4j.appender.filer.layout=org.apache.log4j.PatternLayout lo...

http://www.java-tips.org/ - A Good site for a real quick help in java

A very useful and good site for basic things for a quick review for basic and advanced java stuff. http://www.java-tips.org/

Execute .sql script file using java

A few days back I tried to execute our database scripts file using java in a plain way but I am not sure how good it is? but I am done with my work with no known issues but still I'm thinking is that right way to parse entair .sql file and pass the each line to JDBC API and ask JDBC API to execute that line of SQL? Here it is the method I used... public boolean executeDBScripts(String aSQLScriptFilePath, Statement stmt) throws IOException,SQLException { boolean isScriptExecuted = false; try { BufferedReader in = new BufferedReader(new FileReader(aSQLScriptFilePath)); String str;StringBuffer sb = new StringBuffer(); while ((str = in.readLine()) != null) { sb.append(str + "\n "); } in.close(); stmt.executeUpdate(sb.toString()); isScriptExecuted = true; } catch (Exception e) { System.err.println("Failed to Execute" + aSQLScriptFilePath +". The er...