I'm want to use the n-tier architecture for an application so the client tier, web tier, business tier and data tier is separate. I'm wondering how a message driven bean which has a message save it to the database without changing the architecture. (That is using a normal session bean i retrieved data entered through a JSP page to a servlet and from the servlet called the bean class which had operations to the database, it is not possible to do this with the message driven beans since it already has a overridden method onMessage)
So far i can retrieve the values from the servlet directly using the message bean but i want to change this to a 4-tier architecture where database operations are not in the servlet.
my servlet code
@Resource(mappedName = "jms/dest")
private Queue dest;
@Resource(mappedName = "jms/queue")
private ConnectionFactory queue;
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
String str = request.getParameter("message");
try {
sendJMSMessageToDest(str);
} catch (JMSException ex) {
}
private Message createJMSMessageForjmsDest(Session session, Object messageData) throws JMSException{
TextMessage tm = session.createTextMessage();
tm.setText(messageData.toString());
return tm;
}
private void sendJMSMessageToDest(Object messageData) throws JMSException{
Connection connection = null;
Session session = null;
try {
connection = queue.createConnection();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer messageProducer = session.createProducer(dest);
messageProducer.send(createJMSMessageForjmsDest(session,messageData));
} catch (JMSException ex) {
}
}
You must think in two possible workflows:
Below I draw a possible architecture wich covers boot workflows. The components are:
This architecture enables code reutilization and separation of responsibilities.
Theres is the Diagram with two workflows.