List of usage examples for javax.servlet ServletOutputStream write
public abstract void write(int b) throws IOException;
From source file:com.mbv.web.rest.controller.DeliveryController.java
@RequestMapping(value = "/printPickBatch", method = RequestMethod.GET) public void printPickBatch(HttpServletRequest request, HttpServletResponse response) throws MbvException { String degIdStr = request.getParameter("degIds"); String[] degIdStrs = degIdStr.split(","); String orderCodes = request.getParameter("orderCodes").replace(",", "?"); List<Long> degIds = new ArrayList<Long>(); for (String idStr : degIdStrs) { degIds.add(Long.parseLong(idStr)); }/*from w w w . java2 s.c o m*/ List<GoodBean> goodList = deliveryService.queryGoodListByIds(degIds); String jasperPath = request.getSession().getServletContext().getRealPath("/reports/pick.jrxml"); Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("SUBREPORT_DIR", jasperPath); List<DeliveryDataSource> list = new ArrayList<DeliveryDataSource>(); List<PickBean> goods = new ArrayList<PickBean>(); int i = 0; for (GoodBean goodBean : goodList) { i++; PickBean good = new PickBean(); good.setId(i); good.setCode(goodBean.getProdNum()); good.setName(goodBean.getBrandName() + " " + goodBean.getProductName() + " " + goodBean.getColorName() + " " + goodBean.getSizeName()); good.setNum(goodBean.getQty()); goods.add(good); } DeliveryDataSource deliverySource = new DeliveryDataSource(); deliverySource.setOrdercode(orderCodes); deliverySource.setTable_datas(new JRBeanCollectionDataSource(goods)); list.add(deliverySource); try { JRDataSource dataSource = new JRBeanCollectionDataSource(list); JasperReport jasperReport = JasperCompileManager.compileReport(jasperPath); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, dataSource); request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint); byte[] bytes = JasperExportManager.exportReportToPdf(jasperPrint); response.setContentType("application/pdf"); response.setContentLength(bytes.length); ServletOutputStream out = response.getOutputStream(); out.write(bytes); out.flush(); //end //?? deliveryService.updatePickPrintCount(degIds); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } catch (JRException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.fenixedu.academic.ui.struts.action.publico.candidacies.erasmus.ErasmusIndividualCandidacyProcessPublicDA.java
public ActionForward retrieveLearningAgreement(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { MobilityIndividualApplicationProcess process = (MobilityIndividualApplicationProcess) getProcess(request); final LearningAgreementDocument document = new LearningAgreementDocument(process); byte[] data = ReportsUtils.generateReport(document).getData(); response.setContentLength(data.length); response.setContentType("application/pdf"); response.addHeader("Content-Disposition", "attachment; filename=" + document.getReportFileName() + ".pdf"); final ServletOutputStream writer = response.getOutputStream(); writer.write(data); writer.flush();//ww w . jav a 2 s. c o m writer.close(); response.flushBuffer(); return mapping.findForward(""); }
From source file:com.mbv.web.rest.controller.DeliveryController.java
@RequestMapping(value = "/printDelivery", method = RequestMethod.GET) public String printDelivery(HttpServletRequest request, HttpServletResponse response) throws MbvException { Long degId = Long.parseLong(request.getParameter("degId")); DeliveryBean delivery = deliveryService.getDeliveryBeanById(degId); if (delivery != null) { String province = delivery.getProvince(); String city = delivery.getCity(); String district = delivery.getDistrict(); String address = delivery.getDelivAddress(); delivery.setDelivAddress(province + city + district + address); }/*from w w w .j a v a2s . co m*/ List<GoodBean> goodList = deliveryService.queryGoodByParams(degId); String jasperPath = request.getSession().getServletContext().getRealPath("/reports/delivery.jrxml"); try { List<PickBean> goods = new ArrayList<PickBean>(); int i = 0; for (GoodBean goodBean : goodList) { i++; PickBean good = new PickBean(); good.setId(i); good.setCode(goodBean.getProdNum()); good.setName(goodBean.getBrandName() + " " + goodBean.getProductName() + " " + goodBean.getColorName() + " " + goodBean.getSizeName()); good.setNum(goodBean.getQty()); good.setOnBrandPrc(goodBean.getOnBrandPrc()); good.setUnitPrice(goodBean.getUnitPrice()); String total = df.format(mul(goodBean.getQty(), goodBean.getUnitPrice(), 2)); good.setTotal(total); goods.add(good); } SysParameterEntity sysParam = sysParameterService.selectByPramCode("SYSTEM_PHONE"); String sysPhone = sysParam.getParaVal(); Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("SUBREPORT_DIR", jasperPath); List<PdfDetail> pdfDetail = new ArrayList<PdfDetail>(); PdfDetail detail = new PdfDetail(); detail.setDoc_code(delivery.getDocCode()); detail.setOrdernum(delivery.getOrderSn()); detail.setConsignee(delivery.getConsignee()); detail.setDeliv_address(delivery.getDelivAddress()); detail.setMobile(delivery.getMoblie()); detail.setTtl_qty(delivery.getTtlQty()); detail.setTtl_val(delivery.getTtlVal()); detail.setOrderRemark(delivery.getOrderRemark() == null ? "" : delivery.getOrderRemark()); detail.setSysPhone(sysPhone); detail.setTable_datas(new JRBeanCollectionDataSource(goods)); pdfDetail.add(detail); JasperReport jasperReport = JasperCompileManager.compileReport(jasperPath); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, new JRBeanCollectionDataSource(pdfDetail)); request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint); byte[] bytes = JasperExportManager.exportReportToPdf(jasperPrint); response.setContentType("application/pdf"); response.setContentLength(bytes.length); ServletOutputStream out = response.getOutputStream(); out.write(bytes); out.flush(); //end } catch (IOException ioe) { System.err.println(ioe.getMessage()); return null; } catch (JRException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } return null; }
From source file:com.mbv.web.rest.controller.DeliveryController.java
@RequestMapping(value = "/printDeliveryBacth", method = RequestMethod.GET) public void printDeliveryBacth(HttpServletRequest request, HttpServletResponse response) throws MbvException { String degIdStr = request.getParameter("degIds"); String[] degIds = degIdStr.split(","); List jasperPrintList = new ArrayList<JasperReport>(); SysParameterEntity sysParam = sysParameterService.selectByPramCode("SYSTEM_PHONE"); String sysPhone = sysParam.getParaVal(); try {//from w w w . j a v a 2 s .c o m for (String degStr : degIds) { Long degId = Long.parseLong(degStr); DeliveryBean delivery = deliveryService.getDeliveryBeanById(degId); if (delivery != null) { String province = delivery.getProvince(); String city = delivery.getCity(); String district = delivery.getDistrict(); String address = delivery.getDelivAddress(); delivery.setDelivAddress(province + city + district + address); } List<GoodBean> goodList = deliveryService.queryGoodByParams(degId); String jasperPath = request.getSession().getServletContext().getRealPath("/reports/delivery.jrxml"); List<PickBean> goods = new ArrayList<PickBean>(); int i = 0; for (GoodBean goodBean : goodList) { i++; PickBean good = new PickBean(); good.setId(i); good.setCode(goodBean.getProdNum()); good.setName(goodBean.getBrandName() + " " + goodBean.getProductName() + " " + goodBean.getColorName() + " " + goodBean.getSizeName()); good.setNum(goodBean.getQty()); good.setOnBrandPrc(goodBean.getOnBrandPrc()); good.setUnitPrice(goodBean.getUnitPrice()); String total = df.format(mul(goodBean.getQty(), goodBean.getUnitPrice(), 2)); good.setTotal(total); goods.add(good); } Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("SUBREPORT_DIR", jasperPath); List<PdfDetail> pdfDetail = new ArrayList<PdfDetail>(); PdfDetail detail = new PdfDetail(); detail.setDoc_code(delivery.getDocCode()); detail.setOrdernum(delivery.getOrderSn()); detail.setConsignee(delivery.getConsignee()); detail.setDeliv_address(delivery.getDelivAddress()); detail.setMobile(delivery.getMoblie()); detail.setTtl_qty(delivery.getTtlQty()); detail.setTtl_val(delivery.getTtlVal()); detail.setOrderRemark(delivery.getOrderRemark() == null ? "" : delivery.getOrderRemark()); detail.setSysPhone(sysPhone); detail.setTable_datas(new JRBeanCollectionDataSource(goods)); pdfDetail.add(detail); JasperReport jasperReport = JasperCompileManager.compileReport(jasperPath); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, new JRBeanCollectionDataSource(pdfDetail)); request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint); jasperPrintList.add(jasperPrint); } //byte[] bytes = JasperExportManager.exportReportToPdf(jasperPrint); //?? ByteArrayOutputStream baos = new ByteArrayOutputStream(); JRPdfExporter exporter = new JRPdfExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, jasperPrintList); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos); exporter.exportReport(); byte[] bytes = baos.toByteArray(); response.setContentType("application/pdf"); response.setContentLength(bytes.length); ServletOutputStream out = response.getOutputStream(); out.write(bytes); out.flush(); //end } catch (IOException ioe) { System.err.println(ioe.getMessage()); } catch (JRException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.mbv.web.rest.controller.DeliveryController.java
@RequestMapping(value = "/printExpress", method = RequestMethod.GET) public void printExpress(HttpServletRequest request, HttpServletResponse response) throws MbvException { Long degId = Long.parseLong(request.getParameter("degId")); int printCount = Integer.parseInt(request.getParameter("printCount")); String tspComCode = (String) request.getParameter("tspComCode"); DeliveryBean delivery = deliveryService.getDeliveryBeanById(degId); HttpSession session = request.getSession(); String warehCode = (String) session.getAttribute(MbvConstant.WAREH_CODE); VpSenderEntity sendAddress = deliveryService.getSendAddressByWarehCode(warehCode); if (sendAddress != null) { if (!"sto".equals(tspComCode) && !"yto".equals(tspComCode)) { String province = sendAddress.getProvince(); String city = sendAddress.getCity(); String district = sendAddress.getDistrict(); String address = sendAddress.getAddress(); sendAddress.setAddress(province + " " + city + " " + district + " " + address); }/* ww w.j a v a2 s . co m*/ } List jasperPrintList = new ArrayList<JasperReport>(); if (!"sto".equals(tspComCode) && !"yto".equals(tspComCode)) { String province = delivery.getProvince(); String city = delivery.getCity(); String district = delivery.getDistrict(); String address = delivery.getDelivAddress(); delivery.setDelivAddress(province + " " + city + " " + district + " " + address); } try { for (int i = 0; i < printCount; i++) { String templateName = tspComCode + "_express.jrxml"; String imageName = tspComCode + ".jpg"; String jasperPath = request.getSession().getServletContext() .getRealPath("/reports/" + templateName); String imageurl = request.getSession().getServletContext().getRealPath("/images/" + imageName); List tmpList = new ArrayList(); Map<String, Object> pram = new HashMap<String, Object>(); pram.put("name", delivery.getConsignee() == null ? "" : delivery.getConsignee()); pram.put("phone", delivery.getMoblie() == null ? "" : delivery.getMoblie()); pram.put("code", delivery.getDelivPstd() == null ? "" : delivery.getDelivPstd()); pram.put("province", delivery.getProvince() == null ? "" : delivery.getProvince()); pram.put("city", delivery.getCity() == null ? "" : delivery.getCity()); pram.put("district", delivery.getDistrict() == null ? "" : delivery.getDistrict()); pram.put("company", ""); pram.put("address", delivery.getDelivAddress() == null ? "" : delivery.getDelivAddress()); pram.put("sendName", sendAddress == null ? "" : sendAddress.getConsignor()); pram.put("sendPhone", sendAddress == null ? "" : sendAddress.getMobile()); pram.put("sendCode", sendAddress == null ? "" : sendAddress.getZip()); pram.put("sendAddress", sendAddress == null ? "" : sendAddress.getAddress()); pram.put("sendProvince", sendAddress == null ? "" : sendAddress.getProvince()); pram.put("sendCity", sendAddress == null ? "" : sendAddress.getCity()); pram.put("sendDistrict", sendAddress == null ? "" : sendAddress.getDistrict()); pram.put("sendCompany", ""); pram.put("docCode", delivery.getDocCode() == null ? "" : delivery.getDocCode()); pram.put("imageurl", imageurl); tmpList.add(pram); JasperReport jasperReport = JasperCompileManager.compileReport(jasperPath); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, pram, new JRBeanCollectionDataSource(tmpList)); request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint); jasperPrintList.add(jasperPrint); } //byte[] bytes = JasperExportManager.exportReportToPdf(jasperPrint); //?? ByteArrayOutputStream baos = new ByteArrayOutputStream(); JRPdfExporter exporter = new JRPdfExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, jasperPrintList); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos); exporter.exportReport(); byte[] bytes = baos.toByteArray(); response.setContentType("application/pdf"); response.setContentLength(bytes.length); ServletOutputStream out = response.getOutputStream(); out.write(bytes); out.flush(); //end } catch (IOException ioe) { System.err.println(ioe.getMessage()); } catch (JRException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.mbv.web.rest.controller.DeliveryController.java
@RequestMapping(value = "/printExpressBatch", method = RequestMethod.GET) public void printExpressBatch(HttpServletRequest request, HttpServletResponse response) throws MbvException { HttpSession session = request.getSession(); String warehCode = (String) session.getAttribute(MbvConstant.WAREH_CODE); VpSenderEntity sendAddress = deliveryService.getSendAddressByWarehCode(warehCode); String tspComCode = (String) request.getParameter("tspComCode"); if (sendAddress != null) { if (!"sto".equals(tspComCode) && !"yto".equals(tspComCode)) { String province = sendAddress.getProvince(); String city = sendAddress.getCity(); String district = sendAddress.getDistrict(); String address = sendAddress.getAddress(); sendAddress.setAddress(province + " " + city + " " + district + " " + address); }/* ww w.ja va 2s .c o m*/ } String degIdStr = request.getParameter("degIds"); String[] degIds = degIdStr.split(","); List jasperPrintList = new ArrayList<JasperReport>(); try { for (String degStr : degIds) { Long degId = Long.parseLong(degStr); DeliveryBean delivery = deliveryService.getDeliveryBeanById(degId); if (!"sto".equals(tspComCode) && !"yto".equals(tspComCode)) { String province = delivery.getProvince(); String city = delivery.getCity(); String district = delivery.getDistrict(); String address = delivery.getDelivAddress(); delivery.setDelivAddress(province + " " + city + " " + district + " " + address); } String templateName = tspComCode + "_express.jrxml"; String imageName = tspComCode + ".jpg"; String jasperPath = request.getSession().getServletContext() .getRealPath("/reports/" + templateName); String imageurl = request.getSession().getServletContext().getRealPath("/images/" + imageName); List tmpList = new ArrayList(); Map<String, Object> pram = new HashMap<String, Object>(); pram.put("name", delivery.getConsignee() == null ? "" : delivery.getConsignee()); pram.put("phone", delivery.getMoblie() == null ? "" : delivery.getMoblie()); pram.put("code", delivery.getDelivPstd() == null ? "" : delivery.getDelivPstd()); pram.put("province", delivery.getProvince() == null ? "" : delivery.getProvince()); pram.put("city", delivery.getCity() == null ? "" : delivery.getCity()); pram.put("district", delivery.getDistrict() == null ? "" : delivery.getDistrict()); pram.put("company", ""); pram.put("address", delivery.getDelivAddress() == null ? "" : delivery.getDelivAddress()); pram.put("sendName", sendAddress == null ? "" : sendAddress.getConsignor()); pram.put("sendPhone", sendAddress == null ? "" : sendAddress.getMobile()); pram.put("sendCode", sendAddress == null ? "" : sendAddress.getZip()); pram.put("sendAddress", sendAddress == null ? "" : sendAddress.getAddress()); pram.put("sendProvince", sendAddress == null ? "" : sendAddress.getProvince()); pram.put("sendCity", sendAddress == null ? "" : sendAddress.getCity()); pram.put("sendDistrict", sendAddress == null ? "" : sendAddress.getDistrict()); pram.put("sendCompany", ""); pram.put("docCode", delivery.getDocCode() == null ? "" : delivery.getDocCode()); pram.put("imageurl", imageurl); tmpList.add(pram); JasperReport jasperReport = JasperCompileManager.compileReport(jasperPath); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, pram, new JRBeanCollectionDataSource(tmpList)); request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint); jasperPrintList.add(jasperPrint); } //byte[] bytes = JasperExportManager.exportReportToPdf(jasperPrint); //?? ByteArrayOutputStream baos = new ByteArrayOutputStream(); JRPdfExporter exporter = new JRPdfExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, jasperPrintList); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos); exporter.exportReport(); byte[] bytes = baos.toByteArray(); response.setContentType("application/pdf"); response.setContentLength(bytes.length); ServletOutputStream out = response.getOutputStream(); out.write(bytes); out.flush(); //end } catch (IOException ioe) { System.err.println(ioe.getMessage()); } catch (JRException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.wso2.carbon.webapp.list.ui.WebappAdminClient.java
public void downloadWarFileHandler(String fileName, String hostName, String webappType, HttpServletResponse response) throws AxisFault { try {/*from w ww . j a v a 2 s . c o m*/ ServletOutputStream out = response.getOutputStream(); DataHandler handler = stub.downloadWarFileHandler(fileName, hostName, webappType); if (handler != null) { if ("jaggeryWebapp".equals(webappType)) { if (!fileName.endsWith(".zip")) { fileName = fileName.concat(".zip"); } } else if (!fileName.endsWith(".war")) { fileName = fileName.concat(".war"); } response.setHeader("Content-Disposition", "fileName=" + fileName); response.setContentType(handler.getContentType()); InputStream in = handler.getDataSource().getInputStream(); int nextChar; while ((nextChar = in.read()) != -1) { out.write((char) nextChar); } out.flush(); in.close(); } else { out.write("The requested webapp was not found on the server".getBytes()); } } catch (RemoteException e) { handleException("error.downloading.war", e); } catch (IOException e) { handleException("error.downloading.war", e); } }
From source file:com.globalsight.everest.webapp.pagehandler.tasks.UpdateLeverageHandler.java
@ActionHandler(action = "getPercentage", formClass = "") public void getPercentage(HttpServletRequest p_request, HttpServletResponse p_response, Object form) throws Exception { String jobId = p_request.getParameter("jobId"); int percentage = percentageMap.get(Long.parseLong(jobId)); String fakeParam = p_request.getParameter("fresh"); if (logger.isDebugEnabled()) { logger.debug(//from w ww .j av a 2s. c om "FakeParam is " + fakeParam + "; Current jobId is " + jobId + "; Percentage is " + percentage); } ServletOutputStream out = p_response.getOutputStream(); try { p_response.setContentType("text/plain"); out = p_response.getOutputStream(); StringBuffer sb = new StringBuffer(); sb.append("{\"updateLeveragePercentage\":"); sb.append(percentage).append("}"); out.write(sb.toString().getBytes("UTF-8")); } catch (Exception e) { logger.error(e.getMessage(), e); } finally { out.close(); pageReturn(); } }
From source file:org.apache.lucene.replicator.http.ReplicationService.java
/** Executes the replication task. */ public void perform(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String[] pathElements = getPathElements(req); if (pathElements.length != 2) { throw new ServletException("invalid path, must contain shard ID and action, e.g. */s1/update"); }// ww w. j av a 2s . c o m final ReplicationAction action; try { action = ReplicationAction.valueOf(pathElements[ACTION_IDX].toUpperCase(Locale.ENGLISH)); } catch (IllegalArgumentException e) { throw new ServletException("Unsupported action provided: " + pathElements[ACTION_IDX]); } final Replicator replicator = replicators.get(pathElements[SHARD_IDX]); if (replicator == null) { throw new ServletException("unrecognized shard ID " + pathElements[SHARD_IDX]); } // SOLR-8933 Don't close this stream. ServletOutputStream resOut = resp.getOutputStream(); try { switch (action) { case OBTAIN: final String sessionID = extractRequestParam(req, REPLICATE_SESSION_ID_PARAM); final String fileName = extractRequestParam(req, REPLICATE_FILENAME_PARAM); final String source = extractRequestParam(req, REPLICATE_SOURCE_PARAM); InputStream in = replicator.obtainFile(sessionID, source, fileName); try { copy(in, resOut); } finally { in.close(); } break; case RELEASE: replicator.release(extractRequestParam(req, REPLICATE_SESSION_ID_PARAM)); break; case UPDATE: String currVersion = req.getParameter(REPLICATE_VERSION_PARAM); SessionToken token = replicator.checkForUpdate(currVersion); if (token == null) { resOut.write(0); // marker for null token } else { resOut.write(1); token.serialize(new DataOutputStream(resOut)); } break; } } catch (Exception e) { resp.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR); // propagate the failure try { /* * Note: it is assumed that "identified exceptions" are thrown before * anything was written to the stream. */ ObjectOutputStream oos = new ObjectOutputStream(resOut); oos.writeObject(e); oos.flush(); } catch (Exception e2) { throw new IOException("Could not serialize", e2); } } finally { resp.flushBuffer(); } }
From source file:com.jd.survey.web.settings.SurveyDefinitionController.java
/** * Returns the survey logo image binary * @param departmentId//from w w w. jav a 2 s. c o m * @param uiModel * @param httpServletRequest * @return */ @Secured({ "ROLE_ADMIN", "ROLE_SURVEY_ADMIN" }) @RequestMapping(value = "/logo/{id}", produces = "text/html") public void getSurveyLogo(@PathVariable("id") Long surveyDefinitionId, Model uiModel, Principal principal, HttpServletRequest httpServletRequest, HttpServletResponse response) { try { uiModel.asMap().clear(); User user = userService.user_findByLogin(principal.getName()); //Check if the user is authorized if (!securityService.userIsAuthorizedToManageSurvey(surveyDefinitionId, user)) { log.warn("Unauthorized access to url path " + httpServletRequest.getPathInfo() + " attempted by user login:" + principal.getName() + "from IP:" + httpServletRequest.getLocalAddr()); throw (new RuntimeException("Unauthorized access to logo")); } SurveyDefinition surveyDefinition = surveySettingsService.surveyDefinition_findById(surveyDefinitionId); //response.setContentType("image/png"); ServletOutputStream servletOutputStream = response.getOutputStream(); servletOutputStream.write(surveyDefinition.getLogo()); servletOutputStream.flush(); } catch (Exception e) { log.error(e.getMessage(), e); throw (new RuntimeException(e)); } }