List of usage examples for javax.servlet.http HttpServletResponse addHeader
public void addHeader(String name, String value);
From source file:org.jasig.portlet.notice.controller.rest.JPANotificationRESTController.java
/** * Create a new addressee for a notification. * * @param req the Http request/*from ww w . j ava2 s. c om*/ * @param resp the Http response * @param id the notification id * @param addressee the list of addressees * @return the persisted addressee */ @RequestMapping(value = "/{notificationId}/addressees", method = RequestMethod.POST) @ResponseBody @ResponseStatus(HttpStatus.CREATED) public AddresseeDTO addAddressee(HttpServletRequest req, HttpServletResponse resp, @PathVariable("notificationId") long id, @RequestBody AddresseeDTO addressee) { AddresseeDTO dto = restService.createAddressee(id, addressee); if (dto == null) { resp.setStatus(HttpStatus.NOT_FOUND.value()); return null; } String url = getSingleNotificationRESTUrl(req, id) + "/addressee/" + dto.getId(); resp.addHeader("Location", url); return dto; }
From source file:com.delpac.bean.OrdenRetiroBean.java
public void commitCreate1() throws SQLException, JRException, IOException { int keyGenerated = daoOrdenRetiro.crearOrdenRetiro(ord, temperado, sessionUsuario, ingresado); conexion con = new conexion(); try {/*from ww w . j a v a 2 s . c o m*/ FacesContext context = FacesContext.getCurrentInstance(); ServletContext servleContext = (ServletContext) context.getExternalContext().getContext(); String temperatura = temperado == true ? "ReporteFreezer.jasper" : "ReporteNoFreezer.jasper"; String jrxmlPath = temperatura.equals("ReporteFreezer.jasper") ? "ReporteFreezer.jrxml" : "ReporteNoFreezer.jrxml";//server String nom_archivo = "OR_BK_" + ord.getBooking() + ".pdf"; String exportDir = System.getProperty("catalina.base") + "/OrdenesRetiro/";//server String exportPath = exportDir + nom_archivo;//server String dirReporte = servleContext.getRealPath("/reportes/" + temperatura); File reporte = new File(servleContext.getRealPath("/reportes/") + jrxmlPath); HashMap<String, Object> parametros = new HashMap<String, Object>(); List<JasperPrint> prints = new ArrayList<JasperPrint>(); for (int cont = 1; cont <= ingresado; cont++) { parametros.put("RutaImagen", servleContext.getRealPath("/reportes/")); parametros.put("cod_ordenretiro", keyGenerated); keyGenerated--; JasperPrint jasperPrint = JasperFillManager.fillReport(dirReporte, parametros, con.getConnection());//server prints.add(jasperPrint); } HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse(); response.addHeader("Content-disposition", "attachment;filename=" + nom_archivo); response.setContentType("application/pdf"); JRPdfExporter exporter = new JRPdfExporter(); exporter.setExporterInput(SimpleExporterInput.getInstance(prints)); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(response.getOutputStream())); SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration(); configuration.setCreatingBatchModeBookmarks(true); exporter.setConfiguration(configuration); exporter.exportReport(); context.responseComplete(); } catch (Exception e) { System.err.println(e); } listadoOrdenes = daoOrdenRetiro.findAllOrdenes(); }
From source file:mx.edu.um.mateo.rh.web.SolicitudVacacionesEmpleadoController.java
private void generaReporte(String tipo, List<SolicitudVacacionesEmpleado> vacacioness, HttpServletResponse response) throws JRException, IOException { log.debug("Generando reporte {}", tipo); byte[] archivo = null; switch (tipo) { case "PDF": archivo = generaPdf(vacacioness); response.setContentType("application/pdf"); response.addHeader("Content-Disposition", "attachment; filename=clavesEmpleado.pdf"); break;//from w ww . j a va 2 s .co m case "CSV": archivo = generaCsv(vacacioness); response.setContentType("text/csv"); response.addHeader("Content-Disposition", "attachment; filename=clavesEmpleado.csv"); break; case "XLS": archivo = generaXls(vacacioness); response.setContentType("application/vnd.ms-excel"); response.addHeader("Content-Disposition", "attachment; filename=clavesEmpleado.xls"); } if (archivo != null) { response.setContentLength(archivo.length); try (BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream())) { bos.write(archivo); bos.flush(); } } }
From source file:mx.edu.um.mateo.rh.web.JefeRHController.java
private void generaReporte(String tipo, List<Jefe> jefes, HttpServletResponse response) throws JRException, IOException { log.debug("Generando reporte {}", tipo); byte[] archivo = null; switch (tipo) { case "PDF": archivo = generaPdf(jefes);//from w w w. j a va 2 s . c o m response.setContentType("application/pdf"); response.addHeader("Content-Disposition", "attachment; filename=clavesEmpleado.pdf"); break; case "CSV": archivo = generaCsv(jefes); response.setContentType("text/csv"); response.addHeader("Content-Disposition", "attachment; filename=clavesEmpleado.csv"); break; case "XLS": archivo = generaXls(jefes); response.setContentType("application/vnd.ms-excel"); response.addHeader("Content-Disposition", "attachment; filename=clavesEmpleado.xls"); } if (archivo != null) { response.setContentLength(archivo.length); try (BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream())) { bos.write(archivo); bos.flush(); } } }
From source file:mx.edu.um.mateo.rh.web.VacacionesEmpleadoController.java
private void generaReporte(String tipo, List<VacacionesEmpleado> vacacionesEmpleados, HttpServletResponse response) throws JRException, IOException { log.debug("Generando reporte {}", tipo); byte[] archivo = null; switch (tipo) { case "PDF": archivo = generaPdf(vacacionesEmpleados); response.setContentType("application/pdf"); response.addHeader("Content-Disposition", "attachment; filename=clavesEmpleado.pdf"); break;//from ww w . ja v a 2 s. co m case "CSV": archivo = generaCsv(vacacionesEmpleados); response.setContentType("text/csv"); response.addHeader("Content-Disposition", "attachment; filename=clavesEmpleado.csv"); break; case "XLS": archivo = generaXls(vacacionesEmpleados); response.setContentType("application/vnd.ms-excel"); response.addHeader("Content-Disposition", "attachment; filename=clavesEmpleado.xls"); } if (archivo != null) { response.setContentLength(archivo.length); try (BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream())) { bos.write(archivo); bos.flush(); } } }
From source file:com.dp2345.interceptor.MemberInterceptor.java
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { HttpSession session = request.getSession(); Principal principal = (Principal) session.getAttribute(Member.PRINCIPAL_ATTRIBUTE_NAME); if (principal != null) { return true; } else {/* w w w .j av a 2 s. c o m*/ // ajax String requestType = request.getHeader("X-Requested-With"); if (requestType != null && requestType.equalsIgnoreCase("XMLHttpRequest")) { // ajax response.addHeader("loginStatus", "accessDenied"); response.sendError(HttpServletResponse.SC_FORBIDDEN); return false; } else { // GET if (request.getMethod().equalsIgnoreCase("GET")) { String redirectUrl = request.getQueryString() != null ? request.getRequestURI() + "?" + request.getQueryString() : request.getRequestURI(); response.sendRedirect(request.getContextPath() + loginUrl + "?" + REDIRECT_URL_PARAMETER_NAME + "=" + URLEncoder.encode(redirectUrl, urlEscapingCharset)); } else { // POST response.sendRedirect(request.getContextPath() + loginUrl); } return false; } } }
From source file:sys.core.manager.RecursosManager.java
public void viewArchivo(String archivo) { FacesContext context = FacesContext.getCurrentInstance(); HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse(); response.setContentType("application/force-download"); response.addHeader("Content-Disposition", "attachment; filename=\"" + archivo + "\""); ApplicationMBean applicationMBean = (ApplicationMBean) WebServletContextListener.getApplicationContext() .getBean("applicationMBean"); byte[] buf = new byte[1024]; try {//w w w. ja v a2s.c o m File file = new File(applicationMBean.getRutaArchivos() + archivo); long length = file.length(); BufferedInputStream in = new BufferedInputStream(new FileInputStream(file)); ServletOutputStream out = response.getOutputStream(); response.setContentLength((int) length); while ((in != null) && ((length = in.read(buf)) != -1)) { out.write(buf, 0, (int) length); } in.close(); out.close(); } catch (Exception exc) { logger.error(exc); } }
From source file:inti.ws.spring.resource.ResourceController.java
protected void applyCachingHeader(HttpServletResponse response, WebResource resource, ConfigParserSettings settings) { ResourceWorkingContext ctx = contexts.get(); if (settings != null) { if (settings.getExpires() > 0) { // http://en.wikipedia.org/wiki/List_of_HTTP_header_fields ctx.clearBuilder();/*from w w w . j a v a 2s . c o m*/ dateFormatter.formatDate(System.currentTimeMillis() + settings.getExpires(), ctx.getBuilder()); response.addHeader(HttpHeaders.EXPIRES, ctx.getBuilder().toString()); if (resource.getMessageDigest() != null) { response.setHeader(HttpHeaders.ETAG, resource.getMessageDigest()); } if (resource.getLastModifiedString() != null) { response.setHeader(HttpHeaders.LAST_MODIFIED, resource.getLastModifiedString()); } } else { response.addHeader(HttpHeaders.EXPIRES, EXPIRES_IMMEDIATELY); } if (settings.getCacheControl() != null) { response.setHeader(HttpHeaders.CACHE_CONTROL, settings.getCacheControl()); } } }
From source file:org.jasig.portlet.notice.controller.rest.JPANotificationRESTController.java
/** * Create a new event./* w w w . j a va 2 s.c om*/ * * @param req the Http request * @param resp the Http response * @param notificationId the notification id * @param event the event id * @return The newly persisted object */ @RequestMapping(value = "/{notificationId}/events", method = RequestMethod.POST) @ResponseStatus(HttpStatus.CREATED) @ResponseBody public EventDTO createEvent(HttpServletRequest req, HttpServletResponse resp, @PathVariable("notificationId") long notificationId, @RequestBody EventDTO event) { EventDTO dto = restService.createEvent(notificationId, event); if (dto == null) { resp.setStatus(HttpStatus.NOT_FOUND.value()); return null; } String url = getSingleNotificationRESTUrl(req, notificationId) + "/state/" + dto.getId(); resp.addHeader("Location", url); return dto; }