Thursday, 26 March 2015

Multi-module Java EE web application

The subject of the application is simple examination tool. User can configure answers to questions 'Administrate answers' and then 'Take an exam'.

Run the example application: http://examstarter-phojnacki.rhcloud.com/

To implement a starter example I've chosen:

  - Java,
  - EJB,
  - JBoss,
  - Maven,
  - Struts 2 (+Conventions Plugin)




I divided an application into following modules

- exam-business-logic-api - interfaces on which depend ejb and web modules,
- exam-business-logic - ejb module with business logic implementation,
- exam-business-logic-ear - ear with business logic (intentionally deployed separately to test remote communication - in JBoss 7 each deployment unit classes are loaded using different Class Loader),
- exam-web - web application based on Struts 2 framework (whole configured with Conventions Plugin), also deployed separately as war.



Application has been implemented using Struts2 MVC framework . I configured actions with annotations solely (dependency on Struts 2 Conventions Plugin). I also followed Post-Redirect-Get web design pattern.

You can configure exam questions in business logic module:

@Stateless(mappedName = "ExamQuestionsService")
@Remote(ExamQuestionsService.class)
public class ExamQuestionsServiceBean implements ExamQuestionsService {
 
    @Override
    public List<ExamQuestion> getExamQuestions() {
        ExamQuestion examQuestion1 = new ExamQuestion();
        examQuestion1.setQuestion("What is the current version of Struts?");
        examQuestion1.setAnswer("2.3.20");
        ExamQuestion examQuestion2 = new ExamQuestion();
        examQuestion2.setQuestion("How many principles are in S.O.L.I.D.?");
        examQuestion2.setAnswer("5");
        ExamQuestion examQuestion3 = new ExamQuestion();
        examQuestion3.setQuestion("Software design pattern in which an (..)");
        examQuestion3.setAnswer("Observer");
 
        List result = new ArrayList();
        result.add(examQuestion1);
        result.add(examQuestion2);
        result.add(examQuestion3);
 
        return result;
    }
 
}

To review or clone an example please visit my exam GitHub repository. Instructions of building and deploying are attached in README file.

 GitHub repository of this starter application

I've deployed ear and war artifacts on RedHat OpenShift (examstarter application).

No comments: