Tuesday, April 7, 2015

Updating Confluence page using Rest API

Context: Recently one of our Linux administrator requested us to provide an API to update atlassian wiki(confluence) in an automated way through some of their script(script will generate an output file - According to atlassian wiki storage format and pass that output file as confluence content). I did google to see any one has already created a REST API based, but I didn't find. so created this module and sharing with other people. 


Modules dependency: 
MIME::Base64, REST::Client and JSON

Steps:

  • Copy the below perl module(REST.pm) in the perl library path(folder hierarchy should be <perl_lib>/Confluence/Client/REST.pm
  • Code to update the page:



 

Wednesday, May 28, 2014

Debugging the tomcat startup error messages - "SEVERE: Error listenerStart"

Today I was trying to deploy one of my web applications in the test server, tomcat was simply throwing this exception:

SEVERE: Error listenerStart

This exception occurs when an exception is thrown in the contextInitialized method of a ServletContextListener. Unfortunately by default, tomcat won't provide you with any details about the cause of the error. Infact it wont even tell you which listener is failing. This can be big problem in applications of significant size that have many listeners configured. Fortunately there is a solution. In your webapplication's WEB-INF/classes folder you can create a logging.properties file with the following contents

org.apache.catalina.core.ContainerBase.[Catalina].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].handlers = java.util.logging.ConsoleHandler


Now you will be presented with the stacktrace

 

Wednesday, August 21, 2013

Working with H2 database

 H2 is Java SQL database. It helps during development and testing of Java/JEE applications. It can act as in-momory database or as storing physically. The following are main features of this database:
  • Very fast, open source, JDBC API
  • Embedded and server modes; in-memory databases
  • Browser based Console application
  • Small footprint: around 1.5 MB jar file size
How to use in my Java/JEE app?

Define following dependency in the pom.xml
 Define the datasource bean definition:

<bean id="jpaDataSource"  class="org.springframework.jdbc.datasource.DriverManagerDataSource">
      <property name="driverClassName" value="org.h2.Driver" />
      <property name="url" value="jdbc:h2:~/foo_db;DB_CLOSE_DELAY=-1" />
</bean>



Use the following hibernate dialect(if your app is using hibernate as entity manager)

org.hibernate.dialect.H2Dialect

You are all set to use this database.

Where the database files are stored?

When using database URLs like jdbc:h2:~/test, the database is stored in the user directory. For Windows, this is usually C:\Documents and Settings\<userName> or C:\Users\<userName>. If the base directory is not set (as in jdbc:h2:test), the database files are stored in the directory where the application is started (the current working directory). When using the H2 Console application from the start menu, this is <Installation Directory>/bin. The base directory can be set in the database URL. A fixed or relative path can be used. When using the URL jdbc:h2:file:data/sample, the database is stored in the directory data (relative to the current working directory). The directory is created automatically if it does not yet exist. It is also possible to use the fully qualified directory name (and for Windows, drive name). Example: jdbc:h2:file:C:/data/test

Monday, March 19, 2012

How to make Derby DB listen to client requests that originate from both localhost and from other machines on the network?

While start a server, you have to pass additional param -h with IP address to access the db other than localhost.


java org.apache.derby.drda.NetworkServerControl start -h 0.0.0.0


A server that is started with the -h 0.0.0.0 option will listen to client requests that originate from both localhost and from other machines on the network.

However, administrative commands (for example, org.apache.derby.drda.NetworkServerControl shutdown) can run only on the host where the server was started, even if the server was started with the -h option.

Friday, March 16, 2012

Java Compilation error: unmappable character for encoding UTF-8

Some times we add java documentation & stuff through Eclipse or some text editor which might be causing a compilation error(unmappable character for encoding UTF-8). It can be solved using the <encoding> tag in the compiler plugin.

Thursday, September 22, 2011

Maven: Exclude a specific module's artifact deployment during deploy phase

There are cases, we might be intested to exclude some of the module's artifact upload to remote repository during deployment phase. This can be achieved through the maven-deploy-plugin. Here is an example:
Upon including the above plugin, you should see the following after running mvn deploy in your build output:
[INFO] [deploy:deploy]
[INFO]  skipping artifact deployement
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------

Thursday, June 30, 2011

3 litres and 5 litres containers puzzle

