Friday, December 30, 2016

Active MQ with MYSql JDBC setup


Active MQ (5.14.3) JDBC setup on Mysql(5.7.17)
-------------------------------------

CREATE DATABASE activemq;
CREATE USER 'activemq'@'%' IDENTIFIED BY 'activemq';
GRANT ALL ON activemq.* TO 'activemq'@'%';
flush privileges;

2. cp mysql-connector-java-5.1.22-bin.jar /opt/activemq/lib/optional/

3.  sudo chown -R activemq:activemq mysql-connector-java-5.1.22-bin.jar

4. sudo nano /opt/activemq/conf/activemq.xml

modify:

<persistenceAdapter>
     <jdbcPersistenceAdapter dataDirectory="${activemq.base}/data" dataSource="#mysql-ds"/>
  </persistenceAdapter>

add the following bean just after the ending broker element (</broker>)

 <bean id="mysql-ds" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
   <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
   <property name="url" value="jdbc:mysql://localhost/activemq?relaxAutoCommit=true"/>
   <property name="username" value="xxxxx"/>
   <property name="password" value="xxxxx"/>
   <property name="poolPreparedStatements" value="true"/>
 </bean>

Monday, December 19, 2016

Active MQ Resource Adapter Config with Wildfly 10.1

Active MQ v 5.15.9 Config with Wildfly 10.1
----------------------------------------
Do the Config on WildFly Server

1. cd /opt

2. sudo wget https://repository.apache.org/content/repositories/releases/org/apache/activemq/activemq-rar/5.14.3/activemq-rar-5.15.9.rar


3. cd /opt/wildfly/modules/system/layers/base/org/apache/activemq
4. mkdir main
5.  sudo chown -R wildfly:wildfly main
6. cd main
7. sudo unzip /opt/activemq-rar-5.15.9.rar
8.  sudo chown -R wildfly:wildfly .
9.  sudo vi META-INF/ra.xml


 <resourceadapter>
        <resourceadapter-class>org.apache.activemq.ra.ActiveMQResourceAdapter</resourceadapter-class>
        <config-property>
            <description>
              The URL to the ActiveMQ server that you want this connection to connect to.  If using
              an embedded broker, this value should be 'vm://localhost'.
            </description>
            <config-property-name>ServerUrl</config-property-name>
            <config-property-type>java.lang.String</config-property-type>
            <config-property-value>tcp://1.2.3.4:61616</config-property-value>
            <!-- <config-property-value>vm://localhost</config-property-value> -->
        </config-property>
8. sudo vi broker-config.xml

 <transportConnectors>
      <transportConnector name="openwire" uri="tcp://1.2.3.4:61616"/>
    </transportConnectors>


9. sudo vi module.xml [create new file]

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.3" name="org.apache.activemq">
    <resources>
        <resource-root path="." />
                <resource-root path="activemq-broker-5.15.9.jar" />
                <resource-root path="activemq-client-5.15.9.jar" />
                <resource-root path="activemq-jms-pool-5.15.9.jar" />
                <resource-root path="activemq-kahadb-store-5.15.9.jar" />
                <resource-root path="activemq-openwire-legacy-5.15.9.jar" />
                <resource-root path="activemq-pool-5.15.9.jar" />
                <resource-root path="activemq-protobuf-1.1.jar" />
                <resource-root path="activemq-ra-5.15.9.jar" />
                <resource-root path="activemq-spring-5.15.9.jar" />
                <resource-root path="guava-18.0.jar"/>
                <resource-root path="commons-net-3.6.jar"/>
                <resource-root path="commons-pool2-2.4.2.jar"/>
                <resource-root path="commons-logging-1.2.jar"/>
                <resource-root path="hawtbuf-1.11.jar"/>
                <resource-root path="spring-aop-4.3.18.RELEASE.jar"/>
                <resource-root path="spring-beans-4.3.18.RELEASE.jar"/>
                <resource-root path="spring-context-4.3.18.RELEASE.jar"/>
                <resource-root path="spring-core-4.3.18.RELEASE.jar"/>
                <resource-root path="spring-expression-4.3.18.RELEASE.jar"/>
                <resource-root path="xbean-spring-4.2.jar"/>
    </resources>

    <dependencies>
                <module name="javax.api"/>
                <module name="org.slf4j"/>
                <module name="javax.resource.api" slot="main"/>
                <module name="javax.jms.api" slot="main"/>
                <module name="javax.management.j2ee.api" slot="main"/>
    </dependencies>
</module>


10. sudo chown -R wildfly:wildfly module.xml

