Wednesday, April 24, 2013

Post data with curl when you are behind proxy

I found that SoapUI 4.5.1 have so problems to access some web service endpoint when you are behind proxy. It seems that your authentications is not processed correctly, my proxy server always return HTTP error 407. So I started to play with 'curl' command. Let me show ho to do that:
curl -v --proxy proxy.something.com:8080 --proxy-user myname:password \
 --request POST \
 --header "Content-Type: text/xml;charset=UTF-8" \
 --header "SOAPAction: http://somesite.com:80/adistc/axis2/services/interaface/getAvailableNames" \
 --data @request.txt \
 http://somesite.com:80/adistc/axis2/services/interaface/
Most of parameters are self explaining. Note that @ in parameter --data means that posted data should be find in file 'request.txt'. Headers are not necessary. Obviously in request.xml is your soap XML request. Switch -v shows you request and response data.

Saturday, April 6, 2013

MySQL and Hibernate exception

Following exception made me some problem.
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690)
        at java.lang.Thread.run(Thread.java:662)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.Connection was implicitly closed due to underlying exception/err


** BEGIN NESTED EXCEPTION **

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException
MESSAGE: Communications link failure

Last packet sent to the server was 18788 ms ago.

STACKTRACE:

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

Last packet sent to the server was 18788 ms ago.
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
        at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
        at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2985)
        at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2871)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3414)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542)
        at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1734)
        at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1885)
        at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
        at org.hibernate.loader.Loader.getResultSet(Loader.java:1953)
        at org.hibernate.loader.Loader.doQuery(Loader.java:802)
        at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
My environment was MySQL 5.0.77, Java 1.6.0_24-b07, Apache Tomcat 6.0.32, Hibernate 3.6.0.Final.
This exception never occurs at development or continues integration environment. This problem appears just in production after one day of running without application restart. After some time of testing JDBC connection handling, TCP/IP connection to MySQL database I found that problem is caused by incorrect hibernate dialect configuration
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
After correcting to:
<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
everything works fine.