Tag: log4j

  • Radius, ldap, log4j, sms token

    I’ve already mentioned about that project. We used great library for it it’s called TinyRadius. In the sources you get extra example codes of TestClient and TestServer implementation. That is really helpful. The project is written using Netbeans and Maven tools. That is really comfortable. You just got your pom.xml and it does care about all dependencies. It’s simply download them from the web.

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>pl.johnnyjavago.developement.radiustest</groupId>
        <artifactId>MyWebRadiusServer</artifactId>
        <packaging>war</packaging>
        <version>1.0-SNAPSHOT</version>
        <name>MyWebRadiusServer JEE5 Webapp</name>
        <url>http://maven.apache.org</url>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>2.0.2</version>
                    <configuration>
                        <source>1.6</source>
                        <target>1.6</target>
                    </configuration>
                </plugin>
            </plugins>
        </build>
        <dependencies>
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>servlet-api</artifactId>
                <version>2.5</version>
                <type>jar</type>
            </dependency>
            <dependency>
                <groupId>javax.servlet.jsp</groupId>
                <artifactId>jsp-api</artifactId>
                <version>2.1</version>
                <scope>provided</scope>
            </dependency>
    
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>3.8.1</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.tinyradius</groupId>
                <artifactId>tinyradius</artifactId>
                <version>0.9.9</version>
                <scope>compile</scope>
            </dependency>
            <dependency>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
                <version>1.1</version>
            </dependency>
            <dependency>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
                <version>1.2.14</version>
                <scope>compile</scope>
            </dependency>
            <dependency>
                <groupId>com.novell.ldap</groupId>
                <artifactId>jldap</artifactId>
                <version>4.3</version>
            </dependency>
            <dependency>
                <groupId>xstream</groupId>
                <artifactId>xstream</artifactId>
                <version>1.2.2</version>
                <scope>compile</scope>
            </dependency>
            <dependency>
                <groupId>javaee</groupId>
                <artifactId>javaee-api</artifactId>
                <version>5</version>
                <scope>compile</scope>
            </dependency>
        </dependencies>
    </project>

    That is simply amazing technique. To start and instance of the server I implemented well know ServletContextListener :)

    public class ActivatorServletContextListener implements ServletContextListener {
    
        MyRadiusServer server = new MyRadiusServer();
    
        @Override
        public void contextInitialized(ServletContextEvent arg0) {
            server.start(true, true);
            System.out.println("Server started.");
        }
    
        @Override
        public void contextDestroyed(ServletContextEvent arg0) {
            System.out.println("Stop server");
            server.stop();
        }
    }

    It does a great job too. And for logs we used log4j, it cool also. You can drive your logs wherever you want. Here is log4j.properties file: (from path src/main/resources)

    # #### Use two appenders, one to log to console, another to log to a file
     log4j.rootCategory=debug, R
    #
    # #### First appender writes to console
     log4j.appender.stdout=org.apache.log4j.ConsoleAppender
     log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
    #
    # # Pattern to output the caller's file name and line number.
     log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F%L) - %m%n
    
    log4j.appender.R = org.apache.log4j.DailyRollingFileAppender
    log4j.appender.R.File = logs/my-radius.log
    log4j.appender.R.Append = true
    log4j.appender.R.DatePattern = '.'yyy-MM-dd
    log4j.appender.R.layout = org.apache.log4j.PatternLayout
    log4j.appender.R.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %c{1} [%p] %m%n
  • Log4j stopped logging on Glassfish

    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