Sunday, September 4, 2011

Java EE6 - First Application

Pre-requisites

/**
 * TODO: Generate setters/getters
 */
@Entity
public class User implements Serializable {
  @Id
  @GeneratedValue
  private long id;

  @NotNull
  @Size(min = 5, max = 100)
  private String fullName;

  @NotNull
  @Column(unique = true)
  @Pattern(regexp = ".+@.+\\..+", message = "{constraint.email}")
  private String email;

  @NotNull
  @Size(min = 6, max = 10)
  private String password;
}

Java EE6 - Applications Servers

Some of Java EE Application Servers available on the market today:
  • Apache Tomcat (Servlet/JSP container only)
  • ATG Dynamo
  • BEA WebLogic
  • Borland Enterprise Server
  • Caucho Resin (Servlet/JSP container only)
  • Fujitsu Software Interstage 
  • GlassFish
  • Hitachi Cosminexus
  • IBM Websphere
  • JBoss AS
  • Mort Bay Consulting Jetty (Servlet/JSP container only)
  • Macromedia JRun Server
  • Novell exteNd
  • ObjectWeb JOnAS
  • Oracle Application Server 10g
  • Pramati Server
  • SAP AG Web Application Server
  • Sun Java System Application Server
  • Sybase EAServer
  • TmaxSoft JEUS
  • Together Teamlösungen EDV-Dienstleistungen GmbH. in cooperation with ObjectWeb Enhydra Server
  • Trifork Enterprise Application Server

Saturday, September 3, 2011

Java EE6 - Introduction

What is JEE?
  • As a super-set of Java SE, Java EE adds additional specifications, libraries, documentation, and tools.(see Java EE Architecture Diagram). See Java EE Architectures Diagram.
  • Java EE is an open and standard-based platform for developing, deploying, and managing multi-tier, web-enabled, server-centric, and component-based enterprise applications 
Multi-tier




  • Web Tier over HTTP.
  • Client Tier (B2B) is a set of external applications that makes requests into the Business Tier through Web Services over SOAP or directly through Java’s RMI.
  • Web Tier is usually implemented with Servlets, JSPs, and simple JavaBeans, based on the Model-View-Controller design pattern.
  • Business Tier is composed of EJBs and/or plain old Java objects (POJOs).
  • Data Access Tier is either managed by the applications (e.g. BMP, DAO), O/R mapping tools (e.g. Hibernate), or through Container Managed Persistence (CMP).
  • Connector/Messaging Tier allows asynchronous access to legacy systems or other external systems.
  • Legacy/External Tier consists of enterprise information systems.
  • Data Tier is usually composed of RDBMS and/or LDAP Directory Servers. 
Web-Enabled
  • Thanks to Servlet/JSP technology, Java EE applications are automatically web-enabled:
    • Efficient, Java/OO, Easy, I18N, MVC
  • Complete support for web-services
    • Clients
    • End-points 
Server-Centric
  • Java EE apps run within a Java EE application server that provides all middle-tier services.
  • Thin (web-based) clients
  • Support for rich clients through RMI, Web Services, etc.
    • The design of such clients is beyond the scope of Java EE
Component-Based Distributed Architecture


Java EE applications and services are built out of components that can run in a single or multiple (distributed) Java EE Application Server instances.

Enterprise Applications
  • Java EE applications are made up of:
    • Presentation logic
    • Business logic
    • Data access logic and model
  • Java EE facilitates separation of concerns
The goal of Java EE is to significantly reduce the cost, time, and complexity of developing and managing multi-tier enterprise applications.

Annexe

Some of Java EE Application Servers available on the market today:
  • Apache Tomcat (Servlet/JSP container only)
  • ATG Dynamo
  • BEA WebLogic
  • Borland Enterprise Server
  • Caucho Resin (Servlet/JSP container only)
  • Fujitsu Software Interstage
  • Hitachi Cosminexus
  • IBM Websphere
  • JBoss AS
  • Mort Bay Consulting Jetty (Servlet/JSP container only)
  • Macromedia JRun Server
  • Novell exteNd
  • ObjectWeb JOnAS
  • Oracle Application Server 10g
  • Pramati Server
  • SAP AG Web Application Server
  • Sun Java System Application Server
  • Sybase EAServer
  • TmaxSoft JEUS
  • Together Teamlösungen EDV-Dienstleistungen GmbH. in cooperation with ObjectWeb Enhydra Server
  • Trifork Enterprise Application Server 
