Ludovic Champenois's complete blog can be found at: http://weblogs.java.net/blog/ludo/

Items:   1 to 5 of 40   Next »

Monday, August 24, 2009

Bonjour, Comment Java?

This coming Thursday(08/27/09) 'll be at GooglePlex (Mountain View) for an Eclipse Day...The entire genda is at http://wiki.eclipse.org/Eclipse_Day_At_Googleplex_2009.

2 presos seem to be very interesting so far:

and possibly others...The Google crowd is impressive.

There is a waiting list for people who did not register in time:-) But I am sure online videos of the conference will be available as well.

Ludo (Testing the new Java.net Blog system)

 

 

 

 


Monday, August 3, 2009

Bonjour Comment Java?



ishot-210.png



today is some type of historical milestone for Java EE 6: This is
Milestone 1 of NetBeans 6.8 and Java EE 6 support with the latest
GlassFish v3 (build 57). The bundle is only 132Mb and contains
everything you need to start with Java EE 6: the IDE, the Java EE 6
current runtime, the JavaEE 6 JavaDocs (for code completion), the
JavaDB database, and very very cool features from the plaform or its
implementation:

  • No Need for web.xml in Web Application  (and
    support for web-fragment.xml)
  • Servlet Annotations
  • EJB inside Web Application Projects
  • Embedded Web Browser for fast testing (Mozzilla XULRunner)
  • GlassFish v3 build 57 pre-registered
  • Stellar GlassFish v3 startup time 
  • Stellar Deploy on Save for Java EE projects (redeploy in
    less than a second), with Session preservation
  • JSF 2.0 and Facelet Support
  • Java EE 6 Javadoc (preview) in Code completion (not many
    IDEs have this support:-)
  • Singleton EJB support
  • All current Java EE 6 APIs available: 
    • REST JAX-RS 1.1 and associated wizards
    • JAXB 2.2
    • Metro 2.0
    • JAX-WS 2.2
    • JPA 2.0
    • Beans Validation Framework
    • etc...
  • Maven support

And more and more (i.e all the NetBeans 6.7.x features as well).



ishot-211.png



Read more at  http://wiki.netbeans.org/NewAndNoteworthyNB68
and get the Milestone 1 bits at href="http://bits.netbeans.org/netbeans/6.8/m1/">http://bits.netbeans.org/netbeans/6.8/m1/





Ludo





Tuesday, May 26, 2009

This is the worst ever Java EE 6 Blog...Stop reading now.

Monday, May 25, 2009

Bonjour, comment Java?

I'm preparing some Java EE 6 JavaOne demos. While doing that, I was thinking: how can I compress most of the Java EE 6 technology inside *one* single Java Class?
If you are my manager, stop reading now...
If you believe you are an architect, stop reading now...
If you are a member of the Java Blueprints team, stop reading now...
If you are a regular java blog reader, stop reading now...
The following code is PG 40. Talk to you parents if you are less than 40.

Still reading? Not sure why, but here we go.

The following Java EE 6 compliant Application is a Web Application with just 2 source files: MonsterServlet.java and persistence.xml.
It demonstrates the following Java EE 6 features:

  • Annotated Servlets 3.0, avoiding the need for web.xml!!!
  • EJB without local Interface: 100% POJO, and transactional (managed by the container) and securable
  • EJB inside a Web Application
  • JPA (still needs a persistence.xml ,  here it's defined as creating the tables at deploy time, assuming the database is already running)
  • EclipseLink Implementation
  • Default GlassFish v3 JavaDB database registered as "jdbc/__default" datasource.
  • Beans Validation framework (JSR 303...Merci Emmanuel)
  • Injection of EJBs inside a Servlet

Are you still reading? Remember the 3 tier architecture, with Data Layer, Business Layer, then Presentation Layer? Well forget it for this monster application which merges all the layers into one single Java Class, which is a Servlet, an EJB and a Entity JPA bean validated with some Bean Validation annotations...

MonsterServlet.java
package monster;

import java.io.*;
import java.util.*;
import javax.ejb.*;
import javax.servlet.annotation.*;
import javax.servlet.http.*;
import javax.naming.*;
import javax.persistence.*;
import javax.servlet.*;
import javax.validation.*;
import javax.validation.constraints.*;
/**
* @author: Not Me!!!
**/
@Stateless @Entity @WebServlet(urlPatterns = "/monster")
@Table(name = "MONSTERTABLE")
@NamedQueries({@NamedQuery(name = "MonsterEJB.findAll", query = "SELECT c FROM MonsterServlet c")})
@PersistenceContext(name = "monsterContext", unitName = "MonsterWebAppPU")
public class MonsterServlet extends HttpServlet {
    @Id @GeneratedValue(strategy = GenerationType.SEQUENCE) private int monsterId;
    @Max(2) @NotNull private String name;
    @Transient @EJB MonsterServlet monsterEJB;
   /*@Transient @PersistenceUnit(unitName = "MonsterWebAppPU") //does not work see EclipeLink bug
    private EntityManagerFactory emf;*/ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=277550
   
    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response)
               throws
ServletException, IOException {
       response.getWriter().println("In Servlet calling the EJB side " + monsterEJB.EJBBusinessMethod("" + this));
    }

    public String EJBBusinessMethod(String name) {
   try {
        InitialContext ic = new InitialContext();
        EntityManager em = (EntityManager) ic.lookup("java:comp/env/monsterContext");
       this.name = name;

        em.persist(this);

        Query allMonsterQuery = em.createNamedQuery("MonsterEJB.findAll");
        List allMonsters = allMonsterQuery.getResultList();
        String error = validateTheMonsterJPA((MonsterServlet) allMonsters.get(0));
       return "BusinessMethod from EJB" + allMonsters.toString() + error;
    } catch (NamingException ex) {
      return "Error in EJBBusinessMethod "+ex.getMessage();
    }
   }

    private String validateTheMonsterJPA(MonsterServlet m) {
       String error=" ";
       ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
       Validator validator = factory.getValidator();
       Set> s = validator.validate(m);
      for (ConstraintViolation c : s) {
            error = error+ " Contraint Violation: " + c.getMessage());
       }
     return error;
    }
}


