Tuesday, January 25, 2011

jquery IE AJAX issues

The list of issues when working with jquery IE AJAX issues are so huge and painful that I plan to maintain a log here :

1. trim() javascript function is not implemented in IE.
 Solution: Use $.trim('str ') instead of javascript trim()

2. Use javascript stacktrace jquery plugin. This is a life savior for identifying IE issues..
http://eriwen.com/javascript/js-stack-trace/
Open source in git here



Friday, January 21, 2011

Spring mvc 3 junit test

Below is a code snippet to easily test a spring annotated web controller


public abstract class BaseWebControllerTest {
    @Autowired
    protected ApplicationContext context;
    protected MockHttpServletRequest request;
    protected MockHttpServletResponse response;
    protected HandlerAdapter handlerAdapter;

    public void before() {
        handlerAdapter = context.getBean(HandlerAdapter.class);
    }
   
    void handle(HttpServletRequest request, HttpServletResponse response) throws Exception {
        final HandlerMapping handlerMapping = context.getBean(HandlerMapping.class);
        final HandlerExecutionChain handler = handlerMapping.getHandler(request);
        assertNotNull("No handler found for request, check you request mapping", handler);

        final Object controller = handler.getHandler();

        final HandlerInterceptor[] interceptors = handlerMapping.getHandler(request).getInterceptors();
        for (HandlerInterceptor interceptor : interceptors) {
            final boolean carryOn = interceptor.preHandle(request, response, controller);
            if (!carryOn) {
                return;
            }
        }

        handlerAdapter.handle(request, response, controller);
    }

}


@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/spring/test-app-config.xml")

public class MyControllerTest extends BaseWebControllerTest{
    MyController controller;

    @Before
    public void before() {
        super.before();
        controller = context.getBean(MyController.class);
    }

    @Test
    public void testGetRestRequest() throws Exception {
        request = new MockHttpServletRequest();
        response = new MockHttpServletResponse();
       
        request.setContentType("application/json");
        request.setMethod("GET");
        request.setRequestURI("/rule/"+id);

        handle(request, response);
       
        String result =response.getContentAsString();
        logger.info("RESULT : "+result);
        //assert json response is right.
    }
}

Reference:
http://efreedom.com/Question/1-2314377/Testing-Spring-MVC-Annotations

Thursday, January 13, 2011

Batch scripts

Context : If you are a java programmer? and you use tomcat  on windows? and you do not want repeated stress injury?
If yes then below are the scripts:

#1# Script to shutdown tomcat, deploy app, and startup ##
set tomcat_home=C:\..\apache-tomcat-6.0.20
set CATALINA_HOME = %tomcat_home%
cmd /c %tomcat_home%\bin\shutdown.bat

cmd /c mvn clean package -Dmaven.test.skip
rmdir /s /q %tomcat_home%\webapps\coacs

copy target\myhotapp.war %tomcat_home%\webapps
cmd /c %tomcat_home%\bin\startup.bat

#2# Run tomcat in debug mode  - store this under tomcat/bin as tomcat-debug.bat ##
set CATALINA_HOME=C:\Apps\apache-tomcat-6.0.20
set JPDA_ADDRESS=8000
set JPDA_TRANSPORT=dt_socket
%CATALINA_HOME%\bin\catalina.bat jpda start




Friday, January 7, 2011

Oracle fix for schema table prefix and running scripts from sql developer

In oracle it appears like a NON_OWNER user though granted access(select, insert, delete, update) to tables created by OWNER of the table cannot directly view them without the schema prefix.

This would mean all the queries in the java application will have to have this table owner user name prefix.

The possible options to drop this prefix :

1. ALTER SESSION SET CURRENT_SCHEMA= OWNER_SCHEMA ; (AFTER LOGON trigger as mentioned here )
But this works only for the current session unless we have a logon trigger. This seems like a preferred approach as per various forum threads.

2. Create views/synonyms from the NON_OWNER current user per table. So the tables can be accessed without prefix.

3. It could be something simpler as well (I am no DB expert) like setting the default current schema for the NON_OWNER user in some other way.


Running scripts from SQL developer:


To run this from sqldeveloper :
1. Set a default Path: Tools menu > Preferences > Database > Worksheet > Select default path to look for scripts
2. open run.sql from sqldeveloper File > Open
3. Run script.

Tuesday, January 4, 2011

iPhone apps - App-le a day

iPhone apps seems like the new trend and what else should a developer be doing in his spare time?



My motivation:

1. Millions of users. You can share apps with the world and make a small earning till iphone user base exists. Isn't that cool

2. Its market place is excellent

3. One of the best integration of technology man possesses - all in the palms of your hand.

4. Good way to know more about Apple & their products.





Few iPhone apps that I have been churning are now live on itunes:




1. AutoSignIn(free) - formerly called LogMeIn.




An auto login app to help you login to most of the popular sites -like gmail, admob, ebay, yahoo, gdocs, etc.. As iphone has no provision to store your password/email this should be handy. I use most of the time.
The idea is that you dont need an app for every popular website on the internet. Just an autologin app should do as most websites are mobile friendly these days.
Was formerly called
LogMeIn. Due to copyright issues had to rename to AutoSignIn with a better icon. Hope we enjoy.

2. gDox (free)



An auto login app for gDocs. Live now.




3. Radio players (free)



Has a very intuitive interface for couple of iphone radio apps i have been spamming itunes store with (until they said no more). Some are regional. Below is the list.
  • Radio kannada
  • Tamil Hits
  • Telugu hits
  • Radio Eye - English radio stations organized based on top stations and genre
  • Hindi hits




4. aMaze!! (free)



An attempt to use Chipmunk physics engine and sparrow framework to build a maze game with balls moved into target square through iphone movement. Its a free app with some nice music and interface (except that the physics engine is not that great).
Learnings:
Chipmunk C library is free but hard to code(its objective C library costs 200 bucks and i didn't wanted to shell out a $). Though this was a good experience with physics engine, i found it to be unstable and not so easy to work around memory and timer issues of chipmunk C library. Would not recommend anyone to use chipmunk c library (don't know if the paid objective C bundle is better). Better go for cocos 2d. Its more popular.



5. Java JEE IQ (Was $1. Now free)



Java/j2ee quick notes for revision etc esp. during interview. It consists of notes from an industry perspective- has spring/hibernate/struts/JSR's/core java/ etc and some useful pdfs. This was my first app and i spent a lot of time learning objective c/buying macbook & ipod touch/installing snow leopard/xml parsing library/xcode/interface builder/ and understanding how to make a release to itunes. I am charging a $ for all that effort of mine. Hope it is acceptable.




All the above apps can be found by searching 'bri8' on itunes store or following this link:
http://itunes.apple.com/us/artist/bri8-ltd/id396468155



OpenID

It is so convenient to pull out information from account which user already has instead of making the user key in the boring registration form. In a way it follows DRY(do no repeat yourself) principle.

Here comes OpenID. You can also auto register the user with this php script. Cool stuff for my community site..

Open ID +PHP : http://devzone.zend.com/article/3581