List of usage examples for javax.servlet.http HttpServletResponse addHeader
public void addHeader(String name, String value);
From source file:waffle.spring.handlers.CustomAccessDeniedHandler.java
@Override public void handle(final HttpServletRequest request, final HttpServletResponse response, final AccessDeniedException ex) throws IOException, ServletException { // here we can add custom headers or response status, data or redirect response.addHeader("Custom-header", "some value"); response.sendError(HttpServletResponse.SC_UNAUTHORIZED); }
From source file:hmock.http.impl.DefaultServiceSpec.java
private void injectHeaders(HttpServletResponse servResponse, Map<String, String> headers) { for (Map.Entry<String, String> entry : headers.entrySet()) { servResponse.addHeader(entry.getKey(), entry.getValue()); }//from ww w . j a v a 2s.c o m }
From source file:Bean.liquidacionBean.java
public void exportarPDF(String liqventa) throws JRException, NamingException, SQLException, IOException { dbManager conn = new dbManager(); Connection con = null;/*from w w w. j a va 2 s .c o m*/ con = conn.getConnection(); Map<String, Object> parametros = new HashMap<String, Object>(); if (StringUtils.isNotBlank(liqventa)) { parametros.put("liqventa", liqventa); System.out.println(liqventa); File jasper = new File("D:/reporte/liquidacion.jasper"); JasperPrint jasperPrint = JasperFillManager.fillReport(jasper.getPath(), parametros, con); HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance() .getExternalContext().getResponse(); response.addHeader("Content-disposition", "attachment; filename=Liquidacin" + liqventa + ".pdf"); ServletOutputStream stream = response.getOutputStream(); JasperExportManager.exportReportToPdfStream(jasperPrint, stream); stream.flush(); stream.close(); FacesContext.getCurrentInstance().responseComplete(); } else { FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Error", "Generar Crdito.")); } }
From source file:com.healthcit.analytics.servlet.DataExportServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentType(Constants.PLAIN_TEXT); resp.addHeader(Constants.PRAGMA_HEADER, Constants.NO_CACHE); resp.setHeader(Constants.CACHE_CONTROL_HEADER, Constants.NO_CACHE); String token = req.getParameter("token"); PrintWriter writer = resp.getWriter(); try {//from w ww . j a v a 2 s . c o m if (token != null) { DownloadStatus status = TOKENS_MAP.get(token); if (status != null) { writer.print(status.name()); if (DownloadStatus.FINISHED.equals(status)) { TOKENS_MAP.remove(token); } } else { writer.print(DownloadStatus.ERROR.name()); } } else { writer.print(DownloadStatus.ERROR.name()); } } finally { writer.close(); } }
From source file:net.jadler.stubbing.server.jetty.JadlerHandler.java
private void insertResponseHeaders(final KeyValues headers, final HttpServletResponse response) { for (final String key : headers.getKeys()) { for (final String value : headers.getValues(key)) { response.addHeader(key, value); }//from w ww .j a v a 2s. c om } }
From source file:io.mapzone.arena.geocode.GeocodeServlet.java
private void handleCors(HttpServletRequest req, HttpServletResponse resp) { String origin = req.getHeader("Origin"); resp.addHeader("Access-Control-Allow-Origin", StringUtils.isBlank(origin) ? "*" : origin); resp.addHeader("Access-Control-Allow-Headers", req.getHeader("Access-Control-Request-Headers")); resp.addHeader("Access-Control-Allow-Methods", "GET"); }
From source file:no.dusken.momus.controller.ArticleController.java
@RequestMapping(value = "/{id}/export", method = RequestMethod.GET) public @ResponseBody String getIndesignExport(@PathVariable("id") Long id, HttpServletResponse response) { IndesignExport indesignExport = articleService.exportArticle(id); response.addHeader("Content-Disposition", "attachment; filename=\"" + indesignExport.getName() + ".txt\""); response.addHeader("Content-Type", "text/plain;charset=UTF-16LE"); // Encoding InDesign likes return indesignExport.getContent(); }
From source file:com.groupon.odo.controllers.BackupController.java
/** * Get all backup data// w ww . ja v a 2 s . c o m * * @param model * @return * @throws Exception */ @SuppressWarnings("deprecation") @RequestMapping(value = "/api/backup", method = RequestMethod.GET) public @ResponseBody String getBackup(Model model, HttpServletResponse response) throws Exception { response.addHeader("Content-Disposition", "attachment; filename=backup.json"); response.setContentType("application/json"); Backup backup = BackupService.getInstance().getBackupData(); ObjectMapper objectMapper = new ObjectMapper(); ObjectWriter writer = objectMapper.writerWithDefaultPrettyPrinter(); return writer.withView(ViewFilters.Default.class).writeValueAsString(backup); }
From source file:com.gsr.myschool.server.reporting.convocation.ConvocationController.java
@RequestMapping(value = "test", method = RequestMethod.GET, produces = "application/pdf") @ResponseStatus(HttpStatus.OK)/*from ww w . ja v a2 s . co m*/ public void generateReportTest(@RequestParam String niveauId, @RequestParam String sessionId, HttpServletResponse response) { ReportDTO dto = convocationService.generateConvocationTest(Long.valueOf(niveauId), Long.valueOf(sessionId)); try { response.addHeader("Content-Disposition", "attachment; filename=convocation.pdf"); BufferedOutputStream outputStream = new BufferedOutputStream(response.getOutputStream()); byte[] result = reportService.generatePdf(dto); outputStream.write(result, 0, result.length); outputStream.flush(); outputStream.close(); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:de.mpg.escidoc.services.aa.web.client.BasicAaClient.java
private boolean testLogin(HttpServletRequest request, HttpServletResponse response) throws Exception { String auth = request.getHeader("authorization"); if (auth == null) { response.addHeader("WWW-Authenticate", "Basic realm=\"Validation Service\""); response.sendError(HttpServletResponse.SC_UNAUTHORIZED); return false; } else {//ww w . j a v a2s.c om auth = auth.substring(6); String cred = new String(Base64.decodeBase64(auth.getBytes())); if (cred.contains(":")) { String[] userPass = cred.split(":"); String userName = "admin"; String password = "nimda"; if (!userPass[0].equals(userName) || !userPass[1].equals(password)) { response.sendError(HttpServletResponse.SC_FORBIDDEN); return false; } else { return true; } } else { response.sendError(HttpServletResponse.SC_FORBIDDEN); return false; } } }