11. Add the following on standalone-full.xml under
        

  1. <subsystem xmlns="urn:jboss:domain:resource-adapters:4.0">
  2.             <resource-adapters>
  3.                 <resource-adapter id="activemq-remote.rar">
  4.                     <module slot="main" id="org.apache.activemq"/>
  5.                     <transaction-support>XATransaction</transaction-support>
  6.                     <config-property name="ServerUrl">
  7.                         tcp://<hostname>:61616?jms.rmIdFromConnectionId=true
  8.                     </config-property>
  9.                     <config-property name="UserName">
  10.                         xxxxx
  11.                     </config-property>
  12.                     <config-property name="UseInboundSession">
  13.                         false
  14.                     </config-property>
  15.                     <config-property name="Password">
  16.                         xxxxx
  17.                     </config-property>
  18.                     <connection-definitions>
  19.                         <connection-definition class-name="org.apache.activemq.ra.ActiveMQManagedConnectionFactory" jndi-name="java:/AMQConnectionFactory" enabled="true" pool-name="AMQConnectionFactory">
  20.                             <xa-pool>
  21.                                 <min-pool-size>20</min-pool-size>
  22.                                 <max-pool-size>50</max-pool-size>
  23.                                 <prefill>false</prefill>
  24.                                 <is-same-rm-override>false</is-same-rm-override>
  25.                             </xa-pool>
  26.                         </connection-definition>
  27.                     </connection-definitions>
  28.                     <admin-objects>
  29.                         <admin-object class-name="org.apache.activemq.command.ActiveMQTopic" jndi-name="java:jboss/activemq/topic/TestTopic" use-java-context="true" pool-name="TestTopic">
  30.                             <config-property name="PhysicalName">
  31.                                 activemq/topic/TestTopic
  32.                             </config-property>
  33.                         </admin-object>
  34.                         <admin-object class-name="org.apache.activemq.command.ActiveMQQueue" jndi-name="java:jboss/activemq/queue/TestQueue" use-java-context="true" pool-name="TestQueue">
  35.                             <config-property name="PhysicalName">
  36.                                 activemq/queue/TestQueue
  37.                             </config-property>
  38.                         </admin-object>
  39.                         <admin-object class-name="org.apache.activemq.command.ActiveMQQueue" jndi-name="java:jboss/activemq/queue/nswpf_hip_log_queue" pool-name="log_queue">
  40.                             <config-property name="PhysicalName">
  41.                                 activemq/queue/log_queue
  42.                             </config-property>
  43.                         </admin-object>
  44.                         <admin-object class-name="org.apache.activemq.command.ActiveMQQueue" jndi-name="java:jboss/activemq/queue/nswpf_hip_error_queue" pool-name="error_queue">
  45.                             <config-property name="PhysicalName">
  46.                                 activemq/queue/error_queue
  47.                             </config-property>
  48.                         </admin-object>
  49.                     </admin-objects>
  50.                 </resource-adapter>
  51.             </resource-adapters>
  52.         </subsystem>


  53. Change Below for ejb3
  54. ------------------------------


  55.  <mdb>
  56.              <resource-adapter-ref resource-adapter-name="${ejb.resource-adapter-name:activemq-remote.rar}"/>
  57.            <bean-instance-pool-ref pool-name="mdb-strict-max-pool"/>
  58.  </mdb>

Sunday, December 18, 2016

APIMAN Installation on Centos 7 with Wildfly 10.1



APIMAN Installation
----------------------------------------
1. cd /opt

2. hostname

3. ping hostname


4.  sudo wget http://downloads.jboss.org/apiman/1.2.8.Final/apiman-distro-wildfly10-1.2.8.Final-overlay.zip

5. sudo yum install zip unzip -y

6. sudo service wildfly stop
7. sudo unzip -o apiman-distro-wildfly10-1.2.8.Final-overlay.zip -d wildfly-10.1.0.Final

8.  sudo nano wildfly-10.1.0.Final/standalone/configuration/standalone-apiman.xml
     change management binding address to 0.0.0.0 and HTTP port to 28080

9. sudo nano /etc/default/wildfly
      change WILDFLY_CONFIG to standalone-apiman.xml

10. sudo chown wildfly:wildfly /opt/wildfly/standalone/data/keycloak.h2.db
      sudo chown wildfly:wildfly /opt/wildfly/standalone/data/bootstrap
       sudo chown wildfly:wildfly /opt/wildfly/apiman
       sudo chown wildfly:wildfly /opt/wildfly/themes/

11.  sudo service wildfly start

12.  tail -100f /opt/wildfly/standalone/log/server.log

13. test @ http://www.localhost.com:28080/apimanui

Saturday, December 17, 2016

CentOS 7 Java installation

