Wednesday, November 23, 2016

How to connect to HSQL DB via console

I was using Spring boot(1.4.0.RELEASE)  with HSQL DB(hsqldb-2.2.6) for one of my projects. For one of my purpose, I needed to log to my HSQL DB via console and execute queries manually. After few searchings, I found a specific tool called sqltool(sqltool-2.2.6) which can be used for that purpose.

  1. Download  sqltool(sqltool-2.2.6) via http://www.hsqldb.org/repos/org/hsqldb/sqltool/2.2.6/
  2. Place the sqltool-2.2.6.jar in the same location where hsqldb-2.2.6.jar is available.
  3. Run the sqltool jar using following command.

  4. java -jar <path_to_sql_tool_jar>/sqltool-2.2.6.jar --inlineRc=url=jdbc:hsqldb:file:<path_to_db_where_.log_.propertis_.script>/<db_name>,user=<db_user_name>

  5. Then password will be asked. After authentication, you will log to console.
  6. Remember to close all the other connections to the particular DB otherwise, Database lock acquisition failure will be occured.

Sunday, October 16, 2016

ActiveMQ Message Attribute definitions

[Details are collected from several online references to ActiveMQ documentation, StackOverflow, blogs, mailing lists etc. Expecting expert comments or reviews regarding this post since it was difficult to find a direct trustful resource related to this topic.]

Property
Description
Delivery Mode
Delivery mode can be either persistent(integer value 2) or nonpersistent(integer value 1).
ID
An Unique ID for the message. Automatically assigned when the message is received to JMS server.
Priority
A priority level for each message. Priority range is 0-9. 0 is the lowest priority and 9 is highest.
Re-Delivery
Value is a boolean. If the true message will be considered for redelivery. If the false message will not be considered for redelivery.
Timestamp
for the time when the message is received by the JMS server.

ActiveMQ Queue Attribute definitions

[Details are collected from several online references to ActiveMQ documentation, StackOverflow, blogs, mailing lists etc. Expecting expert comments or reviews regarding this post since it was difficult to find a direct trustful resource related to this topic.]

Property
Description
Size
Available messages in the queue or topic.
Producer Count
Number of producers for the particular destination.
Average Enqueue Time
On average, the amount of time (ms) that messages
remained enqueued.
Average Message Size
Average message size in bytes related to the specific queue.
Broker ID
ID of the JMS broker which the particular queue/topic is own by
Broker Name
Name of the JMS broker which the particular queue/topic is own by
Consumer Count
Number of consumers for the particular destination.
Dequeue Count
Total number of messages removed from a queue and committed. This value reset on the JMS startup.
Destination Name
Name of the particular queue or topic.
Dispatch Count
Dequeue count + Inflight Count
Enqueue Count
Total number of messages sent to a queue and committed. This value reset on the JMS startup.
Expired Count
The total number of messages in the queue that were not delivered since they are expired.
Inflight Count
Total number of messages sent from the queue to consumers but not committed.
Max Enqueue Time
The maximum amount of time(ms) that messages remain enqueued.
Memory Limit
Memory limit, in bytes, used for holding undelivered messages before paging to temporary storage.
Memory Percent Usage
Percent of memory limit used.
Memory Usage
Total memory usage for available messages in the queue. Value is in Bytes.
Messages Cached
Number of messages in cache. [Need to verify]
Min Enqueue Time
The minimum amount of time(ms) that messages remain enqueued.

ActiveMQ Broker Attribute definitions

[Details are collected from several online references to ActiveMQ documentation, StackOverflow, blogs, mailing lists etc. Expecting expert comments or reviews regarding this post since it was difficult to find a direct trustful resource related to this topic.]