Resources

    Java EE6 - Profiles

    Profiles
     
    The Java EE 6 specification introduces the notion of “profiles”:
    A profile is a sub-set of Java EE APIs geared towards a particular class of applications in mind (for e.g.: Web Profile - see below). 

    More: See JSR-00316 page 6

    Web Profile

    A separate specification, the Java EE 6 Web Profile Specification, defines the Java EE Web Profile, the first new profile of the Java EE 6 platform.
    The Java EE Web Profile only include APIs that are likely to be used in most Java web applications.
    Although Java EE 6 defines the rules for creating new Profiles through separate JSRs, only one Profile, the Web Profile is included in platform this time.
    Additional profiles may be defined in accordance with the rules of the Java Community Process.

    The following technologies are required/optional components of the Web Profile (download specs here):

    Required Components
    • Servlet 3.0
    • JavaServer Pages (JSP) 2.2
    • Expression Language (EL) 2.2
    • Debugging Support for Other Languages (JSR-45) 1.0
    • Standard Tag Library for JavaServer Pages (JSTL) 1.2
    • JavaServer Faces (JSF) 2.0
    • Common Annotations for theJava Platform (JSR-250) 1.1
    • Enterprise JavaBeans (EJB) 3.1 Lite
    • Java Transaction API (JTA) 1.1
    • Java Persistence API (JPA) 2.0
    • Bean Validation 1.0
    • Managed Beans 1.0
    • Interceptors 1.1
    • Contexts and Dependency Injection for the Java EE Platform 1.0
    • Dependency Injection for Java 1.0
    Optional Components
    There are no optional components in the Web Profile.

    Java EE6 - Architecture and Services

    Resources

    Java EE Architecture Diagram

    Click to enlarge

     

    JAX-RPC (JSR-101): Java API for XML-Based RPC
    The RPC (Remote Procedure Call) mechanism enables a remote procedure call from a client to be communicated to a remote server.

    JAX-WS (JSR-224): Java API for XML-Based Web Services
    JAX-WS is a follow-on to JAX-RPC extending it, with new specifications and new versions of the standards it depends on.

    SAAJ (JSR-67): SOAP with Attachments API for Java
    SAAJ is used mainly for the SOAP messaging that goes on behind the scenes in JAX-WS handlers and JAXR implementations.

    JAX-RS (JSR-311): Java API for RESTful Web Services
    Set of Java APIs for the development of Web services built according to the Representational State Transfer (REST) architectural style.
    A JAX-RS application is a web application that consists of classes that are packaged as a servlet in a WAR file along with required libraries.

    The JAX-RS API is new to the Java EE 6 platform.

    JAXR (JSR-93): Java API for XML Registries
    JAXR API aims to be the confluence of the various registry specifications (OASIS, eCo Framework, ebXML and UDDI).

    JASPIC (JSR-196): Java Authentication Service Provider Interface for Containers
    The  JASPIC specification defines a service provider interface (SPI) by which authentication providers that implement message authentication mechanisms may be integrated in client or server message processing containers or runtimes. 

    Authentication providers integrated through this interface operate on network messages provided to them by their calling container. They transform outgoing messages so that the source of the message may be authenticated by the receiving container, and the recipient of the message may be authenticated by the message sender. They authenticate incoming messages and return to their calling container the identity established as a result of the message authentication.

    The JASPIC API is new to the Java EE 6 platform.

    JACC (JSR-115): Java Authorization Service Provider Contract for Containers
    The Java ACC API defines a contract between a Java EE application server and an authorization policy provider. All Java EE containers support this contract.

    The Java ACC API defines java.security.Permission classes that satisfy the Java EE authorization model. The specification defines the binding of container access decisions to operations on instances of these permission classes. It defines the semantics of policy providers that employ the new permission classes to address the authorization requirements of the Java EE platform, including the definition and use of roles.

    CDI & DI (JSR-299): Contexts and Dependency Injection
    Contexts and Dependency Injection (CDI) provides Dependency Injection (DI) power and flexibility. Both are part of the Java Platform, Enterprise Edition (Java EE) 6 specification and ready to use.

    The CDI API is new to the Java EE 6 platform.

    Web Services (JSR-109): Java Web Services
    Web services is a service oriented architecture which allows for creating an abstract definition of a service, providing a concrete implementation of a service, publishing and finding a service, service instance selection, and interoperable service use. In general a Web service implementation and client use may be decoupled in a variety of ways. Client and server implementations can be decoupled in programming model. Concrete implementations may be decoupled in logic and transport

    WS Metadata (JSR-181): Web Services Metadata
    This API allows to reduces the amount of information required to implement Web Services on J2EE by using metadata to specify declaratively the Web Services that each application provides. The metadata annotates the Java source file that implements the Web Service.

    Management (JSR-77): Java Management API
    The J2EE Management Model is a specification of the attributes, operations and architecture of the managed objects required by compliant J2EE platform implementations. The model is designed to be interoperable with a variety of industry standard management systems and protocols.

    JMS (JSR-914): Java Message Service (JMS) API
    JMS provides a common way for Java programs to create, send, receive and read an enterprise messaging system’s messages.

    Connectors (JSR-322): Java EE Connector Architecture (JCA)
    The Java EE Connector architecture defines a standard architecture for connecting the Java EE platform to heterogeneous EISs. Examples of EISs include Enterprise Resource Planning (ERP), mainframe transaction processing (TP), and database systems. By using the J2EE Connector architecture, EIS vendors no longer need to customize their product for each application server. Application server vendors who conform to the J2EE Connector architecture do not need to add custom code whenever they want to add connectivity to a new EIS.

    See also:  JSR-112

    JTA (JSR-907): Java Transaction API
    Java Transaction API (JTA) specifies standard Java interfaces between a transaction manager and the parties involved in a distributed transaction system: the resource manager, the application server, and the transactional applications. 

    Persistence (JSR-317): Java Persistence
    The Java Persistence 2.0 API addresses improvements in the areas of domain modeling, object/relational mapping, EntityManager and Query interfaces, and the Java Persistence query language. It adds an API for criteria queries, a metamodel API, and support for validation.

    JSF (JSR-314): Java Server Faces
    JavaServer Faces (JSF) is a user interface (UI) framework for Java web applications. It is designed to significantly ease the burden of writing and maintaining applications that run on a Java application server and render their UIs back to a target client.

    Note: See also JSR-127

    JSTL (JSR-52): Java Server Pages Standard Tag Library
    The ultimate goal of JSTL is to help simplify Java Server Pages (JSP) page authors’ lives. A page author is someone who is responsible for the design of a web application’s presentation layer using JSP pages. Many page authors are not fluent in any programming language.
    A key aspect of JSTL is an expression language (EL) designed specifically for the page author.

    JavaMail (JSR-919): JavaMail
    The JavaMail API provides a set of abstract classes defining objects that comprise a mail system. The API defines classes like Message, Store and Transport. The API can be extended and can be subclassed to provide new protocols and to add functionality when necessary.

    Others

    Management (JSR-160): Java Management EXtension  (JMX) Remote API
    Although JSR-3 defines terminology for remote access to instrumentation, it does not standardize any particular remote access API or protocol. Many solutions exist for exporting JMX API instrumentation
    either through existing management protocols such as the simple network management protocol (SNMP) or through proprietary protocols. This JSR (JSR 160) standardizes one such solution.
    The principal goals of this standard are interoperability, transparency, security, and flexibility.

    Note: JMX 1.x were defined by JSR-3 of the Java Community Process. The changes proposed in the JSR-160 are intended as interim steps towards JSR-255 ("JMX Specification, version 2.0"), which will contains larger set of updates to the JMX Remote specification.
    An extension of the JMX Remote API for Web Services is being developed under JSR-262.

    Application Deployement (JSR-88): Java Application Deployment
    Defines standard APIs to enable deployment of components and applications based on the J2EE platform, as well as the development of platform-independent deployment tools.

    Java Network Launch Protocol (JSR-56): JNLP
    The Java Network Launching Protocol and API (JNLP) is a Web-centric provisioning protocol and application environment for Web-deployed Java applications. An application implementing this specification is called a JNLP Client.

    JSP (JSR-245): Java Server Pages
    A JSP page is a textual document that describes how to create a response object from a request object for a given protocol. The processing of the JSP page may involve creating and/or using other objects.

    Servlets (JSR-154): Java Servlets
    A servlet is a Java technology-based Web component, managed by a container, that generates dynamic content. Like other Java technology-based components, servlets are platform-independent Java classes that are compiled to platform-neutral byte code that can be loaded dynamically into and run by a Java technology-enabled Web server. Containers, sometimes called servlet engines, are Web server extensions that provide servlet functionality. Servlets interact with Web clients via a request/response paradigm implemented by the servlet container.

    JavaBeans Activation Framework (JSR-925):  JAF
    The Java platform (including JavaBeans) already provides some support for a modest activation framework. The JAF leverages as much of that existing technology as possible. The JAF integrates these mechanisms.

    Java Authentication and Authorization Service : JAAS
    The Java Authentication and Authorization Service (JAAS) was introduced as an optional package (extension) to the Java 2 SDK, Standard Edition (J2SDK), v 1.3. 
    Since J2SDK 1.4, JAAS has been integrated into the JDK (including JSE 7).

    Java Naming and Directory Interface: JNDI
    The JNDI is included in the Java 2 SDK, v1.3 and later releases (including JSE 7). It is also available as a Java Standard Extension for use with the JDK 1.1 and the Java 2 SDK, v1.2.
    JNDI is an API specified in Java technology that provides naming and directory functionality to applications written in the Java programming language.

    Java EE6 - Install development environment

    Objectives
    1. Install the environment of development
    Tools

     Installation

      StepToolAction                 Optional ActionExample
      1Java SELaunch installerCustomize directoryu:\dev\java\jse\jdk7
      2JBoss- Extract JBoss
      - Set the JBOSS_HOME
      - From  <JBOSS_HOME>\bin launch either the domain or standalone script
      Customize directory u:\dev\java\srv\jboss7
      3MySQLLaunch installerCustomize directoryu:\dev\db\mysql
      -dddd



      Customize installation optionsDeveloper Default, 
      Connector/J 5.15.0, 
      Developer Machine, Enable TCP/IP Networking
      4MySQL- Launch MySQL Workbench
      - Double-click "Local instance MySQL55" to connect to the DB
      - Create database called EJB3


      5MySQL Connector/J- Unzip
      - Create dir  <JBOSS_HOME>\modules\com\mysql\main if not exists
      -  Copy the MySQL Connector/J jar file into this directory

      6JBoss
      - Create file <JBOSS_HOME>\modules\com\mysql\main\module.xml (see Notes below)
      - Edit <JBOSS_HOME>\domain\configuration\domain.xml
      and/or <JBOSS_HOME>\standalone\configuration\standalone.xml (see Notes below)


      7Eclipse- Extract Eclipse
      - Launch Eclipse
      - Install JBoss Tools from Eclipse
      - In Eclipse, add the Server View
      - From the Server View, add JBoss AS 7
      - From the Server View, launch JBoss AS 7
      - Check JBoss in running going to  http://localhost:8080/ (change port if customized)
      Customize directoryu:\dev\java\ide\eclipse\jee-indigo

      Notes on JBoss AS 7
      • JBoss Administration Console: http://localhost:8080/console (change port if customized)
      • Require JSE 6 (1.6.0) min or higher.
      • Before launching the domain or standalone scripts, ensure the port 8080 is not already in used. If already in use, change the ports in uses editing:
        If domain: <JBOSS_OME>\domain\configuration\ domain.xml and in host.xml if needed.
        If standalone: U:\srv\jboss7\standalone\configuration\standalone.xml
        And restart either the domain or standalone script.
      • JBoss domain is a new addition to JBoss AS 7.
      • See also:
        Getting Started Developing Application Guide
        User Guide
        Videos (part 1, part 2)
        JBoss docs

      Note installing MySQL/J Connector
      • modules.xml

        <module name="com.mysql" xmlns="urn:jboss:module:1.0">
          <resources>
            <resource-root path="mysql-connector-java-5.1.17-bin.jar">
          </resource-root></resources>
          <dependencies>
            <module name="javax.api">
          </module></dependencies>
        </module> 
        
      • <JBOSS_HOME>\standalone\configuration\standalone.xml  and/or <JBOSS_HOME>\domain\configuration\domain.xmlLocate the <datasources> .. </datasources> section. Replace with:

         <datasources>
           <datasource jndi-name="java:jboss/datasources/MySqlDS" pool-name="MySqlDS">
             <connection-url>jdbc:mysql://localhost:3307/EJB3</connection-url>
             <driver>com.mysql</driver>
             <transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
             <pool>
               <min-pool-size>10</min-pool-size>
               <max-pool-size>100</max-pool-size>
               <prefill>true</prefill>
              </pool>
              <security>
                <user-name>test</user-name>
                <password>test</password>
               </security>
               <statement>
                <prepared-statement-cache-size>32</prepared-statement-cache-size>
               </statement>
              </datasource>
              <drivers>
               <driver name="com.mysql" module="com.mysql">
                 <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
               </driver>
              </drivers>
            </datasources> 
      • See also: Installing the JDBC Driver on the JBoss doc in case of problem

      FAQs

      1. JBoss AS: Which version: Web Profile Only (Java EE6 Certified) or Everything (NOT Java EE6 Certified) ?

        See: Java EE6 Specs - Web Profile and JBoss Comparison Table.

      Alternatives Open Sources Recommended Tools for Developpers

      CategoryToolDescription
      JEE ServerOpenEJBEmbeddable and lightweight. Can be used as a standalone server or embedded into Tomcat, JUnit, TestNG, Eclipse, IntelliJ, Maven, Ant, and any IDE or application.

      GlassFishGlassFish is a Java EE open source application server. Also for Production environments.
      DatabaseHSQLDBOpen source relational database implemented entirely in Java.

      Apache DerbyOpen source relational database implemented entirely in Java.

      Oracle APEXOracle Application Express (Oracle APEX) is a rapid web application development tool for the Oracle database. Using only a web browser and limited programming experience, you can develop and deploy professional applications that are both fast and secure.

      Others JEE Applications Servers for Development and/or Production Environment

      See also: JEE 6 - Applications Servers