29 July, 2016

Cordova plugin download error

I was trying to download few Cordova plugin today.
So I fired a simple command, 

> cordova plugin add org.apache.cordova.device
Error: Registry returned 404 for GET on https://registry.npmjs.org/org.apache.cordova.device

I found it's strange, that all the tutorial say this is the way you should download and add a plugin. But it doesn't work and throws a strange error.

Atlast, I found that actually the problem is in repository. After cordova version 5, the naming convention of the package has been changed. Strangely the top tutorials never updated the same. I find it's worth a shout which I have learnt the hard way

All you need to transform the package name org.apache.cordova* to cordova-plugin-*
SO in the above example, the correct package name should have been cordova-plugin-device

... and the correct command would have been, 
> cordova plugin add cordova-plugin-device 
Fetching plugin "cordova-plugin-device" via npm
Installing "cordova-plugin-device" for android


and it works like a cream.

20 July, 2016

How to log PHP debugging message?

I am really novice in the field of PHP, but found it is so critical to debug a PHP application.
I just wanted to print some debug statements from PHP code, and uplon GOOGLEing i was end up in 100 lines of custom LOG classes. which has dependency on another 1000 lines of codes.
PHEW!!!

But at last it turned out to be so simple.
write a function global scope

function phplog( $message)
{
       error_log("\n" . $message, 3, "phplog.log");
 }


And then log it through the call...

phplog ("Hello world!!!");


I found this here, do visit for more info on this.

15 July, 2016

How to use resource adapters with JBOSS application server.

When we start using resource adapter, the first question that comes to my mind is ‘why do I need it’. Imagine, our application is a client to IBM WebSphere MQ. We can implement our application either using JMS or IBM MQ api. In some cases we are bound to use MQ apis because there are some features which are not available in JMS(like FIPS, Queue Managers etc.). If we use MQ apis then our application is tightly coupled with them.

Resource adapter enables us to export the configuration and lets us use JMS, so that it doesn’t create undue tight coupling with any proprietary apis .

Steps to configure

PART1: Server Configuration:
  • Get the resource adapter in RAR format e.g. wmq.jmsra.rar. And deploy it to the JBOSS server.
  • Standalone.xml needs to configured. Below is an example configuration
<subsystem xmlns="urn:jboss:domain:resource-adapters:1.1">
    <resource-adapters>
        <resource-adapter id="wmq.jmsra.rar">
            <archive>
                wmq.jmsra.rar
            </archive>
            <transaction-support>NoTransaction</transaction-support>
            <connection-definitions>
                <connection-definition 
                    class-name="com.ibm.mq.connector.outbound.ManagedQueueConnectionFactoryImpl" jndi-                          name="java:jboss/confac" pool-name="wmq.jmsra">
                     <config-property name="channel">
                         channel name
                     </config-property>
                     <config-property name="hostName">
                         host name or ip
                     </config-property>
                     <config-property name="transportType">
                         CLIENT
                     </config-property>
                     <config-property name="queueManager">
                         queue manager n ame
                     </config-property>
                     <config-property name="port">
                         port
                     </config-property>
                     <security>
                         <application/>
                     </security>
                 </connection-definition>
             </connection-definitions>
             <admin-objects>
                 <admin-object class-name="com.ibm.mq.connector.outbound.MQQueueProxy" jndi-name="java:jboss/Queue" use-java-context="true" pool-name="MQ.QUEUE">
                     <config-property name="baseQueueName">
                          queue name
                     </config-property>
                     <config-property name="targetClient">
                         MQ
                     </config-property>
                 </admin-object>
             </admin-objects>
         </resource-adapter>
     </resource-adapters>
</subsystem>

PART 2: Client side configuration
3.       To configure the MDBs (for inbound connections) the following annotation can be used.
@MessageDriven( name = "ScpmsConsumerNASL",
       activationConfig = {
                                                        @ActivationConfigProperty(propertyName  = "destinationType", propertyValue = "javax.jms.Queue"),
                                                        @ActivationConfigProperty(propertyName  = "destination", propertyValue = “java:jboss/Queue”), // Ext. JNDI Name
                                                        @ActivationConfigProperty(propertyName  = "useJNDI", propertyValue = "true") // Ext. JNDI Name
                        }
)
@ResourceAdapter(value = "wmq.jmsra.rar")