Property
Description
Average Enqueue Time
On average, the amount of time (ms) that messages
remained enqueued.
Average Message Size
Average message size in bytes related to all the destinations in the broker.
Broker ID
An unique ID for the JMS broker. Automatically assigned in the startup.
Broker Name
A name for the JMS broker. This can be configured when the Broker is initialized. If not configured a default value will be assigned eg: localhost
Consumer Count
Total number of consumers related to all available destinations of the JMS broker.
Data Directory
ActiveMQ DB file store location.
Dequeue Count
Total Number of messages removed and committed from all the available queues of the JMS broker. This value resets on the JMS startup.
Dispatch Count
Dequeue Count + Inflight Count
Enqueue Count
Total Numbers of messages sent to all available queues and committed. This value resets on the JMS startup.
Expired Count
Total number of undelivered messages in all of the queues due to message expiration.
Inflight Count
Total number of messages sent from all the queues available in JMS broker to consumers but not committed.
Max Enqueue Time
The maximum amount of time(ms) that messages remain enqueued.
Memory Limit
Memory limit, in bytes, used for holding undelivered messages before paging to temporary storage.
Memory Percent Usage
Percentage of memory allocated for the broker to keep track of destinations, cache messages etc.
Memory Usage
Amount of memory available for the broker from the JVM memory
Messages Cached
Number of messages in the cache. [Need to verify]
Min Enqueue Time
The minimum amount of time(ms) that messages remain enqueued.
OpenWire
If OpenWire transportconnector is defined in activemq.xml, connection URL for that transport.
Size
Total available message count of all destinations in the JMS broker.
Producer Count
Total number of producers related to all available destinations of the JMS broker.
SSL

Stomp
If Stomp transportconnector is defined in activemq.xml, connection URL for that transport.
Stomp+ssl
If Stomp over SSL transportconnector is defined in activemq.xml, connection URL for that transport.
Store Limit
Assigned disk space to store persistent messages.
Store Percent Usage
Percentage of the assigned disk space that has been used up to store persistent messages.
Store Usage
Disk space used by the persistence messages.
Temp Limit
Assigned disk storage to spool non-persistent messages.
Temp Percent Usage
Percentage of the assigned disk storage that has been used up to spool non-persistent messages.
Temp Usage
Disk space used by the non-persistent messages.
VM
Connection URL for VM transportconnector.

Monday, September 12, 2016

Apache camel routing to return the Exact HTTP error code

Let's say we need an apache camel routing configuration which acts as a HTTP proxy. It does only hand over the message to an external system which is given to the ESB by another external system. No any message modification happens in the ESB.

System A >>>>> ESB >>>>> System B

Let's take an example.

System A sends a request to the ESB without required Authorization header. ESB just forewards that message to the System B. So, System B returns a 401(Unauthorized) status code to the ESB. According to the default behavior ESB returns HTTP 500 back to the System A which we don't like to expect from a proxy setup. We need exactly what System B has sent to ESB. To achieve that behavior from ESB, we can apply following routing configuration.

<route>
            <from
                uri="jetty:http://{{xxx.esb.host}}:{{xxx.esb.port}}/?matchOnUriPrefix=true" />
            <setHeader headerName="CamelHttpMethod">
                <simple>${headers.CamelHttpMethod}</simple>
            </setHeader>
            <setHeader headerName="RestEndpointURL">
                <simple>
                    http://{{xxx.rest.endpoint.host}}:{{cgx.rest.endpoint.port}}${headers.CamelHttpUri}?bridgeEndpoint=true
                </simple>
            </setHeader>
            <setHeader headerName="Exchange.HTTP_PATH">
                <constant></constant>
            </setHeader>
            <recipientList>
                <simple>${headers.RestEndpointURL}</simple>
            </recipientList>

            <onException>
                <exception>java.lang.Exception</exception>
                <handled>
                    <simple> true </simple>
                </handled>
                <setHeader headerName="Exchange.HTTP_RESPONSE_CODE">
                    <simple>${exception.statusCode}</simple>
                </setHeader>
            </onException>


        </route> 

Thursday, August 25, 2016

