List of usage examples for javax.servlet ServletOutputStream flush
public void flush() throws IOException
From source file:it.openprj.jValidator.spring.SchemaFieldsPopupUpdateController.java
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String idSchema = request.getParameter("idSchema"); String idSchemaField = request.getParameter("idSchemaField"); String idFieldType = request.getParameter("idFieldType"); String name = request.getParameter("name"); String description = request.getParameter("description"); String minLenght = request.getParameter("minLenght"); String maxLenght = request.getParameter("maxLenght"); String nillableAlphanumeric = request.getParameter("nillableAlphanumeric"); String idCheckType = request.getParameter("extraCheck"); String minInclusive = request.getParameter("minInclusive"); String maxInclusive = request.getParameter("maxInclusive"); String fractionDigits = request.getParameter("fractionDigits"); String nillableNumeric = request.getParameter("nillableNumeric"); String numericType = request.getParameter("numericType"); String idDateTimeType = request.getParameter("idDateTimeType"); String idDateType = request.getParameter("idDateType"); String idTimeType = request.getParameter("idTimeType"); String isForecastable = request.getParameter("isForecastable"); String forecastAccuracy = request.getParameter("forecastAccuracy"); String forecastSpeed = request.getParameter("forecastSpeed"); String nillableDate = request.getParameter("nillableDate"); String size = request.getParameter("size"); String idCustomError = request.getParameter("idCustomError"); String maxOccurs = request.getParameter("maxOccurs"); String linkToDb = request.getParameter("linkToDb"); String isAttribute = request.getParameter("isAttribute"); String errorType = request.getParameter("errorType"); String selectedExtraCheckVals = request.getParameter("selectedExtraCheck"); int errorToleranceValue = Integer.parseInt(request.getParameter("errorToleranceValue") == null ? "-1" : request.getParameter("errorToleranceValue")); SchemaEntity schemaEntity = schemasDao.find(Long.parseLong(idSchema)); SchemaFieldEntity schemaFieldEntity = schemaFieldsDao.find(Long.parseLong(idSchemaField)); schemasXSDDao.destroy(schemaFieldEntity.getIdSchema()); String oldLinkToDb = schemaFieldEntity.getLinkToDb(); schemaFieldEntity.setIdFieldType(Integer.parseInt(idFieldType)); schemaFieldEntity.setName(name);//from w w w. ja v a2s .co m schemaFieldEntity.setDescription(description.replace('\u200b', ' ')); schemaFieldEntity.setErrorToleranceValue(errorToleranceValue); if (errorType != null) schemaFieldEntity.setErrorType(Integer.parseInt(request.getParameter("errorType"))); if ("1".equals(isAttribute) || "true".equals(isAttribute)) { schemaFieldEntity.setIs_Attribute(true); } else { schemaFieldEntity.setIs_Attribute(false); } if (maxOccurs != null && !maxOccurs.equals("")) { schemaFieldEntity.setMaxOccurs(Integer.parseInt(maxOccurs)); } else { schemaFieldEntity.setMaxOccurs(1); } boolean isLinkedToDbChanged = false; if (linkToDb != null && !linkToDb.isEmpty()) { schemaFieldEntity.setLinkToDb(linkToDb); isLinkedToDbChanged = true; } if (idCustomError != null && !idCustomError.isEmpty() && Long.parseLong(idCustomError) != -7) { schemaFieldEntity.setIdCustomError(Long.parseLong(idCustomError)); } if (schemaFieldEntity.getIdFieldType() == FieldType.alphanumeric) { if (minLenght != null && !minLenght.equals("")) { schemaFieldEntity.setMinLength(Integer.parseInt(minLenght)); } else { schemaFieldEntity.setMinLength(null); } if (maxLenght != null && !maxLenght.equals("")) { schemaFieldEntity.setMaxLength(Integer.parseInt(maxLenght)); } else { schemaFieldEntity.setMaxLength(null); } if (idCheckType != null && !idCheckType.equals("")) { schemaFieldEntity.setIdCheckType(Integer.parseInt(idCheckType)); } else { schemaFieldEntity.setIdCheckType(0); } if (StringUtils.isNotEmpty(selectedExtraCheckVals)) { // Delete existing entries from database schemaFieldsDao.destroySchemFieldCheckTypes(Long.parseLong(idSchemaField)); String[] extraCheckIds = selectedExtraCheckVals.split(","); Set<SchemaFieldCheckTypesEntity> schemaFieldCheckTypeSet = new HashSet<SchemaFieldCheckTypesEntity>( extraCheckIds.length); SchemaFieldCheckTypesEntity schemaFieldCheckTypesEntity; for (String extraCheck : extraCheckIds) { schemaFieldCheckTypesEntity = new SchemaFieldCheckTypesEntity(); schemaFieldCheckTypesEntity.setIdCheckType(Long.parseLong(extraCheck)); schemaFieldCheckTypesEntity.setSchemaFieldEntity(schemaFieldEntity); schemaFieldCheckTypeSet.add(schemaFieldCheckTypesEntity); schemaFieldCheckTypesEntity = null; } schemaFieldEntity.setSchemaFieldCheckTypeSet(schemaFieldCheckTypeSet); } else { List<String> list = schemaFieldsDao.findSchemaFieldCheckTypes(Long.parseLong(idSchemaField)); if (list.size() > 0) { // Delete existing entries from database schemaFieldsDao.destroySchemFieldCheckTypes(Long.parseLong(idSchemaField)); Set<SchemaFieldCheckTypesEntity> schemaFieldCheckTypeSet = new HashSet<SchemaFieldCheckTypesEntity>(); schemaFieldEntity.setSchemaFieldCheckTypeSet(schemaFieldCheckTypeSet); } } if (schemaEntity.getIdStreamType() == StreamType.flatFileFixedPosition) { String idAlignAlphanumeric = request.getParameter("idAlignAlphanumeric"); String fillCharAlphanumeric = request.getParameter("fillCharAlphanumeric"); schemaFieldEntity.setNillable(false); schemaFieldEntity.setSize(size); if (idAlignAlphanumeric != null && !idAlignAlphanumeric.equals("")) { schemaFieldEntity.setIdAlign(Integer.parseInt(idAlignAlphanumeric)); } else { schemaFieldEntity.setIdAlign(null); } if (fillCharAlphanumeric != null && !fillCharAlphanumeric.equals("")) { schemaFieldEntity.setFillChar(fillCharAlphanumeric); } else { schemaFieldEntity.setFillChar(null); } } else { if (nillableAlphanumeric != null && (nillableAlphanumeric.equals("1") || nillableAlphanumeric.equals("true"))) { schemaFieldEntity.setNillable(true); } else { schemaFieldEntity.setNillable(false); } } } if (schemaFieldEntity.getIdFieldType() == FieldType.numeric) { if (!minInclusive.equals("")) { schemaFieldEntity.setMinInclusive(Double.parseDouble(minInclusive)); } else { schemaFieldEntity.setMinInclusive(null); } if (!maxInclusive.equals("")) { schemaFieldEntity.setMaxInclusive(Double.parseDouble(maxInclusive)); } else { schemaFieldEntity.setMaxInclusive(null); } if (!fractionDigits.equals("")) { schemaFieldEntity.setFractionDigits(Integer.parseInt(fractionDigits)); } else { schemaFieldEntity.setFractionDigits(null); } if (numericType.equals("1")) { schemaFieldEntity.setIdNumericType(1); } else { schemaFieldEntity.setIdNumericType(2); } schemaFieldEntity.setIsForecastable(Boolean.parseBoolean(isForecastable)); schemaFieldEntity.setForecastSpeed(Integer.parseInt(forecastSpeed)); schemaFieldEntity.setForecastAccuracy(Integer.parseInt(forecastAccuracy)); if (schemaEntity.getIdStreamType() == StreamType.flatFileFixedPosition) { String idAlignNumeric = request.getParameter("idAlignNumeric"); String fillCharNumeric = request.getParameter("fillCharNumeric"); schemaFieldEntity.setNillable(false); schemaFieldEntity.setSize(size); if (!idAlignNumeric.equals("")) { schemaFieldEntity.setIdAlign(Integer.parseInt(idAlignNumeric)); } else { schemaFieldEntity.setIdAlign(null); } if (!fillCharNumeric.equals("")) { schemaFieldEntity.setFillChar(fillCharNumeric); } else { schemaFieldEntity.setFillChar(null); } } else { if (nillableNumeric.equals("1") || nillableNumeric.equals("true")) { schemaFieldEntity.setNillable(true); } else { schemaFieldEntity.setNillable(false); } } } if (schemaFieldEntity.getIdFieldType() == FieldType.date) { int maxLength = 0; schemaFieldEntity.setIdDateFmtType(Integer.parseInt(idDateTimeType)); if (!idDateType.equals("")) { schemaFieldEntity.setIdDateType(Integer.parseInt(idDateType)); switch (Integer.parseInt(idDateType)) { case DateTimeType.DDMMYY: maxLength = 6; break; case DateTimeType.slashDDMMYY: case DateTimeType.signDDMMYY: case DateTimeType.dotDDMMYY: case DateTimeType.DDMMYYYY: case DateTimeType.YYYYMMDD: maxLength = 8; break; case DateTimeType.slashDDMMYYYY: case DateTimeType.signDDMMYYYY: case DateTimeType.dotDDMMYYYY: case DateTimeType.slashYYYYMMDD: case DateTimeType.signYYYYMMDD: case DateTimeType.dotYYYYMMDD: maxLength = 10; break; } } else { schemaFieldEntity.setIdDateType(null); } if (!idTimeType.equals("")) { schemaFieldEntity.setIdTimeType(Integer.parseInt(idTimeType)); if (maxLength > 0) { maxLength = maxLength + 1; } switch (Integer.parseInt(idTimeType)) { case DateTimeType.dblpnthhmm: case DateTimeType.dothhmm: maxLength = maxLength + 5; break; case DateTimeType.dblpnthhmmss: case DateTimeType.dothhmmss: maxLength = maxLength + 8; break; case DateTimeType.dblpntZhhmmss: case DateTimeType.dotZhhmmss: maxLength = maxLength + 11; break; case DateTimeType.dblpnthmmss: case DateTimeType.dothmmss: maxLength = maxLength + 7; break; } } else { schemaFieldEntity.setIdTimeType(null); } schemaFieldEntity.setMaxLength(maxLength); if (schemaEntity.getIdStreamType() == StreamType.flatFileFixedPosition) { schemaFieldEntity.setNillable(false); schemaFieldEntity.setSize(maxLength + ""); } else { if (nillableDate.equals("1") || nillableDate.equals("true")) { schemaFieldEntity.setNillable(true); } else { schemaFieldEntity.setNillable(false); } } int dateTimeType = schemaFieldEntity.getIdDateTimeType(); if ((dateTimeType == DateTimeType.xsdDateTime || dateTimeType == DateTimeType.xsdDate || dateTimeType == DateTimeType.xsdTime || dateTimeType == DateTimeType.unixTimestamp) && schemaEntity.getIdStreamType() == StreamType.flatFileFixedPosition) { String idAlignDateTime = request.getParameter("idAlignDateTime"); String fillCharDateTime = request.getParameter("fillCharDateTime"); schemaFieldEntity.setSize(size); if (!idAlignDateTime.equals("")) { schemaFieldEntity.setIdAlign(Integer.parseInt(idAlignDateTime)); } else { schemaFieldEntity.setIdAlign(null); } if (!fillCharDateTime.equals("")) { schemaFieldEntity.setFillChar(fillCharDateTime); } else { schemaFieldEntity.setFillChar(null); } } else { schemaFieldEntity.setIdAlign(null); schemaFieldEntity.setFillChar(null); } } Update update = schemaFieldsDao.update(schemaFieldEntity); if (update.isSuccess()) { schemaEntity.setIsActive(0); schemasDao.update(schemaEntity); } if (linkToDb != null && linkToDb.trim().length() > 0 && linkToDb.indexOf(".") == -1) { if (oldLinkToDb == null || oldLinkToDb.trim().length() == 0) { addLinkedTableFields(schemaFieldEntity, linkToDb); } else if (!linkToDb.equals(oldLinkToDb)) { deleteLinkedTableFields(schemaFieldEntity, oldLinkToDb); addLinkedTableFields(schemaFieldEntity, linkToDb); } } if (isLinkedToDbChanged) { update.setExtraMessage("isLinkedToDbChanged"); } ObjectMapper mapper = new ObjectMapper(); response.setContentType("application/json"); ServletOutputStream out = response.getOutputStream(); out.write(mapper.writeValueAsBytes(update)); out.flush(); out.close(); return null; }
From source file:it.openprj.jValidator.spring.EventTriggerValidator.java
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String code = request.getParameter("code"); String name = request.getParameter("name"); String addReq = request.getParameter("addReq"); String result = null;/* w ww . java 2 s. c o m*/ ObjectMapper mapper = new ObjectMapper(); ServletOutputStream out = null; response.setContentType("application/json"); out = response.getOutputStream(); if (StringUtils.isEmpty(code) || StringUtils.isEmpty(name)) { result = I18n.getMessage("error.trigger.invaliddata");//"Failed. Reason:Invalid Data"; } else { name = name.trim(); if (addReq.equalsIgnoreCase("true")) { ReadList list = eventTriggerDao.findTriggersByName(name); if (list != null && CollectionUtils.isNotEmpty(list.getResults())) { result = I18n.getMessage("error.trigger.name.alreadyexist");//"Failed. Reason:Name alredy exist"; out.write(mapper.writeValueAsBytes(result)); out.flush(); out.close(); return null; } } try { File sourceDir = new File(System.getProperty("java.io.tmpdir"), "jValidator/src"); sourceDir.mkdirs(); String classNamePack = name.replace('.', File.separatorChar); String srcFilePath = sourceDir + "" + File.separatorChar + classNamePack + ".java"; File sourceFile = new File(srcFilePath); if (sourceFile.exists()) { sourceFile.delete(); } FileUtils.writeStringToFile(new File(srcFilePath), code); DynamicClassLoader dynacode = DynamicClassLoader.getInstance(); dynacode.addSourceDir(sourceDir); EventTrigger eventTrigger = (EventTrigger) dynacode.newProxyInstance(EventTrigger.class, name); boolean isValid = false; if (eventTrigger != null) { Class clazz = dynacode.getLoadedClass(name); if (clazz != null) { Class[] interfaces = clazz.getInterfaces(); if (ArrayUtils.isNotEmpty(interfaces)) { for (Class clz : interfaces) { if (clz.getName() .equalsIgnoreCase("it.openprj.jValidator.eventtrigger.EventTrigger")) { isValid = true; } } } else if (clazz.getSuperclass() != null && clazz.getSuperclass().getName() .equalsIgnoreCase("it.openprj.jValidator.eventtrigger.EventTriggerImpl")) { isValid = true; } } } if (isValid) { result = "Success"; } else { result = I18n.getMessage("error.trigger.wrongimpl");//"Failed. Reason: Custom code should implement it.openprj.jValidator.eventtrigger.EventTrigger Interface"; } } catch (Exception e) { result = "Failed. Reason:" + e.getMessage(); } } out.write(mapper.writeValueAsBytes(result)); out.flush(); out.close(); return null; }
From source file:gov.nih.nci.calims2.ui.report.filledreport.FilledReportController.java
/** * //from www.j ava 2 s . c o m * @param response The servlet response. * @param id The id of the filledreport to view. * @param formatName The format of the pdf file. */ @RequestMapping("/exportReport.do") public void exportReport(HttpServletResponse response, @RequestParam("id") Long id, @RequestParam("format") String formatName) { FilledReport filledReport = getMainService().findById(FilledReport.class, id); Report report = filledReport.getReport(); FilledReportFormat format = FilledReportFormat.valueOf(formatName); try { ServletOutputStream servletOutputStream = response.getOutputStream(); File exportedFile = ((FilledReportService) getMainService()).exportJasperReport(id, tempfiledir, format); response.setContentType(format.getContentType()); DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyyMMdd-HHmmss"); String filename = report.getName() + fmt.print(filledReport.getExecutionTime()) + format.getExtention(); response.setHeader("Content-Disposition", "attachment;filename=" + filename); FileInputStream fileInputStream = new FileInputStream(exportedFile); IOUtils.copyLarge(fileInputStream, servletOutputStream); IOUtils.closeQuietly(fileInputStream); servletOutputStream.flush(); servletOutputStream.close(); exportedFile.delete(); } catch (IOException e1) { throw new RuntimeException("IOException in exportReport", e1); } catch (ReportingException e) { throw new RuntimeException("ReportingException in exportReport", e); } }
From source file:jp.co.opentone.bsol.framework.web.view.util.ViewHelper.java
protected void doWrite(HttpServletResponse response, byte[] content) throws IOException { ServletOutputStream o = response.getOutputStream(); o.write(content);// ww w . j a v a 2 s. co m o.flush(); o.close(); }
From source file:org.fenixedu.parking.ui.Action.ParkingManagerDispatchAction.java
public ActionForward exportToPDFParkingCard(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception { String parkingPartyID = request.getParameter("parkingPartyID"); final ParkingParty parkingParty = FenixFramework.getDomainObject(parkingPartyID); String parkingGroupID = request.getParameter("groupID"); if (parkingGroupID != null) { String parkingRequestID = request.getParameter("code"); if (request.getParameter("groupID") == null) { saveErrorMessage(request, "group", "error.invalidGroup"); request.setAttribute("externalId", parkingRequestID); return showRequest(mapping, actionForm, request, response); }/*from w w w . j av a 2 s. c o m*/ if (!isValidGroup(parkingGroupID)) { saveErrorMessage(request, "group", "error.invalidGroup"); request.setAttribute("externalId", parkingRequestID); return showRequest(mapping, actionForm, request, response); } } ParkingGroup parkingGroup = null; if (parkingGroupID != null) { parkingGroup = FenixFramework.getDomainObject(parkingGroupID); } else { parkingGroup = parkingParty.getParkingGroup(); } Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("imageUrl", "images/Logo_IST_color.tiff"); Person person = (Person) parkingParty.getParty(); parameters.put("number", getMostSignificantNumberString(person, parkingGroup)); List<Person> persons = new ArrayList<Person>(); persons.add(person); ReportResult report = ReportsUtils.generateReport("parkingManager.parkingCard", parameters, persons); byte[] data = report.getData(); response.setContentType(report.getContentType()); response.addHeader("Content-Disposition", "attachment; filename=cartao." + report.getFileExtension()); response.setContentLength(data.length); ServletOutputStream writer = response.getOutputStream(); writer.write(data); writer.flush(); writer.close(); response.flushBuffer(); return mapping.findForward(""); }
From source file:org.fenixedu.parking.ui.Action.ParkingManagerDispatchAction.java
public ActionForward exportToExcel(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws IOException { ParkingRequestSearch parkingRequestSearch = new ParkingRequestSearch(); setSearchCriteria(request, parkingRequestSearch); parkingRequestSearch.doSearch();//from w w w . jav a2s. com List<ParkingRequest> parkingRequestList = parkingRequestSearch.getSearchResult(); StyledExcelSpreadsheet spreadsheet = new StyledExcelSpreadsheet("Pedidos_Parque", 15); spreadsheet.newHeaderRow(); spreadsheet.addHeader("Categoria"); spreadsheet.addHeader("Nmero"); spreadsheet.addHeader("Nome", 9000); spreadsheet.addHeader("Estado"); spreadsheet.addHeader("Data Pedido"); spreadsheet.addHeader("Outras Informaes", 6000); final ResourceBundle enumerationBundle = ResourceBundle.getBundle("resources.EnumerationResources", I18N.getLocale()); for (ParkingRequest parkingRequest : parkingRequestList) { if (parkingRequest.getParkingParty().getParty().isPerson()) { Person person = (Person) parkingRequest.getParkingParty().getParty(); spreadsheet.newRow(); int firstRow = spreadsheet.getRow().getRowNum(); spreadsheet .addCell(enumerationBundle.getString(parkingRequestSearch.getPartyClassification().name())); spreadsheet.addCell(parkingRequest.getParkingParty().getMostSignificantNumber()); spreadsheet.addCell(person.getName()); spreadsheet.addCell(enumerationBundle.getString(parkingRequest.getParkingRequestState().name())); spreadsheet.addDateTimeCell(parkingRequest.getCreationDate()); if (!parkingRequest.getParkingParty().getDegreesInformation().isEmpty()) { Iterator<String> iterator = parkingRequest.getParkingParty().getDegreesInformation().iterator(); String degreeInfo = iterator.next(); spreadsheet.addCell(degreeInfo); while (iterator.hasNext()) { spreadsheet.newRow(); degreeInfo = iterator.next(); spreadsheet.addCell(degreeInfo, 5); } int lastRow = firstRow + parkingRequest.getParkingParty().getDegreesInformation().size() - 1; if (firstRow != lastRow) { for (int iter = 0; iter < 5; iter++) { spreadsheet.getSheet() .addMergedRegion(new Region(firstRow, (short) iter, lastRow, (short) iter)); } } } } } response.setContentType("application/vnd.ms-excel"); response.setHeader("Content-Disposition", "attachment; filename=pedidos_parque.xls"); final ServletOutputStream writer = response.getOutputStream(); spreadsheet.getWorkbook().write(writer); writer.flush(); response.flushBuffer(); return null; }
From source file:com.viewer.controller.ViewerController.java
@RequestMapping(value = "/GetFile") @ResponseBody/* w w w.j a v a 2s.co m*/ private void GetFile(@RequestParam String path, Boolean getPdf, Boolean useHtmlBasedEngine, Boolean supportPageRotation, HttpServletResponse response) throws Exception { File file = new File(path); String displayName = path; String nameWithoutExtension = removeExtention(path); Stream fileStream; File newFile = new File(nameWithoutExtension + ".pdf"); displayName = newFile.getPath(); PdfFileOptions options = new PdfFileOptions(); options.setGuid(path); FileContainer pdfFileResponse = _htmlHandler.getPdfFile(options); response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", "attachment; filename=\"" + displayName + "\""); InputStream fileIn = pdfFileResponse.getStream(); ServletOutputStream out = response.getOutputStream(); byte[] outputByte = new byte[4096]; while (fileIn.read(outputByte, 0, 4096) != -1) { out.write(outputByte, 0, 4096); } fileIn.close(); out.flush(); out.close(); }
From source file:bd.gov.forms.web.FormBuilder.java
@RequestMapping(value = "/excelExport", method = RequestMethod.GET) public String excelExport(@RequestParam(value = "formId", required = true) String formId, @RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "colName", required = false) String colName, @RequestParam(value = "colVal", required = false) String colVal, @RequestParam(value = "sortCol", required = false) String sortCol, @RequestParam(value = "sortDir", required = false) String sortDir, ModelMap model, HttpServletResponse response, HttpServletRequest request) throws IOException { String access = UserAccessChecker.check(request); if (access != null) { return access; }/*from w w w.ja va2 s.c om*/ if (page == null) { page = 1; } Form form = formDao.getFormWithFields(formId); List<HashMap> list = formDao.getEntryList(form, page, colName, colVal, sortCol, sortDir, false); List<String> headers = getEntryListHeaders(form); response.setContentType("application/vnd.ms-excel"); //TODO: file name HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet("Excel Report"); int r = 0; HSSFRow row = sheet.createRow((short) r++); int count = 0; for (String header : headers) { HSSFCell cell = row.createCell(count++); cell.setCellValue(header); } for (HashMap hashmap : list) { row = sheet.createRow((short) r++); count = 0; HSSFCell cell = row.createCell(count++); cell.setCellValue((String) hashmap.get("entry_date")); cell = row.createCell(count++); cell.setCellValue((String) hashmap.get("entry_time")); cell = row.createCell(count++); cell.setCellValue((String) hashmap.get("entry_status")); for (Field field : form.getFields()) { cell = row.createCell(count++); cell.setCellValue((String) hashmap.get(field.getColName())); } } String fileName = "Report-" + formId + ".xls"; response.setHeader("Content-Disposition", "inline; filename=" + fileName); response.setContentType("application/vnd.ms-excel"); ServletOutputStream outputStream = response.getOutputStream(); sheet.getWorkbook().write(outputStream); outputStream.flush(); return null; }
From source file:org.efs.openreports.services.servlet.ReportServiceServlet.java
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {//from w ww .j av a 2 s . c o m ServletReportServiceInput reportInput = buildReportServiceInput(request); reportInput.setParameterMap(request.getParameterMap()); ReportEngineOutput reportOutput = reportService.generateReport(reportInput); if (reportOutput instanceof QueryEngineOutput) { QueryEngineOutput queryReport = (QueryEngineOutput) reportOutput; request.getSession().setAttribute("properties", queryReport.getProperties()); request.getSession().setAttribute("results", queryReport.getResults()); request.getSession().setAttribute("reportName", StringUtils.deleteWhitespace(reportInput.getReportName())); response.sendRedirect("report-viewer/query-report.jsp"); //getServletContext().getRequestDispatcher("/report-viewer/query-report.jsp").forward(request, response); return; } ServletOutputStream out = response.getOutputStream(); if (reportOutput.getContent() != null) { if (reportInput.getExportType() != ReportEngine.EXPORT_HTML) { response.setContentType(reportOutput.getContentType()); response.setContentLength(reportOutput.getContent().length); response.setHeader("Content-disposition", "inline; filename=" + StringUtils.deleteWhitespace(reportInput.getReportName()) + reportOutput.getContentExtension()); } out.write(reportOutput.getContent(), 0, reportOutput.getContent().length); } else { out.write(reportOutput.getContentMessage().getBytes()); } out.flush(); out.close(); } catch (Exception e) { response.getOutputStream().write(e.toString().getBytes()); } }
From source file:com.esri.gpt.control.cart.XslBundler.java
/** * Processes the HTTP request./*www . j a v a 2s. c o m*/ * @param request the HTTP request * @param response HTTP response * @param context request context * @throws Exception if an exception occurs */ @Override public void execute(HttpServletRequest request, HttpServletResponse response, RequestContext context) throws Exception { String[] keys = this.readKeys(request, context, true); String sXsltPath = Val.chkStr(request.getParameter("xslt")); String sMimeType = Val.chkStr(request.getParameter("mimeType")); String sContentDisposition = Val.chkStr(request.getParameter("contentDisposition")); if ((keys.length > 0) && (sXsltPath.length() > 0)) { if (!assertWhiteList(context, "catalog.cart.xslt.whitelist", sXsltPath)) { throw new ServletException("Invalid xslt parameter"); } XsltTemplate template = this.getCompiledTemplate(sXsltPath); ServletOutputStream out = response.getOutputStream(); if (sMimeType.length() == 0) { sMimeType = "text/plain"; } response.setContentType(StringEscapeUtils.escapeHtml4(Val.stripControls(sMimeType)) + ";charset=UTF-8"); if (sContentDisposition.length() > 0) { response.addHeader("Content-Disposition", StringEscapeUtils.escapeHtml4(Val.stripControls(sContentDisposition))); } try { for (String sKey : keys) { String sXml = this.readXml(request, context, sKey); String sResult = Val.chkStr(template.transform(sXml)); if (sResult.length() > 0) { byte[] bytes = sResult.getBytes("UTF-8"); out.write(bytes); out.flush(); } } } finally { out.flush(); out.close(); } } }