PMP Preparation

I found below simulator very useful.





First RESTful Webservice

To create RESTful webservice using plain JDK, tomcat and Jersey (JAX-RS sample implementation)

Pre Requisite:
  1. JDK
  2. Tomcat ( any other servlet container)
  3. Jersey - Its sample JAX-RS implementation. It uses servlet controller that handle REST URLS.
Steps :
1. Create eclipse project with following structure
WEB-INF
--classes
--lib
--web.xml

2. Download latest Jersey jars from http://download.java.net/maven/2/com/sun/jersey/jersey-archive/ and extract it under lib folder.

3. Create following java class under src and make sure to set output folder in eclipse to WEB-INF/classes.

package com.rahul.ws;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

@Path("helloworld")
public class HelloWorldResource {
    @GET
    @Produces("text/plain")
    public String getMessage() {
        return "This is sample REST service";
    }
}

4. Add entry into web.xml for Jersey controller


    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
        http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
   
        RestfulContainer
        com.sun.jersey.spi.container.servlet.ServletContainer
       
            com.sun.jersey.config.property.packages
            com.rahul.ws
       

        1
   

   
        RestfulContainer
        /resources/*
   


5. Create war file using "%JAVA_HOME%\bin\jar" cvf restful.war WEB-INF

6. Deploy this war under tomcat and access the service using
    http://localhost:9090/restful/resources/helloworld
7. That's it !!


Changing Timezone for OpenBibilo Library system

OpenBibilo is an open source, simple, easy to use but a power library management system. It highly  suitable for low to mid volume libraries having low budget.

Last week I was implementing it for one of the library that wanted to use Singapore time. By default OpenBibilo follows the timezone of your hosted environment and there is no configuration to use a different timezone.

But you could easily change  it by following below steps:
  • Replace all occurances of sysdate() used in SQL queries to UTC timestamp and add the required offset. There are around 19 occurances in the PHP files ( for version 0.0.7) ,   e.g sysdate() -->  (UTC_TIMESTAMP()+ INTERVAL 8 HOUR)
  • There is one occurance of now(), that need to be replaced as well                                 e.g  now() -->(UTC_TIMESTAMP()+ INTERVAL 8 HOUR)
  • These steps takes care of database timezone,
  • One last step needed to maek sure your php dates are too on the same timezone. It can be done by setting timezone in shared\common.php. Just add below line in common.php date_default_timezone_set('Asia/Singapore');
That's it! Your timezone is set to whatever you want. Of course there is a better way of having this done in some common place. But this is quick way to set timezone at this point.

Joomla website weird problem of wrong URLs

I have one joomla site which was working fine for last 2 years. Suddenly I noticed that the most of the links on my site are weird. Some of the links content actual IP address of the website, some link contained ftp user name ( xx.com/~xx/index.php). I was sure that nothing has been changed no the website and had no clue why its happening.

Upon careful observation, I noticed that someone accessed the website using adding IP address and user name (~xx) as context root (it was same as website name..so he must have guessed it). And since the joomla caching was enabled, all the pages were cached that contained these links. any new hits were served using this pages and even newly cached pages were following same context root !

Once the problem was identified, solution was simple. Simply clear the cache/ (or disable it for time being).


Oracle: Check for special character in SQL

select str, dump(str)
from test
where translate(upper(str),
CHR(0)||'QWERTYUIOPASDFGHJKLZXCVBNM ,.<>/?;:''"[{]}1234567890-=!@#$%^&*()_+\|`~',
CHR(0)
) IS NOT NULL