Java

Troubleshooting a Performance Problem Using NewRelic

Or, how to poorly implement adding css and javascript resources to a page One of the tools we use at work is the MagnoliaCMS. It powers some portions of some of our properties. For those who have not heard of it (I had not until a few years ago), think of it as WordPress, but more enterprise-y. Recently we noticed that some of the properties …

Troubleshooting a Performance Problem Using NewRelic Read More »

Switching from Essentials4J to Kotlin

At work we have a project that used Essentials4J, and its predecessor Rapidoid Fluent, to simplify some stream/collection APIs. We have been converting this project to Kotlin, and no longer need that library. The conversion was very simple. It highlights some of the things you can do with collections with Kotlin’s standard library. Do.group(…).by(…) Do.map(…).to(…) Do.map(…).to(…) with unique values d639a7ccf9252433

Automatic file encoding detection in Java

A few months ago I worked on a process that imports Facebook Leads into a legacy system. Facebook sends its advertising data as UTF-16 encoded CSV. The tool also had to support the CSV files occasionally being ended by hand, which reverted the encoding to something a bit more standard. Thankfully, there was a small library out there that helped. So, in case you ever …

Automatic file encoding detection in Java Read More »

Using Consumer in Spring Validator to validate nested collections

In one of my projects I have a custom Spring Validator that validates a nested object structure, and adds per-field error messages. As an example, a field nested inside an array might produce an error like the following: array[0].field must be a valid value The Errors object works as a stack, so field names have to be pushed as the validator iterates through arrays and nested …

Using Consumer in Spring Validator to validate nested collections Read More »

Hibernate Logging Options

For years I have relied on a simple property “show-sql=true” to see Hibernate’s generated SQL. This option is fairly limited: it bypasses the logging framework in the rest of my apps (SLF4J) it doesnt show parameters, just question marks it doesn’t show any timing information Frustrated at these limitations, I set out to understand all of the other options available to me. This is very …

Hibernate Logging Options Read More »

Making JMeter accept a HTTP 404 as success

One of the projects I am currently working on involves re-writing a REST service written in ColdFusion into Java/Spring. I’m in the testing phase, and am trying to make sure the endpoints behave the same as the ColdFusion versions. One of the tests I am performing is to replay a month’s worth of GET requests from production against this service, and look for differences in …

Making JMeter accept a HTTP 404 as success Read More »

Java 8: Optional

A fellow developer today asked me a question about the Optional interface in Java 8. My team is still working on a Java 6 stack, but his team is blazing the trail to Java 8. I’ve used Optional a little bit in some side work, and I am a little more familiar with Guava’s version. His use case centered around the correct syntax to rewrite this using map() instead …

Java 8: Optional Read More »

Mockito AdditionalAnswers

Sometimes you use a framework for years, and then discover something new that it can do. I had one of those moments today with Mockito. I have an API that I am mocking, where I need to capture the argument passed in for further testing, that had a line that ended up looking something like this: when(mockRepository.save(captor.capture())).thenReturn(captor.capture()); This is actually incorrect Mockito syntax. The captor.capture() doesn’t …

Mockito AdditionalAnswers Read More »

Mocking Time with Joda

A big project I have been developing over the last year has been an automated billing system. There is a part of it that involves scheduling bills, and has a lot of pieces that need to know various dates – when bills are due, when they were created, and the current time. We are trying to write good unit tests, and I am trying to make sure the …

Mocking Time with Joda Read More »

Encrypting config files with Spring 3.1 and jasypt

I’ve been working on a project that at one point needed encrypted configuration files. The JASYPT library provides a very nice tie-in with Spring. There were some pieces I had to put together, so here are the results of my @Configuration file that handles encryption. It will scan a given directory (specified by the VM argument config.dir) for any .properties files, and uses JASYPT to …

Encrypting config files with Spring 3.1 and jasypt Read More »

Full Spring 3.1 Config

Someone asked for my full Spring 3.1 annotation configuration. I’ve stripped all domain-specific information, but the overall structure is intact. SpringConfig.java – this is the top level class, is empty except for @ComponentScan and @Import statements. The web.xml references this. SpringMvcConfiguration – Any MVC related configuration DatabaseConfiguration @Configuration @ComponentScan(basePackageClasses = { SpringConfig.class}) @Import({ SpringMvcConfiguration.class, DatabaseConfiguration.class}) public class SpringConfig { } @Configuration @EnableWebMvc @Import({ MvcComponents.class,BeanConfiguration.class }) …

Full Spring 3.1 Config Read More »

Spring 3.1, No-XML, Hibernate, Cglib, and PermGen errors

Lately I have been maintaining several Spring-MVC applications written from the ground up with Spring 3.1. They use the purely Java based configuration scheme that comes in version 3.1, Hibernate. The apps do not have the pattern of “an interface for every class” that some Spring apps have, so it proxies concrete classes using Cglib. When the apps are deployed to Tomcat, we do a …

Spring 3.1, No-XML, Hibernate, Cglib, and PermGen errors Read More »

Making Java, Coldfusion, Tomcat and PayflowPro Play Nicely

One of the more odd parts of our architecture at work involves a cluster of Tomcat instances running ColdFusion and Java services side by side. We are porting our existing ColdFusion services over to Java/SpringMVC applications, and during the transition they are being served up by the same app servers. One of these services interacts with Paypal/PayflowPro. We have a ColdFusion Component (CFC) that makes …

Making Java, Coldfusion, Tomcat and PayflowPro Play Nicely Read More »

Google GSON and Thread Safety

At work we are using gson to do some soft serialization between some applications. Our production application started to throw some errors this afternoon, and after looking into the problem it would appear that gson has a static reference to SimpleDateFormat (or, more correctly, a static member that was constructed with DateFormat.getDateTimeInstance(), which returns a SimpleDateFormat).  You can see the problem here, line 58. A …

Google GSON and Thread Safety Read More »