Running tests through JUnit SwingUI Test Runner and JDeveloper 10g

Submitted by Jochus on Wed, 20/02/2013 - 21:13 | Posted in: Java
Posted in

Problem

The following error occurred when running a JUni test

org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [com/psws/psbilling/test/spring/dataSourceContext.xml]; nested exception is java.lang.IllegalArgumentException: Class [org.springframework.beans.factory.xml.SimplePropertyNamespaceHandler] does not implement the NamespaceHandler interface
Caused by: java.lang.IllegalArgumentException: Class [org.springframework.beans.factory.xml.SimplePropertyNamespaceHandler] does not implement the NamespaceHandler interface
	at org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.initHandlerMappings(DefaultNamespaceHandlerResolver.java:119)
	at org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.<init>(DefaultNamespaceHandlerResolver.java:96)
	at org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.<init>(DefaultNamespaceHandlerResolver.java:82)
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.createDefaultNamespaceHandlerResolver(XmlBeanDefinitionReader.java:526)
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.createReaderContext(XmlBeanDefinitionReader.java:515)
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:495)
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:340)
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:317)
	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:125)
	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:141)
	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:167)
	at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:113)
	at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:79)
	at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:94)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:292)
	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:92)
	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:77)
	at org.springframework.test.AbstractSingleSpringContextTests.loadContextLocations(AbstractSingleSpringContextTests.java:182)
	at org.springframework.test.AbstractSingleSpringContextTests.loadContext(AbstractSingleSpringContextTests.java:152)
	at org.springframework.test.AbstractSpringContextTests.getContext(AbstractSpringContextTests.java:105)
	at org.springframework.test.AbstractSingleSpringContextTests.setUp(AbstractSingleSpringContextTests.java:83)
	at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69)

Solution

After Googling a while, I noticed some classes are cached inside the Spring context. Theses classes cannot be accessed from the classloader which is used to startup the JUnit Testrunner. So the dependency injection fails.

The following step solved this issue:

  • Add in your home folder (e.g.: /Users/jochen/) the file: junit.properties
  • Provide the following file contents:
    loading=false

MySQL table names always converted to lowercase

Submitted by Jochus on Thu, 14/02/2013 - 16:58 | Posted in: Mac
Posted in

Problem

When I execute DDL statements to my MySQL database on my Mac installation, every table is converted to lowercase letters - even if the name is in uppercase letters in my script. This leads to errors in ALTER TABLE operations to add foreign keys (because of case sensitive).

Solution

According to this page:

How table and database names are stored on disk and used in MySQL is affected by the lower_case_table_names system variable, which you can set when starting mysqld. lower_case_table_names can take the values shown in the following table. This variable does not affect case sensitivity of trigger identifiers. On Unix, the default value of lower_case_table_names is 0. On Windows the default value is 1. On Mac OS X, the default value is 2.

I updated my my.cnf file:

$ sudo nano /private/etc/my.cnf

... by adding the following line:

lower_case_table_names=0

Installing Windows fonts on a fresh Ubuntu installation

Submitted by Jochus on Tue, 12/02/2013 - 15:00 | Posted in: Linux
Posted in

Problem

Fonts like Tahoma, Verdana, ... are missing on a standard Ubuntu installation. I was looking to install the Microsoft TrueCrypt fonts so I could open Word documents (created in Microsoft Office) correctly in OpenOffice. Also, I had the issue some of my webpages were not looking ok in Firefox (Linux) - fonts were missing, so pages could look totally different.

Solution

  • Install package msttcorefonts
  • $ sudo aptitude install msttcorefonts

  • To be able to reload the fonts, without rebooting the machine, execute the command:
  • $ sudo fc-cache -fv

How to disallow content copying and printing of a PDF (aka securing a PDF)

Submitted by Jochus on Mon, 11/02/2013 - 21:18 | Posted in: Java
Posted in


I came across some issues with processing secured PDF's. These PDF files were encrypted. After reading the following documentation: http://publib.boulder.ibm.com/infocenter/zos/v1r11/index.jsp?topic=/com…, I tried securing one of my own PDF's.

Goal

Encrypting the PDF so text cannot be copy/pasted and the PDF could not be printed

Requirements

  • iText
  • BouncyCastle jars

Libraries used

  • iText: 5.3.5
  • BouncyCastle: bcprov-jdk14-1.47.jar and bcprov-ext-jdk14-1.47.jar

Code

import java.io.FileOutputStream;
 
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
import com.itextpdf.text.pdf.PdfWriter;
 
public class EncryptPDF {
 
	private static final String INPUT_FILENAME = "/tmp/test.pdf";
	private static final String OUTPUT_FILENAME = "/tmp/test_encrypted.pdf";
	private static final String USER_PASSWORD = "";
	private static final String OWNER_PASSWORD = "foobar";
 
