Posts

WebSphere stdout/stderr logging redirect

Working on an application using log4j and deployed in WebSphere, we had the need to output the logs on the SystemOut.log and SystemErr.log files. In WebSphere with the normal configuration it outputs all the logs in the SystemOut.log. We wanted only the ERROR and WARN level logs redirected to the SystemErr.log file, so we used the configuration below for the log appenders. log4j.properties ######################################## # LOG4J-properties ######################################## # This is the configuring for logging displayed in the Application Server log4j.rootCategory=DEBUG, stdout, stderr log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.Threshold=DEBUG log4j.appender.stdout.Target=System.out log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=[%-5p] %t (%d{dd/MM/yy HH:mm:ss}) %c {1} - %m\n log4j.appender.stdout.filter.filter1=org.apache.log4j.varia.LevelR

Message Bundle from DB - Part 1 (J2EE)

This is the first part of a post about message bundles. Having to work on applications requiring support for different languages I had the need to have a message bundle retrieving the translation from a DB. With a  DB was easier to update labels not correctly translated without the need of restarting the application. We are going to build a service providing the functionality to store and retrieve localized messages from a database. In the second part we will build the same with the Spring Framework. Source code: https://github.com/oivarc/j2ee-samples.git The source code you will find on the repository contains a bit more of what is showed here. There is also a simple page used for test that gives the possibility to add/edit the label in different languages. The code has been tested using NetBeans, Glassfish 4.1, JavaDB. It uses the EclipseLink for the JPA connection and PrimeFaces for the UI. Let's start introducing the database structure we will utilize to store the loca

Spring Data Repositories: Query by Specification

Working with Spring and Spring Data repositories I got the need to have flexible queries based on some of the property of an entity class that should be put in OR in the query if they were present. Instead of creating a query for each combination of properties, I used one of the facilities provided by Spring-Data: the query by Specification. Before going into the details some background information. What I am going to show is an example based on the JpaRepository using Hibernate as persistency layer. A full working example can be found here:  query-by-spec The trick is in the use of the Specification interface in combination with a JpaSpecificationExecutor. Let's start... First we define an entity with some properties: @Entity @Table(name = "person") public class Person { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @Column(name = "name") private String name; @Column(name = "surname") private Strin

How to take screenshots of your android app

Image
In this post I will explain how to take the screenshots you need to publish your app on google play shop. I know that searching around the web you can find a lot of other posts on the same argument, but I wrote this as my reminder. Prerequisites This article suppose you have already installed the Android SDK and that you know how to setup you device to use the debugging mode. I will write other articles on those topics in future posts. Take a screenshot Taking a screenshot is a very easy operation to do. If you follow the steps below you will get it in few seconds (well few if you match the prerequisites :-) ). Ok, stop talking and let's take the shots: 1. Connect your device in debug mode to the pc 2. Start your Eclipse with the Android SDK configured 3. Switch to the DDMS perspective 4. On the left panel you should see the devices you connected to the pc in debug mode. Select the one from which you want to take screenshots  5. Click on the small camera

JSF2 View Scope with Spring Core

Working with Spring and JSF2 I encountered the need to use something like a ViewScope bean. The Spring Framework support the following scopes bean scopes : singleton prototype request session globalSession Adding a new scope is quite simple using Spring. To add the View Scope in the Spring IoC container it is necessary to create a custom scope which implements the org.springframework.beans.factory.config.Scope interface and register it with the Spring Custom Scope Configurer. ViewScope implementation package eu.ac.tutorial.spring.scope; import java.util.Map; import javax.faces.context.FacesContext; import org.springframework.beans.factory.ObjectFactory; import org.springframework.beans.factory.config.Scope; public class ViewScope implements Scope {     @Override     public Object get(String name, ObjectFactory<?> objectFactory) {         if (FacesContext.getCurrentInstance().getViewRoot() != null) {             Map<String, Object> viewMap = FacesContext.getC