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.