JUnit and Glassfish 3.1.1 - Remote EJB tests
Trying to run a JUnit Test with remote EJB lookups from a GlassFish server 3.1.1 it is a little bit tricky. It seems to me that it is not possible to get the maven dependencies working. The gf_client.jar can not be included using a dependency, although the artefact can be located using the glassfish repository from java.net :
.....
<!-- Glassfish -->
<repository>
<id>glassfish-repository</id>
<name>Java.net
Repository for Glassfish</name>
<url>http://download.java.net/maven/glassfish</url>
</repository>
.....
..and adding a dependecy:
...
<dependency>
<groupId>org.glassfish.appclient</groupId>
<artifactId>gf-client</artifactId>
<version>3.1.1</version>
<scope>test</scope>
</dependency>
....
But after all this wont work for me. So the best way is to add the gf_client.jar directly into your classpath.
The gf_client.jar is located in your Glassfish Installation at
$GLASSFISH_HOME/glassfish/lib/gf-client.jar
Now you can write a JUnit test with a remot ejb lookup. See the following example for a remote lookup to Imixs Entity Service
public class TestEntityService {
EntityServiceRemote entityService = null;
@Before
public void setup() {
try {
// set jndi name
String ejbName = "java:global/imixs-workflow-web-sample-0.0.5-SNAPSHOT/EntityService!org.imixs.workflow.jee.ejb.EntityServiceRemote";
InitialContext ic = new InitialContext();
entityService = (EntityServiceRemote) ic.lookup(ejbName);
} catch (Exception e) {
e.printStackTrace();
entityService = null;
}
}
@Test
@Category(org.imixs.workflow.jee.ejb.EntityServiceRemote.class)
public void testService() {
Assert.assertNotNull(entityService);
//....
}Note: To run this JUnit test you have to first deploy your test application. After that you junit test can be run.
Testing secured EJBs
If your remote ejb is annotated with the security annotation @RolesAllowed you need to authenticate your remote lookup.
In GlassFish this can be done using the programmatic Login. To setup a programmatic login in your JUnit test first create a File named 'auth.conf'. The content of that file should look like this:
default {
com.sun.enterprise.security.auth.login.ClientPasswordLoginModule required debug=false;
};
Now you can add the programmatic login into your test setup
@Before
public void setup() {
try {
// set jndi name
String ejbName = "java:global/imixs-workflow-web-sample-0.0.5-SNAPSHOT/EntityService!org.imixs.workflow.jee.ejb.EntityServiceRemote";
// setup programmatic login for GlassFish 3
System.setProperty("java.security.auth.login.config", "/home/rsoika/eclipse_37/imixs-workflow/imixs-workflow-engine/src/test/resources/auth.conf");
ProgrammaticLogin programmaticLogin = new ProgrammaticLogin();
// set password
programmaticLogin.login("Anna", "anna");
InitialContext ic = new InitialContext();
entityService = (EntityServiceRemote) ic.lookup(ejbName);
} catch (Exception e) {
e.printStackTrace();
entityService = null;
}
}
Note: the username/password is defined in this case in a file realm which is the default security realm of my GlassFish
Here are some helpful links:
http://glassfish.java.net/javaee5/ejb/EJB_FAQ.html#StandaloneRemoteEJB
http://www.coderanch.com/t/476090/EJB-JEE/java/EJB-Realms-Remote-Clients
Posted at 09:08PM May 16, 2012
Posted by: Ralph
Category: General
GlassFish - HeapSize settings
After playing around with some VM settings in my GlassFish 3.1.1 environment (development and productive) I came to a setup which brings up my glassfish server much faster. Here are my settings
Development (3GB RAM)
-client
-XX:+AggressiveHeap
-Xmx1024m
-Xms1024m
-Xss128k
-XX:+DisableExplicitGC
Productiv (4GB Ram)
-server
-XX:+AggressiveHeap
-Xmx2048m
-Xms2048m
-Xss128k
-XX:+DisableExplicitGC
Here is also a useful link for further performance settings:
Posted at 04:32PM May 05, 2012
Posted by: Ralph
Category: General
GlassFish - EJB Timer Service not available
Today I had a situation where after a hardware crash my GlassFish Server did not work correctly. Specially the timer service did no longer work. The server log shows a lot of errors about
...EJB Timer Service not available
In the easiest case the reason why the timer service did not start are old db.lck files.
You can check this by stopping the server and then look for any lock files in the domain folder
../lib/databases/ejbtimer/
After removing the files
dbex.lck
db.lck
you can restart the server and every thing should work again.
See also the following thread if this did not work for you:
http://forums.java.net/node/666385
Posted at 03:23PM Apr 23, 2012
Posted by: Ralph
Category: General
Character encoding de_DE on Linux Debian
On my debian server today I run into a problem with the encoding of XSL templates running on a GlassFish server. The problem was that German characters where not displayed correctly.
After a long time of searching, I figured out that the reason for that problem was not my MySQL database, nor my GlassFish installation. It was simply the missing German language support on my linux debian.
You can test the installed locales with the following command:
locale -a
In my case only 'en_US.utf8' was listed.
In debian you can simply add the german language support by changing the file /etc/locale.gen. Simply uncomment the lines:
de_DE ISO-8859-1
de_DE.UTF-8 UTF-8
de_DE@euro ISO-8859-15
and run the command:
locale-gen
After restarting my GlassFish server the xsl transformation works fine with german characters.
The command "locale -a" now displays the following locale:
C
de_DE
de_DE@euro
de_DE.iso88591
de_DE.iso885915@euro
de_DE.utf8
deutsch
en_US.utf8
german
POSIX
Posted at 12:18PM Jan 23, 2012
Posted by: Ralph
Category: General
Eclipse and Gnome Shell
Today I stumbled into a problem with my eclipse IDE running in Ubuntu 11.04 with Gnome shell. When trying to run the BIRT plugin with external XML resources the popup dialog prompting for username/password did no longer appear and I got a http error message 401. I think similar problems can also appear with other plugins in eclipse or eclipse based applications.
To solve such a problem it is necessary to provide a customized startup script. To create such a script change into the folder were your eclipse is installed and create a new file named 'eclipse_gnome'
Next make it executable by running the command
chmod +x ~/eclipse_gnome
Now edit the file with the following lines of code
#!/bin/sh
export GDK_NATIVE_WINDOWS=true
./eclipse
With the GDK_NATIVE_WINDOWS variable eclipse changes the way to handle windows internal. And this will fix difernt problems working with eclipse in Gnome shell.
To start eclipse use the new script.
If you have installed eclipse through the ubuntu software-center then your eclipse executable is located in the folder /usr/lib/eclipse/eclipse. In that case you can change the content of your start script like this:
#!/bin/sh
export GDK_NATIVE_WINDOWS=true
/usr/lib/eclipse/eclipse
Posted at 06:23PM Jan 12, 2012
Posted by: Ralph
Category: General
Gnome3 - Anpassen
Gnome3 - Titelleiste von Anwendungen im maximierten Zustand aublenden [Read More]
Posted at 09:59AM Nov 12, 2011
Posted by: Ralph
Category: General
Birt and Parameter Driven XML Data Source URL
This is a very usfull link how to parameter XML Data Source URIs in Eclipse Birt:
The Trick is to add a 'beforeOpen' Script Event to the XML DataSource. The Script looks like this:
filelist = this.getExtensionProperty("FILELIST");
filelisturl = filelist.substring(0,filelist.indexOf("=")+1);
this.setExtensionProperty("FILELIST", filelisturl + params["TickerSymbol"]);
This means that if you define a Report Parameter named 'TickerSymbol' the value will be added to the XML Data Source URL after the '=' char.
You can also use Variables to replace a part of your XML Datasource URL. In this case the script event can look like this:
filelist = this.getExtensionProperty("FILELIST");
filelisturl = filelist.substring(0,filelist.indexOf("=")+1);
this.setExtensionProperty("FILELIST", filelisturl + vars["NewVar"]);
This means that the part after '=' will be replaced with the current value of the variable named 'NewVar'
Posted at 09:33PM Nov 09, 2011
Posted by: Ralph
Category: General
MySQL and indicies
If you need multiple indecies in a MySQL table over more then one column it is necessary to create only one index for each table containing all affected columns. If you add more then one index to a table MySQL uses only one of them during optimization. So be careful about your index schemas.
Posted at 09:36AM Oct 06, 2011
Posted by: Ralph
Category: General
Eclipse Indigo - Maven and SVN
With the latest release from Eclipse - Indigo - now Maven is well supported. So it is no longer an ordeal to install maven support and especially svn integration.
To add the Maven with SVN into Indigo it is sufficient to got to "help -> install new software"
There you can select the Indigo plugin repository 'Indigo - http://download.eclipse.org/releases/indigo'
Go to the section 'Collaboration' and select the features "m2e - Maven Integration for Eclispe".

Now you have maven support provided by the sonatype plugin "m2Eclipse"
If you need also Subversion support you should add the Subclipse
Plugin. (this works in most cases better than the Subversive SVN Team
Provider). To add sublicpse to Ecipse Indigo you need to add the following plugin site:
http://subclipse.tigris.org/update_1.6.x
From this update site you can choose all Sublicpse Plugins to bee installed.
Checking out a Maven Project from a SVN repository
To check out an existing Maven project from an subversion repository you need the additional scm connector. To get this connector installed simply create at first a new project from the 'New Project wizard' - (menue 'File -> new project')
Select the project type : "Maven -> Checkout Maven Projects from SCM":


The first time you can not choose a valid SCM URL type. You need first to install a SCM Connector for Maven and SVN. Click on the LInk 'm2e Marketplace'
You will see the m2e Marketplace where you can now select the "m2e-sublicpse" or the "m2e-subversive" connector (this depends on the subversion plugin you installed before - as noted here I recommend sublipse instead of subversion! - do not pay attention to the next screen shot!):

Note: If you are using a different SCM system you have to select the corresponding connector type
After the Installation finished you can select the SCM URL Type and enter your repository URL:

Alternatively you can also checkout a project from the SCM view with the option "checkout as maven project"

Posted at 10:37AM Aug 15, 2011
Posted by: Ralph
Category: General
Disabling Glassfish-specific (Non-portable) JNDI names
Today I run into a problem with my EJB 3.1 application after I tried to deploy more than one app with the same EJB module on the same glassfish domain. This results in a JNDI-Naming conflict telling you, that the EJB name is already bound. But since the new concept of JEE6 global portable jndi names this should not happen?
Here is a discussion about the problem: http://home.java.net/node/702307
The solution is quite simple as Glassfish provides a new property to disable the generation of the glassfish-specific non-portable jndi names (which were only provided because of backward compatibility. Simply add the param 'disable-nonportable-jndi-names' with the value 'true' directly into the EJB-Container additional-property section. This will avoid the create of thus names.
See also the following pages for more deails about this topic:
http://download.oracle.com/docs/cd/E18930_01/html/821-2417/gkhtw.html
http://download.oracle.com/docs/cd/E18930_01/html/821-2418/beanx.html#gkndi
http://download.oracle.com/docs/cd/E18930_01/html/821-2416/gglpq.html
Posted at 12:30PM Jul 01, 2011
Posted by: Ralph
Category: General
Web Traffic Tool
Last night I finalized the first version of my new Web Statistik Tool. It includes now trend analyzer and custom time frames.
Read more about this project at: https://code.google.com/p/manik-web-stat/
Your Feedback is welcome.
Posted at 08:21AM Jun 23, 2011
Posted by: Ralph
Category: General
New Web Traffice Analyzer
I started a new open source project providing a web statistic tool. The goal of the project is especially to analyze the web traffic of web applications like JEE WAR or EAR modules. But Manik-Web-Stat can be also used to analyse any kind of web traffic independent from the web servers technology and architecture.
You can read more about the project on: http://code.google.com/p/manik-web-stat/
Your feedback is welcome and you can join the project!
Posted at 07:55PM Jun 16, 2011
Posted by: Ralph
Category: General
Glassfish 3.1 - AccessLog Format
In Glassfish 3.1 there is a uncommon default setting for the AccessLog Format.
you will see the following default setting for the Access Loggin Format:
%client.name% %auth-user-name% %datetime% %request% %status% %response.length%
If you like to see the much more commoon NCSA Log Format you can simply change the value into:
common
or
combined
See also this Blog from Igor: http://blog.igorminar.com/2009/12/configuring-common-access-log-format-in.html
Posted at 08:32PM Jun 12, 2011
Posted by: Ralph
Category: General
Glassfish running in Headless mode
Today I tried to run a Glassfish 3.1 Server on a Linux SuSE box. But the server did not run properly. In the server.log a error message occurred during accessing a jsf application:
Could not initialize class sun.awt.X11GraphicsEnvironment
This problem can be solved setting the glassfish server in a 'headless mode'. This can be done from the Glassfish administration console:
- Login to Glassfish Admin console
- Go to - Configurations - Server Config - JVM Settings - JVM Options TAB - Select Add JVM Option
- Add "-Djava.awt.headless=true" in the text field.
- Hit "Save" button.
- Restart the server.
Now the error message is gone.
Posted at 02:29PM May 31, 2011
Posted by: Ralph
Category: General
Installing Oracle SQL*Plus on Linux Ubuntu
Today I found a very usefull link how to install Oracle SQL*Plus in Ubuntu:
http://samushka.blogspot.com/2009/04/installing-oracle-sqlplus-in-ubuntu.html
Thanks to Sammy Veira
Posted at 12:31PM May 19, 2011
Posted by: Ralph
Category: General