Puzzle: You have two container - one can contain exactly 3 litres of water and the other can contain exactly 5 litres of water. How many minimum steps will you take to get exactly 4 litres of water without using any other container? You can assume the availability of sufficient quantity of water.

Solution: Find below the steps:-
Step #1: fill the 5 litres container (3L - 0, 5L - 5)
Step #2: fill the 3 litres container with the filled 5 litres container (3L - 3, 5L - 2)
Step #3: empty the just filled 3 litres container (3L -0, 5L - 2)
Step #4: transfer the 2 litres of water left in 5 litres container into 3 litres container (3L - 2, 5L - 0)
Step #5: fill the 5 litres container (3L - 2, 5L - 5)
Step #6: fill the 3 litres container (having 2L currently) using just filled 5 litres container (3L - 3, 5L - 4)

So in a minimum of 6 steps you get exactly 4L of water in the 5 litres container.

Friday, June 10, 2011

Java - Sonar: Fix for "POM 'org.codehaus.mojo:sonar-maven-plugin' not found in repository"

This posting is meant for Java developers who has configured the code quality/metrics tool sonar and if it throws "Reason: POM 'org.codehaus.mojo:sonar-maven-plugin' not found in repository: Unable to download the artifact from any repository " while executing "mvn sonar:sonar" to publish the code quality metrics.

Reason for failure: This issue is related to maven. You can read about the actual issue here.

Fix: I'd recommend multiple work-around and try which ever works for you.

1. Try this command : 'mvn -U sonar:sonar' - This will update the local repo files. [OR]


2. Goto your Maven repo home and delete 'mojo' folder from org/codehaus/mojo(in windows:C:\Documents and Settings\\.m2\repository\org\codehaus\mojo) and rerun the sonar(mvn sonar:sonar). [OR]

3. Add the following plugin into your pom.xml and it will solve the issue(In the below code, you can provide the version you are interested in. You may go to Maven local repo and this file :org\codehaus\mojo\sonar-maven-plugin\maven-metadata-central.xml and see the version you are interested in).
        <plugin>
<groupid>org.codehaus.mojo</groupid>
<artifactid>sonar-maven-plugin</artifactid>
<version>1.0-beta-2</version>
</plugin>




Below is the exception message thrown while executing maven.

