Classloaders

First some kudos and credits to the below. None of the material in this post is original, and I have documented it for my personal learning. Please refer to the below original (and superior) articles. ZeroTurnaround’s Jevgeni Kabanov awesome and most practical Do You Really Get Classloaders? Oracle’s A Sundararajan Understanding Java class loading All the way from 1996 by Chuck Mcmanis The basics of Java classloaders Hello java.
Read more →

Struts

Struts, the famous Java MVC web framework of the late 90’s and early 00’s that pioneered well structured server side web logic. Many Java based enterprise applications developed during this era (a metric s#!t ton) still make heavy use of Struts 1.x today. Apache Struts 1 is a discontinued open-source web application framework for developing Java EE web applications. It complements the Servlet API to encourage developers to adopt a model–view–controller (MVC) architecture.
Read more →

wsimport

Thrown into a large, legacy EE code base, I needed to create new SOAP web services, and update some existing ones. To make life interesting, there lacked a repeatable process (e.g. via Ant or Maven) for processing WSDL’s and generating the associated JAXWS and JAXB source code artifacts in a consistent manner. First things first, a repeatable and scriptable procedure. wsimport to the rescue. wsimport has been around so long now, the com.
Read more →

Java Prepared Statement Overflow

On the hunt for an sporadic DB2 SQL Error -805, I took a dive into some logs. It had been rearing its ugly head for weeks now, and starting to impact our business area. The call stack pointed straight to the bad patch of code, the Java EE solution contains a programmatic TimerService, responsible for shuffling data from one database to other; a rudimentary replication solution in other words. The specific source database in this case happened to be DB2 running on AIX.
Read more →

IntelliJ Bad Font Rendering on Linux

Font rendering in IntelliJ on Linux looks horrid. Any Java based application does for that matter. I can’t take it anymore. I just burnt 30 minutes looking into solutions. Fastest option, run it on the Linux optimised JVM tuxjdk. tuxjdk is a series of patched to OpenJDK to enhance user experience with Java-based and Swing-based tools (NetBeans, Idea, Android Studio, etc) Instructions (for me) next time this happens:
Read more →

Eclipse brain damage

In my current project we use IBM’s version of Eclipse. On a Windows 7 VM. The VM crashes weekly. Not only has this made me paranoid about loosing my work (I stash my changes in version control like a demon), it seems to corrupt my RAD/Eclipse instance. Starting RAD produces the useful “An error has occured” error message: !SESSION 2015-09-02 10:53:50.331 ———————————————– eclipse.buildId=unknown java.fullversion=JRE 1.7.0 IBM J9 2.6 Windows 7 amd64-64 Compressed References 20140313_192258 (JIT enabled, AOT enabled) J9VM - R26_Java726_SR6_20140313_1318_B192258 JIT - r11.
Read more →

JAX-WS SOAP Logger

Hot tip, logging helps understand how a piece of software works, long after it has left the cosy confines of the debugger. Logging SOAP message bodies can be really handy, when the thing that is interacting with your software is out of your control (i.e. a vendor or trading partner). And if you’re using web services, the likehood of this is high. Running JAX-WS web services in our servlet container, needed a quick and easy way to acheive this.
Read more →

Logback Boilerplate

A useful starting place logback setup. I needed a way to roll logs not only by date, but also by size, to prevent behemoth log files from being generated. The marvellousSizeAndTimeBasedFNATP triggering policy (which comes out of the box) will gzip roll logs based on date, and then size too. So your logs directory ends up looking something like this: fooapp.log fooapp_2015-08-22.0.log.zip fooapp_2015-08-22.1.log.zip fooapp_2015-08-22.2.log.zip fooapp_2015-08-23.0.log.zip fooapp_2015-08-24.0.log.zip … Here’s a sample logback.
Read more →

JDBC blob extractor

I was dealing with an application that stores image binary data in DB2. DB2 tooling (e.g. IBM Data Studio) didn’t seem to offer a convenient way of extracting images out of the box. I wasn’t suprised. It turns out dragging them out via JDBC was the path of least resistance. Ensure that you give your JDBC driver enough hints about the heavy nature of the result set that is coming back.
Read more →

JVMVRFY012 Stack Shape Inconsistent

Following the routine restart of a WebSphere app server earlier this week, our application refused to start back up. This was an annoying suprise, as the environments are normally incredibly stable. The logs highlighted that a darker force was at play: [15/07/15 13:38:00:581 EST] 000000a9 StandaloneEJB I StandaloneEJBLifeCycle startApplication OpenWebBeans Container is starting… [15/07/15 13:38:00:589 EST] 000000a9 ObserverMetho I ObserverMethodImpl notify Cannot send event to bean in non-active context : [-43735604,Name:null,WebBeans Type:EXTENSION,APITypes:[java.
Read more →

Spring Context Specific Configuration Files

Spring can be configured in lots of different ways and using context specific XML configuration is one of the preferred approaches. Context specific configuration in other words is simply a chunk of XML specific to a single concern (e.g. servlet config, jpa config, and whatever else you need). A classic example of this is the servlet-config.xml that the Dispatcher Servlet binds against: {% highlight xml %} fitTrackerServlet org.springframework.web.servlet.DispatcherServlet contextConfigLocation /WEB-INF/config/servlet-config.
Read more →

Spring MVC

Some of my learning notes about using the excellent Spring MVC framework to build a simple MVC based web application. Spring MVC is an action oriented framework. For a good overview on the differences between UI Component and Action oriented frameworks checkout this link. In action oriented MVC land, the controller dispatches to a specific action, based on information in the request. Each action does a specific thing to transform the request and take action on it, possibly updating the model tier.
Read more →

Spring Data JPA Fun

Maven dependencies: <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.21</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-entitymanager</artifactId> <version>4.1.9.Final</version> </dependency> <dependency> <groupId>javax.transaction</groupId> <artifactId>jta</artifactId> <version>1.1</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>3.2.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-orm</artifactId> <version>3.2.0.RELEASE</version> </dependency> Entity Manager Factory Used to bootstrap JPA and also Hibernate inside our application. The LocalContainerEntityManagerFactoryBean which is packaged in the spring-orm.jar, references the defined persistence unit. <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="persistenceUnitName" value="punit" /> <property name="dataSource" ref="dataSource" /> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> <property name="showSql" value="true" /> </bean> </property> <property name="jpaPropertyMap"> <map> <entry key="hibernate.
Read more →

Java EE Container Context Roots

Occassionally the need to do multiple side-by-side deployments of the same packaged application can arise. In a scenario recently faced, it was useful to have multiple versions of our packaged EAR deployed and configured slightly differently (for example: with and without security in QA environments). As the application is expected to run hot 24/7, the need for a simple side-by-side versioning (e.g. v1, v2) scheme was also important. Allowing us to deploy v1, and later breaking (incompatible) versions v2, v3, given our service consumers the freedom to upgrade when convenient.
Read more →

EJB Timing with Interceptors

Java EE is packed tight with useful functionality. The humble Interceptor provides cross cutting functionality external to the targetted code, without modifying the code itself. In other words AOP. The API is rather simple an involves using @AroundInvoke. The following highlights just how simple it is to log all EJB service call execution times, without the need to modify a single bean. META-INF/ejb-jar.xml <?xml version="1.0" encoding="UTF-8"?> <ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.
Read more →

soapUI freeze on Mac OS X

Well first time for everything. Messing around with some JAX-WS web services, wanted to spin up my favourite SOAP frontend, soapUI. On my Mac. Annoyingly it would just immediately hang. Completely frozen. soapUI by default will try and render a web page on startup. This doesn’t seem to work out so well when running on OSX. A handy little article I found on Anton Perez’s blog, made my day. Start ‘Activity Monitor’ and Force Kill your dead soapUI process.
Read more →

Apache Ant

Lately I’ve gleened some “real world” Apache Ant tips and tricks from some really impressive Java EE developers I’ve had the opportunity of working with over the last year. Apache Ant is a Java library and command-line tool whose mission is to drive processes described in build files as targets and extension points dependent upon each other. Ant supplies a number of built-in tasks allowing to compile, assemble, test and run Java applications.
Read more →

Asynchronous Workloads with WebSphere Application Server

So I’ve been using WebSphere for a while now, and continue to discover new functionality in this powerhouse of an application server. This post focuses on performing background work in WebSphere Application Server (WAS) 7.0, which is an EE 5 compliant container. Firstly a quick outline of the problem. Across a series of web service calls, there exist a number of intensive processes that need to take place. I wanted a way to perform work this asynchronously somewhere else within the application server, without being bound to the request/response cycle that HTTP web services impose…in essence making the actual service calls appear super snappy.
Read more →

REST APIs with RESTEasy and Tomcat

Java EE application servers at times can feel big and heavy…as in behemoth. I’m “lucky” enough to work with an old version of WebSphere AS on a daily basis at the moment. To keep things fast, I’ve resorted to using lighter weight containers for the job at hand. Tomcat is king when it comes to meeting the servlet specification, and no more. Its hell fast. As a result is very lean on what it offers out of the box.
Read more →

Neat and tidy Swing with JGoodies FormLayout

When its comes to laying out slightly complex forms in AWT or Swing, using the baked-in layout managers (BoxLayout, FlowLayout, GridLayout) can feel frustrating. Thankfully I stumbled across the JGoodies FormLayout layout manager whilst working on some Swing applications using IntelliJ IDEA 13. IDEA has an integrated visual GUI builder, that makes it really quick and easy to mock up FormLayout controlled layouts, but for the most precise level of control I found handcrafting to be very clean and simple.
Read more →

Spring Dependency Injection

Spring provides dependency injection capabilities using Setter injection, or Constructor injection. Object models can then be declaratively represented in XML. Here’s a Setter injection based example using the property element: <bean name="shaker" class="net.bencode.model.Shaker"> <property name="proteinPowder" ref="proteinPowder" /> </bean> <bean name="proteinPowder" class="net.bencode.model.ProteinPowder"> <property name="grams" ref="120" /> </bean> Or if XML isn’t your thing, annotations are also an option, using a combination of @Component and @Autowired. @Component public class Shaker { @Autowired private ProteinPowder proteinPowder; .
Read more →

JavaServer Pages

As a follow up to previous post [The Servlet API]({% post_url 2007-02-20-servlet-api %}), this post aims to sweeps over some fundamentals of JSP, a technology which thanks to its simple yet extensible design, still to this day, underpins many modern web application frameworks. JavaServer Pages (JSP) is a technology that helps software developers create dynamically generated web pages based on HTML, XML, or other document types. Released in 1999 by Sun Microsystems.
Read more →

The Servlet API

As you start out building Java web applications, you soon find that it sit upon several well designed building blocks. Once the penny drops, and an intuition about these building blocks is gained, creating web apps on Java becomes a delight. Two key, top level concepts are the mighty Servlet API and JavaServer Pages (JSP). These are deployed to a Web container, also commonly referred to a Servlet (or Web) container.
Read more →