List of usage examples for javax.servlet.http HttpServletResponse setHeader
public void setHeader(String name, String value);
From source file:au.org.ala.layers.web.ObjectsService.java
/** * This method returns all objects associated with a field * * @param id//w ww .j a v a 2s .co m * @return */ @RequestMapping(value = "/objects/csv/{id}", method = RequestMethod.GET) public void fieldObjectAsCSV(@PathVariable("id") String id, HttpServletResponse resp) throws IOException { try { resp.setContentType("text/csv"); resp.setHeader("Content-Disposition", "attachment; filename=\"objects-" + id + ".csv.gz\""); GZIPOutputStream gzipped = new GZIPOutputStream(resp.getOutputStream()); objectDao.writeObjectsToCSV(gzipped, id); gzipped.flush(); gzipped.close(); } catch (Exception e) { logger.error(e.getMessage(), e); resp.sendError(500, "Problem performing download"); } }
From source file:com.hypersocket.auth.json.AuthenticatedController.java
@ExceptionHandler(RedirectException.class) @ResponseStatus(value = HttpStatus.MOVED_TEMPORARILY) public void redirectToLogin(HttpServletRequest request, HttpServletResponse response, RedirectException redirect) {/*from ww w. j av a 2 s. co m*/ response.setHeader(LOCATION, redirect.getMessage()); }
From source file:com.google.code.jcaptcha4struts2.core.actions.support.CaptchaImageResult.java
/** * Action Execution Result. This will write the image bytes to response stream. * //w ww . ja va2 s . c o m * @param invocation * ActionInvocation * @throws IOException * if an IOException occurs while writing the image to output stream. * @throws IllegalArgumentException * if the action invocation was done by an action which is not the * {@link JCaptchaImageAction}. */ public void execute(ActionInvocation invocation) throws IOException, IllegalArgumentException { // Check if the invoked action was JCaptchaImageAction if (!(invocation.getAction() instanceof JCaptchaImageAction)) { throw new IllegalArgumentException( "CaptchaImageResult expects JCaptchaImageAction as Action Invocation"); } JCaptchaImageAction action = (JCaptchaImageAction) invocation.getAction(); HttpServletResponse response = ServletActionContext.getResponse(); // Read captcha image bytes byte[] image = action.getCaptchaImage(); // Send response response.setHeader("Cache-Control", "no-store"); response.setHeader("Pragma", "no-cache"); response.setDateHeader("Expires", 0); response.setContentType("image/jpeg"); response.setContentLength(image.length); try { response.getOutputStream().write(image); response.getOutputStream().flush(); } catch (IOException e) { LOG.error("IOException while writing image response for action : " + e.getMessage(), e); throw e; } }
From source file:mx.edu.ittepic.AEEcommerce.servlets.NewUsers.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request//from w ww . j ava 2 s.co m * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json;charset=UTF-8"); response.setHeader("Cache-Control", "no-store"); PrintWriter out = response.getWriter(); String username = request.getParameter("username"); String password = request.getParameter("password"); String email = request.getParameter("email"); String country = request.getParameter("country"); String state = request.getParameter("state"); String city = request.getParameter("city"); String region = request.getParameter("region"); String neigborhood = request.getParameter("neigborhood"); String street = request.getParameter("street"); String streetnumber = request.getParameter("streetnumber"); String zipcode = request.getParameter("zipcode"); Part file = request.getPart("img"); String phone = request.getParameter("phone"); String cellphone = request.getParameter("cellphone"); String gender = request.getParameter("gender"); String roleid = request.getParameter("roleid"); String companyid = request.getParameter("companyid"); password = DigestUtils.md5Hex(password); out.print(ejb.newUser(username, password, phone, neigborhood, zipcode, city, country, state, region, street, email, streetnumber, file, cellphone, companyid, roleid, gender)); }
From source file:mx.edu.ittepic.AEEcommerce.servlets.Login.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/*ww w .j ava 2s.co m*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json;charset=UTF-8"); response.setHeader("Cache-Control", "no-store"); PrintWriter out = response.getWriter(); CartBean2Remoto ejb = (CartBean2Remoto) request.getSession().getAttribute("ejbsesion"); String user = request.getParameter("usuario"); String password = request.getParameter("password"); System.out.println("password anterior:" + password); password = DigestUtils.md5Hex(password); System.out.println("password nueva:" + password); if (ejb == null) { try { InitialContext ic = new InitialContext(); ejb = (CartBean2Remoto) ic.lookup("java:comp/env/ejbs/CartBean2"); GsonBuilder builder = new GsonBuilder(); Gson gson = builder.create(); //password= DigestUtils.md5Hex(password); Message m = gson.fromJson(ejb.login(user, password), Message.class); if (m.getCode() == 200) { request.getSession().setAttribute("ejbsesion", ejb); } out.print(new GsonBuilder().create().toJson(m)); } catch (NamingException e) { out.print(e.toString()); } } }
From source file:com.music.web.PagesController.java
@RequestMapping("/pack/download") public void downloadPack(@RequestParam long id, HttpServletResponse response) throws IOException { PiecePack pack = packService.getPack(id); if (pack != null) { response.setContentType("application/zip"); response.setHeader("Content-Disposition", "attachment; filename=" + pack.getName().replace(' ', '_').replace('/', '_') + ".zip;"); packService.download(id, response.getOutputStream()); }/*from w ww . jav a2s .co m*/ }
From source file:org.openmrs.module.tracpatienttransfer.web.view.chart.AbstractChartView.java
/** * @see org.springframework.web.servlet.view.AbstractView *///from w w w .j a va 2 s. c om @Override @SuppressWarnings("unchecked") protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception { // Respond as a PNG image response.setContentType("image/png"); // Disable caching response.setHeader("Pragma", "No-cache"); response.setDateHeader("Expires", 0); response.setHeader("Cache-Control", "no-cache"); int width = Integer.valueOf(request.getParameter("width")); int height = Integer.valueOf(request.getParameter("height")); ; JFreeChart chart = createChart(model, request); chart.setBackgroundPaint(Color.WHITE); chart.getPlot().setOutlineStroke(new BasicStroke(0)); chart.getPlot().setOutlinePaint(getBackgroundColor()); chart.getPlot().setBackgroundPaint(getBackgroundColor()); chart.getPlot().setNoDataMessage( TransferOutInPatientUtil.getMessage("tracpatienttransfer.error.noDataAvailable", null)); ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, width, height); }
From source file:com.commercehub.dropwizard.BuildInfoServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { response.setCharacterEncoding(StandardCharsets.UTF_8.name()); response.setHeader(HttpHeaders.CACHE_CONTROL, cacheControl.toString()); response.setStatus(HttpServletResponse.SC_OK); String requestedKey = getRequestedKey(request); if (StringUtils.isNotBlank(requestedKey)) { writeValueForKey(requestedKey, response); } else if (requestedHtml(request)) { writeAllHtml(response);/*from w w w. j a va2 s.c o m*/ } else { writeAllJson(response); } }
From source file:com.netflix.conductor.server.JerseyModule.java
@Provides @Singleton/*w w w . j a va 2 s . com*/ public Filter apiOriginFilter() { return new Filter() { @Override public void init(FilterConfig filterConfig) throws ServletException { } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletResponse res = (HttpServletResponse) response; if (!res.containsHeader("Access-Control-Allow-Origin")) { res.setHeader("Access-Control-Allow-Origin", "*"); } res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT"); res.addHeader("Access-Control-Allow-Headers", "Content-Type, api_key, Authorization"); chain.doFilter(request, response); } @Override public void destroy() { } }; }
From source file:com.lcw.one.modules.sys.web.LoginController.java
/** * ?//from w ww . jav a 2s. c o m */ @RequestMapping(value = "/validateCode", method = RequestMethod.GET) public void validateCode(HttpServletRequest request, HttpServletResponse response) { ValidateCodeInterface validateCode = new EnCharValidateCode(); try { response.setHeader("Pragma", "no-cache"); response.setHeader("Cache-Control", "no-cache"); response.setDateHeader("Expires", 0); response.setContentType("image/jpeg"); String code = validateCode.generate(80, 28, response.getOutputStream()); request.getSession().setAttribute("ValidateCode", code); } catch (IOException e) { e.printStackTrace(); } }