CentOS 7 Java Installation
-----------------------------------------------------

1. goto /opt folder
2. sudo wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u111-b14/jdk-8u111-linux-x64.tar.gz"
3. sudo tar xzf jdk-*.tar.gz
4. sudo alternatives --install /usr/bin/java java /opt/jdk1.8.0_111/bin/java 2
5. sudo alternatives --config java


6. sudo alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_111/bin/jar 2
7. sudo alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_111/bin/javac 2
8. sudo alternatives --set jar /opt/jdk1.8.0_111/bin/jar
9. sudo alternatives --set javac /opt/jdk1.8.0_111/bin/javac

10. java -version

11. export JAVA_HOME=/opt/jdk1.8.0_111
12. export JRE_HOME=/opt/jdk1.8.0_111/jre
13. export PATH=$PATH:/opt/jdk1.8.0_111/bin:/opt/jdk1.8.0_111/jre/bin

14. nano /etc/profile.d/java.sh

if ! echo ${PATH} | grep -q /opt/jdk1.8.0_111/bin ; then

   export PATH=/opt/jdk1.8.0_111/bin:${PATH}

fi

if ! echo ${PATH} | grep -q /opt/jdk1.8.0_111/jre/bin ; then

   export PATH=/opt/jdk1.8.0_111/jre/bin:${PATH}

fi

export JAVA_HOME=/opt/jdk1.8.0_111

export JRE_HOME=/opt/jdk1.8.0_111/jre

export CLASSPATH=.:/opt/jdk1.8.0_111/lib/tools.jar:/opt/jdk1.8.0_111/jre/lib/rt.jar

15. sudo chown root:root /etc/profile.d/java.sh
16. sudo chmod 755 /etc/profile.d/java.sh

Centos 7 Wildfly 10.1 Installation

Centos 7 Wildfly 10.1 Installation

nano /opt/wildfly-install.sh
-----------------------------------
#!/bin/bash
#title           :wildfly-install.sh
#description     :The script to install Wildfly 10.x
#more            :http://sukharevd.net/wildfly-8-installation.html
#author             :Dmitriy Sukharev
#date            :2016-06-18T02:45-0700
#usage           :/bin/bash wildfly-install.sh
#tested-version1 :10.0.0.CR3
#tested-distros1 :Ubuntu 15.10; Debian 7,8; CentOS 7; Fedora 22
#tested-version2 :10.0.0.Final
#tested-distros2 :Debian 8

WILDFLY_VERSION=10.1.0.Final
WILDFLY_FILENAME=wildfly-$WILDFLY_VERSION
WILDFLY_ARCHIVE_NAME=$WILDFLY_FILENAME.tar.gz
WILDFLY_DOWNLOAD_ADDRESS=http://download.jboss.org/wildfly/$WILDFLY_VERSION/$WILDFLY_ARCHIVE_NAME

INSTALL_DIR=/opt
WILDFLY_FULL_DIR=$INSTALL_DIR/$WILDFLY_FILENAME
WILDFLY_DIR=$INSTALL_DIR/wildfly

WILDFLY_USER="wildfly"
WILDFLY_SERVICE="wildfly"
WILDFLY_MODE="standalone"

WILDFLY_STARTUP_TIMEOUT=240
WILDFLY_SHUTDOWN_TIMEOUT=30

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

if [[ $EUID -ne 0 ]]; then
   echo "This script must be run as root."
   exit 1
fi

echo "Downloading: $WILDFLY_DOWNLOAD_ADDRESS..."
[ -e "$WILDFLY_ARCHIVE_NAME" ] && echo 'Wildfly archive already exists.'
if [ ! -e "$WILDFLY_ARCHIVE_NAME" ]; then
  wget -q $WILDFLY_DOWNLOAD_ADDRESS
  if [ $? -ne 0 ]; then
    echo "Not possible to download Wildfly."
    exit 1
  fi
fi

echo "Cleaning up..."
rm -f "$WILDFLY_DIR"
rm -rf "$WILDFLY_FULL_DIR"
rm -rf "/var/run/$WILDFLY_SERVICE/"
rm -f "/etc/init.d/$WILDFLY_SERVICE"

echo "Installation..."
mkdir $WILDFLY_FULL_DIR
tar -xzf $WILDFLY_ARCHIVE_NAME -C $INSTALL_DIR
ln -s $WILDFLY_FULL_DIR/ $WILDFLY_DIR
useradd -s /sbin/nologin $WILDFLY_USER
chown -R $WILDFLY_USER:$WILDFLY_USER $WILDFLY_DIR
chown -R $WILDFLY_USER:$WILDFLY_USER $WILDFLY_DIR/

