List of usage examples for javax.servlet.http HttpServletResponse addHeader
public void addHeader(String name, String value);
From source file:com.lll.util.ServletUtils.java
/** * Header./*from ww w .j a v a 2 s . com*/ */ public static void setNoCacheHeader(HttpServletResponse response) { //Http 1.0 header response.setDateHeader("Expires", 0); response.addHeader("Pragma", "no-cache"); //Http 1.1 header response.setHeader("Cache-Control", "no-cache"); }
From source file:com.github.rnewson.couchdb.lucene.util.ServletUtils.java
public static void setResponseContentTypeAndEncoding(final HttpServletRequest req, final HttpServletResponse resp) { final String accept = req.getHeader("Accept"); if (getBooleanParameter(req, "force_json") || (accept != null && accept.contains("application/json"))) { resp.setContentType("application/json"); } else {/* w w w . ja va 2s.c o m*/ resp.setContentType("text/plain"); } if (!resp.containsHeader("Vary")) { resp.addHeader("Vary", "Accept"); } resp.setCharacterEncoding("utf-8"); }
From source file:com.usefullc.platform.common.utils.IOUtils.java
/** * /*from w w w .ja v a2s .c o m*/ * * @param content * @param fileName * @param response */ public static void download(byte[] content, String fileName, HttpServletResponse response) { try { // response response.reset(); // ??linux ? linux utf-8,windows GBK) String defaultEncoding = System.getProperty("file.encoding"); if (defaultEncoding != null && defaultEncoding.equals("UTF-8")) { response.addHeader("Content-Disposition", "attachment;filename=" + new String(fileName.getBytes("GBK"), "iso-8859-1")); } else { response.addHeader("Content-Disposition", "attachment;filename=" + new String(fileName.getBytes(), "iso-8859-1")); } // responseHeader response.addHeader("Content-Length", "" + content.length); response.setContentType("application/octet-stream"); OutputStream toClient = new BufferedOutputStream(response.getOutputStream()); toClient.write(content); toClient.flush(); toClient.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:csiro.pidsvc.helper.Http.java
/** * Return specific HTTP response code and add a message to HTTP header. * //from ww w . jav a2 s . co m * @param response HttpServletResponse object. * @param httpResponseCode HTTP response code. * @param exception Exception object. */ public static void returnErrorCode(HttpServletResponse response, int httpResponseCode, Exception exception) { try { String message = (exception.getMessage() == null ? "" : exception.getMessage()) + (exception.getCause() == null ? "" : "\n" + exception.getCause().getMessage()); StringWriter sw = new StringWriter(); exception.printStackTrace(new PrintWriter(sw)); response.addHeader(PID_SERVICE_ERROR_HTTP_HEADER, message); response.addHeader(PID_SERVICE_MSG_HTTP_HEADER, sw.toString()); response.sendError(httpResponseCode, exception.getMessage()); } catch (IOException e) { _logger.debug(e); } }
From source file:com.ericsson.eif.hansoft.utils.HttpUtils.java
/** * @param response/*from w ww . j a v a 2 s.com*/ * @param e - unauthorized exception * @throws IOException * @throws ServletException */ public static void sendUnauthorizedResponse(HttpServletResponse response, UnauthorizedException e) throws IOException, ServletException { if (e instanceof HansoftOAuthException) { OAuthServlet.handleException(response, e, HansoftManager.REALM); } else { // Accept basic access or OAuth authentication. response.addHeader(WWW_AUTHENTICATE_HEADER, OAUTH_AUTHENTICATION_CHALLENGE); response.addHeader(WWW_AUTHENTICATE_HEADER, BASIC_AUTHENTICATION_CHALLENGE); response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } }
From source file:com.invbf.sistemagestionmercadeo.reportes.ReportCreator.java
public static void generadorSolicitudBono(Solicitudentrega elemento) { ServletOutputStream servletOutputStream = null; try {//from ww w . j a v a 2 s . c o m SolicitudBonoJuego elementoReporte = new SolicitudBonoJuego(); if (elemento.getSolicitante().getUsuariodetalle().getIdcargo() != null) { elementoReporte.setCargo(elemento.getSolicitante().getUsuariodetalle().getIdcargo().getNombre()); } else { elementoReporte.setCargo(""); } elementoReporte.setCasino(elemento.getIdCasino().getNombre()); SimpleDateFormat formateador = new SimpleDateFormat("dd-MMMM-yy", new Locale("es_ES")); elementoReporte.setFecha(formateador.format(elemento.getFecha())); elementoReporte.setJustificacion(elemento.getJustificacion()); elementoReporte.setNombre(elemento.getSolicitante().getNombreUsuario()); elementoReporte.setProposito(elemento.getPropositoEntrega().getNombre()); elementoReporte.setTipobono(elemento.getTipoBono().getNombre()); List<SolicitudBonoJuegoCliente> clientes = new ArrayList<SolicitudBonoJuegoCliente>(); int item = 1; Float total = 0f; for (Solicitudentregacliente sec : elemento.getSolicitudentregaclienteList()) { clientes.add(new SolicitudBonoJuegoCliente((item) + "", sec.getCliente().getNombres() + " " + sec.getCliente().getApellidos(), sec.getValorTotal().toString(), sec.getAreaid().getNombre())); total += sec.getValorTotal(); item++; } elementoReporte.setClientes(clientes); elementoReporte.setTotal(total.toString()); ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext(); InputStream input = externalContext .getResourceAsStream("/resources/reportes/solicitudbonosjuego.jasper"); InputStream subreport = externalContext .getResourceAsStream("/resources/reportes/solicitudbonosjuego_cliente.jasper"); InputStream logo = externalContext.getResourceAsStream("/resources/reportes/LogoMRCNegro.jpeg"); InputStream logoibf = externalContext.getResourceAsStream("/resources/reportes/IBFLogo01jpeg.jpeg"); ImageIcon tlc = new ImageIcon(IOUtils.toByteArray(logo)); ImageIcon ibf = new ImageIcon(IOUtils.toByteArray(logoibf)); elementoReporte.setIbf(ibf.getImage()); elementoReporte.setLogo(tlc.getImage()); List<SolicitudBonoJuego> lista = new ArrayList<SolicitudBonoJuego>(); lista.add(elementoReporte); JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(lista); JasperReport jasperMasterReport = (JasperReport) JRLoader.loadObject(input); JasperReport jasperSubReport = (JasperReport) JRLoader.loadObject(subreport); elementoReporte.setSubreportclientes(jasperSubReport); Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("logo", lista.get(0).getLogo()); parameters.put("ibf", lista.get(0).getIbf()); parameters.put("clientes", lista.get(0).getClientes()); parameters.put("subreportclientes", jasperSubReport); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperMasterReport, parameters, beanColDataSource); HttpServletResponse httpServletResponse = (HttpServletResponse) FacesContext.getCurrentInstance() .getExternalContext().getResponse(); httpServletResponse.addHeader("Content-disposition", "attachment; filename=ActaSolicitudBonosJuego" + elemento.getId() + ".pdf"); servletOutputStream = httpServletResponse.getOutputStream(); JasperExportManager.exportReportToPdfStream(jasperPrint, servletOutputStream); } catch (IOException ex) { Logger.getLogger(ReportCreator.class.getName()).log(Level.SEVERE, null, ex); } catch (JRException ex) { Logger.getLogger(ReportCreator.class.getName()).log(Level.SEVERE, null, ex); } finally { try { servletOutputStream.close(); } catch (IOException ex) { Logger.getLogger(ReportCreator.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:com.manydesigns.elements.servlet.ServletUtils.java
/** * Marks the resource returned to a web client to be stored in cache for a very long time. * The resource is marked to be cached privately, i.e. on the client only, not in intermediate caches like proxies. * @param response the HTTP response whose headers are set. *///from ww w . ja v a 2 s. c o m public static void markCacheableForever(HttpServletResponse response) { long expiresAfterMillis = System.currentTimeMillis() + ONE_YEAR_MILLIS; response.setHeader(ServletConstants.HTTP_PRAGMA, ""); response.setDateHeader(ServletConstants.HTTP_EXPIRES, expiresAfterMillis); //Private - only authorized users can cache the content response.setHeader(ServletConstants.HTTP_CACHE_CONTROL, ServletConstants.HTTP_CACHE_CONTROL_PRIVATE); response.addHeader(ServletConstants.HTTP_CACHE_CONTROL, ServletConstants.HTTP_CACHE_CONTROL_MAX_AGE + ONE_YEAR_MILLIS); }
From source file:com.invbf.sistemagestionmercadeo.reportes.ReportCreator.java
public static void generadorPreorden(Solicitudentregalotesmaestro elemento) { try {//from ww w . j av a 2 s .c om ActaREciboCustodiaBonosCajaBean elementoReporte = new ActaREciboCustodiaBonosCajaBean(); elementoReporte.setActnumber(elemento.getId().toString()); elementoReporte.setBonosPorDenominacionEntregars(new ArrayList<ListaBonosPorDenominacionEntregar>()); List<bonosnoincluidos> bonosnoincluidos = new ArrayList<bonosnoincluidos>(); for (Solicitudentregalote sel : elemento.getSolicitudentregaloteList()) { ListaBonosPorDenominacionEntregar lbde = new ListaBonosPorDenominacionEntregar(); lbde.setCantidad(sel.getCantidad().toString()); lbde.setDenominacion(getAsString(sel.getLotesBonosid().getDenominacion().getValor() + " ")); if (sel.getLotesBonosid().getTipoBono().getNombre().equals("PROMOCIONAL")) { lbde.setSaladejuego(sel.getLotesBonosid().getIdCasino().getCasinodetalle().getAbreCiudad() + " " + sel.getLotesBonosid().getTipoBono().getNombre()); lbde.setDel(sel.getLotesBonosid().getIdCasino().getCasinodetalle().getAbreCiudad() + "-" + sel.getDesde()); lbde.setAl(sel.getLotesBonosid().getIdCasino().getCasinodetalle().getAbreCiudad() + "-" + sel.getHasta()); } else { lbde.setSaladejuego(sel.getLotesBonosid().getIdCasino().getCasinodetalle().getAbrenopromo() + " " + sel.getLotesBonosid().getTipoBono().getNombre()); lbde.setDel(sel.getLotesBonosid().getIdCasino().getCasinodetalle().getAbrenopromo() + "-" + sel.getDesde()); lbde.setAl(sel.getLotesBonosid().getIdCasino().getCasinodetalle().getAbrenopromo() + "-" + sel.getHasta()); } elementoReporte.getBonosPorDenominacionEntregars().add(lbde); String bonosnoincluidosString = "Bono " + sel.getLotesBonosid().getTipoBono().getNombre() + " " + " / " + sel.getLotesBonosid().getDenominacion().getValor() + " / Faltantes: "; if (sel.getBononoincluidoList().isEmpty()) { for (Bononoincluido bonosnoincluido : sel.getBononoincluidoList()) { bonosnoincluidosString += " " + bonosnoincluido.getConsecutivo(); } bonosnoincluidos.add(new bonosnoincluidos(bonosnoincluidosString)); } } ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext(); InputStream input = externalContext .getResourceAsStream("/resources/reportes/OrdenProduccionLoteBono.jasper"); InputStream subreport = externalContext .getResourceAsStream("/resources/reportes/ReciboCustodiaBonosCaja_detalle.jasper"); InputStream logotexas = externalContext.getResourceAsStream("/resources/reportes/LogoTLCNegro-01.jpeg"); InputStream logomasters = externalContext.getResourceAsStream("/resources/reportes/IBFLogo01jpeg.jpeg"); InputStream logoibf = externalContext.getResourceAsStream("/resources/reportes/LogoMRCNegro.jpeg"); ImageIcon tlc = new ImageIcon(IOUtils.toByteArray(logotexas)); ImageIcon mrc = new ImageIcon(IOUtils.toByteArray(logomasters)); ImageIcon ibf = new ImageIcon(IOUtils.toByteArray(logoibf)); elementoReporte.setIbf(ibf.getImage()); elementoReporte.setMrc(mrc.getImage()); elementoReporte.setTlc(tlc.getImage()); elementoReporte.setBonosnoincluidos(bonosnoincluidos); List<ActaREciboCustodiaBonosCajaBean> lista = new ArrayList<ActaREciboCustodiaBonosCajaBean>(); lista.add(elementoReporte); JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(lista); JasperReport jasperMasterReport = (JasperReport) JRLoader.loadObject(input); JasperReport jasperSubReport = (JasperReport) JRLoader.loadObject(subreport); elementoReporte.setSubreportParameter(jasperSubReport); Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("actnumber", lista.get(0).getActnumber()); parameters.put("tlc", lista.get(0).getTlc()); parameters.put("ibf", lista.get(0).getIbf()); parameters.put("mrc", lista.get(0).getMrc()); parameters.put("subreportParameter", jasperSubReport); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperMasterReport, parameters, beanColDataSource); HttpServletResponse httpServletResponse = (HttpServletResponse) FacesContext.getCurrentInstance() .getExternalContext().getResponse(); httpServletResponse.addHeader("Content-disposition", "attachment; filename=OrdenProduccionLotesBonos" + elemento.getId() + ".pdf"); ServletOutputStream servletOutputStream = httpServletResponse.getOutputStream(); JasperExportManager.exportReportToPdfStream(jasperPrint, servletOutputStream); } catch (JRException ex) { Logger.getLogger(GeneradorSolicitudLotesBonos.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(GeneradorSolicitudLotesBonos.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.lushapp.common.web.utils.WebUtils.java
/** * Header.// ww w .j av a 2 s . c o m */ public static void setNoCacheHeader(HttpServletResponse response) { //Http 1.0 header response.setDateHeader("Expires", 1L); response.addHeader("Pragma", "no-cache"); //Http 1.1 header response.setHeader("Cache-Control", "no-cache, no-store, max-age=0"); }
From source file:com.invbf.sistemagestionmercadeo.reportes.ReportCreator.java
public static void generadorEntregaBonosCaja(Solicitudentregalotesmaestro elemento) { try {/*from w w w. j a v a 2 s . com*/ ActaREciboCustodiaBonosCajaBean elementoReporte = new ActaREciboCustodiaBonosCajaBean(); elementoReporte.setActnumber(elemento.getId().toString()); elementoReporte.setBonosPorDenominacionEntregars(new ArrayList<ListaBonosPorDenominacionEntregar>()); List<bonosnoincluidos> bonosnoincluidos = new ArrayList<bonosnoincluidos>(); for (Solicitudentregalote sel : elemento.getSolicitudentregaloteList()) { ListaBonosPorDenominacionEntregar lbde = new ListaBonosPorDenominacionEntregar(); lbde.setCantidad(sel.getCantidad().toString()); lbde.setDenominacion(getAsString(sel.getLotesBonosid().getDenominacion().getValor() + " ")); if (sel.getLotesBonosid().getTipoBono().getNombre().equals("PROMOCIONAL")) { lbde.setSaladejuego(sel.getLotesBonosid().getIdCasino().getCasinodetalle().getAbreCiudad() + " " + sel.getLotesBonosid().getTipoBono().getNombre()); lbde.setDel(sel.getLotesBonosid().getIdCasino().getCasinodetalle().getAbreCiudad() + "-" + sel.getDesde()); lbde.setAl(sel.getLotesBonosid().getIdCasino().getCasinodetalle().getAbreCiudad() + "-" + sel.getHasta()); } else { lbde.setSaladejuego(sel.getLotesBonosid().getIdCasino().getCasinodetalle().getAbrenopromo() + " " + sel.getLotesBonosid().getTipoBono().getNombre()); lbde.setDel(sel.getLotesBonosid().getIdCasino().getCasinodetalle().getAbrenopromo() + "-" + sel.getDesde()); lbde.setAl(sel.getLotesBonosid().getIdCasino().getCasinodetalle().getAbrenopromo() + "-" + sel.getHasta()); } elementoReporte.getBonosPorDenominacionEntregars().add(lbde); String bonosnoincluidosString = "Bono " + sel.getLotesBonosid().getTipoBono().getNombre() + " " + " / " + sel.getLotesBonosid().getDenominacion().getValor() + " / Faltantes: "; if (sel.getBononoincluidoList().isEmpty()) { for (Bononoincluido bonosnoincluido : sel.getBononoincluidoList()) { bonosnoincluidosString += " " + bonosnoincluido.getConsecutivo(); } bonosnoincluidos.add(new bonosnoincluidos(bonosnoincluidosString)); } } ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext(); InputStream input = externalContext .getResourceAsStream("/resources/reportes/ReciboCustodiaBonosCaja.jasper"); InputStream subreport = externalContext .getResourceAsStream("/resources/reportes/ReciboCustodiaBonosCaja_detalle.jasper"); InputStream bonosno = externalContext .getResourceAsStream("/resources/reportes/ReciboCustodiaBonosCaja_bonosnoincluidos.jasper"); InputStream logotexas = externalContext.getResourceAsStream("/resources/reportes/LogoTLCNegro-01.jpeg"); InputStream logomasters = externalContext.getResourceAsStream("/resources/reportes/IBFLogo01jpeg.jpeg"); InputStream logoibf = externalContext.getResourceAsStream("/resources/reportes/LogoMRCNegro.jpeg"); ImageIcon tlc = new ImageIcon(IOUtils.toByteArray(logotexas)); ImageIcon mrc = new ImageIcon(IOUtils.toByteArray(logomasters)); ImageIcon ibf = new ImageIcon(IOUtils.toByteArray(logoibf)); elementoReporte.setIbf(ibf.getImage()); elementoReporte.setMrc(mrc.getImage()); elementoReporte.setTlc(tlc.getImage()); elementoReporte.setBonosnoincluidos(bonosnoincluidos); List<ActaREciboCustodiaBonosCajaBean> lista = new ArrayList<ActaREciboCustodiaBonosCajaBean>(); lista.add(elementoReporte); JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(lista); JasperReport jasperMasterReport = (JasperReport) JRLoader.loadObject(input); JasperReport jasperSubReport = (JasperReport) JRLoader.loadObject(subreport); JasperReport bonosnoReport = (JasperReport) JRLoader.loadObject(bonosno); elementoReporte.setSubreportParameter(jasperSubReport); elementoReporte.setBonosno(bonosnoReport); Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("actnumber", lista.get(0).getActnumber()); parameters.put("tlc", lista.get(0).getTlc()); parameters.put("ibf", lista.get(0).getIbf()); parameters.put("mrc", lista.get(0).getMrc()); parameters.put("subreportParameter", jasperSubReport); parameters.put("bonosno", bonosnoReport); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperMasterReport, parameters, beanColDataSource); HttpServletResponse httpServletResponse = (HttpServletResponse) FacesContext.getCurrentInstance() .getExternalContext().getResponse(); httpServletResponse.addHeader("Content-disposition", "attachment; filename=ActaReciboCustodiaBonosCaja" + elemento.getId() + ".pdf"); ServletOutputStream servletOutputStream = httpServletResponse.getOutputStream(); JasperExportManager.exportReportToPdfStream(jasperPrint, servletOutputStream); } catch (JRException ex) { Logger.getLogger(GeneradorSolicitudLotesBonos.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(GeneradorSolicitudLotesBonos.class.getName()).log(Level.SEVERE, null, ex); } }