Excetion: waiting for namespace handlers [http://camel.apache.org/schema/cxf

2016-08-26 09:19:06,451 | INFO  | -7.0.0.M2/deploy | BlueprintContainerImpl           | 28 - org.apache.aries.blueprint.core - 1.6.1 | Bundle com.xxxx.yyyyyyy.esb/0.0.1.SNAPSHOT is waiting for namespace handlers [http://camel.apache.org/schema/cxf]

When I was developing an Apache Camel REST project using CXFRS with the blueprint schema in XML DSL, above INFO log was appeared and bundle went to a Grace period. When the issue occurred my xml namespace configurations as below.

<?xml version="1.0" encoding="UTF-8"?>

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util xmlns:cxf="http://camel.apache.org/schema/cxf"     

xsi:schemaLocation=" 
http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd 
http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd"> 

I verified several times for the existence of the camel-cxf.xsd in the schemas of the camel-cxf dependency.

And also verified servicemix container contains the camel-cxf feature installed.

Finally I understood name-spaces and XSD locations should be as follows since I am using the blueprint schema.

xmlns:cxf="http://camel.apache.org/schema/bluprint/cxf" 

http://camel.apache.org/schema/blueprint/cxf http://camel.apache.org/schema/blueprint/cxf/camel-cxf.xsd

Then issue resolved.

Monday, August 22, 2016

Available XML tags in Apache Camel

onException when onCompletion
intercept interceptFrom interceptSendToEndpoint
to toD route
aop aggregate bean
doCatch choice otherwise
convertBodyTo delay dynamicRouter
enrich filter doFinally
idempotentConsumer inOnly inOut
loadBalance log loop
marshal multicast pipeline
policy pollEnrich process
recipientList removeHeader removeHeaders
removeProperties removeProperty resequence
rollback routingSlip sample
script setBody setExchangePattern
setFaultBody setHeader setOutHeader
setProperty sort split
stop threads throttle
throwException transacted transform
doTry unmarshal validate
whenSkipSendToEndpoint wireTap restBinding

Friday, August 5, 2016

How to set message headers for a apache camel restlet request

It is simple to set message headers for camel restlet request (Here we follow XML method to add those headers to a camel routing).

Following route will send a GET request to  http://192.168.1.20:8081/abcsys/services/esbInboundAdaptorServiceRest/V1.0/receiveMessage including Basic Authentication headers with username admin and password admin. A query param also get appended to the URI as http://192.168.1.20:8081/abcsys/services/esbInboundAdaptorServiceRest/V1.0/receiveMessage?message=new message

<route>

                    <!-- Set the query parameters to URI -->
                    <setHeader headerName="CamelHttpQuery">
                        <simple>message=new message</simple>
                    </setHeader>

                    <!-- Set the authentication header username for endpoint authorization -->
                    <setHeader headerName="CamelRestletLogin">
                        <simple>admin</simple>
                    </setHeader>

                    <!-- Set the authorization header password for endpoint authorization -->
                    <setHeader headerName="CamelRestletPassword">
                        <simple>admin</simple>
                    </setHeader>

                    <to
                        uri="restlet:http://192.168.1.20:8081/abcsys/services/esbInboundAdaptorServiceRest/V1.0/receiveMessage" />


</route>

Refer this for possible lists of headers that can be set to restlet requests.

Friday, July 22, 2016

Camel installing dependencies

[Note : Following content is related to a Apache-servicemix-7.0.0.M2 test setup]


When we are creating routing with Camel, we may need to install dependencies to Camel.
As an example if we have created a mail sending route and deploy it in a fresh camel installation, you may get a error like following:

2016-07-22 14:50:35,439 | ERROR | rint Extender: 2 | BlueprintContainerImpl           | 28 - org.apache.aries.blueprint.core - 1.6.1 | Unable to start blueprint container for bundle blueprint.jms/0.0.1.SNAPSHOT due to unresolved dependencies [(&(component=smtps)(objectClass=org.apache.camel.spi.ComponentResolver))]
java.util.concurrent.TimeoutException
    at org.apache.aries.blueprint.container.BlueprintContainerImpl$1.run(BlueprintContainerImpl.java:371)[28:org.apache.aries.blueprint.core:1.6.1]
    at org.apache.aries.blueprint.utils.threading.impl.DiscardableRunnable.run(DiscardableRunnable.java:48)[28:org.apache.aries.blueprint.core:1.6.1]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)[:1.7.0_79]
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)[:1.7.0_79]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178)[:1.7.0_79]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)[:1.7.0_79]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)[:1.7.0_79]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)[:1.7.0_79]
    at java.lang.Thread.run(Thread.java:745)[:1.7.0_79]
 