#mkdir -p /var/log/$WILDFLY_SERVICE

echo "Registrating Wildfly as service..."
# if should use systemd
if [ -x /bin/systemctl ]; then
    # Script from $WILDFLY_DIR/docs/contrib/scripts/systemd/launch.sh didn't work for me
    cat > $WILDFLY_DIR/bin/launch.sh << "EOF"
#!/bin/sh

if [ "x$WILDFLY_HOME" = "x" ]; then
    WILDFLY_HOME="/opt/wildfly"
fi

if [ "x$1" = "xdomain" ]; then
    echo 'Starting Wildfly in domain mode.'
    $WILDFLY_HOME/bin/domain.sh -c $2 -b $3
    #>> /var/log/$WILDFLY_SERVICE/server-`date +%Y-%m-%d`.log
else
    echo 'Starting Wildfly in standalone mode.'
    $WILDFLY_HOME/bin/standalone.sh -c $2 -b $3
    #>> /var/log/$WILDFLY_SERVICE/server-`date +%Y-%m-%d`.log
fi
EOF
    # $WILDFLY_HOME is not visible here
    sed -i -e 's,WILDFLY_HOME=.*,WILDFLY_HOME='$WILDFLY_DIR',g' $WILDFLY_DIR/bin/launch.sh
    #sed -i -e 's,$WILDFLY_SERVICE,'$WILDFLY_SERVICE',g' $WILDFLY_DIR/bin/launch.sh
    chmod +x $WILDFLY_DIR/bin/launch.sh
   
    cp $WILDFLY_DIR/docs/contrib/scripts/systemd/wildfly.service /etc/systemd/system/$WILDFLY_SERVICE.service
    WILDFLY_SERVICE_CONF=/etc/default/$WILDFLY_SERVICE
    # To install multiple instances of Wildfly replace all hardcoding in systemd file
    sed -i -e 's,EnvironmentFile=.*,EnvironmentFile='$WILDFLY_SERVICE_CONF',g' /etc/systemd/system/$WILDFLY_SERVICE.service
    sed -i -e 's,User=.*,User='$WILDFLY_USER',g' /etc/systemd/system/$WILDFLY_SERVICE.service
    sed -i -e 's,PIDFile=.*,PIDFile=/var/run/wildfly/'$WILDFLY_SERVICE'.pid,g' /etc/systemd/system/$WILDFLY_SERVICE.service
    sed -i -e 's,ExecStart=.*,ExecStart='$WILDFLY_DIR'/bin/launch.sh $WILDFLY_MODE $WILDFLY_CONFIG $WILDFLY_BIND,g' /etc/systemd/system/$WILDFLY_SERVICE.service
    systemctl daemon-reload
    #systemctl enable $WILDFLY_SERVICE.service
fi

# if non-systemd Debian-like distribution
if [ ! -x /bin/systemctl -a -r /lib/lsb/init-functions ]; then
    cp $WILDFLY_DIR/docs/contrib/scripts/init.d/wildfly-init-debian.sh /etc/init.d/$WILDFLY_SERVICE
    sed -i -e 's,NAME=wildfly,NAME='$WILDFLY_SERVICE',g' /etc/init.d/$WILDFLY_SERVICE
    WILDFLY_SERVICE_CONF=/etc/default/$WILDFLY_SERVICE
fi

# if non-systemd RHEL-like distribution
if [ ! -x /bin/systemctl -a -r /etc/init.d/functions ]; then
    cp $WILDFLY_DIR/docs/contrib/scripts/init.d/wildfly-init-redhat.sh /etc/init.d/$WILDFLY_SERVICE
    WILDFLY_SERVICE_CONF=/etc/default/wildfly.conf
    chmod 755 /etc/init.d/$WILDFLY_SERVICE
fi

# if neither Debian nor RHEL like distribution
if [ ! -x /bin/systemctl -a ! -r /lib/lsb/init-functions -a ! -r /etc/init.d/functions ]; then
cat > /etc/init.d/$WILDFLY_SERVICE << "EOF"
#!/bin/sh
### BEGIN INIT INFO
# Provides:          ${WILDFLY_SERVICE}
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start/Stop ${WILDFLY_FILENAME}
### END INIT INFO

WILDFLY_USER=${WILDFLY_USER}
WILDFLY_DIR=${WILDFLY_DIR}

case "$1" in
start)
echo "Starting ${WILDFLY_FILENAME}..."
start-stop-daemon --start --background --chuid $WILDFLY_USER --exec $WILDFLY_DIR/bin/standalone.sh
exit $?
;;
stop)
echo "Stopping ${WILDFLY_FILENAME}..."

