Archive for the 'J2EE' Category

What Java web framework to use?

I have a very “neglected open source project”:http://code.google.com/p/teamdocs/ that I am going to start working on again. I am going to rewrite it from the ground up using Hibernate and JPA or Hibernate Annotations (I am not quite sure yet), probably Spring, and some web framework. The problem is that I can’t pick a framework.

I was going to go with “Wicket”:http://wicket.sourceforge.net/, but I am not sure I want to go with something that is component based and I can’t really find any good tutorials. There is suppose to be a book coming out, but I don’t really want to wait. On the other hand, it is supposed to be fairly easy to learn and fun to work with.

I have also been thinking of using “Struts 2″:http://struts.apache.org/2.x/. Yesterday, I found a nice “120 page tutorial on getting started”:http://code.google.com/p/sq1-struts2/ with it that would be a huge help. Struts is the 800 pound gorilla when it comes to web frameworks and Struts 2 is suppose to be easier to learn and work with.

Then there is Spring MVC, Tapestry, Echo2, Trails, Stripes, JSF, etc, etc, etc.

Anyone have any suggestions on which one to learn and use? My only requirements are that it be fairly easy to learn, has very good tutorial and documentation support, being actively developed, and is not Struts 1.x, and has some IDE/tool support.

The Problem with EJBs

I had someone post a question in the comments section of my last post on Behavior-Driven Development “asking about EJBs”:http://www.fuzzylizard.com/archives/2006/09/15/794/#comments. I thought I would answer it with a new post instead of just a comment. Where do I start?

First, I need to define the term EJBs. For me, EJB means either Session Bean (stateless or statefull) or Message-Driven Bean. It does not mean Entity Bean. Entity Beans are just wrong and will not be considered further. As far as I can tell, no one really uses them (yes, there are exceptions, but those people are just masochists).

What is the state of Session and Message-Driven Beans? Some people use them, others do not. I personally would advise against them. The vast majority of applications are not distributed, run in a single app server, and can be completely implemented in the web container.

The main problem with EJBS is that they are completely untestable. This is a huge problem. There is no way for me to run a simple JUnit test against a session bean from within an IDE such as NetBeans or Eclipse. In order to test an EJB, I need to build and deploy the entire application inside of the application server. I then need to figure out some artificial way of entering into the app server and executing a method or two on a single bean. Not a fun way of doing development.

In order to do any kind of real development with EJBs you need to abstract all of you business logic out of the bean and place it into POJO that the bean then calls. In order to do this, you need to introduce another interface to ensure that the bean and your business POJO stay in sync. Then, you are able to test the POJO instead of the bean. However, now, in order to implement a bean, we need to not only implement the bean interfaces (local and remote), but also our own interface.

So now, not only is the bean aware of its environment, through having to implement the bean interfaces, but it is also aware of the business rules as well because of our own interface that it implements. So even to test a bean’s functionality (which eventually does not exist in the bean anyway) we need to jump through hoops. Ugh.

Basically, my personal feeling, and that of many other people, including Sun is that EJBs (at least EJB 2.x) are fundamentally flawed. Thus they were rewritten for EJB 3.0 and the Java Persistence API (JPA).

If you want an excellent article detailing what is wrong with EJBs then check out Bruce Tate’s “Don’t Make Me Eat the Elephant Again“:http://today.java.net/pub/a/today/2004/06/15/ejb3.html.

Porting from JBoss to WebLogic

At work this week, I had to port our application from “JBoss 4.0.x”:http://labs.jboss.com/portal/jbossas to “WebLogic 9.2″:http://www.bea.com/framework.jsp?CNT=index.htm&FP=/content/products/weblogic. We had attempted to do a port from JBoss to the “Sun app server”:http://java.sun.com/javaee/downloads/index.jsp last year and met with total failure. Apparently, the Sun app server is incredibly picky about how certain parts of the J2EE specification is implemented, especially JMS. As a result of this, I expected the port to be fairly hard to do.

I was mostly wrong, which was a very nice surprise.

In total, I think I had to change 2 strings, 1 config file, and 1 class. The config file and the class were both related to “Hibernate”:http://www.hibernate.org. According to WebLogic, it is not possible to store the Hibernate SessionFactory in JNDI, it has to be cached locally in the HibernateUtil.java class. The 2 strings were related to calling WebLogic’s default JMS connection factory and remotely accessing an EJB from a stand alone client.