It is because we have not installed a feature called "mail" as a dependency for Camel. There are several dependencies available. We can display them by typing karaf@root>feature:install camel-  and tab.

We can install those dependencies with following command.
karaf@root>feature:install camel-mail  

Now issue should be resolved.

Wednesday, July 20, 2016

Activemq REST API adapter for external systems

Following content is tested only with Apache ActiveMQ 5.13.3

If we need to implement a communication between a ActiveMQ JMS server and any REST support external system that is implemented with a technology which has no JMS API support, ActiveMQ REST API comes as a solution. So, this REST API can be introduced as an adapter for any External system to be connected with a ActiveMQ JMS server.

ActiveMQ REST API provides following services.
1. Publish a message.
2. Consume a message.
3. Get list of queues.
4. Get list of messages in a particular queue or topic.
5. Get the content of a particular message.

Publish a message

Method : POST
URI format :
http://localhost:8161/api/message/queue_or_topic_name?type=either_queue_or_topic&requestTimeout=time_in_miliseconds&body=message to send&clientId=any_unique_id_for_client
Example URI:
http://localhost:8161/api/message/FOO?type=queue&requestTimeout=1000&body=This is test 34&clientId=soapui

Consume a message

Method :GET
URI format :
http://localhost:8161/api/message/queue_or_topic_name?type=either_queue_or_topic&clientId=any_unique_id_for_client&requestTimeout=time_in_miliseconds
Example URI:
http://localhost:8161/api/message/FOO?type=queue&clientId=soapui&requestTimeout=1000

Get list of queues or topics

Method :GET
URI format :
http://localhost:8161/admin/xml/queues.jsp

Get list of messages in a particular queue or topic

Method :GET
URI format :
http://localhost:8161/admin/queueBrowse/queue_or_topic_name
Example URI:
http://localhost:8161/admin/queueBrowse/FOO 

Get the content of a particular message

Method :GET
URI format :
http://localhost:8161/admin/queueBrowse/queue_or_topic_name?msgId=ID_value_of_a_particular_message_in_mentioned_queue_or_topic
Example URI:
http://localhost:8161/admin/queueBrowse/FOO?msgId=ID:dhcppc1-54766-1469009393902-5:1:1:1:4


NOTE:

If the authentication is enabled in the ActiveMQ admin as example in jetty.xml

 <bean id="securityConstraint" class="org.eclipse.jetty.util.security.Constraint">
        <property name="name" value="BASIC" />
        <property name="roles" value="user,admin" />
        <!-- set authenticate=false to disable login -->
        <property name="authenticate" value="true" />
    </bean>



we have to set security headers. If not 401 response will be received. So, following header should be set in the REST request

Authorization: Basic YWRtaW46YWRtaW4= 

YWRtaW46YWRtaW4= equivalent to the base 64 encoded version of the provided_username:provided_password
(Username and password is one of set which you use to access to the ActiveMq webconsole.)




Activemq REST API adapter for external systems

Following content is tested only with Apache ActiveMQ 5.13.3

If we need to implement a communication between a ActiveMQ JMS server and any REST support external system that is implemented with a technology which has no JMS API support, ActiveMQ REST API comes as a solution. So, this REST API can be introduced as an adapter for any External system to be connected with a ActiveMQ JMS server.

ActiveMQ REST API provides following services.
1. Publish a message.
2. Consume a message.
3. Get list of queues.
4. Get list of messages in a particular queue or topic.
5. Get the content of a particular message.

