List of usage examples for javax.servlet.http HttpServletResponse setHeader
public void setHeader(String name, String value);
From source file:com.hybris.integration.controller.AccessTokenController.java
private void addCustomHeader(HttpServletResponse resp) { resp.setHeader("X-Frame-Options", "SAMEORIGIN"); }
From source file:com.goodhuddle.huddle.web.api.ExportApiController.java
@RequestMapping(value = "/{fileName:.+}", method = RequestMethod.GET) public void downloadExport(@PathVariable String fileName, HttpServletResponse response) throws IOException { log.debug("Downloading export file: {}", fileName); response.setContentType("text/csv"); response.setHeader("Content-Disposition", "attachment; filename=\"members.csv\""); File exportFile = exportService.getExportFile(fileName); try (FileInputStream in = new FileInputStream(exportFile)) { IOUtils.copy(in, response.getOutputStream()); response.flushBuffer();/* ww w. j ava2 s . c om*/ } }
From source file:com.xyxy.platform.examples.showcase.demos.web.StaticContentServlet.java
/** * Gzip HeaderGZIPOutputStream./*from ww w .j a va 2 s.co m*/ */ private OutputStream buildGzipOutputStream(HttpServletResponse response) throws IOException { response.setHeader("Content-Encoding", "gzip"); response.setHeader("Vary", "Accept-Encoding"); return new GZIPOutputStream(response.getOutputStream()); }
From source file:hrpod.web.Upload.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from ww w . j a va2 s . co m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setHeader("Content-Type", "application/json"); response.setCharacterEncoding("utf8"); response.setContentType("application/json"); try (PrintWriter out = response.getWriter()) { try { String uploadType = request.getParameter("type"); IngestDataBL ingest = new IngestDataBL(); ServletFileUpload upload = new ServletFileUpload(); FileItemIterator iterator = upload.getItemIterator(request); while (iterator.hasNext()) { FileItemStream item = iterator.next(); if (item.getName() != null) { if (uploadType.equals("resumes")) { ingest.doIngetsJobs(item.openStream()); } else if (uploadType.equals("jobs")) { ingest.doIngetsJobs(item.openStream()); } } } out.write("SUCCESS"); } catch (Exception e) { e.printStackTrace(); } } }
From source file:mecha.http.servlets.ProxyServlet.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {/*from www .ja v a 2s . c o m*/ response.setCharacterEncoding("UTF-8"); response.setHeader("Access-Control-Allow-Origin", "*"); Map<String, String[]> requestParamMap = request.getParameterMap(); String u = requestParamMap.get("u")[0]; response.getWriter().print(HTTPUtils.fetch(u)); } catch (Exception ex) { Mecha.getMonitoring().error("mecha.http.servlets.macro-servlet", ex); ex.printStackTrace(); } }
From source file:controllers.ColorGroupController.java
@RequestMapping("/getXls") public void getXls(Map<String, Object> model, HttpServletResponse response) throws Exception { response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", "attachment; filename=ColorGroup.xls"); colorGroupService.getXls().write(response.getOutputStream()); }
From source file:it.jugpadova.controllers.ServiceController.java
@RequestMapping public ModelAndView kml(HttpServletRequest req, HttpServletResponse res) throws Exception { logger.info("Requested kml from " + req.getRemoteAddr()); Document doc = jugBo.buildKml(); res.setHeader("Cache-Control", "no-store"); res.setHeader("Pragma", "no-cache"); res.setDateHeader("Expires", 0); res.setContentType("text/xml"); ServletOutputStream resOutputStream = res.getOutputStream(); Serializer serializer = new Serializer(resOutputStream); serializer.setIndent(4);//from w ww .j ava 2 s. c om serializer.setMaxLength(64); serializer.setLineSeparator("\n"); serializer.write(doc); resOutputStream.flush(); resOutputStream.close(); return null; }
From source file:au.com.iglooit.shar.servlet.FileServlet.java
/** * Create a new file given a JSON representation, and return the JSON * representation of the created file./*from w ww . ja va 2 s.c o m*/ */ @Override public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { resp.setHeader("Access-Control-Allow-Origin", "*"); Drive service = getDriveService(getDefaultCredential(req, resp)); ClientFile clientFile = new ClientFile(req.getReader()); File file = clientFile.toFile(); byte[] imageData = Base64.decodeBase64(clientFile.content); ByteArrayContent byteArrayContent = new ByteArrayContent(clientFile.mimeType, imageData); if (!clientFile.content.equals("")) { if (StringUtils.isBlank(file.getId())) { file = service.files().insert(file, byteArrayContent).execute(); } else { file = service.files().update(file.getId(), file, byteArrayContent).execute(); } } else { if (StringUtils.isBlank(file.getId())) { file = service.files().insert(file).execute(); } else { file = service.files().update(file.getId(), file).execute(); } } sendJson(resp, file.getId()); }
From source file:com.sishuok.chapter3.web.controller.StreamingController.java
@RequestMapping("/async3") public void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { resp.setHeader("Connection", "Keep-Alive"); resp.addHeader("Cache-Control", "private"); resp.addHeader("Pragma", "no-cache"); resp.setContentType("text/html;charset=utf-8"); resp.flushBuffer();// www .j av a 2s . c o m //1?? final AsyncContext asyncContext = req.startAsync(); asyncContext.addListener(new AsyncListener() { @Override public void onComplete(final AsyncEvent event) throws IOException { queue.remove(event.getAsyncContext()); } @Override public void onTimeout(final AsyncEvent event) throws IOException { event.getAsyncContext().complete(); queue.remove(event.getAsyncContext()); } @Override public void onError(final AsyncEvent event) throws IOException { queue.remove(event.getAsyncContext()); } @Override public void onStartAsync(final AsyncEvent event) throws IOException { } }); //???? queue.add(asyncContext); }
From source file:org.hdiv.js.ajax.SpringJavascriptAjaxHandlerHDIV.java
public void sendAjaxRedirectInternal(String targetUrl, HttpServletRequest request, HttpServletResponse response, boolean popup) throws IOException { if (popup) {// ww w. ja v a 2s . c om response.setHeader(POPUP_VIEW_HEADER, "true"); } String encodeRedirectURL = response.encodeRedirectURL(targetUrl); if (request.getSession(false) != null) { if (!encodeRedirectURL.startsWith("/")) { String requestUri = request.getRequestURI(); int lastSlash = requestUri.lastIndexOf('/'); encodeRedirectURL = requestUri.substring(0, lastSlash) + "/" + encodeRedirectURL; } LinkUrlProcessor linkUrlProcessor = HDIVUtil .getLinkUrlProcessor(request.getSession().getServletContext()); encodeRedirectURL = linkUrlProcessor.processUrl(request, targetUrl); } /* original... if (request.getSession(false) != null) { ServletContext servletContext = request.getSession().getServletContext(); HDIVConfig hdivConfig = HDIVUtil.getHDIVConfig(servletContext); if (HDIVRequestUtils.hasActionOrServletExtension(encodeRedirectURL, hdivConfig.getProtectedURLPatterns())) { if (!encodeRedirectURL.startsWith("/")) { String requestUri = request.getRequestURI(); int lastSlash = requestUri.lastIndexOf('/'); encodeRedirectURL = requestUri.substring(0, lastSlash) + "/" + encodeRedirectURL; } encodeRedirectURL = HDIVRequestUtils.addHDIVParameterIfNecessary(request, encodeRedirectURL, hdivConfig.isValidationInUrlsWithoutParamsActivated()); } } */ if (log.isDebugEnabled()) { log.debug("Send Ajax Redirect to:" + encodeRedirectURL); } response.setHeader(REDIRECT_URL_HEADER, encodeRedirectURL); }