start-stop-daemon --start --quiet --background --chuid $WILDFLY_USER --exec $WILDFLY_DIR/bin/jboss-cli.sh -- --connect command=:shutdown
exit $?
;;
log)
echo "Showing server.log..."
tail -500f $WILDFLY_DIR/standalone/log/server.log
;;
*)
echo "Usage: /etc/init.d/wildfly {start|stop}"
exit 1
;;
esac
exit 0
EOF
sed -i -e 's,${WILDFLY_USER},'$WILDFLY_USER',g; s,${WILDFLY_FILENAME},'$WILDFLY_FILENAME',g; s,${WILDFLY_SERVICE},'$WILDFLY_SERVICE',g; s,${WILDFLY_DIR},'$WILDFLY_DIR',g' /etc/init.d/$WILDFLY_SERVICE
chmod 755 /etc/init.d/$WILDFLY_SERVICE
fi

if [ ! -z "$WILDFLY_SERVICE_CONF" ]; then
    echo "Configuring service..."
    echo JBOSS_HOME=\"$WILDFLY_DIR\" > $WILDFLY_SERVICE_CONF
    echo JBOSS_USER=$WILDFLY_USER >> $WILDFLY_SERVICE_CONF
    echo WILDFLY_HOME=\"$WILDFLY_DIR\" > $WILDFLY_SERVICE_CONF
    echo WILDFLY_USER=\"$WILDFLY_USER\" > $WILDFLY_SERVICE_CONF
    echo STARTUP_WAIT=$WILDFLY_STARTUP_TIMEOUT >> $WILDFLY_SERVICE_CONF
    echo SHUTDOWN_WAIT=$WILDFLY_SHUTDOWN_TIMEOUT >> $WILDFLY_SERVICE_CONF  
    echo WILDFLY_CONFIG=$WILDFLY_MODE.xml >> $WILDFLY_SERVICE_CONF
    echo WILDFLY_MODE=$WILDFLY_MODE >> $WILDFLY_SERVICE_CONF
    echo WILDFLY_BIND=0.0.0.0 >> $WILDFLY_SERVICE_CONF
fi

echo "Configuring application server..."
sed -i -e 's,sed -i -e 's,,,g' $WILDFLY_DIR/$WILDFLY_MODE/configuration/$WILDFLY_MODE.xml
sed -i -e 's,,,g' $WILDFLY_DIR/$WILDFLY_MODE/configuration/$WILDFLY_MODE.xml
sed -i -e 's,,,g' $WILDFLY_DIR/$WILDFLY_MODE/configuration/$WILDFLY_MODE.xml
sed -i -e 's,,,g' $WILDFLY_DIR/$WILDFLY_MODE/configuration/$WILDFLY_MODE.xml
sed -i -e 's,,,g' $WILDFLY_DIR/$WILDFLY_MODE/configuration/$WILDFLY_MODE.xml

[ -x /bin/systemctl ] && systemctl start $WILDFLY_SERVICE || service $WILDFLY_SERVICE start

echo "Done."






sudo chmod +x /opt/wildfly-install.sh
 
