Writing Cassandra User Defined Types with Spark and Java

Published in Big Data at 10-Feb-2016

Apache Cassandra and Apache Spark allow you to very quickly accomplish some truly cool things with very large sets of data. As a developer primarily focused on Java based technologies, one complication that arises with using the Cassandra/Spark stack is that Spark is written in Scala.  The DataStax Spark Cassandra Java connector allows Java developers to mitigate this, and while much of this connector API is straight forward, a few portions of it are not as intuitive as might be desirable.  One specific example is writing Cassandra rows containing Cassandra User Defined types.

Tags: scala spark java udt cassandra data


Agile Performance Reviews

Published in General at 24-Jan-2016

Almost every company I've ever been at has had some sort of performance review cycle and I don't recall meeting anyone that enjoyed it. It is undoubtably useful for employers to have records of the things employees have accomplished, goals that have been set and achieved, and progress towards professional development - But are yearly performance reviews really the best way to get this information?

Tags: employee programming review performance business


Reverse Proxying Wildfly JMS Connections with NGINX

Published in Java at 29-Nov-2015

Often, you may wish to have NGINX as a proxy, sitting in front of a Wildfly application server. NGINX can serve your HTML, be it a single page web app or static HTML, while Wildfly serves up your Restful API and NGINX proxies requests to that API. You may run into scenarios however, where you want more advanced protocols to talk to your application server without opening more ports on your firewall. Thanks to changes NGINX made a while back to support the Websockets protocol, you can also take advantage of Wildfly's ability to upgrade protocols dynamically and therefore have protocols like JNDI and JMS routed to Wildfly thorugh NGINX.

Tags: jms wildfly proxy java nginx


Read books? I want to work with you.

Published in General at 27-Nov-2017

I don't know if people become good at what they do because they read, or if people who are good at what they do read, but I do know that when I am interviewing people one thing I always look for on a resume is 'Reading' listed as an interest, and it's always a good conversation starter.

Tags: reading learning books interviews


Invoking JSR-303 Validation Automatically in JEE 6

Published in Java at 17-Aug-2014

JSR-303 is a useful feature introduced in JEE 6. It provides the ability to define validation rules declaratively, through the use of built-in validation annotations and the ability to create custom validation behavior. However, to me, JSR-303 seems like somewhat of an afterthought in JEE 6. It provides a framework for declaratively defining the validation rules to apply but does not allow you to declaratively indicate when that validation should be invoked.

Tags: java jee validation cdi jsr-303


Replacing Application Behavior at Build-Time using CDI

Published in Java at 10-Aug-2014

One of the things I am continually amazed by is the simplicity of doing complex things in JEE 6.  The Context and Dependency Injection (CDI) portion of the JEE 6 framework is one of the most useful pieces.  Dependency injection is nothing new, and even JEE 5 had some limited injection abilities, but CDI makes just about anything injectable, just about anywhere.  One very useful application of this technology that I have found lately is controlling the behavior of an application through the build-time injection of concrete implementations.

Tags: java cdi jee


Why Stack Overflow is Good for you

Published in Programming at 22-March-2014

I think everyone would agree that the best way to get better at programming is to program. "Practice makes perfect" as they say.

It's impossible to always be working on programming projects where you can practice all of your skills. It's only so often that I have to use Distributed Transactions or Spring Auto-wiring. If only there was a kind of 'Chess Puzzle' for programmers!

Tags: programming java learning


Java Reference Types

Published in Java at 6-Feb-2012

 The Java language allows the use of four different types of object references (Strong, Soft, Weak and Phantom). The usage, intricacies and benefits of these 4 types of references seem to be a mystery to even many experienced Java developers.  Using Soft, Weak and Phantom references properly can be key tools to develop memory-sensitive caches of data and for object finalization without the problems normally associated with overriding the finalize() method.

Tags: collection java references weak soft garbage phantom


Using Embedded Derby in Tomcat

Published in Java at 10-Jan-2012

When deploying a web application in Tomcat, or another similar servlet container, you may desire that your application be able to access robust RDBMS functionality without the hassle of setting up a full-fledged database server like Oracle, PostgreSQL or MySQL.  Apache Derby is powerful but light-weight ANSI compliant RDBMS written entirely in Java that has the ability to run in Embedded Mode - that is, it runs in the same VM as, and has its life cycle managed by, the application which uses it.  When deploying such a solution, it can be challenging to ensure that the Derby embedded instance is correctly started when the web application is deployed, and also correctly and cleanly shutdown when the application is undeployed.  This article presents one possible approach to managing the life cycle of an embedded Apache Derby database used in a web application deployed in Apache Tomcat.

