Thursday, December 10, 2015

Ubuntu Delete IP-Talbe Rule

Execute the same commands but replace the "-A" with "-D". For example:
iptables -A INPUT -i eth0 -p tcp --dport 443 -j ACCEPT
becomes
iptables -D INPUT -i eth0 -p tcp --dport 443 -j ACCEPT

Tuesday, March 17, 2015

WSO2ESB start as a service in Oracle Linux

OS : Oracle Linux Server release 5.9
ESB : wso2esbv4.8.1

requirement was the start the ESB automatically when restart the server. To achieve this create startup script as solution.
Rather than put /etc/rc.locl put script in /etc/ini.d directory and setup as a service.
How to do

create a script to start and stop the server as below


#!/bin/bash
# chkconfig: 2345 20 80
# description: Description comes here....

# Source function library.
. /etc/init.d/functions

start() {
 /usr/share/server/server-up.sh
}

stop() {
    echo "stop"
}

case "$1" in
    start)
       start
       ;;
    stop)
       stop
       ;;
    restart)
       stop
       start
       ;;
    status)
       # code to check status of app comes here
       # example: status program_name
       ;;
    *)
       echo "Usage: $0 {start|stop|status|restart}"
esac
exit 0

and set executable permission

chmod +x middleware.sh

and change ownership to root

chmod root middleware.sh

create server-up.sh in /usr/share/server/server directory



#!/bin/bash
#set the JAVA_HOME
export JAVA_HOME=/home/virtusa/jdk1.7.0_51
export PATH=/home/virtusa/jdk1.7.0_51/bin:$PATH

screen -A -m -d -S ESB /bin/sh /home/chathura/Middleware/wso2esb-4.8.1/bin/wso2server.sh

date='date'
echo "started at: "$date>> log


*above script start the sever in screen
* has to set java path here because at running time this environment variable not load
then add the script to run levels

chkconfig --add middleware.sh
chkconfig --level 2345 middleware.sh on

Check the script is indeed enabled - you should see "on" for the levels you selected.

chkconfig --list | grep middleware.sh

Hope this is what you were looking for.



Monday, January 19, 2015

WSO2ESB ERROR_HANDLING Another way

To handle errors that occurred in ESB there are inbuilt mediators but from those mediators I cannot catch some expectations like XSLT transformation exception.
For achieve that I use following Hack in sequence. actually this sequence to execute when error occurred in IN sequence.
 <inSequence onError="ErrorSequence">

In error sequence Error message and Error Code can capture. unfortunately ESB returns limited error codes for errors so to catch error ERROR_CODE is not a option. 
ERROR_MESSAGE can be use with filter mediator as follow.

    <filter xmlns:ns="http://org.apache.synapse/xsd" source="get-property('ERROR_MESSAGE')" regex=".*Unable to perform XSLT transformation.*">
<then></then>

</filter>

can be use to regex to detect error messsage and send  response as error to client

complete filter :


 <filter xmlns:ns="http://org.apache.synapse/xsd" source="get-property('ERROR_MESSAGE')" regex=".*Unable to perform XSLT transformation.*">
      <then>
         <payloadFactory media-type="json">
            <format>  "ERROR" : {             "ERORR" : "Error in SXLT Transfotmation"            "ERORR_MESSAGE" : $1                          }  </format>
            <args>
               <arg expression="get-property('ERROR_MESSAGE')" evaluator="xml"></arg>
            </args>
         </payloadFactory>
         <header name="To" action="remove"></header>
         <property name="NO_ENTITY_BODY" action="remove" scope="axis2"></property>
         <property name="RESPONSE" value="true"></property>
         <property name="messageType" value="application/json" scope="axis2"></property>
         <send></send>
      </then>
      <else>
         <payloadFactory media-type="json">
            <format>                            "ERROR" : {                                "ERORR_MESSAGE" : $1                           }            </format>
            <args>
               <arg expression="get-property('ERROR_MESSAGE')" evaluator="xml"></arg>
            </args>
         </payloadFactory>
         <header name="To" action="remove"></header>
         <property name="NO_ENTITY_BODY" action="remove" scope="axis2"></property>
         <property name="RESPONSE" value="true"></property>
         <property name="messageType" value="application/json" scope="axis2"></property>
         <send></send>
      </else>
   </filter>