Category Archives: java

How to get the running port in springboot Tests

To get the random server port in spring boot tests, you must :

  • decorate your test class with : @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
  • add a property in your Test class : @LocalServerPort private String serverPort;

full code snippet:

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
public class RandomPortTest{

    private int serverPort;

    public void validateRandomPort(){
       assertThat(serverPort > 0).isTrue();


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(){};;
  • camel context producer
public class CamelContextFactory {

    CamelContext customize() {
        DefaultCamelContext context = new DefaultCamelContext();
        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:


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

MESSAGE: Broken pipe

STACKTRACE: Broken pipe
	at Method)

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"
          <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=""
                   validationQuery="select current_date()" removeAbandoned="true" removeAbandonedTimeout="300" logAbandoned="false"


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