Copyright: I don’t have anything. This is only my resume to OCMJEA 6 study based on Bambara’s book (an excellent one, if you can, buy it here). All the images are from the book and from Google Images. Personal use only. Sorry for english errors. Sergio Figueras (sergio@yourecm.com).

OCMJEA 6 - Study Book
Java EE 6 Enterprise Architect Certified Master 1Z0-807
3. Integration and Messaging
55226bd3bb4e03cb0317e5d1_Screen%20Shot%202015-04-06%20at%2008.26.58.png55226bf9bb4e03cb0317e5d4_Screen%20Shot%202015-04-06%20at%2008.27.05.png

CERTIFICATION OBJECTIVE 4.01 - System communication in JavaEE technology. Benefits and Drawbacks for each approach

1. Java Messaging Service

JMS provides a standard way to implement Message Oriented Middleware loosely coupled application communications. It can create, send, receives and read messages using Java.

Benefits

- Easy integration of incompatible systems
- Support for message acknowledgement
- Support for transactions (JTA)
Asynchronous messages: 
    – As transaction volumes increases, asynchronous messages can queue requests until they can be processed.
    –Asynchronous messages are less impacted by network, hardware and software failures.
 - When processing capabilities are exceeded, information is not lost, it’s delayed.

Drawbacks

- Not recommended for non Java integrations (legacy systems).
 - Requires support for message based integration

2. JavaEE Connector Architecture

JCA exposes legacy applications functionalities to be consumed by JavaEE projects.

Benefits

Exposes resources in generic / highlevel way

Drawbacks

Require resources vendor connector implementation.
Tightly coupled between EIS and application.

3. Jax-WS (XML WebServices)

API to build webservices between clients that exchange XML data. 

Benefits

Addresses Security and Reliability to enterprise services
Can interoperate with other WebServices
Support for HTTP/HTTPS and SMTP protocols

Drawbacks

XML data only.
Big XMLs transportation (XML envelopes are too big)
No support for async messages.

4. Jax-RS (Restful Webservices)

API to build webservices that uses REST as default communication method.

Benefits

Is embedded in  JavaEE 6 containers and up. In earlier versions we need to configure web.xml
Uses annotations
HTTP methods can easy represent CRUD methods (CREATE, PUT, DELETE, GET, etc)
Supports JSON

Drawbacks

Supports only HTTP/HTTPS methods.
No automatic support for WS Security.
Doesn't support directly asynchronous communications.

5. JDBC (Java Database Connectivity) 

Provides database interaction and is widespread technology in Java platform.

Benefits

Mature technology
Some performance issues must be resolved with JDBC instead of JPA.

Drawbacks

A drive for every database vendor is required.
Code needed to map tables and columns.
Logic is normally featured in SQL code.
No notion of objects. You translate your result set into Java Objects

6. JPA (Java Persistence API)

Benefits

Use of @Annotations to translate database metadata
Can be used outside EJB.

Drawbacks

Some tasks cannot be solved efficiently.
Performance may be affected if you use multiple layers between your app and your database.

7. CORBA

Language independent object distributable pattern defined by OMG. The center of CORBA is the Object Request Broker (ORB). ORB is the distributed programming service that enables objects to locate and iterate with others. CORBA objects have interfaces (IDL). Then the client makes calls to those interfaces as they were running locally. CORBA objects interacts with ORB either through an ORB interface or an Object Adapter.

Benefits

Heterogeneous objects are supported.
IIOP guarantees interoperability between vendors.
Very well documented.

Drawbacks

Objects are not passed by value. Only arguments data is passed.
 The server/client need to reconstitute objects using the data.
Only supported data types can be passed unless CORBA 2.3 is used.

8. Remote Method Invocation (RMI)

Java Implementation of RPC (Remote Procedure Call).

Benefits

Object oriented, objects can be passed.
The datatype can be any Java Object.

Drawbacks

Must use Java on local and remote objects.
Arguments must implement Serializable interface or extends java.rmi.Object

CERTIFICATION OBJECTIVE 4.02 – Identify and detail technologies used to integrate Business components and external resources, including JMS and JCA.

1. Message Driven Bean (MDB)

Message-driven beans are message consumers that can send and receive messages asynchronously. They’re called by EJB container when a Message is received and that bean is registered to this type of message. MDB can receives messages because they implements javax.jms.MessageListener interface. They receive JMS objects in the same manner as any JMS service object. MDBs don’t maintain session states. They call the onMessage() method when receives messages.
 The person which is responsible to assign MDBs to a destination in deploy time is called EJB deployer.
 - Life cycle of a MDB:
 1. Container invokes newInstance() on the MDB
 2. Creates an instance of javax.ejb.MessageDrivenContext()
 3. Set the messageDrivenContext() to the MDB through setMessageDrivenContext(context)
 4. Call ejbCreate() method before put this MDB into the list of available MDB.
 5. Container sets the MDB to available pool.