	public static void main(String[] args) {
		PdfReader reader = null;
		FileOutputStream out = null;
		PdfStamper stamper = null;
 
		try {
			// Define input
			reader = new PdfReader(INPUT_FILENAME);
 
			// Define output
			out = new FileOutputStream(OUTPUT_FILENAME);
 
			// Encrypt document
			stamper = new PdfStamper(reader, out);
			stamper.setEncryption(USER_PASSWORD.getBytes(), OWNER_PASSWORD.getBytes(), 0, PdfWriter.STANDARD_ENCRYPTION_128);
		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
			if (stamper != null) {
				try {
					stamper.close();
				} catch (Exception ex) {
					ex.printStackTrace();
				}
			}
			if (reader != null) {
				try {
					reader.close();
				} catch (Exception ex) {
					ex.printStackTrace();
				}
			}
			if (out != null) {
				try {
					out.close();
				} catch (Exception ex) {
					ex.printStackTrace();
				}
			}
		}
	}
}

Extra

You can also play with the permissions by providing PdfWriter perms instead of the value "0".

stamper.setEncryption(USER_PASSWORD.getBytes(), OWNER_PASSWORD.getBytes(), PdfWriter.ALLOW_ASSEMBLY | PdfWriter.ALLOW_COPY, PdfWriter.STANDARD_ENCRYPTION_128);

Check if PDF is secured

  • When opening the PDF with Acrobat Reader, the title should end with: (SECURED)
  • Open the properties of the PDF in Acrobat Reader ( + D on a Mac ) and look at Document Restrictions Summary

Changing the startup scripts of an Ubuntu installation

Submitted by Jochus on Sun, 10/02/2013 - 19:23 | Posted in: Linux
Posted in

Problem:

When you boot your Ubuntu installation, a lot of scripts are started. A lot of scripts are superfluous. But how to disable the ones you don't need?

Solution:

  • Install rcconf
  • $ sudo aptitude install rcconf

  • Disable the service by toggling the service using the "space bar".
  • $ sudo rcconf

Eclipse code assist in .xhtml pages (JSF tags, Richfaces tags, ...)

Submitted by Jochus on Sat, 09/02/2013 - 17:53 | Posted in: Java
Posted in


If you are missing code assist in XHTML pages, try to the change the following project settings:

  • Right click on project > Properties
  • Choose: Project Facets
  • Check and choose the correct version for Dynamic webmodule
  • Check and choose the correct version for JavaServer Faces

Formatting XML documents using Vi and Xmllint

Submitted by Jochus on Thu, 07/02/2013 - 14:48 | Posted in: Mac
Posted in

If you want to format the following XML document:

<?xml version="1.0" encoding="UTF-8"?><ROOT><FOO><BAR>Hello World</BAR></FOO><BAR><FOO>World Hello</FOO></BAR></ROOT>

... you can use Vi in combination with Xmllint to do the formatting

$ vi example.xml
:%!xmllint --format -

... the result will be:

<?xml version="1.0" encoding="UTF-8"?>
<ROOT>
  <FOO>
    <BAR>Hello World</BAR>
  </FOO>
  <BAR>
    <FOO>World Hello</FOO>
  </BAR>
</ROOT>

Building Richfaces 3.3.x from source code

Submitted by Jochus on Thu, 07/02/2013 - 14:43 | Posted in: Java
Posted in


When building Richfaces 3.3.x from source, you might run into the following error:

richfaces\framework\test\src\main\java\org\ajax4jsf\tests\EnumSupportExpressionFactoryWrapper.java:[32,7] org.ajax4jsf.tests.EnumSupportExpressionFactoryWrapper is not abstract and does not override abstract method coerceToType(java.lang.Object,java.lang.Class) in javax.el.ExpressionFactory

The solution to solve this error:


The problem is that there are different versions of the "el-api-1.0.jar" on the Internet.

The official JAR, with 24432 bytes and SHA1 checksum df8c6ce0406676e70c5d018e5fb988be1bcf1024, is available at the usual locations:
* http://download.java.net/maven/2/javax/el/el-api/1.0/
* http://repo1.maven.org/maven2/javax/el/el-api/1.0/
* http://search.maven.org/#artifactdetails|javax.el|el-api|1.0|jar

RichFaces 3.3.X does not compile when this JAR is used. It needs the "el-api-1.0.jar" from the old Maven 1 repo at http://download.java.net/maven/1/javax.el/jars/ (29309 bytes, SHA1 1e72d5b13b698f99058d35751a29f87ef3066e87).

You don't have to clear the whole local repository or circumvent your Maven proxy. It is just enough to delete all files in %HOME_DIR%\.m2\repository\javax\el\el-api\1.0\ and download http://download.java.net/maven/1/javax.el/jars/el-api-1.0.jar into that folder.