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.