Publish a message

Method : POST
URI format :
http://localhost:8161/api/message/queue_or_topic_name?type=either_queue_or_topic&requestTimeout=time_in_miliseconds&body=message to send&clientId=any_unique_id_for_client
Example URI:
http://localhost:8161/api/message/FOO?type=queue&requestTimeout=1000&body=This is test 34&clientId=soapui

Consume a message

Method :GET
URI format :
http://localhost:8161/api/message/queue_or_topic_name?type=either_queue_or_topic&clientId=any_unique_id_for_client&requestTimeout=time_in_miliseconds
Example URI:
http://localhost:8161/api/message/FOO?type=queue&clientId=soapui&requestTimeout=1000

Get list of queues or topics

Method :GET
URI format :
http://localhost:8161/admin/xml/queues.jsp

Get list of messages in a particular queue or topic

Method :GET
URI format :
http://localhost:8161/admin/queueBrowse/queue_or_topic_name
Example URI:
http://localhost:8161/admin/queueBrowse/FOO 

Get the content of a particular message

Method :GET
URI format :
http://localhost:8161/admin/queueBrowse/queue_or_topic_name?msgId=ID_value_of_a_particular_message_in_mentioned_queue_or_topic
Example URI:
http://localhost:8161/admin/queueBrowse/FOO?msgId=ID:dhcppc1-54766-1469009393902-5:1:1:1:4


NOTE:

If the authentication is enabled in the ActiveMQ admin as example in jetty.xml

 <bean id="securityConstraint" class="org.eclipse.jetty.util.security.Constraint">
        <property name="name" value="BASIC" />
        <property name="roles" value="user,admin" />
        <!-- set authenticate=false to disable login -->
        <property name="authenticate" value="true" />
    </bean>



we have to set security headers. If not 401 response will be received. So, following header should be set in the REST request

Authorization: Basic YWRtaW46YWRtaW4= 

YWRtaW46YWRtaW4= equivalent to the base 64 encoded version of the provided_username:provided_password
(Username and password is one of set which you use to access to the ActiveMq webconsole.)




Tuesday, June 7, 2016

View and Change Current JAVA version in Linux

Even though you have changed the JAVA_HOME variable in linux to chanhge the current java version in linux, java -version command will out put a version which you are not expecting. This may cause system has been installed several java versions.

As a solution for that you can change both JAVA_HOME and update-alternatives.

1) Change the JAVA_HOME variable as usual. (echo $JAVA_HOME to ensure)
2) Then type sudo update-alternatives --config java and follow the provided instructions.
3) Now java -version command should output the expected correct version of the java.

Friday, April 29, 2016

No need of any additional implementation to remove DB objects persisted by Unit test methods

If you have configured your setup with following configurations, no need to remove the DB objects which were persisted by unit test methods.

"In the TestContext framework, transactions are managed by the TransactionalTestExecutionListener which is configured by default, even if you do not explicitly declare @TestExecutionListeners on your test class. To enable support for transactions, however, you must configure a PlatformTransactionManager bean in the ApplicationContext that is loaded via @ContextConfiguration semantics (further details are provided below). In addition, you must declare Spring’s @Transactional annotation either at the class or method level for your tests."

- http://docs.spring.io/spring/docs/4.2.5.RELEASE/spring-framework-reference/html/integration-testing.html#testcontext-tx

Thursday, March 31, 2016

How to change file permission in Linux

There are several ways to change the permission of a file in Linux. But I feel following way is more clear and easy.

Let's Consider following file.

-rw-------. 1 udara udara 3066 Mar 25 10:07 settings.xml

After the initial dash,
First 3 places denoted permission for 'user' level
next 3 places denoted permission for 'group' level
last 3 places denoted permission for 'other' level

'r' indicates permission for read
'w' indicates permission for write
'x' indicates permission for execute

So, to change the permission for the file we can use following code syntax.
With the following command we are going to provide execute permission for above file only for 'user' level.

chmod u+x settings.xml  

