Wednesday, July 5, 2017

PDF generation with Apache FOP

What is Apache FOP?
Apache FOP is a print formatter driven by XSL formatting objects(XSL-FO). It is a library to read XSL FO objects and generate documents with specified output format. Here I have used pdf as the output format.

What is XSL?

XSL is a language for expressing stylesheets. It describes how to display data in an XML file.

What is XSL FO?

XSL FO is a part of XSL which is a markup language for XML document formatting. Follow W3school tutorial for XSL FO.

How Apache FOP generate PDFs.


I have generated javaFX form to enter the data and when I click the print button after filling data, PDF will be created in a folder called PDFs. source code for this available in https://github.com/laki88/PatientDischargeForm.




Thursday, March 23, 2017

JDBC drivers and connection strings

Recently I was fixing a bug in gadget creation in WSO2 DAS 3.1.0 in which gadget creation throws errors on some database types. So I have to check for major database types for gadget creation and I came up with following database drivers and connection strings and little more information their JDBC drivers.

MySQL
Driver class : com.mysql.jdbc.Driver
Connection string : jdbc:mysql://localhost:3306/databaseName

You can download JDBC driver from their official site.

MSSQL
Driver class : com.microsoft.sqlserver.jdbc.SQLServerDriver
Connection string :jdbc:sqlserver://hostName:1433;database=databaseName

You can download MSSQL driver from microsoft site. According to the JRE it comes from several flavours as below.

• Sqljdbc41.jar requires a JRE of 7 and supports the JDBC 4.1 API
• Sqljdbc42.jar requires a JRE of 8 and supports the JDBC 4.2 API

Apart from official MSSQL driver there are other supported drivers like jtds as well. You can find more information about them by referring this stackoverflow question.

PostgreSQL
Driver class : org.postgresql.Driver
Connection string : jdbc:postgresql://localhost:5432/databaseName

You can download the PostgreSQL driver from their official site and it also comes in different flavours depend on the Java version. It would be very easy to work with PostgresSQL if you are using postgres.app. For mac users, note that to uninstall all previous versions of PostgreSQL versions to work with postgres app.

DB2
Driver class : com.ibm.db2.jcc.DB2Driver
Connection string : jdbc:db2://myhost:5021/mydb

You can download db2 JDBC driver from their official site.

Oracle
Driver class : oracle.jdbc.OracleDriver
Connection string : jdbc:oracle:thin:@hostName:1521/wso2qa11g

You can download Oracle JDBC driver from their official site.

Tuesday, February 28, 2017

Simple wait and notify example in Java

This example demonstrate wait and notify example. Main thread(ThreadA) will create threadB and will start threadB. After threadB started, it just print that it is started and will go to WAITING state by calling wait(). Meanwhile threadA goes to sleep for 3 seconds and will print that it is awaked and will notify threadB by calling notify(). This will cause to threadB goes to RUNNABLE state. Then it will resume the threadB's execution and will print that it is notified.


Note that when we call wait() and notify(), it should call inside synchronised context. Otherwise it will throw java.lang.IllegalMonitorStateException. We have to pass a lock object to the synchronised block. That object will be blocked during the execution of synchronisation block. In this case I pass the threadB itself as the lock object.

Monday, January 23, 2017

Customize the place where tomcat instance creating for wso2 4.4.x servers

WSO2 4.4.x servers run on an OSGIfied tomcat. It creates the tomcat instance on <CARBON_HOME>/lib/tomcat directory. You can customize this path to your own one by changing the property "catalina.base" in wso2server.sh.

How to choose IP address range for resources for AWS virtual private cloud

You will often need to allocate  an IP address range when you design the network of an AWS VPC. Since VPC is a small network of resources(E...