纯JSP生成下载内容

String fileDownloadPath =

        AAAResourceReader.in.getSafeString

("ReportQueue.queue.FUND_SELECTION_REPORT.REQUEST_URL");

 

        PrintInfo printInfo =

                (PrintInfo) session.getAttribute(RRRRWebKeys.RRRR_PRINT_INFO_WRAPPER);

        session.setAttribute(RRRRWebKeys.RRRR_PRINT_INFO_WRAPPER, null);

 

        String username = printInfo.username;

        String password = printInfo.password;

        String token = printInfo.token;

        String queueCategory = printInfo.queueCategory;

 

        URL url = new URL(fileDownloadPath);

        URLConnection connection = url.openConnection();

        connection.setDoOutput(true);

        // 131018 - START

        connection.setRequestProperty("accept-charset", "UTF-8");

        connection.setRequestProperty("content-type", "application/x-www-form-urlencoded; charset=utf-8");

inputXmlEnRequest = FieldUtil.encodeBytesMS950(inputXmlEnRequest); 

        inputXmlEnRequest = URLEncoder.encode(inputXmlEnRequest,"UTF-8"); 

        inputXmlZhRequest = FieldUtil.encodeBytesMS950(inputXmlZhRequest); 

        inputXmlZhRequest = URLEncoder.encode(inputXmlZhRequest,"UTF-8");

        // 131018 - START

        PrintWriter outStream = new PrintWriter(connection.getOutputStream());

        outStream.print("username=" + username);

        outStream.print("&password=" + password);

        outStream.print("&xml=" + inputXmlEnRequest.replaceAll("%", "%25").replaceAll("&", "%26"));

outStream.print("&zhxml=" + inputXmlZhRequest.replaceAll("%", "%25").replaceAll("&", "%26")); // 131018

        outStream.print("&source=" + PrintInfo.SOURCE_WEB);

        outStream.print("&token=" + token);

        outStream.print("&queue_category=" + queueCategory);

        outStream.print("&agent_code=" + agentCode);

        outStream.print("&report_name=" + reportName);

        outStream.close();

 

        InputStream in = connection.getInputStream();

        if (!checkIsIPad(request)) {

            response.setContentType("application");

            response.setHeader("Content-disposition", "attachment; filename=" + reportName);

        } else {

            setIpadContentType(response, "application", reportName);

        }

 

        ServletOutputStream ostream = response.getOutputStream();

 

        //response.setContentLength(in.available());

        copyFile(in, ostream);

        response.flushBuffer();

        Logger.logStat(Logger.endAction(session.getId()) + request.getParameter("action"));

 

    } catch (Exception e) {

        // *** if the username and password is invalid or any other exception throw in file server. ***

        Logger.logError("RRRR_aw223_fund_selection_report_print.jsp: " + e.getCause());

        response.setContentType("text/plain");

        if (!checkIsIPad(request)) {

            response.setHeader("Content-disposition", "attachment; filename=Error.txt");

        }

        out.print("The file server is temporarily unavailable, please try again later.");

    }

-------------

public static void copyFile(InputStream in, OutputStream out) throws IOException {

        try {

            byte[] buf = new byte[4096];

            int i = 0;

            while ((i = in.read(buf)) != -1) {

                out.write(buf, 0, i);

            }

        } catch (IOException e) {

            Logger.logError("RRRR_aw223_fund_selection_report_print.jsp: " + e.getCause());

            throw e;

        } finally {

            try {

                in.close();

                out.flush();

                out.close();

            } catch (IOException e) {

                Logger.logError("RRRR_aw223_fund_selection_report_print.jsp: " + e.getCause());

            }

        }

    }

_______________________________________

