Saturday, 29 July 2017

Error handling in Camel Spring DSL

Error handling is one big the major advantage of Camel. It's basically a mimic of the regular try catch finally in the Java language but with more power.The Try Catch Finally as DSL you can use directly on your route.

Sysntax:

<route>
    <from uri="direct:start"/>
    <!-- here the try starts. its a try .. catch .. finally just as regular java code -->
    <doTry>
        <process ref="processorFail"/>
        <to uri="mock:result"/>
        <doCatch>
            <!-- catch multiple exceptions -->
            <exception>java.lang.exception</exception>
            <exception>java.lang.IllegalStateException</exception>
            <to uri="mock:catch"/>
        </doCatch>
        <doFinally>
            <to uri="mock:finally"/>
        </doFinally>
    </doTry>
</route>


Example :


<
route id="BLOG_TIMEOUT" >
    <from uri="direct:start"/>
    <!-- here the try starts. its a try .. catch .. finally just as regular java code -->
    <doTry>
       <to uri="{{HTTPURL}}?httpClient.soTimeout=50(Timout in milliseconds)" />
 <to uri="direct:catch"/>
 <!-- catch multiple exceptions -->
        <doCatch>
            <exception>java.net.SocketTimeoutException</exception>
          <handled><constant>true<constant></handled>
            <to uri="direct:catch"/>
        </doCatch>
    <doCatch>
           <exception>java.lang.Exception</exception>
           <handled><constant>true<constant></handled>
            <to uri="direct:catch"/>
        </doCatch>
        <doFinally>
            <to uri="direct:finally"/>
        </doFinally>
    </doTry>
</route>

Above camel route calling one HTTP end point.While returning a response if any error it will fall into catch block and execute the catch endpoint.To simulate rethrowing an exception from a doCatch you should use the handled predicate. If it is evaluated to false Camel will reattach the exception on the Exchange.




Camel HTTP endpoint Timeout configuration using Apache HttpClient

I have used  Apache HttpClient for a timeout in Camel HTTP end point.It specifically for HTTP calls.

We have various types of timeouts
  1. The Connection Timeout – the time to establish the connection with the remote host
  2. The Socket Timeout – the time to waiting for data – after the connection was established; maximum time wait for response
  3. The Connection Manager Timeout (http.connection-manager.timeout) – the time to wait for a connection from the connection manager/pool
I have used Socket Timeout to handle timeouts in Camel HTTP endpoint.Below things based on Spring DSL.We can do the same way in Java DSL.

Syntax :

{{HTTPURL}}?httpClient.soTimeout=50(Timout in milliseconds)

Syntax with Camel route:

   <route id="BLOG_TIMEOUT">
        <from uri="direct:blog.start"/>
         <to  uri="{{HTTPURL}}?httpClient.soTimeout=50(Timout in milliseconds)" />
        <to uri="direct:blog.end"/>
    </route>

BLOG_TIMEOUT -- route id
direct:blog.start -- from uri
{{HTTPURL}}?httpClient.soTimeout=50(Timout in milliseconds) -- http enpoint with socket timeout 
blog.start - one more endpoint

Tuesday, 23 June 2015

Faster Databases Import & Export Process in MySQL

Normally We are exporting and Importing Mysql database using .sql format.It's exporting and importing process speed depend on size of Database.But while using compress format increase the speed of export.

 Use of  gzip we can increase speed of import and export process of mysql databases.

  For Export Database

   mysqldump -uroot -p database_name | gzip -v > database_name.sql.gz

 For Import Database

    zcat database_name.sql.gz | mysql -uroot -p database_name


These comments very useful for database size is very large.

  

Wednesday, 13 November 2013

Resolving NameAlreadyBoundException in Jasper

If you are running multiple instances of JasperReports Server v5.x in same machine we may encountered this NameAlreadyBoundException 10990 exception.

Root cause is


Caused by: java.io.IOException: Cannot bind to URL
[rmi://localhost:10990/jasperserver]:
javax.naming.NameAlreadyBoundException: jasperserver [Root exception is
java.rmi.AlreadyBoundException: jasperserver]
at javax.management.remote.rmi.RMIConnectorServer.newIOException(RMIConnectorServer.java:826)
at javax.management.remote.rmi.RMIConnectorServer.start(RMIConnectorServer.java:431)
at org.springframework.jmx.support.ConnectorServerFactoryBean.afterPropertiesSet(ConnectorServerFactoryBean.java:187)
at
 
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
at
 
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
... 26 more
Caused by: javax.naming.NameAlreadyBoundException: jasperserver [Root exception is java.rmi.AlreadyBoundException: jasperserver]
at com.sun.jndi.rmi.registry.RegistryContext.bind(RegistryContext.java:139)
at com.sun.jndi.toolkit.url.GenericURLContext.bind(GenericURLContext.java:226)
at javax.naming.InitialContext.bind(InitialContext.java:419)
at javax.management.remote.rmi.RMIConnectorServer.bind(RMIConnectorServer.java:643)
at javax.management.remote.rmi.RMIConnectorServer.start(RMIConnectorServer.java:426)
... 29 more
Caused by: java.rmi.AlreadyBoundException: jasperserver
at sun.rmi.registry.RegistryImpl.bind(RegistryImpl.java:153)
at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:409)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:267)
at sun.rmi.transport.Transport$1.run(Transport.java:177)
at sun.rmi.transport.Transport$1.run(Transport.java:174)
at java.security.AccessController.doPrivileged(Native Method)



Solution for above is 

On one of the instances,

Change the port number on ../jasperserver-pro/WEB-INF/js.diagnostic.properties

Change the default diagnostic port 10990 to 10991(or some thing like 10992,10993).

Now you have one instance running on port 10990 and another running on port 10991.

Database Remote Access

Remote Access of DataBase in Different Host by use of following comment


mysql > GRANT ALL PRIVILEGES ON *.* TO 'USERNAME'@'%' IDENTIFIED BY ‘PASSWORD’;

Example :
mysql > GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY ‘root’;

above command gives access for all privileges. we can grand specific privilege also.


1. Select permission

mysql> GRANT SELECT ON *.* TO 'USERNAME'@'%' IDENTIFIED BY ‘PASSWORD’;

2. Select and update permission

mysql> GRANT SELECT,UPDATE ON *.* TO 'USERNAME'@'%'  IDENTIFIED BY ‘PASSWORD’;