Tuesday, February 22, 2011

Spring Integration In Action- Book Review

In last few weeks I have red two very interesting books (Camel in Action and Spring Integration in Action) from Manning. These two books are implements/supports Enterprise Integration Pattern. Well, this review is about “Spring Integration in Action”, so let’s talk about that. Before we go further in to book review, I would like to congrates Mark Fisher & authors as they have done tremendous job in writing this book.

After reading first chapter "Introduction to Spring Integration", you could sense that this book is very well written with well defined chapters. This book can be very informative to user who doesn't know anything about Messaging and for advanced users ready to play with Spring Integration and want to apply some Enterprise Integration Pattern.

Inside the Book

This book contain some where are around 19 chapters and since not all of them are out yet, but so far and each chapter is well defined and up to the point.

Chapter 1 covers good introduction to "Core Messaging" and tooling around Messaging like Router, Message Adopter and spillter. Also, I like the approach taken by Authors by saying "Spring Integration" support Enterprise Integration Pattern instead of Implementing EIP.

Chapter 2 covers Fundamental of EIP "Enterprise Integration Pattern" - This makes this chapter a must read for beginners as this cover some background about EIP and some basic fundamental about EIP.

Chapter 3 covers messages, channel and transaction and relationship between them, and also provides some good examples.

Chapter 4 & 5 provides details about End point, topics and transformer and different types of Channel Adopter available in Spring Integration framework.

Chapter 6 will take you deep in with some examples as how you can build and test some of the POJOs, and how to connect them to channel -

Chapter 7 will take you to another big topic called Router and Filter APIs, and different types of router provided by Spring Integration.

Chapter 9 will provide you details about XML messages payloads and how spring integration provides supports for XML messages.

Chapter 10- This is very interesting chapter as this provides details about relationship between JMS and Spring Integration Framework. I think this chapter is very useful for folks who have used JMS APIs.

Chapter 12 - This chapter cover about how to integrate file system with Spring Integration and how to use one of the channel adopter.

Chapter 18 - This chapter cover scalability messaging with OSGI and integration with RabbitMQ,

Chapter 19- Testing with Spring Integration with set of examples to better understand Spring Integration concepts.

If you have played with Spring Framework and would like to use Spring Integration framework, this book will provide you basic as well as advanced topics. Check it out and ENJOY..

Hope this would help.

Saturday, February 19, 2011

EJB 3.1 Security example

I have been playing with different bean types from EJB3.1. EE6 and really improved JEE specs, EJB has been around for sometime now and until now its been really hard for developer to manage them with interfaces, deployment descriptor etc.
EE6 introduced new era of EJB3.1 that I think this should make life easy for developer (who wants to use EJBs). And surely annotations will reduce more code base in applications.
I have not been big fan of EJBs, that MIGHT change now as EJBs now more or less look like POJOs.
Let me show you how easy it is now to write EJB. Here's security EJB example from EJB3.1

First we have write EJB code with different security annotations. I have written Servlets to test it with EJB injection in to Servlet.
This example has been tested in GlassFish, to run this you need to have Global security set up and also you need to map role with defined users, in this case its "Authorized"...

here you go..

import javax.annotation.Resource;
import javax.annotation.security.DeclareRoles;
import javax.annotation.security.PermitAll;
import javax.annotation.security.RolesAllowed;
import javax.ejb.LocalBean;
import javax.ejb.SessionContext;
import javax.ejb.Stateless;
/**
* Session Bean implementation class MathSecTestEJb
*/
@Stateless
@LocalBean
@DeclareRoles({"Authorized"})
public class MathSecTestEJb {
/**
* Default constructor.
*/
public MathSecTestEJb() {
// TODO Auto-generated constructor stub
}

@Resource SessionContext ctx;
@RolesAllowed("Authorized")
public void printRoleName(){
System.out.println(ctx.getCallerPrincipal().getName());
}

@PermitAll
public int addNumber(int a, int b){
return a+b;
}
}
import java.io.IOException;
import javax.annotation.security.RolesAllowed;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.HttpConstraint;
import javax.servlet.annotation.ServletSecurity;
import javax.servlet.annotation.ServletSecurity.TransportGuarantee;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import vk.test.secejb.MathSecTestEJb;
/**
* Servlet implementation class MathSecServlet
*/
@WebServlet("/MathSecServlet")
@ServletSecurity(
@HttpConstraint(rolesAllowed = {"Authorized"}))
@RolesAllowed({"Authorized"})
public class MathSecServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* @see HttpServlet#HttpServlet()
*/
public MathSecServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doPost(request,response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
processNumber(request, response);
processRole(request, response);
}

@EJB MathSecTestEJb mathejb;
public void processNumber(HttpServletRequest request, HttpServletResponse response) throws IOException{
response.getOutputStream().println(mathejb.addNumber(5, 10));
}

@EJB MathSecTestEJb mathej;
@RolesAllowed({"Authorized"})
public void processRole(HttpServletRequest request, HttpServletResponse response) throws IOException{
mathej.printRoleName();
}

}

Thursday, February 3, 2011

Camel In Action - Book Review

Last few days I have been reading Camel In Action from Manning Publication. After reading this "In Action" series book, I must say as always manning books are great for beginner and advanced users. Let's talk about book "Camel In Action" this books provides good overview of "Apache Camel" and why it's one of the best Enterprise Integration Pattern out there. This books cover good implementation details about Apache Camel with lots of code example to make it easier for developers.

Inside the Book

Although, this book contain some where are around 14 chapter and all of them make it really good read. I'm going to cover first eight chapters as these chapters considered as core camel.

Chapter 1 - This Chapter names as "Meet with Camel", as described from its name, this chapter provides good details about Apache Camel and it's architecture.

Chapter 2&3- This chapter covers fundamental concepts like routing and transformation with some very good example codes.

Chapter 4- This chapter covers details about how to work with simple beans with Camel and also provides examples to integrate with Spring.

Chapter 5- Error handing as one of most important aspect of any programming, this chapter divide errors in two segment "recoverable" and "irrecoverable" and covers it very well
with some nice example.

Chapter 6 - Testing with Camel, as name suggested, this chapter talks about testing Junit and testing mock component with Camel.

Chapter 7- This chapter covers different components like Asynchronous messaging , web services etc...in camel.

Chapter 8 - Enterprise Integration Pattern, as name suggested this chapter cover fundamental of Enterprise Integration pattern and details about EIP (e.g aggregator, spillter)

There are some very interesting chapters ahead like transaction, concurrency and scalability, developing camel projects etc. Which makes this book a must read if you really want to know about "Apache Camel".

I hope this review would help.