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.xml configuration that: ...

August 22, 2015 · 2 min

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. For DB2 ResultSet.TYPE_FORWARD_ONLY and ResultSet.CONCUR_READ_ONLY worked well. ...

August 21, 2015 · 2 min

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.lang.Object,org.apache.webbeans.jsf.scopes.Jsf2ScopesExtension,javax.enterprise.inject.spi.Extension],Qualifiers:[javax.enterprise.inject.Default]] [15/07/15 13:38:00:958 EST] 000000a9 ApplicationMg E WSVR0101W: An error occurred starting, ZizzledApp [15/07/15 13:38:00:959 EST] 000000a9 ApplicationMg A WSVR0217I: Stopping application: ZizzledApp [15/07/15 13:38:00:972 EST] 000000a9 WSEJBIntercep E CWOWB0102E: A JCDI error has occurred: <null> [15/07/15 13:38:00:977 EST] 000000a9 WSEJBIntercep E CWOWB0102E: A JCDI error has occurred: <null> [15/07/15 13:38:01:003 EST] 000000a9 ServletWrappe I com.ibm.ws.webcontainer.servlet.ServletWrapper doDestroy SRVE0253I: [ZizzledApp] [/ZizzledAppService/v1] [ZizzledAppServiceImpl]: Destroy successful. [15/07/15 13:38:01:039 EST] 000000a9 SharedEJBRunt I WSVR0041I: Stopping EJB jar: ZizzledAppEJB.jar [15/07/15 13:38:01:099 EST] 000000a9 SharedEJBRunt I WSVR0059I: EJB jar stopped: ZizzledAppEJB.jar [15/07/15 13:38:01:137 EST] 000000a9 ApplicationMg A WSVR0220I: Application stopped: ZizzledApp [15/07/15 13:38:01:208 EST] 000000a9 CompositionUn E WSVR0194E: Composition unit WebSphere:cuname=ZizzledApp in BLA WebSphere:blaname=ZizzledApp failed to start. [15/07/15 13:38:01:234 EST] 000000a9 FfdcProviderW com.ibm.ws.ffdc.impl.FfdcProvider logIncident FFDC1003I: FFDC Incident emitted on /var/logs/WebSphere8/ffdc/bencode02_9315bb77_15.07.15_13.38.01.2112090578995796253353.txt com.ibm.ws.runtime.component.CompositionUnitMgrImpl 679 [15/07/15 13:38:01:269 EST] 000000a9 DMAdapter I com.ibm.ws.ffdc.impl.DMAdapter getAnalysisEngine FFDC1009I: Analysis Engine using data base: /usr/WebSphere8/AppServer/properties/logbr/ffdc/adv/ffdcdb.xml [15/07/15 13:38:01:338 EST] 000000a9 FfdcProviderW com.ibm.ws.ffdc.impl.FfdcProvider logIncident FFDC1003I: FFDC Incident emitted on /var/logs/WebSphere8/ffdc/bencode02_9315bb77_15.07.15_13.38.01.235306456357083187192.txt com.ibm.ws.management.AdminServiceImpl.invoke 679 Wanting more details than an error occurred starting, tried my luck with the FFDC logs listed toward the end of the log: ...

July 25, 2015 · 3 min

Marketing Strategy and Branding

Building Strong Brands Marketing’s most basic premise: An exchange occurs between a buyer and a seller. 3 principles of marketing Customer value. What motivates the customer to want your product/service. Differentiation. What makes you stand out from the competition? Segmentation, targeting and positioning. Disecting your market horizon. 4 P’s of Marketing (Marketing Mix) The fundamental ingredients of the “exchange”. Each of the P’s can altered independently from each other in very interesting ways. ...

June 7, 2015 · 9 min

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.xml {% endhighlight %} Other Context specific configuration files can be registered by hacking your web.xml. Here’s an example for defining a place to stick JPA related cruft: ...

May 31, 2015 · 1 min

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. This approach does not try to hide the request/response model of the underlying HTTP, and it also says absolutely nothing about the specifics of the HTML/CSS/JS comprising the UI. ...

May 31, 2015 · 4 min

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.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" /> <entry key="hibernate.hbm2ddl.auto" value="none" /> <entry key="hibernate.format_sql" value="true" /> </map> </property> </bean> Transaction Manager The JpaTransactionManager (packaged within spring-tx.jar) which sucks in a reference to the entityManagerFactory, is responsible for taking care of transactions within the JPA layer. ...

May 29, 2015 · 4 min

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. ...

May 23, 2015 · 2 min

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.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd" version="3.1"> <display-name>SerivceModuleEJB</display-name> <assembly-descriptor> <interceptor-binding> <ejb-name>*</ejb-name> <interceptor-class> net.bencode.common.ServicePerformanceInterceptor </interceptor-class> </interceptor-binding> </assembly-descriptor> </ejb-jar> ServicePerformanceInterceptor.java ...

May 13, 2015 · 1 min

Microservices

Amped by @yaamehn’s opinionated Microservices A Reference Architecture recent talk at the Microservices Australia Meetup, has got me thinking about the many interesting possibilities Microservices stirs up. Many useful techniques are touched on, regardless of whether actually adopting Microservices. On the surface Microservices doesn’t appear to be anything groundbreakingly new. It does however push tried-and-trued concepts (e.g. abstraction, decoupling, modularisation, continuous delivery) to extreme levels. Fused with innovations in the operations space such as containerising like Docker, can lead to some very powerful outcomes; such efficient continuous delivery (on a micro scale), decoupling of domains allowing for a best of bread technlogies, and so on. ...

April 26, 2015 · 6 min