List of usage examples for javax.servlet.http HttpServletResponse setHeader
public void setHeader(String name, String value);
From source file:net.sf.j2ep.responsehandlers.TraceResponseHandler.java
/** * Will either respond with data from the underlying server * or the proxy's own data./*from w w w . j a va 2 s . com*/ * @see net.sf.j2ep.model.ResponseHandler#process(javax.servlet.http.HttpServletResponse) */ public void process(HttpServletResponse response) throws IOException { if (proxyTargeted) { response.setStatus(HttpServletResponse.SC_OK); response.setHeader("content-type", "message/http"); response.setHeader("Connection", "close"); String path = method.getPath(); String protocol = method.getParams().getVersion().toString(); PrintWriter writer = response.getWriter(); writer.println("TRACE " + path + " " + protocol); Header[] headers = method.getRequestHeaders(); for (int i = 0; i < headers.length; i++) { writer.print(headers[i]); } writer.flush(); writer.close(); } else { setHeaders(response); response.setStatus(getStatusCode()); sendStreamToClient(response); } }
From source file:com.sambrannen.samples.events.web.RestEventController.java
@RequestMapping(method = POST) @ResponseStatus(HttpStatus.CREATED)/*from w w w. j a va2 s .c om*/ public void createEvent(@RequestBody Event postedEvent, HttpServletRequest request, HttpServletResponse response) { Event savedEvent = repository.save(postedEvent); String newLocation = buildNewLocation(request, savedEvent.getId()); response.setHeader("Location", newLocation); }
From source file:org.apereo.openlrs.CORSFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { if (log.isDebugEnabled()) { log.debug("CORSFilter invoked"); }// w w w . ja va 2 s . c o m response.setHeader("Access-Control-Allow-Origin", "*"); response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE"); response.setHeader("Access-Control-Max-Age", "3600"); response.setHeader("Access-Control-Allow-Headers", "x-requested-with, " + XApiConstants.XAPI_VERSION_HEADER + ", Authorization, Content-Type"); filterChain.doFilter(request, response); }
From source file:com.google.code.pentahoflashcharts.StaticContentGenerator.java
protected void allowBrowserCache(IPluginResourceLoader resLoader) { String maxAge = resLoader.getPluginSetting(StaticContentGenerator.class, "settings/max-age"); //$NON-NLS-1$ if (maxAge == null || "0".equals(maxAge)) { //$NON-NLS-1$ return;/*from ww w . j a va 2s . co m*/ } IParameterProvider pathParams = parameterProviders.get("path"); //$NON-NLS-1$ if (maxAge != null) { HttpServletResponse response = (HttpServletResponse) pathParams.getParameter("httpresponse"); //$NON-NLS-1$ if (response != null) { response.setHeader("Cache-Control", "max-age=" + maxAge); //$NON-NLS-1$ //$NON-NLS-2$ } } }
From source file:de.otto.jsonhome.registry.controller.RegistryJsonHomeController.java
@RequestMapping(value = "/json-home", produces = { "application/json-home" }) @ResponseBody/* w w w .j a v a 2 s . co m*/ public Map<String, ?> getAsApplicationJsonHome( @RequestParam(required = false) @Doc(value = "The name of the json-home registry.") final String registry, final HttpServletResponse response) { LOG.info("Returning json-home in application/json-home format."); // home document should be cached: response.setHeader("Cache-Control", "max-age=" + maxAge); response.setHeader("Vary", "Accept"); final String selectedRegistry = registry != null ? registry : defaultRegistry; return toRepresentation(jsonHomeSource.getJsonHome(selectedRegistry), APPLICATION_JSONHOME); }
From source file:io.neba.core.resourcemodels.metadata.ModelStatisticsConsolePlugin.java
private void setNoCacheHeaders(HttpServletResponse res) { res.setHeader("Expires", "Sat, 6 May 1970 12:00:00 GMT"); res.setHeader("Cache-Control", "no-store, no-cache, must-revalidate"); res.addHeader("Cache-Control", "post-check=0, pre-check=0"); res.setHeader("Pragma", "no-cache"); }
From source file:cz.fi.muni.xkremser.editor.server.AuthenticationServlet.java
private void requrireAuthentication(HttpServletResponse resp) throws IOException { resp.setHeader("WWW-Authenticate", "BASIC realm=\"users\""); resp.sendError(HttpServletResponse.SC_UNAUTHORIZED); }
From source file:de.otto.jsonhome.registry.controller.RegistryJsonHomeController.java
@RequestMapping(value = "/json-home", produces = { "application/json" }) @ResponseBody/*w ww. j av a 2 s.c o m*/ public Map<String, ?> getAsApplicationJson( @RequestParam(required = false) @Doc(value = "The name of the json-home registry.") final String registry, final HttpServletResponse response) { LOG.info("Returning json-home in application/json format."); // home document should be cached: response.setHeader("Cache-Control", "max-age=" + maxAge); response.setHeader("Vary", "Accept"); try { final String selectedRegistry = registry != null ? registry : defaultRegistry; return toRepresentation(jsonHomeSource.getJsonHome(selectedRegistry), APPLICATION_JSON); } catch (final IllegalArgumentException e) { try { response.sendError(SC_NOT_FOUND, e.getMessage()); } catch (IOException ignore) { } throw e; } }
From source file:org.fishwife.jrugged.spring.StatusController.java
private void setCachingHeaders(HttpServletResponse resp) { long now = System.currentTimeMillis(); resp.setDateHeader("Date", now); resp.setDateHeader("Expires", now); resp.setHeader("Cache-Control", "no-cache"); }
From source file:it.eng.spagobi.kpi.service.KpiExporterAction.java
/** * This action is called by the user who wants to export the result of a Kpi in PDF * /*w ww . j a v a 2 s . c om*/ */ public void service(SourceBean serviceRequest, SourceBean serviceResponse) throws Exception { File tmpFile = null; logger.debug("IN"); HttpServletRequest httpRequest = getHttpRequest(); HttpSession session = httpRequest.getSession(); this.freezeHttpResponse(); try { // get KPI result List<KpiResourceBlock> listKpiBlocks = (List<KpiResourceBlock>) session.getAttribute("KPI_BLOCK"); //List<KpiResourceBlock> listKpiBlocks=executeKpi(objectId); // recover BiObject Name Object idObject = serviceRequest.getAttribute(SpagoBIConstants.OBJECT_ID); if (idObject == null) { logger.error("Document id not found"); return; } Integer id = Integer.valueOf(idObject.toString()); BIObject document = DAOFactory.getBIObjectDAO().loadBIObjectById(id); String docName = document.getName(); //Recover user Id HashedMap parameters = new HashedMap(); String userId = null; Object userIdO = serviceRequest.getAttribute("user_id"); if (userIdO != null) userId = userIdO.toString(); it.eng.spagobi.engines.exporters.KpiExporter exporter = new KpiExporter(); tmpFile = exporter.getKpiReportPDF(listKpiBlocks, document, userId); String outputType = "PDF"; String mimeType = "application/pdf"; logger.debug("Report exported succesfully"); HttpServletResponse response = getHttpResponse(); response.setContentType(mimeType); response.setHeader("Content-Disposition", "filename=\"report." + outputType + "\";"); response.setContentLength((int) tmpFile.length()); BufferedInputStream in = new BufferedInputStream(new FileInputStream(tmpFile)); int b = -1; while ((b = in.read()) != -1) { response.getOutputStream().write(b); } response.getOutputStream().flush(); in.close(); logger.debug("OUT"); } catch (Throwable e) { logger.error("An exception has occured", e); throw new Exception(e); } finally { tmpFile.delete(); } }