Thursday, August 20, 2009

The BASEDIR environment variable is not defined correctly

Tomcat Issue

The BASEDIR environment variable is not defined correctly
This environment variable is needed to run this program

This will occur due to using a copy of tomcat which is packed someone else.

The solution for this is go to the bin and change the mod into 777 of all .sh file.
chmod 777 *.sh

Saturday, July 18, 2009

How to convert string date into Date object.

How to convert string date into Date object.

Date date = getDate("18/07/2009 15:15:45");

private static Date getDate(String fullDate) throws ParseException {
          SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
          df.setLenient(false); return df.parse(fullDate);
}


Wednesday, July 15, 2009

Getting the IP Address of a Hostname

Getting the IP Address of a Hostname

        try {
                InetAddress addr = InetAddress.getByName("google.com");
                byte[] ipAddr = addr.getAddress();

                // Convert to dot representation
                String ipAddrStr = "";
                for (int i=0; i<ipAddr.length; i++) {
                    if (i > 0) {
                        ipAddrStr += ".";
                    }
                    ipAddrStr += ipAddr[i]&0xFF;
                }
            System.out.println("ipAddrStr = " + ipAddrStr);
            } catch (UnknownHostException e) {
            }

Wednesday, June 17, 2009

SVN: Merging a Branch into Trunk

Merge a Branch into Trunk

  1. Check out a copy of trunk:
    svn co svn+ssh://server/path/to/trunk
  2. Check out a copy of the branch you are going to merge:
    svn co svn+ssh://server/path/to/branch/myBranch
  3. Change your current working directory to "myBranch"
  4. Find the revision "myBranch" began at:
    svn log --stop-on-copy
    This should display back to you the changes that have been made back to the point the branch was cut. Remember that number (should be rXXXX, where XXXX is the revision number).
  5. Change your current working directory to trunk
  6. Perform an SVN update:
    svn up
    This will update your copy of trunk to the most recent version, and tell you the revision you are at. Make note of that number as well (should say "At revision YYYY" where YYYY is the second number you need to remember).
  7. Now we can perform an SVN merge:
    svn merge -rXXXX:YYYY svn+ssh://server/path/to/branch/myBranch
    This will put all updates into your current working directory for trunk.
  8. Resolve any conflicts that arose during the merge
  9. Check in the results:
    svn ci -m "MERGE myProject myBranch [XXXX]:[YYYY] into trunk"

That is it. You have now merged "myBranch" with trunk.

Friday, June 5, 2009

Java code base log apender

Create Log apender using java code.

This is a small example which use to log the text in different log files according to the shortcode provided.

    private void doLog(String shortCode, String text) {
        if (!loginBuffers.containsKey(shortCode)) {
            String fileName = shortCode + ".cdr";
            logger.info("Create cdr log for " + fileName);
            Logger smsLogger = Logger.getLogger("sms." + shortCode);
            DailyRollingFileAppender appender = new DailyRollingFileAppender();
            PatternLayout layout = new PatternLayout();
            layout.setConversionPattern(conversionPattern);
            appender.setDatePattern(appenderRollingDatePattern);
            appender.setLayout(layout);
            try {
                appender.setFile(path + File.separator + fileName, true, false, 1);
            } catch (IOException e) {
                logger.error("Can not create log file [" + path + File.separator + fileName + "]", e);
            }
            appender.setBufferedIO(false);
            appender.setImmediateFlush(true);
            appender.setBufferSize(1);  //4096
            appender.activateOptions();
            appender.setName("sms_" + shortCode);
            appender.setThreshold(Priority.INFO);
            smsLogger.addAppender(appender);
            loginBuffers.put(shortCode, smsLogger);
        }
        loginBuffers.get(shortCode).info(text);

        if (logger.isDebugEnabled()) {
            logger.debug("SMS is logged into " + loginBuffers.get(shortCode).getName());
        }
    }