'u' is for 'user', there can be 'g' (group), 'o' (other)
'+' is to indicate add a permission and '-' is to indicate remove a permission
'x' is for execution permission. There can be r,w,x characters.

-rwx------. 1 udara udara 3066 Mar 25 10:07 settings.xml


Friday, January 8, 2016

Filter out only the necessary values from s JSON String

Have you ever needed to filter out a JSON and get only the values that you want. Try with following JavaScript application. Definitely you will need many customization.
 

<html>
    <head>
        <script language="javascript">
            var jsObject = null;


            //Function to convert the json string to javascript object
            function extractFromJson(jsonText){
                jsObject = JSON.parse(jsonText);          
            }

            //Function to filter out values under a specific property
            function filterjsObject(key){
                if(key != ""){ //if object has multiple properties
                    var object = jsObject[key];
                }else{ //if object is single
                    var object = jsObject;              
                }
                var combinedValues = "";
                for(var key in object){
                    combinedValues = combinedValues + object[key] + '<br>';          
                }
                console.log(combinedValues);
                document.getElementById('plainJsonValues').innerHTML = combinedValues;
            }
          
            //Function to get JSON key list
            function getJsonKeys(jsonString){
                var select = document.getElementById("jsonProperties");
                var jsonString = JSON.parse(document.getElementById('jsonString').value);
                var jsonKeys = Object.keys(jsonString);
                console.log(jsonString);
                var properties = "";              

                for(var i = 0; i < jsonKeys.length; i++) {
                    properties = properties + jsonKeys[i] + '<br>';
                }
              
                document.getElementById('jsonProperties').innerHTML = properties;
            }
          
            //Function execution point
            function execute(){
                extractFromJson(document.getElementById('jsonString').value);
                filterjsObject(document.getElementById('jsonKey').value);
                getJsonKeys(document.getElementById('jsonString').value);          
            }

        </script>
    </head>


    <body>
        <p>JSON String : </p>
        <textarea id="jsonString" cols="80" rows="10"></textarea> <br>
        <p>JSON property (Optional) : </p>
        <input type="text" id="jsonKey"><br><br>
        <input type="button" onClick="execute()" value ="Process"><br>
        <p>JSON properties : </p>
        <p id="jsonProperties"></p>
        <p>Values for selected properties : </p>
        <p id="plainJsonValues"></p>
      
    </body>

</html>

Tuesday, January 5, 2016

Extract only the values from a select element on a web page hosted in internet

Do you need to extract only the values from a html select element which is on a web site hosted in the internet.

  • Then just copy and paste following html code and save it with any_name.html and open it with a web browser
  • Go to the site and get the relevant html code set for the select box.(You can extract it using a tool like web developer tools available in the browser)
  • Copy and paste above code set on the text area of our generated web page.  
  • Then click process button on the page
  • It will filter out only the required values.


<html>
    <head>
        <script language="javascript">
            function getModels(){
                var selectContent = document.getElementById("selectContent").value;
                var indexToStart = selectContent.indexOf(">") + 1;
                var targetString = selectContent.substring(indexToStart);
                var optionSet = targetString.split("</option>");
                var optionArrLength = optionSet.length;
                var modelSet = [];

                for(var counter = 0 ; counter < optionArrLength; counter++){   
                    modelSet[counter] = (optionSet[counter].split(">"))[1];
                }
               
                var resultLength = modelSet.length;
                var currentDivContent = "";
                for(var counter = 0; counter < resultLength; counter ++){
                    currentDivContent = currentDivContent + modelSet[counter] + "<br>";
                   
                }
                document.getElementById("resultText").innerHTML = currentDivContent;   
                console.log(currentDivContent);
            }
        </script>
    </head>

    <body>
       
        <form>
            <textarea id = "selectContent" rows=20 cols=100></textarea>
            <input type="button" value="Process" OnClick="getModels()">
        </form>
       
        <div>
            <p id = "resultText"></p>
        </div>
    </body>
</html>