Java classes/example for every tech. might not be possible in single post because what you asked is evolution industry went through in last decade and still evolving. So, what happened over last decade can not be covered in one post. However, its good to understand how it went through this phase and why new technology stack required and what kind of problem it solves.
EJBs
Enterprise Java Beans serverside component architecture. It enables rapid and simplified development of
1) distributed(where multiple application server talks to each other, server components(e.g. service calling other service hosted on different server).
2) transactional - persistance bean (DB TXNs), most important part of any simple/web/distributed application. Easy development e.g configuration base. Write XML which takes care of the transaction e.g. when to commit, when to roll back(on exceptions) etc. JPA Java Persistance APIs provide object relationship maping. Such as your table row is mapped to your java object through the xml configuration.
3) secure - authentication(uid/pwd) and authorization(role based- who is logged in user and what all task he can do?).
This looks good at one point to develope any enterprise application however it has got some disadvantages e.g. its very heavy (all jars included in it.). Classes used as bean should confirm to EJB standards (classes should have implemented certain interface for EJB engine to understand which type of bean it is).
To overcome such scenarioes, there are many alternatives are available in industry for EJBs e.g Hibrnate does same things such as OR mapping, TXN handling same provided by persistance bean in EJB. Spring, light weight framework and simplifies business logic (you can use your already build class which need not to implement any interface, checked exceptions or extends some of the mandatory abstract classes).
Now a days, most of the compnies realy on the light weight frame work such as Spring, Hibernate, IBatis, Axis-2.
Service-Oriented Architecture (SOA)
Service Oriented Architecture is an answer to the platform independence at the enterprise level.
OR
To integrate your application faster, to communicate between different application server.
Just think that you want to implement solution where you are providing option for hotel booking all over the world. Your requirement is to check availability of rooms in those hotels. Now, it means that you need to interact with multiple hotel applications at a time. It's not necessary that every hotel is using same standard or their application(server, programming language) may be deployed on the different application servers. At a same time, its not practical to write different applications which can talk to all different type of the application server. We need some standard based solution which can solve this problem. It's possible through the Web services.
It is possible because web services are sending message in the SOAP(Simple Object Access Protocol), based on the XML. XML is used to interchange data across any language, platform or network protocol.
Web services can be classified SOAP Based and REST.
SOAP based service JAX-RPC and JAX-WS (http://www.ibm.com/developerworks/webservices/library/ws-tip-jaxwsrpc/index.html)
Web services can be developed
contract first - first write WSDL.
code first - first write code.
Now, lets talk how to start for the web services practically.
Simplest web service or hello world(JAXWS) can be written as follows:-
http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/java_first_jaxws/
- Message-Oriented Middleware (MOM)
- JMS
Message Queue (Point-to-Point)
MOM is required to over come disadvantages of request-response style communication. Server need to be alive when client sends response. Client wait for response till server executes and respond back.
Request response - application will fail if server or client is down.
MOM - Either of the end point is not required to be on time you send the request message for the processing.
MOM is concept and JMS is specification on this concept. Many vendors have implementation of this specification e.g IBM has MQ, OpenJMS open source implementation, EMS from Tibco etc.
JMS specification has majorly two patterns. Pub/sub and ponin-to-point.
Pub/sub is topic, your application want to publish certain information to all the interested parties. e.g. dash board. (Stock application want to notify certain message to all the registered listeners).
Point-to-Point communication is done through message queue.
Business use case- think you have application e.g customer request to the customer care. Other side you have multiple customer care representatives and other side customers sometimes more than customer care representatives, at a time one and only one representative will get the request to be processed and he/she will not get next request until finishes the task. (Same one queue multiple windows and which ever window is free will process the request). You can think of other complexity in this e.g what if one of the node is failed, request not processed and particular type of request needs to be process by particular node. etc.
Produce code:- http://docs.oracle.com/javaee/1.4/tutorial/examples/jms/simple/src/SimpleProducer.java
Consumer synchronous code:- (POJO classes)
http://docs.oracle.com/javaee/1.4/tutorial/examples/jms/simple/src/SimpleSynchConsumer.java
http://www.java2s.com/Code/Java/J2EE/ThisexampleisasimpleJMSclientapplication.htm
Consume asynchronous code:- (Spring by example - reads message from destination till program will not be stopped.)
http://www.springbyexample.org/examples/simple-spring-jms-listener-config.html
Though, its just basic there are many aspects to be covered in this MOM e.g. what's fail-over mechanism, what is selector, durable message, message acknowledgement modes etc...
- Service Bus/ESB
- Endpoints & Routes
- Apache Camel
- Mule
Now, lets say you have adopted SOA and MOM long back and you have bunch of services which talks to each others to accomplish enterprise wide task. Imagine to manage logic such as multiple destination whom should be redirected from where will be very cumbersome. Some people call this application logic. Service buses will be used to reduce application logic and focus more on the business logic(functionality provided by app).
In Simple words, consider End point as URL exposed on server. You will use this url/end point to invoke your service.
e.g.
http://localhost:8888/Context/MyService?wsdl
in code:-
String endpointAddress = "http://localhost:8080/jaxws/services/hello_world?wsdl";
// Add a port to the Service
service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, endpointAddress);
HelloWorld hw = service.getPort(HelloWorld.class);
System.out.println(hw.sayHi("World"));
Routes
When service bus receives particular message, it will route it through no of services/broker destinations such as queue/topics. This path is known as route.
E.g your stock application has got some input by analyst, it will be processed through the application/web component and then result will be published to all the interested/registered members for particular stock update.
Apache Camel and Muel http://camel.apache.org/how-does-camel-compare-to-mule.html
provides solution for the enterprise integration.