Tags: servletcontextlistener database servlet derby apache tomcat embedded


Hashing and Salting Passwords with Spring Security

Published in Java at 28-Dec-2011

As application developers, we rely on a huge number of factors for security, many of which are largely out of our control: the operating system, the server software being used, the security framework being used. While we can strive to use secure coding practices, we never know when a fundamental flaw, in the operating system for example, may give a malicious attacker access to our application database – including our users' names and passwords.   Despite experts warning of the dangers, with so many accounts, it is extremely common for users to reuse usernames and passwords on a variety of different sites.

Spring Security gives us some tools, much of which can be enabled with only a few simple lines of configuration, to help ensure that the damage from such a breach is as contained as possible.

Tags: salt mvc java login password hash spring security


Comparing Interned Strings In Java

Published in Java at 2-Dec-2011

Recently, I came across a conversation thread in one of the LinkedIn discussion groups on comparing strings in Java.  The discussion started with what seems like a fairly simple question: What is the output of this simple snippet of code:

The Code

public class Test {
    public static void main(String[] args) {
        String a = "Hello";
        String b = "Hello";

        if (a == b) {
            System.out.println("a == b");
        } else {
            System.out.println("a != b");
        }
    }
}

Note: This is a reasonable approximation of the code being discussed, it may not be verbatim.

What I found most amazing was that the discussion over the output of this simple piece of code went on for days, with dozens and dozens of posts, even after the right answer had been given and had been clearly explained. As such, it seems that what is going on in this bit of code may not be as widely understood as I thought it would be.

Tags: equals intern string java compare


Extra Login Fields with Spring Security

Published in Java at 22-Nov-2011

The Spring framework is an excellent tool for accelerating and simplifying Java enterprise application development.  For many commonplace tasks, simply adding a few lines to an XML configuration file is all you need to introduce fairly complex functionality - eliminating the need for much of the boilerplate code that the application developer would otherwise have to implement.  

However, when it is necessary to develop a feature with Spring that deviates from the typical use-cases, it can be a little more complicated to configure correctly.

Recently, I was developing a web portal for a client.  Part of the login process required that the user specify their username and password in addition to a company code.  The standard Spring Security configuration easily handles logins that require a username and a password, but how can this basic configuration be modified to handle what amounts to a multi-part username?

Tags: password login username security mvc spring


A Quick Introduction

Published in General at 22-Nov-2011

Hello! 

I have played around with the idea of creating a tech blog for some time now, but I wasn't sure I really had enough to say to warrant it.  What finally made me decide that I did want to start writing about some of my adventures in programming was somewhat selfish.  

There are many things in software development that I have had to do several times, but not regularly enough that I end up committing them to memory.  Usually, when it comes time to implement a feature like this, I end up doing a bit of Googling to refresh my memory, and usually have to end up checking out a half dozen web sites, including technical documentation, APIs and other blogs, before I remember all the details necessary.

So, in an effort to save time, I thought that it might be a good idea if I try to aggregate some of this information together in one place.  Not only does it help me solidify it in my memory, but it ensures that I can easily find it again, without having to turn to Google, or digging desperately through my browser history, a few months or years down the road when I need it next.

Hopefully some of you are trying to implement some of the things I will write about here, and I hope that I will be able to save you some time by doing the legwork in advance.

I am primarily an Enterprise Software developer, specializing in Java Enterprise Edition, although I have done a fair bit of Enterprise .NET development as well.  I believe strongly in open source software, and one of the things I most like about Java is the huge and diverse open source community that has sprung up around it.  I am interested in all facets of application development, from desktop and web UI development, to database development and everything in between.  I develop primarily using Linux, although I haven't yet completely been able to free myself of Windows, and I hope to include several articles on this blog related to enterprise software development using the Linux OS.

I sincerely would appreciate any feedback you have on any of the articles I present here.  I do on occasion (and sometimes frequently) get things wrong and I would be pleased to make any corrections or updates that are necessary.  Also, if you know of a better way of doing something than what I present in the various articles here, please let me know.  I am always interested in learning and improving.

Thanks,

Daniel Morton 

Tags: source java software programming open linux

About the Author

dan.jpg

Daniel Morton is a Software Developer with Shopify Plus in Waterloo, Ontario and the co-owner of Switch Case Technologies, a software development and consulting company.  Daniel specializes in Enterprise Java Development and has worked and consulted in a variety of fields including WAN Optimization, Healthcare, Telematics, Media Publishing, and the Payment Card Industry.