Project ID: org.codehaus.mojo:sonar-maven-plugin
Reason: POM 'org.codehaus.mojo:sonar-maven-plugin' not found in repository: Unable to download the artifact from any repository
org.codehaus.mojo:sonar-maven-plugin:pom:2.0-SNAPSHOT
from the specified remote repositories:
central (http://repo1.maven.org/maven2)
for project org.codehaus.mojo:sonar-maven-plugin
[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.lifecycle.LifecycleExecutionException: Unable to build project information for plugin 'org.codehaus.mojo:sonar-maven-plugin': POM 'org.codehaus.mojo:sonar-maven-plugin' not found in repository: Unable to download the artifact from any repository
org.codehaus.mojo:sonar-maven-plugin:pom:2.0-SNAPSHOT
from the specified remote repositories:
central (http://repo1.maven.org/maven2)

for project org.codehaus.mojo:sonar-maven-plugin
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.verifyPlugin(DefaultLifecycleExecutor.java:1557)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.getMojoDescriptor(DefaultLifecycleExecutor.java:1851)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.segmentTaskListByAggregationNeeds(DefaultLifecycleExecutor.java:462)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:175)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.InvalidPluginException: Unable to build project information for plugin 'org.codehaus.mojo:sonar-maven-plugin': POM 'org.codehaus.mojo:sonar-maven-plugin' not found in repository: Unable to download the artifact from any repository

 

Wednesday, April 13, 2011

File manipulation - Recursively (including subdirectories)

Some times you may want to manipulate particular file pattern from the current directory and all it's sub-directories. Here, I've demonstrated how to loop through the .txt file then display them using echo then delete it. Likewise, you can manipulate them inside loop.


echo off
rem ********************************************************************
rem * *
rem * Author: Raghunathan K Semburakkiannan *
rem * *
rem ********************************************************************


echo ~~~~~~~~~~~ List of files ~~~~~~~~~~~
echo.
pushd .
for /F "tokens=*" %%i in ('dir /s /b *.txt') do (
echo %%i
del %%i
)
popd
echo.
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo.
echo.
pause

Thursday, January 6, 2011

Sum of numbers until single digit

When you buy a vehicle in india the registration number assignment for the vehicle will stay for ever(per my knowledge, not sure if there any way to change the number some time later). Always people prefer and think certain numbers(sum of numbers until signle digit) are considered to be auspicious. So they usually say, I want a number 9 or 3 or 1 etc.(between 0 to 9).

If you pay some money, Motor registry office will provide you 1000 numbers(like choose number between 853 to 1852) and you can choose one number from that 1000 numbers(there is a possibility that some number might have taken already with in that 1000. So you have to keep telling your favorite numbers and choose the one available in that).

I also ran into this situation and want to choose the lucky number 9. It's hard to list all numbers its sum is 9. So I wrote a small Java program where you can specify the lucky number, starting number and end number, it will print out all the numbers matching you lucky number. I thought it might be useful for some of you, so putting this program in blog.


public class VehicleLuckyNumber {
final static int LUCKY_NUMBER = 9;
final static int STARTING_NUMBER = 853;
final static int END_NUMBER = 1852;

public static void main(String[] args) {
int count=0;
for (int i=STARTING_NUMBER;i<= END_NUMBER; i++) {
if (sumValue(i)== LUCKY_NUMBER){
System.out.println(i);
count+=1;
}
}
System.out.println("Total count in lucky number("+LUCKY_NUMBER+") :"+count);

}

public static int sumValue(int number){
int sum = 0;
int digit = 0;
while(number > 0){
digit = number%10;
sum += digit;
number = number/10;
}
if (sum > 10) sum = sumValue(sum);
return sum;
}
}

Tuesday, September 14, 2010

How to Resize All Window Columns with a Single Keystroke

When you’re dealing with an application that displays data in a set of columns, it’s often frustrating to have to resize each column separately—but today we’ve got a great trick for you that resizes all the columns with a single keystroke.

The secret keystroke to use is Ctrl and the Numpad’s + key, and it only works if you have a separate number pad on your PC.

Monday, August 23, 2010

Working with 'vi' editor

People who use Linux/Unix as their OS should have used the vi editor. This editor is more powerful editor I've seen ever. I'm here with listing some basic & important 'vi' commands which needed to do file manipulation/editing.

Save & Exit:

:x --> quit vi, writing out modified file to file named in original invocation
:x --> quit vi, writing out modified file to file named in original invocation
:wq --> quit vi, writing out modified file to file named in original invocation
:q --> quit (or exit) vi
:q! --> quit vi even though latest changes have not been saved for this vi call

Screen manipulation:

^f -->move forward one screen
^b -->move backward one screen
^d -->move down (forward) one half screen
^u -->move up (back) one half screen

Working with Multiple files:

To open multiple files:

$vi main.pl maintenance.pl

To hop between them:

:n --> Next file
:prev --> Previous file
:args --> To see which are the files open.

Tuesday, August 17, 2010

Ctrl+V for Pasting in the Windows Command Prompt

1. Install AutoHotkey

2. Save the following code as PasteCommandPrompt.ahk

#IfWinActive ahk_class ConsoleWindowClass
^V::
SendInput {Raw}%clipboard%
return
#IfWinActive



3. Double click PasteCommandPrompt.ahk file. Now you all set. You can apply Ctrl + V in command window.

Tuesday, June 8, 2010

Eclipse IDE tips

Often I hate with Eclipse editor is, switching between editor. I mean if you have multiple java files opened with eclipse one way to switch between 'next files' using default shortcut 'CTRL + F6'. To do that ideally you have to use your both hand to handle it. I mean F6 key is all the way up on the top where as CTRL key is all the way down to the keyboard.



You can change this default behaviour and make it 'CTRL + Tab' like other windows application. To do that make a 'Binding' for the command Next Editor under Window > Preferences > General > Keys.



After changing this, you can pretty much switch between files easily with your left hand.



I'd ask every programmer to think all these kind of small small things to make their life better.

Friday, May 14, 2010

Screen capture - Java

This might be very helpful for GUI developer in java. At times its hard to figureout the some error happens in the user end. I mean, End user usually just complain that while clicking so and so button or tab or something it failed. In those cases if you have users screen, you can guess something. To do that, you can make the following code as an API and store screen shot in your log location and you can verify them later.

License key generator for Java applications (free)

Just a quick note that if you happen to be looking for a license key generator (or "license key manager") for a Java desktop (Swing) application, I've been taking a look at the TrueLicense library on java.net, and although it is several years old now, it seems to work well, and the author certainly put a lot of time and thought into it.

As a word of caution, I did find the author's tutorial difficult to read, so I highly recommend looking at an introductory doc written by Martin Paulo. (Just search for his name on the TrueLicense homepage and you'll find a link to that doc.) After reading that doc, the author's tutorial made more sense to me.

I don't know how many people need a Java license key generator, but if you're in the market for one, and "free" (or donation-ware) is your right price, I recommend taking a look at the TrueLicense license key generator for Java applications.

Java Store update

In a related note, the "Java Store" is still in beta. If you haven't heard of it before, the Java Store "is an application storefront that provides an easy and secure way to discover Java applications for your desktop." I don't know what they're doing for software licensing and license management, but I thought I'd mention this "store" again here today. I appreciate what they're doing, I just wish this was available a long, long time ago.

Friday, May 7, 2010

Personalize your windows command prompt

Some times you may want to customize your windows command prompt to display font color differently. I mean instead of white color font with black back groud color, you may want to display them in red color font or something else. Typically people go to window properties and choose the color. Instead you can achieve through DOS command. This is not just for a fun always, it might be useful to have unique color for the batch file/app you write to do some tasks.

Here is the help information:


C:\workspace\perl>color /h
Sets the default console foreground and background colors.

COLOR [attr]

attr Specifies color attribute of console output

Color attributes are specified by TWO hex digits -- the first
corresponds to the background; the second the foreground. Each digit
can be any of the following values:

0 = Black 8 = Gray
1 = Blue 9 = Light Blue
2 = Green A = Light Green
3 = Aqua B = Light Aqua
4 = Red C = Light Red
5 = Purple D = Light Purple
6 = Yellow E = Light Yellow
7 = White F = Bright White

If no argument is given, this command restores the color to what it was
when CMD.EXE started. This value either comes from the current console
window, the /T command line switch or from the DefaultColor registry
value.

The COLOR command sets ERRORLEVEL to 1 if an attempt is made to execute
the COLOR command with a foreground and background color that are the
same.

Example: "COLOR fc" produces light red on bright white


For example:


C:\workspace\perl>color 7

Tuesday, May 4, 2010

Linux - Basic & useful commands

How to find CPU & Memory detail of linux
cat /proc/cpuinfo (CPU)
cat /proc/meminfo (Memory)


How to find if any service is listening on particular port or not ?
netstat -an grep {port no}
For example if you know that tomcat is running on 8080 port so to check if tomcat service is listening or not then use
netstat -an grep 8080

How to sort files based on Size of file ? ( useful to find large files in log directory to delete in case disk is full )
ls -l sort -nrk 5 more

How to delete files older than N number of days ? (Useful in delete log, trace, tmp file )
find . -name ‘*.*’ -mtime +[N in days] -exec rm {} \; ( This command will delete files older then N days in that directory, always good to use it when you are in applcsf/ tmp,out,log directory)


How to create symbolic link to a file ?
ln -s pointing_to symbolic_name

e.g. If you want to create symbolic link from a -> b
ln -s b a
(Condition:you should have file b in that directory & there should not be any file with name a)

How to find the Unix/Linux version of a particular host ?
uname -a

How to set/unset line numbers in vi editor?
To set line number
:set number

To unset line number
:set nonumber

Total number of files in particular directory

find /usr/local/perl-5.10.1 -ls wc -l


How to set an alias for complex/different commands?

alias l=“ls –alF”
alias cls=clear




/Proc file system - Various Kernel Statistics
/proc file system provides detailed information about various hardware devices and other Linux kernel information.

cat /proc/cpuinfo
cat /proc/meminfo
cat /proc/zoneinfo
cat /proc/mounts


Search the particular key word content in a file

grep -iR <phrase>
< phrase > -> word you want to search if you want to search a sentence enclose within '' (single quotes)

To make your search more faster if you know what type of files to be searche use the following


find -iname "*.xml" | xargs grep -iR <phrase>

Disk Usage listing with depth one level depth:
du -h --max-depth=1 .