Category Archives: java

Configure camel -openwebbeans – deltaspike to get a standalone camel application running with cdi

here are code snippet to get camel, OpenWebBeans container and deltaspike .

  • The code that boots the app
  org.apache.camel.cdi.Main maincdi = new org.apache.camel.cdi.Main(){};
  maincdi.run();
  • camel context producer
public class CamelContextFactory {

    @Produces
    @ApplicationScoped
    CamelContext customize() {
        DefaultCamelContext context = new DefaultCamelContext();
        context.setName("my-custom-camel-context");
        return context;
    }

    void cleanUp(@Disposes CamelContext context) {
        // ...
    }
}

Continue reading Configure camel -openwebbeans – deltaspike to get a standalone camel application running with cdi

Proper Tomcat Resource configuration for MySql

Lately, I was faced with a mysql error when configured as a Resource in the tomcat server.xml configuration file.

The error looked the following:

STACKTRACE:

com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception: 

** BEGIN NESTED EXCEPTION ** 

java.net.SocketException
MESSAGE: Broken pipe

STACKTRACE:

java.net.SocketException: Broken pipe
	at java.net.SocketOutputStream.socketWrite0(Native Method)
	at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)

The problem was that I was not using the validationQuery parameter to be sure that the connection is still alive. So the parameter I neede absolutely were :

    validationQuery="select current_date()" removeAbandoned="true" removeAbandonedTimeout="300" logAbandoned="false" initialSize="3"

Here is part of the server.xml file


     <Engine name="Catalina8680" defaultHost="localhost8680">
          <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
                 resourceName="UserDatabase"/>
          <Host name="localhost8680"  appBase="webapps8680"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false">
                <Context reloadable="true" displayName="myapp" docBase="/opt/apache-tomcat-6.0.20/webapps8680/myapp" path="/myapp" workDir="work/Catalina8680/localhost8680/myapp">
                
                <Resource name="jdbc/myapp_ds_0409085721" auth="Container" type="javax.sql.DataSource"
                   maxActive="10" maxIdle="3" maxWait="10000"
                   username="myapp_db" password="myapp_prod" driverClassName="org.gjt.mm.mysql.Driver"
                   url="jdbc:mysql://localhost:3306/myapp" 
                   validationQuery="select current_date()" removeAbandoned="true" removeAbandonedTimeout="300" logAbandoned="false"
                   initialSize="3"/>

...


Tomcat Mutual ssl configuration

Lately I had to configure tomcat for mutual SSL. I ran into some problems and here is what helped me.

In fact, My problem was not having the correct certification path in my keystore.
I had the following certificate :

"SERIALNUMBER=2010,CN=Government CA,C=BE" 

and the certificate sended by the client was certified by the intermediary :

"SERIALNUMBER=2011,CN=Government CA,C=BE". 

=> the only difference is 2010 => 2011. The problem was solved after adding the correct certificate to my keystore.
Continue reading Tomcat Mutual ssl configuration