I personally found this to be very cool. It means that it is possible to develop a J2EE application and leave the decision of what app server to use until very near the end of development. It also means that you can develop one application and test deploy it to two servers.

Hibernate and c3p0 errors

I have spent most of the afternoon battling various “Hibernate”:http://www.hibernate.org or “c3p0″:http://www.mchange.com/projects/c3p0/index.html errors. The biggest was with c3p0.

I wanted to change my application over from using Hibernate’s JDBC connection pooling (which is not for production) to using c3p0. So I added the correct lines to my Hibernate.cfg.xml file and everything broke. I have a JUnit test set up for testing my PersistenceDao class against a real database and not a single test was passing. The problem was that once it came time to run my tests, Hibernate could not open any connections.

I searched Google and found nothing usefull. In the end the solution came from playing around with the config file. I commented out the following line:

update

And all of my tests started to pass. Cool. I just wish I understand why that one line made such a difference. I am expecting that I will have problems with this down the road. The solution cannot be that simple.

Now the problem that I am trying to fix is that when I run app in Tomcat, the lazy loading isn’t working. The error message keeps saying that it can’t create a proxy, even though I have lazy loading turned off. It should be eagerly fetching all of my collections, but it ain’t. Time to check Google again.

Demystifying Java Security

Here are “Part 1″:http://searchappsecurity.techtarget.com/originalContent/0,289142,sid92_gci1195320,00.html and “Part 2″:http://searchappsecurity.techtarget.com/originalContent/0,289142,sid92_gci1195332,00.html of an article on demystifying Java security, written by Ramesh Nagappan, the author of Core Security Patterns.

Java Security topic is huge

One thing I have been studying for work is Java security, in particular, I have been looking at “Acegi Security”:http://www.acegisecurity.org/, “JAAS”:http://java.sun.com/products/jaas/, and “JGuard”:http://jguard.net/. So far, the main thing that I have found out is that this topic is huge. I have also found out that there is very little information out there about which one is best, however, I do realize that the word “best” is rather ambiguous, but it is the best word that I can think of at the moment.

