Java: Pass By Value or Pass By Reference

Posted in IT StuffTagged

Data is shared between functions by passing parameters. Now, there are 2 ways of passing parameters: Passing by value: this method copies the value of actual parameter. The called function creates its own copy of argument value and the use it inside the code. As soon as the work is done on the copied value,….

Spring 4+ with Ehcache 3.x

Posted in IT StuffTagged , ,

This post describes an example of using Ehcache with a Spring MVC application deployed on Tomcat (not using Spring boot). It is a legacy app that needs to be upgraded. The dependencies are: Application context must be updated in this way: The method must be annotated with @Cacheable so that Spring will handle the caching. As a result….

Java: Sort a list of objects according to matching string/pattern

Posted in IT StuffTagged

I need to sort a list of objects in which the matching items come up and others will go down so. For instance, a list of objects on which all the labels are in alphabetical order except for all the values that start with P that will be put on the top of the list…..

How to use Spring DataSource bean as data source for Log4j 2 JDBC appender

Posted in IT StuffTagged , ,

I would like to log log4j2 messages into a relational database using the datasource defined on application context and initialized using spring using log4j 2.10. One possibility is to add a JDBC appender inside log4j2 xml configuration but, Log4j is initialized before Spring so, dataSource won’t be available at runtime so the only solution is….

Warning about SSL connection when connecting to MySQL database

Posted in IT StuffTagged ,

After a recent update of mySql, I get this warning: WARN: Establishing SSL connection without server’s identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn’t set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to….

Convert timestamp long to normal date format

Posted in IT StuffTagged

One simply way to convert a Long time stamp into a formatted string is (time paramter is Long timestamp): Date date = new Date(time); Format format = new SimpleDateFormat("yyyy MM dd HH:mm:ss"); return format.format(date);Date date = new Date(time); Format format = new SimpleDateFormat("yyyy MM dd HH:mm:ss"); return format.format(date); These packages must be included. import java.sql.Date;….

How do I fix a 65535 bytes limit Stacktrace?

Posted in IT StuffTagged ,

It is possible that after an upgrade you may encounter this error on some of the more complex pages and root cause provided by tomcat console is : To solve the issue you need to locate the file [Tomcat_Home]/conf/web.xml and search the file for ‘JspServlet’. This should return an xml node of containing some values…..

MappingJacksonHttpMessageConverter not found

Posted in IT StuffTagged , ,

I was trying to run a java batch that call an application context without success (it’s a java app that calls a Camel spring context). This is what I get during the startup: ERROR ApplicationProperties @ addApplicationProperty [28] org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from file [/MessageRouting/src/test/resources/META-INF/spring/LOCALHOST-db-context.xml]; nested exception is java.lang.NoClassDefFoundError: org/springframework/http/converter/json/MappingJacksonHttpMessageConverter Fatal error! java.lang.RuntimeException:….

Which log4j configuration are you using?

Posted in IT StuffTagged ,

Sometimes log4j is not working properly and you need to verify where it is actually writing the log entries. This can be easily verified turning on the log4j.debug: -Dlog4j.debug-Dlog4j.debug It will print to System.out lots of helpful information about which file it used to initialize itself, which loggers / appenders got configured and how etc.

Parse an unknown JSON with Jquery

Posted in IT StuffTagged , , ,

Sometime it happens to receive a JSON string than need to be visualized without knowing the structure. Suppose we have an HTML table: <tbody id="reportTable"> </tbody><tbody id="reportTable"> </tbody> To populate this table with jQuery it’s possible to use this simple code: var rows = ${reportRows}; var html = $.each(rows, function(key, value){   $("#reportTable").append("<tr>");   $.each(value,….