1 package com.instantbank.collections.creditInfo.web;
2
3 import java.io.IOException;
4 import java.io.OutputStreamWriter;
5 import java.io.PrintWriter;
6 import javax.servlet.RequestDispatcher;
7 import javax.servlet.ServletConfig;
8 import javax.servlet.ServletContext;
9 import javax.servlet.ServletException;
10 import javax.servlet.http.HttpServlet;
11 import javax.servlet.http.HttpServletRequest;
12 import javax.servlet.http.HttpServletResponse;
13 import javax.servlet.http.HttpSession;
14 import com.instantbank.collections.creditInfo.ejb.AccountInfoServices;
15 import com.instantbank.collections.creditInfo.ejb.AccountInfoServicesHome;
16 import com.instantbank.collections.util.FilterChain;
17 import com.instantbank.collections.util.InstantbankException;
18 import com.instantbank.collections.util.ServiceLocator;
19 import com.instantbank.collections.util.StringFormat;
20
21 public class AccountDetailsController extends HttpServlet {
22 AccountInfoServices accountInfoServices;
23 AccountInfoServicesHome ahome;
24
25
26
27 PrintWriter out;
28 HttpSession session;
29
30
31 public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
32 this.doPost(request, response);
33 }
34
35
36 public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
37 String action = "";
38 com.instantbank.collections.util.FilterChain chain;
39 try {
40 action = request.getParameter("action");
41 session = request.getSession(false);
42 session.setAttribute("hasException", "0");
43 try {
44 chain = new com.instantbank.collections.util.FilterChain(true, getServletConfig().getServletContext());
45 if(chain.processFilter(request, response)) {
46 return;
47 }
48 if(action.equals("initialize")) {
49 initialize(request, response);
50 }
51 else {
52 throw new InstantbankException("242001", "Action " + action + " not supported");
53 }
54 }
55 catch(Exception e) {
56 throw new InstantbankException(e, "242002", "Failed to execute controller action " + action);
57 }
58 }
59 catch(InstantbankException e) {
60 session.setAttribute("hasException", "1");
61 session.setAttribute("Exception", e);
62 if(response.isCommitted()) {
63 return;
64 }
65 response.sendRedirect("../main_web/ControllerError.jsp?showTechnical=0");
66 }
67 }
68
69
70 public void init(ServletConfig config) throws ServletException {
71 try {
72 super.init(config);
73 ahome = (AccountInfoServicesHome)ServiceLocator.instance().createEJB("AccountInfoServicesHome", AccountInfoServicesHome.class, false);
74 accountInfoServices = ahome.create();
75
76
77 }
78 catch(Exception e) {
79 throw new ServletException(e);
80 }
81 }
82
83
84 private void initialize(HttpServletRequest request, HttpServletResponse response) throws InstantbankException, IOException, ServletException {
85 String agrmDetails;
86 Long agrmId = null;
87 Long agrmCode;
88 String collateral;
89 Long companyId;
90 String data;
91 String fromQueuing = "N";
92 String outXmlString = "";
93 String primary;
94 ServletContext sctx = getServletConfig().getServletContext();
95 String status;
96
97
98 try {
99 agrmId = (Long)request.getAttribute("agrmId");
100 companyId = (Long)session.getAttribute("companyId");
101 fromQueuing = request.getParameter("fromQueuing");
102 primary = StringFormat.cleanXml(accountInfoServices.getPrimaryCustomer(companyId, agrmId));
103 collateral = StringFormat.cleanXml(accountInfoServices.getCollateralInfo(companyId, agrmId));
104 agrmDetails = StringFormat.cleanXml(accountInfoServices.getAgreementDetails(companyId, agrmId, true, true, true, true));
105 status = StringFormat.cleanXml(accountInfoServices.getStatusValues(companyId, agrmId));
106
108 outXmlString = "<?xml version=\"1.0\" encoding=\"ISO8859-1\"?><AccountDetails>" + primary + collateral + agrmDetails + status + "</AccountDetails>";
109 request.setAttribute("data", outXmlString);
110 RequestDispatcher rd = sctx.getRequestDispatcher("/creditInfo_web/AccountDetailsView.jsp");
111 rd.forward(request, response);
112 }
113 catch(Exception e) {
114 response.setContentType("text/html");
115 OutputStreamWriter osw = new OutputStreamWriter(response.getOutputStream());
116 PrintWriter out = new PrintWriter(osw);
117 out.println("<html>");
118 out.println("<head><title>Accounts no found</title></head>");
119 out.println("<body>");
120 out.println("<H2>Account number not found.</H2>");
121 out.println("</body></html>");
122 out.println("<script>");
123 out.println("/*");
124 e.printStackTrace(out);
125 out.println("*/");
126 out.println("</script>");
127 out.close();
128 }
129 }
130 }
131
132