6. If the MDB throws any exception, the MDB is removed from available pool and the container rollback any transaction started by the container or MDB.
MDBs cannot invoke methods of acknowledge, as acknowledge() or rollback(), they are permitted for the container only.
AUTO_ACKNOWLEDGE permits the message to be delivered once.
DUPS_OK_ACKNOWLEDGE permits the message to be delivered duplicated after failure.

2. EJB Container

Are services provided by an EJB container:
 – Handles all communication for JMS services
 – Checks the availability of which MDB must be used.
 – Enables a propagation of the Security Context associating the role from Deployment Descriptor to the appropriate security thread.
 – Creates transactional context if is specified in Deployment Descriptor.
 – Passes the message into onMessage() method, according with the type of the message.
 – Reallocates the MDB to the pool of resources.

3. Java Connector Architecture
5522d7c3bb4e03cb0317f466_Screen%20Shot%202015-04-06%20at%2016.07.48.png

The application Server (AS) provides connection, security and transaction management. The application’s component contract via JCA resource is provided by Common Client Interface (CCI) that is consistent with accessing other resources like JDBC and JMS.

4. SOAP

SOAP is a protocol to exchange data between applications. It uses XML and transports in HTTP/HTTPS protocols, but can also be found in SMTP, TCP and JMS. SOAP messages have the following elements:
 - Envelope: defines what is in the message and how treat those informations.
 - Header: contains application specific information.
 - Body: contains the SOAP message
 - Fault: Contains the error messages describing faults on the processing. If present, it will appear as a child element of the body.
A SOAP based design must include the following characteristics:
 - A formal contract must be estabilished to describe the service. WSDL is a kind of formal contract that include messages, operations, bindings, and the location of the Web Service. You can also process SOAP messages in JAX-WS without a WSDL.
 - The architecture must provide complex non functional requirements. Such security, transactions, addressing, trust, etc.

Requirements for JAX-WS Endpoints
 – Must start with annotation javax.jws.WebService or javax.jws.WebServiceProvider
 - The business methods must be declared public and not static or final.
 - Exposed methods must be annotated with @WebMethod annotation.
 - Exposed methods must have compatible parameters and return type. 
 - The implementing class can't be declared as final and abstract.
 - The implementing class must have a default public constructor.
 - Can use @PostConstruct and @PreDestroy annotations.

5522db1ca5aeddb90cdaae2e_SOAP.jpg

The major problem in this approach is because if the requirements starts to getting bigger, the message will also be bigger and requires more CPU to parse the message.

5. WSDL (WebService Definition Language)

XML format describing the service functionalities and params for each of them. 

5522dc13a5aeddb90cdaae3e_wsdl.png
6. XSD (XML Schema Definition)

A XML Schema definition is a XML format language to define if a given XML is valid according their rules.

5522dc8dbb4e03cb0317f520_xsd.png
7. RESTful Web Services

Best suited for basic, ad hoc integration scenarios. Integrates better with HTTP than XML Web Services because it doesn't need XML configurations, a WSDL, and other stuff. Project Jersey is the project-ready implementation for JAX-RS specification. The following conditions specify a good set of requirements to build RESTful web services:
 - Completely stateless environment. A good test of it is consider wether the interaction can survive a restart of the server.
 - A caching infrastructure can be levaraged for performance. If the data suited by the server is not dinamically generated, caching infrastructure can be generated with the resouces that web servers already provides. You must take care because these caches are limited to HTTP GET method.
 - You don't have schemas to describe the data, so, both of producer and consumer must know the context they're talking. Basically, you don't have how to describe your data. Most of REST providers delivers development kit with each description of features.
 - RESTful is a good option in cases of limited bandwidth. PDAs and Mobile phones for example, doesn't have a good bandwidth and the XML payload of a SOAP requisition is not a good option.
 - Improves the developers production because it's easier than JAX-WS web services and you can consume them in your web  pages without refactoring. 
 - @Produces: indicates the mimetype of the content generated of that method
- @Consumes: indicates the mimetype consumed by that method

CERTIFICATION OBJECTIVE 4.04 – Identify how SOA (Service Oriented Architecture) is a good way to integrate systems.

1. Benefits of SOA Strategy

 - The ability to reuse functionalities across multiple projects
 - Easy  integration across platforms.
- Use of standards, agile approach.

SOA Patterns
5522e0e5a5aeddb90cdaaed3_Screen%20Shot%202015-04-06%20at%2016.46.35.png