Counting active accounts with Metrics

Based on a request parameter in a servlet context Recently I had the task to report active accounts based on http requests. Here I’m going to show you my solution with Dropwizard Metrics. Basically I am using a servlet filter togehter with an counter. [code] @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws …

Update your package dependencies

So why should I update the deps for my application? Keeping your dependencies up-to-date is more important than ever One reason is that if you update the dependencies regularly than you can do painless migrations. Nearly every 6 months major releases of frameworks e.g like angular or react with API breaking changes are available. And such a …

Workaround – No tests found with Testrunner JUnit 5

Java 8, Eclipse, JUnit 5 & Gradle It seems to be a bug in Eclipse and it’is fixed in the Oxgen Release 3 (4.7.3). But I still have the problem in my Java 8 project. So I did a little trick. I changed the version for the engine and the launcher back to 5.1.0. [code] …

Calculate memory usage of Java objects

With Twitter’s ObjectSizeCalculator If you are looking for an easy way to estimate the object size than this could interest you. [code] // gradle dependency // https://mvnrepository.com/artifact/com.twitter.common/objectsize  compile group: ‚com.twitter.common‘, name: ‚objectsize‘, version: ‚0.0.12‘ System.out.println( ObjectSizeCalculator.getObjectSize(myObject) ); [/code] The memory size of your object depends on the architecture, the actual vm implementation and whether the …

Embedded Jetty with Servlet and Annotations

How do I programmatically configure Jetty that I can use Servlet Annotations? If you doing just servlets with jetty, this article could be interesting for you. I show you how I did it. Here comes the configuration: [code] … server = new Server(port); server.addBean(LOG); WebAppContext webAppContext = new WebAppContext(); webAppContext.setContextPath("/"); String webxmlLocation = JettyServer.class.getResource("/webapp/WEB-INF/web.xml").toString(); webAppContext.setDescriptor(webxmlLocation); …

Why you should use new language features

A quick list I put together a list with a number of reasons why you should use new language features. The list includes points which are obvious, I learned or I found on the internet. improved design * easier to understand * easier to change * less defects effectiveness * using standards * getting help …

Every push a build with Travis CI

Build and test your software projects automatically I wanted that cool build passed badge for my projects as I have seen at Github. So I had a look at Travis CI, which is a continuous integration service used to build and test software projects. Let’s have a look at the build file. .travis.yml [code] language: …

Unit Testing Servlets with Mockito

A quick example how to write unit tests for servlets Okay, I’m writing a Servlet. So I want to write a unit test too. With Mockito this is a quite simple task. Here I show you a simple unit test for a Hello World Servlet. The Servlet returns only „Hello World“. [code] public class HelloWorldServletTest …

Find duplicate code with CPD

A copy/paste detector I’m sure that you know PMD, the famous static code analyzer. But have you ever tried CPD? Installation CPD belongs to PMD. You have to install PMD first. [code] $ cd $HOME $ wget https://github.com/pmd/pmd/releases/download/pmd_releases%2F5.8.1/pmd-bin-5.8.1.zip $ unzip pmd-bin-5.8.1.zip $ alias pmd="$HOME/tools/pmd-bin-5.8.1/bin/run.sh pmd" $ alias cpd="$HOME/tools/pmd-bin-5.8.1/bin/run.sh cpd" [/code] Command line usage I give you some examples …

Consent Management Platform von Real Cookie Banner