Thursday, June 25, 2015

Some Commonly used postgre sql commands

Log in command to access the postgre sql database

psql -U

psql -U postgresadmin postgres

List down all the in schemas in the database


List down all the tables in a schema


List down all the tables in a schema


Executing a sql file in a schema

psql -U postgresadmin -f /usr/local/script/userdb/postgresql.sql -d userdb;

Wednesday, June 24, 2015

How to handle ldap certificate exception with WSO2 carbon server

WSO2 Identity product can be configured to use external ldap as a primary or secondary user store. You can follow the document to learn more about configuring ldap.

After configuring the ldap and during server startup, you may experience the following handshake error message

TID: [0] [IS] [2015-06-24 08:29:51,120] ERROR {org.wso2.carbon.user.core.ldap.LDAPConnectionContext} -  Error obtaining connection.Trying again to get connection...  {org.wso2.carbon.user.core.ldap.LDAPConnectionContext}
javax.naming.CommunicationException: [Root exception is PKIX path building failed: unable to find valid certification path to requested target]
        at com.sun.jndi.ldap.Connection.(
        at com.sun.jndi.ldap.LdapClient.(
        at com.sun.jndi.ldap.LdapClient.getInstance(
        at com.sun.jndi.ldap.LdapCtx.connect(
        at com.sun.jndi.ldap.LdapCtx.(
        at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(
        at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(
        at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(
        at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(
        at javax.naming.spi.NamingManager.getInitialContext(
        at javax.naming.InitialContext.getDefaultInitCtx(
        at javax.naming.InitialContext.init(
        at javax.naming.InitialContext.(
        at org.wso2.carbon.user.core.ldap.LDAPConnectionContext.getContext(

In order to solve this issue, you have to import the public key of the ldap in to the client-trustore,jks(CARBON_HOME/repository/resources/security).

You can obtain the ldap's public certificate by executing following command

echo -n | openssl s_client -connect | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ldapserver.crt

Later you can import the cer file in to client-truststore.jks to be used by WSO2 carbon products

keytool -import -trustcacerts -alias ldapcert -file ldapserver.crt -keystore client-truststore.jks

You can validate the certificate by running following command

 keytool -list -keystore client-truststore.jks -alias ldapcert

Saturday, June 6, 2015

How to create web app specific custom log file in WSO2 carbon platform

Use case

Need to have a custom log file to log the web applications deployed into wso2 Application Server 5.2.1.



You can have the basic idea about log4j 1.2 by going through following link.

You can create the log file from the code like this.

As an alternative, you can prepare your own file for the web application and configure it to load the configurations from the file. I will be explaining that approach.

I am going to modify the web application which can be found in AS_HOME/samples/Jaxws-Jaxrs/jaxrs_basic.

I did following modifications to the web app
  1. Modified the the pom.xml file to add the commons-logging and log4j dependencies. Changed the scope to provided for the dependencies of cxf, and commons client.
  2. Removed the "packagingExcludes" option to make sure that the jars related to log4j is packed in the WEB-INF/lib folder. We are packing this in to lib folder to make sure, that the defined files is loaded again for the web application. If not the logging will use the defined in carbon environment.
  3. Updated the "maven-antrun-plugin" to copy the "" files in to the target/classes in web app war file.
You can view the pom file over here.

Once you build this maven file, you can deploy it into Application Server and check for the log file in the custom path that you defined in file.

You can check for logs by hitting the endpoint with the following url

The source code can be found here for this web app.