public String handle(HttpServletRequest req, String actionRequest, String previousPage

            , ExceptionInfoHolder holder) {

        try{

 

            StringBuffer sb = new StringBuffer();

            HttpSession session = req.getSession();

 

            ppppppppEditView ppppppppEditView = (ppppppppEditView) session.getAttribute(

                ppppppppWebKeys.pppppppp_EDIT_VIEW);

            AgentView agentView = (AgentView) session.getAttribute(AimWebKeys.AIM_AGENT_VIEW);

            IndppppppppHK ip = ppppppppEditView.getIndppppppppHK();

        

            if (ppppppppPrintServer.ppppppppEmailPath == null) {

                ppppppppPrintServer.ppppppppEmailPath = aaaResourceReader.in.getSafeString("ppppppppEmail.path");

                

            }

            

            String urlString = ppppppppPrintServer.ppppppppEmailPath;

            

            Integer queueStatus = (Integer) session.getAttribute(ppppppppWebKeys.pppppppp_PRINT_QUEUE_STATUS);

            Logger.logAppDebug("queueStatus:[" + queueStatus + "]");

            if (queueStatus != null && queueStatus.intValue() == PrintppppppppQueue.PRINT_NOW) {

                GenericResourceReader printQueueResourceReader = new GenericResourceReader("aaappppppppPrintQueue_en_HK");

                urlString = printQueueResourceReader.getSafeString("pppppppp_PRINT_QUEUE_NOW_URL");

            }

 

            URL url = new URL(urlString);

            URLConnection connection = url.openConnection();

            connection.setDoOutput(true);

                

            PrintInfoWrapper pw =  (PrintInfoWrapper)session.getAttribute(ppppppppWebKeys.pppppppp_PRINT_INFO_WRAPPER);

            session.setAttribute(ppppppppWebKeys.pppppppp_PRINT_INFO_WRAPPER, null);

                

            String username = pw.username;

            String password = pw.password;

            String actionType = pw.actionType;

            String queueCategory = pw.queueCategory;

            String from = pw.from;

            String to = pw.to;

            String subject = pw.subject;

            String message = pw.message;

            //String xml = URLEncoder.encode(pw.xml);

            //String propNr = pw.propNo;

            String propNr = ip.getppppppppNoStr();

            String agentCode = pw.agentCode;

            String basicPlanCode = pw.basicPlanCode;

            String pcid = pw.pcid;

            String productAlias = pw.productAlias;

            String printLangPeCode = pw.printLangPeCode;

            String branchCode = pw.branchCode;

            String location = pw.location;

            String token = pw.token;

            String propRefNo = pw.propRefNo;

 

            // *** change big5 to ISO ***

            //xml = (xml==null)?"":new String(xml.getBytes("BIG5"), "ISO8859_1") ;

            String xml = FieldUtil.encodeBytesMS950HKCS(pw.xml);  // 20111017

            xml = URLEncoder.encode(xml); 

 

            PrintWriter outStream = new PrintWriter(

                                      connection.getOutputStream());

 

            outStream.print("username=" + username);

            outStream.print("&password=" + password); 

 

            outStream.print("&source=" + PrintInfoWrapper.SOURCE_WEB);

            outStream.print("&action_type=" + PrintInfoWrapper.EMAIL);

            outStream.print("&token=" + token);

            outStream.print("&queue_category=" + queueCategory);

 

            outStream.print("&with_print=" + "Y");

            outStream.print("&from=" + from);

            outStream.print("&to=" + to);

            outStream.print("&subject=" + subject);

            outStream.print("&message=" + message);

            outStream.print("&xml=" + xml);

            outStream.print("&prop_no=" + propNr);

            outStream.print("&agent_code=" + agentCode);

            outStream.print("&basic_plan_code=" + basicPlanCode);

            outStream.print("&pcid=" + pcid);

            outStream.print("&product_alias=" + productAlias);

            outStream.print("&print_lang_pe_code=" + printLangPeCode);

            outStream.print("&branch_code=" + branchCode);

            outStream.print("&location=" + location);

            outStream.print("&prop_ref_no=" + propRefNo);

 

sb.append(urlString);

sb.append("username=" + username);

sb.append("&password=" + password); 

sb.append("&source=" + PrintInfoWrapper.SOURCE_WEB);

sb.append("&action_type=" + PrintInfoWrapper.EMAIL);

sb.append("&token=" + token);

sb.append("&queue_category=" + queueCategory);

sb.append("&with_print=" + "Y");

sb.append("&from=" + from);

sb.append("&to=" + to);

sb.append("&subject=" + subject);

sb.append("&message=" + message);

sb.append("&xml=" + xml);

sb.append("&prop_no=" + propNr);

sb.append("&agent_code=" + agentCode);

sb.append("&basic_plan_code=" + basicPlanCode);

sb.append("&pcid=" + pcid);

sb.append("&product_alias=" + productAlias);

sb.append("&print_lang_pe_code=" + printLangPeCode);

sb.append("&branch_code=" + branchCode);

sb.append("&location=" + location);

sb.append("&prop_ref_no=" + propRefNo);

            

            outStream.close();

            

Logger.logAppDebug(this, "Email URL: " + sb.toString());

                

                

            BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));

            String inputLine;

            boolean alive = false;

                

            while((inputLine = in.readLine()) != null) {

                if (inputLine.indexOf("OK") > -1) {

                    alive = true;

                }

            }

            

            if (alive){

                holder.add("E45354"); // success message

 

                if ("Y".equalsIgnoreCase(req.getParameter(ppppppppPrintOptionPage.SENT_SMS))){

                    ppppppppPrintOptionPage ppppppppPrintOptionPage = (ppppppppPrintOptionPage) session.getAttribute(

                            ppppppppWebKeys.pppppppp_PRINT_OPTION_PAGE);

                    ppppppppPrintOptionPage.values.put(ppppppppPrintOptionPage.SENT_EMAIL_OK, "Y");

                }

 

            } else {

                holder.add("E45353"); // Fail message

            }

        } catch (Exception e){

            Logger.logAppDebug(this,"Exception for sending email: " + e.toString());

            holder.add("E45353");

 

        }

                        

        return previousPage;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值