Currently I think Acegi Security is the winner. I will post more info as I collect it. It would be nice to find a scholarly paper somewhere that showed a comprehensive study comparing the advantages and disadvantages of each framework in different situations, but I have a feeling that that is asking too much :-(

My article to-read list

This post is mainly for me so that I can clear out part of my “Bloglines”:http://www.bloglines.com list of saved articles. Theoretically, these are articles that I intend to read at some point in time.

* “Using Dependency Injection in Java EE 5.0″:http://www.onjava.com/pub/a/onjava/2006/01/04/dependency-injection-java-ee-5.html?CMP=OTC-FP2116136014&ATT=Using+Dependency+Injection+in+Java+EE+5.0
* “An Exception Handling Framework for J2EE Applications”:http://www.onjava.com/pub/a/onjava/2006/01/11/exception-handling-framework-for-j2ee.html?CMP=OTC-FP2116136014&ATT=An+Exception+Handling+Framework+for+J2EE+Applications
* “Using Lucene to Search Java Source Code”:http://www.onjava.com/pub/a/onjava/2006/01/18/using-lucene-to-search-java-source.html?CMP=OTC-FP2116136014&ATT=Using+Lucene+to+Search+Java+Source+Code
* “Twelve Best Practices For Spring XML Configurations”:http://www.onjava.com/pub/a/onjava/2006/01/25/spring-xml-configuration-best-practices.html?CMP=OTC-FP2116136014&ATT=Twelve+Best+Practices+For+Spring+XML+Configurations
* “Using Spring with JDO and Hibernate”:http://www.onjava.com/pub/a/onjava/excerpt/springadn_ch05/index1.html?CMP=OTC-FP2116136014&ATT=Using+Spring+with+JDO+and+Hibernate
* “Integrating Ant with Eclipse, Part 1″:http://www.onjava.com/pub/a/onjava/excerpt/anttdg2_ch11/index.html?CMP=OTC-FP2116136014&ATT=Integrating+Ant+with+Eclipse+Part+1
* “Integrating Ant with Eclipse, Part 2″:http://www.onjava.com/pub/a/onjava/excerpt/anttdg2_ch11/index1.html?CMP=OTC-FP2116136014&ATT=Integrating+Ant+with+Eclipse+Part+2
* “Asynchronous Messaging Made Easy With Spring JMS”:http://www.onjava.com/pub/a/onjava/2006/02/22/asynchronous-messaging-with-spring-jms.html?CMP=OTC-FP2116136014&ATT=Asynchronous+Messaging+Made+Easy+With+Spring+JMS
* “Scheduling Jobs in a Java Web Application”:http://www.onjava.com/pub/a/onjava/2006/03/01/job-scheduling-in-web-application.html?CMP=OTC-FP2116136014&ATT=Scheduling+Jobs+in+a+Java+Web+Application
* “Proper handling of database-related exceptions”:http://www.oreillynet.com/onjava/blog/2006/03/proper_handling_of_databaserel.html?CMP=OTC-FP2116136014&ATT=Proper+handling+of+database-related+exceptions
* “Zero Configuration Networking: Using the Java APIs, Part 1″:http://www.onjava.com/pub/a/onjava/excerpt/bonjour_ch08/index.html?CMP=OTC-FP2116136014&ATT=Zero+Configuration+Networking:+Using+the+Java+APIs+Part+1
* “Advanced Configuration of the Spring MVC Framework”:http://www.onjava.com/pub/a/onjava/2006/03/22/advanced-spring-configuration.html?CMP=OTC-FP2116136014&ATT=Advanced+Configuration+of+the+Spring+MVC+Framework
* “Zero Configuration Networking: Using the Java APIs, Part 2″:http://www.onjava.com/pub/a/onjava/excerpt/bonjour_ch08/index1.html?CMP=OTC-FP2116136014&ATT=Zero+Configuration+Networking:+Using+the+Java+APIs+Part+2
* “Zero Configuration Networking: Using the Java APIs, Part 3″:http://www.onjava.com/pub/a/onjava/excerpt/bonjour_ch08/index2.html?CMP=OTC-FP2116136014&ATT=Zero+Configuration+Networking:+Using+the+Java+APIs+Part+3
* “Maven 2.0: Compile, Test, Run, Deploy, and More”:http://www.onjava.com/pub/a/onjava/2006/03/29/maven-2-0.html?CMP=OTC-FP2116136014&ATT=Maven+2.0:+Compile+Test+Run+Deploy+and+More
* “Agile Object to Relational Database Replication with db4o”:http://www.onjava.com/pub/a/onjava/2006/04/12/object-to-relational-database-replciation-with-db40.html?CMP=OTC-FP2116136014&ATT=Agile+Object+to+Relational+Database+Replication+with+db4o
* “Database Connection Pooling with Tomcat”:http://www.onjava.com/pub/a/onjava/2006/04/19/database-connection-pooling-with-tomcat.html?CMP=OTC-FP2116136014&ATT=Database+Connection+Pooling+with+Tomcat
* “Configuration Management in Java EE Applications Using Subversion”:http://www.onjava.com/pub/a/onjava/2006/05/03/j2ee-configuration-management-with-subversion.html?CMP=OTC-FP2116136014&ATT=Configuration+Management+in+Java+EE+Applications+Using+Subversion
* “Testing Java in an Object-Oriented Way”:http://today.java.net/pub/a/today/2006/03/28/testing-java-object-oriented.html
* “Understanding Service Oriented Architecture”:http://today.java.net/pub/a/today/2006/04/04/understanding-service-oriented-architecture.html
* “Exception-Handling Antipatterns”:http://today.java.net/pub/a/today/2006/04/06/exception-handling-antipatterns.html
* “Why Spring JDBC?”:http://today.java.net/pub/a/today/2006/05/09/why-spring-jdbc.html
* “An Introduction to Java Persistence for Client-Side Developers”:http://today.java.net/pub/a/today/2006/05/23/ejb3-persistence-api-for-client-side-developer.html
* “Learn how to discern which design patterns and frameworks would work best for your enterprise applications”:http://www.javaworld.com/javaworld/jw-01-2006/jw-0130-pojo.html?lsrc=jwrss

Not too many articles to read, eh? :-P

Next Page »