I use log4j library for confirmation what is being send to db server by my EJB code. Everything was working fine till one day. It simply stopped logging. (it turned out that I’ve used somehow newer version of log4j in my project, I’ve changed pointer in Libraries in Netbeans).

  • I’ve created a new domain on my local server and deployed there my EJB webservice and log4j was logging fine:
    DEBUG java.sql.Connection - ooo Connection Opened
    DEBUG java.sql.PreparedStatement - ==>  Executing: select count(*) from network_elements
    DEBUG java.sql.PreparedStatement - ==> Parameters:
    DEBUG java.sql.ResultSet - <==    Columns: 1
    DEBUG java.sql.ResultSet - <==        Row: 0
    DEBUG java.sql.Connection - xxx Connection Closed
  • I’ve noticed it should be a domain/server problem and started googling for this issue and found a solution:
  • Log4j
  • Glassfish v3 and later + log4j seem to have some sort of classloader problem: log4j library is loaded by different classloaders and this causes some kind of conflict if you deploy log4j with your application. The only solution I could find was to copy log4j-1.2.16.jar to <glassfish-installation>/glassfish/domains/domain1/lib. So please do this before proceding.
  • it comes from Hibernate JPA 2.0 on glassfish v3 with Netbeans IDE setup tutorial another amazing blog :)

My Log4j knowledge is very basic, I just use a given example of configuration: sort1.properties from examples directory from log4j librabry:

log4j.rootLogger=DEBUG, stdout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

log4j.appender.stdout.layout.ConversionPattern=%5p %c - %m%n

Posted

Somewhere earlier on this blog I said there is fine php framework called cakephp. I tried it and what convinced me to use it was the main motto of it. IT’S PIECE OF CAKE! And that was so true. I got even eclipse for PHP and started experimenting with it… Although there was something against php in my head. Exactly the opinion of my college from work (java developer). He said: ‘Dude what’s wrong with you? are you using php?’ I asked my self, shit what’s wrong with php and started to seek over the web for term ‘java vs php’ and red the first one which wasn’t against any, and was looking hopefully on php in future. So yes I am going to stay being java developer and improving myself in this world but still I will be cakephp and symphony fan! Which programming languages are fastest?

Posted

I know there is no Sun courses any longer. There are Oracle Java courses. I have been to some. GlassFish ESB 2.1 for Implementers (SAS-4300) and Developing Applications for the Java EE 6 Platform (FJ-310-EE6). But also I have student workbook for Sun GlassFish Enterprise Server Administration and Developement SAS 4455 what looks interesting. Instaling and configuring is just obvious. But setting clusters, nodes, configuring load balancer and session replication sound really interesting. I am software developer but setting just right the environment for all the stuff is also important. I would hire administrator just for maintaining the system no for starting the whole world up :)

Posted

There is interesting free java development environment called Google App Engine. My sample app hansguestbook deployed there. It can me easly integrated with your favorite IDE (I hope) I use netbeans and it works fine. I hope I be able to code some sample apps and run there. There is some limitations but always you can register another google account and put there your over limit apps. I will try to put there GWT simple app to check if GWT works fine with GoogleAppEngine (It should). Any difference I’ve noticed (comparing to ordinary AS) there is JDO in data tier. I hope this works exactly like JPA. Will test it. Instaling your SDK you get GoogleAppEninge server instance and while you are developing you deploy your stuff too localhost, having “baked” you send it to GoogleAppE.

Posted

Previously I’ve just mentioned that I am working on JbossCache deployed to glassfish. I want to have it distributed. My frustration was I couldn’t find any configuration file online of replication mode. It turned out that example configuration was inside JBoss Cache zip file, Core Edition version 3.2.5 “Malagueta” (download full zip jbosscache-core-3.2.5.GA-all.zip) in file jbosscache-core-3.2.5.GA\etc\config-samples\total-replication.xml.

  • remember to put your configuration-cache.xml in WEB-INF/classes
  • I’ve changed they way of communication from sync to async. (should be faster)
  • upload 7 jar to your AS and restart: commons-logging.jar, jbosscache-core.jar, jboss-common-core.jar, jboss-logging-spi.jar, jboss-transaction-api.jar, jcip-annotations.jar, jgroups.jar

After loading 7jars to domain/libs and restarting Glassfish I was able to deploy web application with one class: JbossCacheActivatorServletContextListener

public class JbossCacheActivatorServletContextListener implements ServletContextListener {

    private Cache cache = null;

    public void contextInitialized(ServletContextEvent sce) {
        try {
            CacheFactory factory = new DefaultCacheFactory();
            cache = factory.createCache("cache-configuration.xml");
            InitialContext ctx = new InitialContext();
            ctx.bind("JBossCacheRef", cache);
        } catch (NamingException ex) {
            Logger.getLogger(JbossCacheActivatorServletContextListener.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void contextDestroyed(ServletContextEvent sce) {
        try {
            InitialContext ctx = new InitialContext();
            ctx.unbind("JBossCacheRef");
            cache.stop();
        } catch (NamingException ex) {
            Logger.getLogger(JbossCacheActivatorServletContextListener.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

after all if there is cache instance. You can login to jconsole localhost:8686 and look for (ObjectName jboss.cache) it under MBeans node.

Testing.

  1. I run cache on two separate Glassfish AS. They are in the same network (same mask; I am sure it works either in opposite condition but it will need more configuration).
  2. I’ve coded two ejb’s as with @WebService annotation, one i puting into cache and second is reading from it.
  3. I’ve turned off one node and put something into second one cache. I check for content… is ok. Then I start first node and check… and content is being replicated from the second what makes it work perfect.

Attention.

In jboss cache user guide guys from jboss cache suggest to register it into JMX (5.4.2. Registering the CacheJmxWrapper with the MBeanServer). As you can see I put referance to cache into InitialContext. That is why becasue I could not get into jbosscache trought the jmx mbeans cuz Glassfished sets a different ObjectName for this object, so I’ve got problems with finding it.

Posted