I have used JNDI in my application, this can be implemented without it as well.

01 July, 2016

Demistifying Javascript Variables

The JavaScript variables are not easy as it seems to be.
In this shout I am trying to demystify few of them. Feel free to add if you have experienced similar behaviors which are hidden and not written explicitly.

  • Reference or Value : Always wondered are JavaScript variables are references or values. let us go through some examples.
    1. Scalar variables - Consider the snippet
      var s1 = "I am Einstein";
      var s2 = s1;
      console.log("1 :: S1=" + s1);
      console.log("1 :: S2=" + s2);

      s1 = "I am Newton";
      console.log("2 :: S1=" + s1);
      console.log("2 :: S2=" + s2);


      ... what do you think the output can be. Here it is.

      1 :: S1=I am Einstein
      1 :: S2=I am Einstein
      2 :: S1=I am Newton
      2 :: S2=I am Einstein

      So the conclusion here is the scalar types will always be kept as value.
    2.  Array Types - consider the snippet
      var v1 = { "name" : "Tom", "skill" : "java"};
      var v2 = v1;
      console.log("1 :: v1=" + JSON.stringify(v1));
      console.log("1 :: v2=" + JSON.stringify(v2));

      v2.skill = "java, javascript";
      console.log("2 :: v1=" + JSON.stringify(v1));
      console.log("2 :: v2=" + JSON.stringify(v2));

      ... now do you think the output would change like previous one. Here it is.
      1 :: v1={"name":"Tom","skill":"java"}
      1 :: v2={"name":"Tom","skill":"java"}
      2 :: v1={"name":"Tom","skill":"java, javascript"}
      2 :: v2={"name":"Tom","skill":"java, javascript"}
      ... this is because JavaScript always keep the Object/JSON as refrences. And the statement "v2=v1" copy the references not the value unlike the previous case. After the any change in v1 would also change the v2 as they are pointing to the same object.

    3. Vector Types (Object/JSON) - consider the snippet
      var a1 = ["Einstein","Newton"];
      var a2 = a1;
      console.log("1 :: a1=" + a1);
      console.log("1 :: a2=" + a2);

      ... here also the result is same as previous
      console.log("2 :: a1=" + a1); console.log("2 :: a2=" + a2);


  • Associative Array: Javascript Associative arrays do not keep the ordering of the same. it depends on the hashing of the keys.
    var scientists  = { 2: "Einstein" ,  "1" :  "Newton" , 3: "Feynman"};
    console.log("1 :: scientists=" + JSON.stringify(scientists));
    var scientistsSorted  = {"S2":"Einstein" , "S1" : "Newton","S3": "Feynman"};
    console.log("2 :: scientists=" + JSON.stringify(scientistsSorted));
    ... see the output minutely,
    1 :: scientists={"1":"Newton","2":"Einstein","3":"Feynman"}
    2 :: scientists={"S2":"Einstein","S1":"Newton","S3":"Feynman"}
    ... what is going on, in case of #1, the hashing is done in an numeric way. So please be careful if you have an associative array with the keys as integer (even in form of a string), JavaScript will not be able to keep the ordering as you added. In order to avoid that you have prefix the keys with some character. see #2.

29 June, 2016

Problem managing the resources in Java Web Applications

Whenever we are developing an web application in any language we faced a few problem.
  1. No Centralized way of managing Web Resources (js,css)
    This is very helpful when you have large project, where your one js or css is being used in more than one pages.
  2. No way of "do-way" of the browser caching.
    There is a trick of put versioning in the resources file.
So, developed a simple framework in my ongoing assignments to solve this problems. The framework is called YorL. It is easy to configure and very lightweight.

Feel free to read more and use this  here