cd /opt
sudo ./wildfly-install.sh 
 
 
Test Server 
------------------
sudo service wildfly status
sudo service wildfly restart 
To access Control panel [http://xxx.xxx.xxx:9990/console/]
----------------------------------
1. add user [a,username,password, enter, no]
2. in standalone.xml change ip bindings to
<interfaces>
        <interface name="management">
            <inet-address value="${jboss.bind.address.management:0.0.0.0}"/>
        </interface>
3. Linux firewall check 
sudo firewall-cmd --reload
sudo systemctl status firewalld
sudo systemctl start firewalld
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-forward-port=port=80:proto=tcp:toport=28080
sudo firewall-cmd --reload

sudo firewall-cmd --zone=public --add-port=9990/tcp --permanent

Tuesday, December 6, 2016

RESTful principles provide strategies to handle CRUD actions using HTTP methods

RESTful principles provide strategies to handle CRUD actions using HTTP methods mapped as follows:

    GET /objects - Retrieves a list of objects
    GET /objects/12 - Retrieves a specific object
    POST /objects - Creates a new object
    PUT /objects/12 - Updates object #12
    PATCH /objects/12 - Partially updates object #12
    DELETE /objects/12 - Deletes object #12



The great thing about REST is that you're leveraging existing HTTP methods to implement significant functionality on just a single /objects endpoint. There are no method naming conventions to follow and the URL structure is clean & clear.


But how do you deal with relations?
If a relation can only exist within another resource, RESTful principles provide useful guidance.
Let's look at this with an example. A Object in Enchant consists of a number of messages.
These messages can be logically mapped to the /objects endpoint as follows:

    GET /objects/12/messages - Retrieves list of messages for object #12
    GET /objects/12/messages/5 - Retrieves message #5 for object #12
    POST /objects/12/messages - Creates a new message in object #12
    PUT /objects/12/messages/5 - Updates message #5 for object #12
    PATCH /objects/12/messages/5 - Partially updates message #5 for object #12
    DELETE /objects/12/messages/5 - Deletes message #5 for object #12

Alternatively, if a relation can exist independently of the resource, it makes sense to just include an identifier for it within the output representation of the resource. The API consumer would then have to hit the relation's endpoint. However, if the relation is commonly requested alongside the resource, the API could offer functionality to automatically embed the relation's representation and avoid the second hit to the API.

Friday, September 16, 2016

Json Array or multiple Objects / non Array parsing



JSON non-Array objects Parsing
----------------------------------------------------


try {
                   JSONObject jsonObject = new JSONObject(response);
                  //  boolean success = jsonObject.getBoolean("success");
                    Log.v(" ", "Json length : "+jsonObject.length());
                    for (int i =0; i                       // String taskname = jsonObject.getJSONObject("0").getString("TASK_NAME");
                        String taskname = jsonObject.getJSONObject(jsonObject.names().getString(i)).getString("TASK_NAME");
                        String taskloc = jsonObject.getJSONObject(jsonObject.names().getString(i)).getString("TASK_LOC");
                        String taskid = jsonObject.getJSONObject(jsonObject.names().getString(i)).getString("ID");
                        Log.v(""," Json Object : " + taskname +"  " +taskloc+"   "+taskid);
                        itemContents.add(taskname);
                    }

                    for(int i = 0; i                        Log.v("", "key = " + jsonObject.names().getString(i) + " value = " + jsonObject.get(jsonObject.names().getString(i)));
                    }

                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }

        };



Json Array Parsing
--------------------------------------


JSONArray jsonArray = new JSONArray(response);
for (int i =0; i    String taskname = jsonArray.getJSONObject(i).getString("TASK_NAME");   // String taskname = jsonObject.getJSONObject(jsonObject.names().getString(i)).getString("TASK_NAME");    String taskloc = jsonArray.getJSONObject(i).getString("TASK_LOC");    String taskid = jsonArray.getJSONObject(i).getString("ID");    Log.v(""," Json Object : " + taskname +"  " +taskloc+"   "+taskid);
    itemContents.add(taskname);}

Tuesday, September 13, 2016

Android Technology Available to use




Android Technologies
------------------------
1.
- Android Volley

