Example usage for javax.servlet.http HttpServletResponse setHeader

List of usage examples for javax.servlet.http HttpServletResponse setHeader

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse setHeader.

Prototype

public void setHeader(String name, String value);

Source Link

Document

Sets a response header with the given name and value.

Usage

From source file:technology.tikal.ventas.service.catalogo.CatalogoService.java

@RequestMapping(method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)/*from   w  ww .  j a  v a  2s. c om*/
public void crearCatalogoProducto(@Valid @RequestBody final Catalogo request, final BindingResult result,
        final HttpServletRequest httpRequest, final HttpServletResponse httpResponse) {
    if (result.hasErrors()) {
        throw new NotValidException(result);
    }
    Catalogo nuevo = catalogoController.crear(request);
    httpResponse.setHeader("Location", httpRequest.getRequestURI() + "/" + nuevo.getId());
}

From source file:org.javarebel.chart.ChartComponentListener.java

@Override
public void beforePhase(PhaseEvent arg0) {
    FacesContext context = arg0.getFacesContext();
    ExternalContext eCtx = context.getExternalContext();

    HttpServletRequest req = (HttpServletRequest) eCtx.getRequest();
    String data_KEY = req.getParameter("data_KEY");
    logger.info("Chart Data Key is " + data_KEY);

    HttpSession session = req.getSession();
    if (data_KEY != null) {
        Object chartData = session.getAttribute(data_KEY);

        if (chartData != null) {

            ChartData data = ChartData.class.cast(chartData);
            logger.info("Chart Type received is " + data.getType());
            IChartGenerator chartGen = ChartGeneratorFactory.getChartGenerator(data.getType());
            logger.info("ChartGenerator in use -> " + chartGen.getClass().getName());
            JFreeChart chart = chartGen.generateChart(data);

            BufferedImage img = chart.createBufferedImage(Integer.valueOf(data.getWidth()),
                    Integer.valueOf(data.getHeight()));
            try {
                HttpServletResponse response = (HttpServletResponse) eCtx.getResponse();
                response.setContentType("image/png");
                response.setHeader("Cache-Control", "no-store");
                response.setHeader("Pragma", "no-cache");
                response.setDateHeader("Expires", 0L);

                ServletOutputStream output = response.getOutputStream();
                ImageIO.write(img, "png", output);

                session.removeAttribute(data_KEY);

                context.responseComplete();
            } catch (Exception e) {
                logger.log(Level.SEVERE, e.getMessage(), e);
                throw new IllegalStateException(e);
            }/*from ww w.  j  ava  2 s.c  o  m*/
        }
    }
}

From source file:org.fenixedu.ulisboa.integration.sas.ui.spring.controller.manageScholarshipReportRequests.ScholarshipReportRequestController.java

@RequestMapping(value = "/downloadFile/{oid}", method = RequestMethod.GET)
public void getFile(@PathVariable("oid") ScholarshipReportFile file, HttpServletResponse response) {
    try {/*from  www. j ava 2 s .  c om*/
        response.setContentType(file.getContentType());
        response.setHeader("Content-disposition", "attachment; filename=" + file.getFilename());
        InputStream is = new ByteArrayInputStream(file.getContent());
        IOUtils.copy(is, response.getOutputStream());
    } catch (IOException ex) {
        throw new RuntimeException("IOError writing file to output stream");
    }

}

From source file:ru.org.linux.user.UserEventApiController.java

@ResponseBody
@RequestMapping(value = "/notifications-count", method = RequestMethod.GET)
public int getEventsCount(HttpServletRequest request, HttpServletResponse response) throws Exception {
    Template tmpl = Template.getTemplate(request);
    if (!tmpl.isSessionAuthorized()) {
        throw new AccessViolationException("not authorized");
    }// ww  w  . ja v a 2 s .c o  m

    response.setHeader("Cache-control", "no-cache");

    return tmpl.getCurrentUser().getUnreadEvents();
}

From source file:technology.tikal.ventas.service.pedido.PedidoRaizService.java

@RequestMapping(method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)//w w w  .  ja  va2s .c  o m
public void crear(@Valid @RequestBody final PedidoRaiz request, final BindingResult result,
        final HttpServletRequest httpRequest, final HttpServletResponse httpResponse) {
    if (result.hasErrors()) {
        throw new NotValidException(result);
    }
    PedidoRaiz nuevo = pedidoRaizController.crear(request);
    httpResponse.setHeader("Location", httpRequest.getRequestURI() + "/" + nuevo.getId());
}

From source file:webcomicreader.webapp.controller.BackupRestoreController.java

/**
 * Downloads the entire contents of the database in a json format.
 *//*from ww w. j  ava 2s  . c  o  m*/
@RequestMapping(value = "/dumpdb", method = RequestMethod.GET)
public void dumpDatabase(HttpServletResponse response) throws IOException {
    String dateStr = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm").format(new Date());
    String dumpdbStr = storage.dumpdb();
    response.setCharacterEncoding("UTF-8");
    response.setHeader("Content-Disposition", "attachment; filename=dumpdb_" + dateStr + ".json");
    response.setContentType("application/json");
    response.getWriter().write(dumpdbStr);
}

From source file:com.ddubyat.develop.jhawtcode.web.InternalResourceController.java

/**
 * Controller method to deliver application JS
 *
 * @param response The http response object from a spring controller
 * @param request The http request object from a spring controller
 * @throws IOException if the js file was inaccessible
 */// w w w .ja v  a 2s  .  c  om
@RequestMapping(value = "/jhawtcode/jhc.js", method = { RequestMethod.GET })
public void requestJS(HttpServletRequest request, HttpServletResponse response) throws IOException {
    log.debug("Creating application JS");

    response.setHeader("Server", "jhawtconsole");
    response.setContentType("application/javascript");
    response.setHeader("Cache-Control", "no-cache,no-store,must-revalidate");
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("Expires", -1);

    if (!propertyUtil.canHawtTheCode()) {
        log.trace("Not delivering CSS, application not enabled");
    }

    setTraceProps(request);

    String javascript = resourceUtil.readLocalResource(new String[] { "classpath:/js/jhawtcode.js" });
    javascript = javascript.replace("|systemUUID|", systemUUID);
    javascript = javascript.replace("|username|", username);
    javascript = javascript.replace("|license|", license);
    javascript = javascript.replace("|lCode|", PropertyUtil.license);
    javascript = javascript.replace("|appname|", appname);

    log.debug("Attempting to return JS");
    response.getWriter().write(javascript);
}

From source file:technology.tikal.ventas.service.envio.EnvioService.java

@RequestMapping(method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)//www  .  ja  va  2s.com
public void crear(@PathVariable final Long pedidoId, @Valid @RequestBody final Envio request,
        final BindingResult result, final HttpServletRequest httpRequest,
        final HttpServletResponse httpResponse) {
    if (result.hasErrors()) {
        throw new NotValidException(result);
    }
    Envio nuevo = envioController.crear(pedidoId, request);
    httpResponse.setHeader("Location", httpRequest.getRequestURI() + "/" + nuevo.getId());
}

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 {/*  ww  w .  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();
    }
}