Monitoring EJB’s inside Glassfish V2

Interresting ressources regarding EJB monitoring in Glassfish 2.1.1:

http://docs.sun.com/app/docs/doc/820-4335/ablur?a=view

http://dlc.sun.com/pdf/820-4343/820-4343.pdf

Write and read to a samba shared directory using java (JCIFS)

Challenge of the day: publish a file to a microsoft shared directory and then re-read it.

Windows OSes rely on the SAMBA protocol to share files and directories. Thanks to the JCIFS project( http://jcifs.samba.org/), an open source library, we can access theses kind of shares via java.

Under linux, we could have performed it a the shell level using the SMBclient command line utility.

The example is pretty self explanatory, just remember to add jcifs-1.2.25.jar to your classpath and to adapt the authentication parameters to your real login in the url.

import jcifs.smb.*;
public class SMBClient {
  public static void main(String[] args) {
    try{
      // jcifs.Config.setProperty( "jcifs.netbios.wins", "192.168.1.220" );
      //smb://[[[domain;]username[:password]@]server[:port]/[[share/[dir/]file]][?[param=value[param2=value2[...]]]
      String url="smb://domain;user_name:user_password@server_name/directory/test_file.txt";
      String content="hello !";
      SmbFileOutputStream out = new SmbFileOutputStream(url);
      out.write(content.getBytes());
 
      System.out.println("File written, now trying to re-read it:");
      SmbFileInputStream in = new SmbFileInputStream(url);
      byte[] b = new byte[10000];
      int n;
      while(( n = in.read( b )) > 0 ) {
        System.out.write( b, 0, n );
      }
    }catch(Exception e){
  System.out.println(e);
  }
 }
}

Thanks to Cyril for the challenge 🙂 and to the forums of developpez.net (in french) for an example.

Spring configuration tips

So, we decided to use Spring framework… here comes hell !

Without a little management, spring configuration files grow quite fast and may soon become hard to maintain.

Craig Walls’s offers us some spring best-pratices in his excellent Spring-cleaning presentation (pdf).

Another good source is the SpringTips blog that offers us 12 best-practices for spring xml configuration.

To Spring or not ?

I have been spending last weeks defining the architecture of a new web application.

The main driver is to rely on a MDA (Model driven architecture) to generate the major part of the application code thanks to Acceleo . We build custom template files that are converted to a fully working application via acceleo generators.

A proof of concept:

The first versions of this project was developped as a Struts 1 webapp on top of hibernate ORM. The choice of Struts was mainly driven by the fact that the team new this framework quite well … and that we had exmples of code available for it. So we ended up developing our struts-specific templates files to generate the views and controllers of the application.

Spring time has come !

It’s now time to “industrialize” this first version. The main constraint is that we keep what has been developed for Struts. But we also need to implement new functionnality (integration with LDAP, data synchronization with other applications, audit logging, exposition of webservices….).I start to feel that Struts (especialy 1.x) is pretty limited and wil force us to develop modules that could be found out of the box in other Frameworks.

From other projects, I retain that Spring is a very modularized framework, that can be used “on demand”, to provide from basic services to full web application framework.

Why Spring ?

  • we reuse 99% of our existing truts code. By using the dynamic proxies of Spring, we can rely on AOP to add functionnality to our code (the detailled method (IBM)).
  • forces a better modularity of code
  • … that strongly encourages (and ease) unit testing.
  • allows us to modularize the application itself.
  • simplify integration with external systems (mail, LDAP) by providing easy to use templates.

Why not ?

  • Spring configuration files might become complex as they grow.. but we generate them.
  • and… is that all ?

Ressources

It was quite hard to find arguments against Spring, so I will list pro-spring resources here (comments welcome !).