- Retrofit (http://square.github.io/retrofit/)

2. Android Async (http://loopj.com/android-async-http/)

3. zxing (https://github.com/zxing/zxing)

4. ViewPagerIndicator (http://viewpagerindicator.com/)

5. ActionBarSherlock (http://actionbarsherlock.com/)

6.

-  Glide (https://github.com/bumptech/glide/ )

 - ImageViewZoom MIT (https://github.com/sephiroth74/ImageViewZoom)


7. Barcode4J  (http://barcode4j.sourceforge.net/)

8. StickyListHeaders (https://github.com/emilsjolander/StickyListHeaders)

Sunday, August 28, 2016

Linux Commands on centos 7


linux commands
-----------------------------
1. yum remove java*

2. Create /etc/profile.d/java.sh


if ! echo ${PATH} | grep -q /opt/jdk18/bin ; then
   export PATH=/opt/jdk18/bin:${PATH}
fi
if ! echo ${PATH} | grep -q /opt/jdk18/jre/bin ; then
   export PATH=/opt/jdk18/jre/bin:${PATH}
fi
export JAVA_HOME=/opt/jdk18
export JRE_HOME=/opt/jdk18/jre
export CLASSPATH=.:/opt/jdk18/lib/tools.jar:/opt/jdk18/jre/lib/rt.jar



Php permission error to connect to server with error on Centos 7

fsockopen($address, $this->port, $errno, $errstr, 60);

Try this command in your linuxbox (as root).

setsebool -P httpd_can_network_connect 1

Linux Commands on centos 7


linux commands
-----------------------------
1. yum remove java*

2. Create /etc/profile.d/java.sh


if ! echo ${PATH} | grep -q /opt/jdk18/bin ; then
   export PATH=/opt/jdk18/bin:${PATH}
fi
if ! echo ${PATH} | grep -q /opt/jdk18/jre/bin ; then
   export PATH=/opt/jdk18/jre/bin:${PATH}
fi
export JAVA_HOME=/opt/jdk18
export JRE_HOME=/opt/jdk18/jre
export CLASSPATH=.:/opt/jdk18/lib/tools.jar:/opt/jdk18/jre/lib/rt.jar



Php permission error to connect to server with error on Centos 7

fsockopen($address, $this->port, $errno, $errstr, 60);

Try this command in your linuxbox (as root).

setsebool -P httpd_can_network_connect 1

Monday, August 15, 2016

CentOS 7 Android studio setup



Let us know install studio by downloading the ide file from Android site and unzipping the same.
[root@li1260-39 tmp]# unzip android-studio-ide-141.2343393-linux.zip
Move android-studio directory to /opt directory
[root@li1260-39 tmp]# mv /tmp/android-studio/ /opt/
You can create a simlink to the studio executable to quickly start it whenever you need it.
[root@li1260-39 tmp]# ln -s /opt/android-studio/bin/studio.sh /usr/local/bin/android-studio
Now launch the studio from a terminal: ./studio.sh

From the IDE config the centos desktop icon

 Issues:

1. Unable to run mksdcard SDK tool CentOS


Solution for 64 bit:

yum install glibc.i686 glibc-devel.i686 libstdc++.i686 zlib-devel.i686 ncurses-devel.i686 libX11-devel.i686 libXrender.i686 libXrandr.i686

2. KVM



Thursday, July 21, 2016

Standard Middleware Architecture



IBM Integration Issues

Error :

1. BIP2132E: Invalid codepage '0' or conversion table 'ibm-0' missing or invalid.

Use

CALL CopyMessageHeaders();
or
SET OutputRoot.Properties = InputRoot.Properties;

Saturday, April 9, 2016

Messaging Protocol to use


The differences between XMPP and MQTT. What are they, actually?

XMPP (eXtensible Messaging and Presence Protocol) was born as a protocol for messaging apps. Jabber uses it, Google Talk (today Hangouts) used it, WhatsApp uses it. It's a great and reliable messaging protocol, far more reliable than GCM is. It also has many implementation guides/tutorials/examples.
MQTT  (MQ Telemetry Transport) instead, was born as a communication protocol designed for low-power devices which have limited power capacity and low computational power. It's fast and reliable, and uses far less data&power than XMPP needs to do the same exact work. Facebook Messenger uses it. However it's not very popular and may lack tutorials/examples for beginning developers.
Here's a small table comparison on how much data those protocols use: XMPP versus MQTT: comparing apples with pears
...and here's a battery consumption comparison: Power Profiling: HTTPS Long Polling vs. MQTT with SSL, on Android


To conclude, which one you're going to use is up to you.
Both are good and reliable application protocols, even though XMPP relies on HTTP, which makes it automatically more heavyweight but it doesn't mean it's less adequate for this job.


https://www.quora.com/Which-is-the-best-protocol-to-use-for-IOT-implementation-MQTT-CoAP-XMPP-SOAP-UPnP
 

Wednesday, April 6, 2016

Mqtt client Sample

Server : Eclipse IOT for Mqtt
Client : paho 9eclipse project)
 Messaging : Active MQ
Download the jar files below to run the client

https://repo.eclipse.org/content/repositories/paho-releases/org/eclipse/paho/org.eclipse.paho.client.mqttv3/1.0.2/
https://repo.eclipse.org/content/repositories/paho-releases/org/eclipse/paho/org.eclipse.paho.mqtt.utility/1.0.2/


import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;


public class MqttPublishSample {
   
    public static void main(String[] args) {

        String topic        = "MQTT Examples";
        String content      = "Message from MqttPublishSample";
        int qos             = 2;
     
        String broker       = "tcp://x.x.x.x:1883";
        String clientId     = "JavaSample";
        MemoryPersistence persistence = new MemoryPersistence();

        try {
            MqttClient sampleClient = new MqttClient(broker, clientId, persistence);
            MqttConnectOptions connOpts = new MqttConnectOptions();
            connOpts.setCleanSession(true);
            System.out.println("Connecting to broker: "+broker);
            sampleClient.connect(connOpts);
            System.out.println("Connected");
            System.out.println("Publishing message: "+content);
            MqttMessage message = new MqttMessage(content.getBytes());
            message.setQos(qos);
            sampleClient.publish(topic, message);
            System.out.println("Message published");
            sampleClient.disconnect();
            System.out.println("Disconnected");
            System.exit(0);
        } catch(MqttException me) {
            System.out.println("reason "+me.getReasonCode());
            System.out.println("msg "+me.getMessage());
            System.out.println("loc "+me.getLocalizedMessage());
            System.out.println("cause "+me.getCause());
            System.out.println("excep "+me);
            me.printStackTrace();
        }
    }
   
   

}




import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.eclipse.paho.client.mqttv3.MqttTopic;
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;

public class MqttSubscribeSample implements MqttCallback {
   
    MqttClient myClient;
    MqttConnectOptions connOpt;
   
    static final String BROKER_URL = "tcp://xxxxx:1883";
    static final String M2MIO_DOMAIN = "";
    static final String M2MIO_STUFF = "things";
    static final String M2MIO_THING = "desktop13";//clientid //"";
    static final String M2MIO_USERNAME = "";
    static final String M2MIO_PASSWORD_MD5 = "";

    // the following two flags control whether this example is a publisher, a subscriber or both
    static final Boolean subscriber = true;
    //static final Boolean publisher = true;
   
    String myTopic = "VirtualTopic.News";
    String content = "Message from MqttPublishSample";
    int qos = 0;

   
    public static void main(String[] args) {
        MqttSubscribeSample smc = new MqttSubscribeSample();
        smc.runClient();
    }
   
   
   
    public void runClient() {
        // setup MQTT Client
        String clientID = M2MIO_THING;
        connOpt = new MqttConnectOptions();
       
        connOpt.setCleanSession(true); // non-durable subscriber
        connOpt.setKeepAliveInterval(30);
        connOpt.setUserName(M2MIO_USERNAME);
        connOpt.setPassword(M2MIO_PASSWORD_MD5.toCharArray());
       
        // Connect to Broker
        try {
            myClient = new MqttClient(BROKER_URL, clientID);
            myClient.setCallback(this);
            myClient.connect(connOpt);
        } catch (MqttException e) {
            e.printStackTrace();
            System.exit(-1);
        }
       
        System.out.println("Connected to " + BROKER_URL);

        // setup topic
        // topics on m2m.io are in the form //
        //String myTopic = M2MIO_DOMAIN + "/" + M2MIO_STUFF + "/" + M2MIO_THING;
        //MqttTopic topic = myClient.getTopic(myTopic);

        // subscribe to topic if subscriber
        if (subscriber) {
            try {
                int subQoS = 2;
                myClient.subscribe(myTopic, subQoS);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }
   

    @Override
    public void connectionLost(Throwable t) {
        System.out.println("Connection lost!");
        // code to reconnect to the broker would go here if desired
       
    }

    @Override
    public void deliveryComplete(IMqttDeliveryToken arg0) {
        // TODO Auto-generated method stub
       
    }

    @Override
    public void messageArrived(String arg0, MqttMessage message) throws Exception {
        // TODO Auto-generated method stub
        System.out.println("-------------------------------------------------");
        System.out.println("| Topic:" + myTopic);
        System.out.println("| Message: " + new String(message.getPayload()));
        System.out.println("| Time: " + System.currentTimeMillis());
        System.out.println("-------------------------------------------------");
    }

}


 import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;

public class MqttQueueSample {
  
     public static void main(String[] args) {
        
          String topic        = "VirtualTopic.News";
            String content      = "Message from offline test";
          
       
            int qos             = 0;
       
            String broker       = "tcp://xxxxx:1883";
            String clientId     = "desktopclient1";
            MemoryPersistence persistence = new MemoryPersistence();

            try {
                MqttClient sampleClient = new MqttClient(broker, clientId, persistence);
                MqttConnectOptions connOpts = new MqttConnectOptions();
                connOpts.setCleanSession(true);
                System.out.println("Connecting to broker: "+broker);
                sampleClient.connect(connOpts);
                System.out.println("Connected");
              
               // sampleClient.
               // System.out.println("Message Subscrived");
              
                System.out.println("Publishing message: "+content);
                MqttMessage message = new MqttMessage(content.getBytes());
                message.setQos(qos);
                sampleClient.publish(topic, message);
                System.out.println("Message published");
              
              
              
                sampleClient.disconnect();
                System.out.println("Disconnected");
                System.exit(0);
            } catch(MqttException me) {
                System.out.println("reason "+me.getReasonCode());
                System.out.println("msg "+me.getMessage());
                System.out.println("loc "+me.getLocalizedMessage());
                System.out.println("cause "+me.getCause());
                System.out.println("excep "+me);
                me.printStackTrace();
            }

      
        }

  }







 

Tuesday, March 15, 2016

Best Opensource Projects Implemented by JAVA


Ecommerce Solution for a middle - big businesses, try ofbiz, because ofbiz gives you a platform for building enterprise class e-commerce solution

1. Apache OfBiz
http://ofbiz.apache.org/


2. Broadleaf Commerce is somewhere in the middle

http://www.broadleafcommerce.org/

3. OpenMRS for Medical
http://openmrs.org/