And the persistence.xml to put in the WEB-INF/classes/META-INF directory of this Web Application

xml version="1.0" encoding="UTF-8"?>
version="1.0" xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"<... class="xml-tag">>

    name="MonsterWebAppPU" transaction-type="JTA">
   >jdbc/__default>
rties>
   name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
>
>
sistence>

This Web Application can be deployed as it to the latest builds of GlassFish v3. The page output is something like:

In Servlet calling the EJB side BusinessMethod from EJB[monster.MonsterServlet@5718c3a7]  Contraint Violation: must be less than or equal to 2

Now the quiz:

  1. Explain the following statement: @Stateless @Entity @WebServlet
  2. what do you need to change in the code to remove the Contraint Violation statement in the output?
  3. Why do we need to inject the EJB aspect of this class into the servlet and cannot  just use "this" ?
  4. Do you think this bug will be fixed?  https://bugs.eclipse.org/bugs/show_bug.cgi?id=277550 

Still reading? Now I have just corrupted your brain: while not recommended, it is possible to write a 3-tier Java EE 6 Application with Servlets, EJBs, JPAs, Beans Validation in one single Java class and one single xml file...
Can't wait for Java EE 7 when persistence.xml will become optional:-)

See you at JavaOne. You can now forget this blog. Someone had to write it. It's over now:-)
Ludo


Friday, May 22, 2009

Bonjour Comment Java?

Finally the GlassFish Tools bundle for Eclipse has been released: version 1.0 is available at http://download.java.net/glassfish/eclipse

The Tools bundle contains:

  • Eclipse 3.4.2 IDE with WTP Java EE support
  • GlassFish v2.1 pre-registered and configured
  • GlassFish v3 Prelude pre-registered and configured
  • JavaDB sample database pre-registered and configured
  • GlassFish Plugins
  • GlassFish documentation
  • And optionally, a JDK 1.6.
splash1.0.bmp

Installers are available for Windows and MacOSX, and tar.gz for Linux systems.
If you have used a preview release (pre version 1.0), make sure to read the release notes  http://download.java.net/glassfish/eclipse/releasenotes.html for information about a known issue regarding reusing workspaces created with preview releases. Commercial support for this bundle is also available at http://developers.sun.com/services/buying_guide.jsp.

I like the fact that the GlassFish servers are preconfigured, ready to use, even with a sample Java DB database pre registered (to use the JPA entities tooling). By default the "Deploy On Save" feature is enabled for GlassFish v3 Prelude: it means that the moment you save a Servlet, a utility class, or even an EJB, the application is automatically updated and redeployed to the running server in an optimal way. If you want to play with leading edge bits for GlassFish v3 Java EE 6, you can even register and download from the bundle a promoted build (happens every week) of the latest GlassFish v3 server. We will demo more about that at the JavaOne conference.

We are now working on a version 1.1 (and nightly builds will be available next week. Version 1.1 will add the OpenSolaris 2009.05 target, an optimized installer with Pack200 technology to reduce the download size by almost 2!, the JAX-WS and JAX-RS Jersey RestFul GlassFish Plugins, Maven 2, a MySQL JDBC driver pre registered for better out of the box experience with the MySQL database, the entire Java EE 6 Javadoc available in the Eclipse Editor code completion, and of course the latest bug fixes.

I hope to see you at JavaOne 2009.
Ludo


Items:   1 to 5 of 40   Next »