e.printStackTrace(ps); log.error("Error sending Certificate Request to " + remoteAddr, e);
    public void doGet(HttpServletRequest req,  HttpServletResponse res) throws java.io.IOException, ServletException {        log.debug(">doGet()");        // Check if authorized        EjbcaWebBean ejbcawebbean= (se.anatom.ejbca.webdist.webconfiguration.EjbcaWebBean)                                   req.getSession().getAttribute("ejbcawebbean");        if ( ejbcawebbean == null ){          try {            ejbcawebbean = (se.anatom.ejbca.webdist.webconfiguration.EjbcaWebBean) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "se.anatom.ejbca.webdist.webconfiguration.EjbcaWebBean");           } catch (ClassNotFoundException exc) {               throw new ServletException(exc.getMessage());           }catch (Exception exc) {               throw new ServletException (" Cannot create bean of class "+"se.anatom.ejbca.webdist.webconfiguration.EjbcaWebBean", exc);           }           req.getSession().setAttribute("ejbcawebbean", ejbcawebbean);        }		// Check if authorized		CAInterfaceBean cabean= (se.anatom.ejbca.webdist.cainterface.CAInterfaceBean)								   req.getSession().getAttribute("cabean");		if ( cabean == null ){		  try {			cabean = (se.anatom.ejbca.webdist.cainterface.CAInterfaceBean) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "se.anatom.ejbca.webdist.cainterface.CAInterfaceBean");		   } catch (ClassNotFoundException exc) {			   throw new ServletException(exc.getMessage());		   }catch (Exception exc) {			   throw new ServletException (" Cannot create bean of class "+"se.anatom.ejbca.webdist.cainterface.CAInterfaceBean", exc);		   }		   req.getSession().setAttribute("cabean", cabean);		}        try{          ejbcawebbean.initialize(req, "/super_administrator");                  } catch(Exception e){           throw new java.io.IOException("Authorization Denied");        }		try{		  cabean.initialize(req, ejbcawebbean);		} catch(Exception e){		   throw new java.io.IOException("Error initializing CACertReqServlet");		}                                        String command;        // Keep this for logging.        String remoteAddr = req.getRemoteAddr();        command = req.getParameter(COMMAND_PROPERTY_NAME);        if (command == null)            command = "";        if (command.equalsIgnoreCase(COMMAND_CERTREQ)) {            try {                                PKCS10CertificationRequest pkcs10request = cabean.getPKCS10RequestData();				ByteArrayOutputStream bOut = new ByteArrayOutputStream();				DEROutputStream dOut = new DEROutputStream(bOut);				dOut.writeObject(pkcs10request);				dOut.close();								          				byte[] b64certreq = se.anatom.ejbca.util.Base64.encode(bOut.toByteArray());				String out = "-----BEGIN CERTIFICATE REQUEST-----\n";				out += new String(b64certreq);				out += "\n-----END CERTIFICATE REQUEST-----\n";                                if (res.containsHeader("Pragma")) {                    log.debug("Removing Pragma header to avoid caching issues in IE");                    res.setHeader("Pragma",null);                }                if (res.containsHeader("Cache-Control")) {                    log.debug("Removing Cache-Control header to avoid caching issues in IE");                    res.setHeader("Cache-Control",null);                }                                String filename = "pkcs10certificaterequest.pem";                res.setHeader("Content-disposition", "attachment; filename=" +  filename);                res.setContentType("application/octet-stream");                res.setContentLength(out.length());                res.getOutputStream().write(out.getBytes());                log.info("Sent latest Certificate Request to client at " + remoteAddr);            } catch (Exception e) {                PrintStream ps = new PrintStream(res.getOutputStream());                res.sendError(HttpServletResponse.SC_NOT_FOUND, "Error sending Certificate Request.");                e.printStackTrace(ps);                log.error("Error sending Certificate Request to " + remoteAddr, e);                return;            }        }		if (command.equalsIgnoreCase(COMMAND_CERT)) {			 try {			 	Certificate cert = cabean.getProcessedCertificate();			 					byte[] b64cert = se.anatom.ejbca.util.Base64.encode(cert.getEncoded());					RequestHelper.sendNewB64Cert(b64cert, res, RequestHelper.BEGIN_CERTIFICATE_WITH_NL, RequestHelper.END_CERTIFICATE_WITH_NL);										 } catch (Exception e) {				 PrintStream ps = new PrintStream(res.getOutputStream());				 res.sendError(HttpServletResponse.SC_NOT_FOUND, "Error getting processed certificate.");				 e.printStackTrace(ps);				 log.error("Error sending processed certificate to " + remoteAddr, e);				 return;			 }		 }		if (command.equalsIgnoreCase(COMMAND_CERTPKCS7)) {			 try {				Certificate cert = cabean.getProcessedCertificate();				        byte[] pkcs7 =  getSignSession().createPKCS7(ejbcawebbean.getAdminObject(), cert, true);							 				    byte[] b64cert = se.anatom.ejbca.util.Base64.encode(pkcs7);				    RequestHelper.sendNewB64Cert(b64cert, res, RequestHelper.BEGIN_PKCS7_WITH_NL, RequestHelper.END_PKCS7_WITH_NL);																		 								 } catch (Exception e) {                 log.error("Error sending processed certificate to " + remoteAddr, e);				 PrintStream ps = new PrintStream(res.getOutputStream());                 e.printStackTrace(ps);				 res.sendError(HttpServletResponse.SC_NOT_FOUND, "Error getting processed certificate.");				 return;			 }		 }    } // doGet