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:com.xumpy.timesheets.controller.pages.TimesheetsCtrl.java

@RequestMapping(value = "timesheets/printTimesheet", method = RequestMethod.GET)
public @ResponseBody ResponseEntity<byte[]> fetchDocumentBlob(@RequestParam Integer jobsGroupId,
        @RequestParam String month, HttpServletResponse response) throws IOException {
    OutputStream out = response.getOutputStream();

    response.setContentType("application/pdf");
    response.setHeader("Content-Disposition", "inline;filename=\"timesheet.pdf\"");

    out = timesheetSrv.getTimesheet(jobsGroupId, month, out);

    out.flush();/*  w  w  w  .  j  ava 2 s.  co  m*/
    out.close();

    return null;
}

From source file:cn.leancloud.diamond.server.controller.ConfigController.java

public String getProbeModifyResult(HttpServletRequest request, HttpServletResponse response,
        String probeModify) {/*  www  .  jav a 2 s  . c om*/
    response.setHeader("Content-Type", "text/html;charset=UTF-8");
    final String address = getRemortIP(request);
    if (address == null) {
        // ?400
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        return "400";
    }

    if (GlobalCounter.getCounter().decrementAndGet() >= 0) {
        response.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
        return "503";
    }

    final List<ConfigKey> configKeyList = getConfigKeyList(probeModify);

    StringBuilder resultBuilder = new StringBuilder();
    for (ConfigKey key : configKeyList) {
        String md5 = this.configService.getContentMD5(key.getDataId(), key.getGroup());
        if (!StringUtils.equals(md5, key.getMd5())) {
            resultBuilder.append(key.getDataId()).append(Constants.WORD_SEPARATOR).append(key.getGroup())
                    .append(Constants.LINE_SEPARATOR);
        }
    }

    String returnHeader = resultBuilder.toString();
    try {
        returnHeader = URLEncoder.encode(resultBuilder.toString(), "UTF-8");
    } catch (Exception e) {
        // ignore
    }

    request.setAttribute("content", returnHeader);
    // ?
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("Expires", 0);
    response.setHeader("Cache-Control", "no-cache,no-store");
    return "200";
}

From source file:com.github.dbourdette.otto.web.controller.api.ApiController.java

@RequestMapping(value = "/imgapi/sources/{name}/event.gif")
public void gifPost(@PathVariable String name, HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    remoteEventsFacade.post(name, copyParams(request));

    response.setHeader("Cache-Control", "private, no-cache");
    response.setHeader("Content-Type", "image/gif");
    response.setHeader("Pragma", "no-cache");
    response.setStatus(200);//  ww  w. j  a v a 2  s  .c o  m
    response.getOutputStream().write(EMPTY_GIF);
}

From source file:edu.mayo.xsltserver.controller.AdminController.java

/**
 * download./*from  w w  w .  jav  a2  s  . co  m*/
 *
 * @param response the response
 * @param fileName the file name
 * @throws Exception the exception
 */
@RequestMapping(value = "/admin/file/{fileName}")
public void download(HttpServletResponse response, @PathVariable String fileName) throws Exception {

    File file = this.fileService.getFile(fileName);

    response.setContentType("text/xml");
    response.setHeader("Content-Disposition", "attachment; filename=\"" + file.getName() + "\"");

    FileCopyUtils.copy(new FileInputStream(file), response.getOutputStream());
}

From source file:technology.tikal.customers.service.ContactService.java

@RequestMapping(method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)/*  www. j av a 2  s.c  om*/
public void createContact(@PathVariable final Long customerId, @Valid @RequestBody final Contact data,
        final BindingResult result, final HttpServletRequest request, final HttpServletResponse response) {
    if (result.hasErrors()) {
        throw new NotValidException(result);
    }
    Contact created = customersController.createContact(customerId, data);
    response.setHeader("Location", request.getRequestURI() + "/" + created.getId());
}

From source file:MyPack.AjaxAlbumList.java

/**
 * Handles the HTTP <code>GET</code> method.
 *
 * @param request servlet request/*w w  w .  java 2 s.c  o  m*/
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    processRequest(request, response);
    response.setContentType("text/html;charset=UTF-8");
    response.setHeader("Cache-control", "no-cache, no-store");
    response.setHeader("Pragma", "no-cache");
    response.setHeader("Expires", "-1");
    HttpSession s = request.getSession(true);
    try (PrintWriter out = response.getWriter()) {
        //getting AJAX parameter
        String query = request.getParameter("term");
        //Creating JSONArray Object
        JSONArray arrayObj = new JSONArray();
        //Changing Case of AJAX parameter
        query = query.toLowerCase();
        try {
            Connection con = ConnectionClass.getConnected();
            PreparedStatement p = con
                    .prepareStatement("select albumName from album where albumName LIKE '" + query + "%'");
            ResultSet rs = p.executeQuery();
            while (rs.next() == true) {
                arrayObj.put(rs.getString(1));
            }
            out.println(arrayObj.toString());
            out.close();
        } catch (SQLException ea) {
        }
    }
}

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

@RequestMapping(method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)//  w  w w.  j ava  2  s. c om
public void crear(@PathVariable final Long idCatalogo, @Valid @RequestBody final Producto request,
        final BindingResult result, final HttpServletRequest httpRequest,
        final HttpServletResponse httpResponse) {
    if (result.hasErrors()) {
        throw new NotValidException(result);
    }
    Producto nuevo = productoController.crear(idCatalogo, request);
    httpResponse.setHeader("Location", httpRequest.getRequestURI() + "/" + nuevo.getId());
}

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

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

From source file:de.tu_dortmund.ub.hb_ng.middleware.MiddlewareHbNgEndpoint.java

public void doOptions(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    response.setHeader("Access-Control-Allow-Methods",
            this.config.getProperty(HBNGStatics.CORS_ACCESS_CONTROL_ALLOW_METHODS_IDENTIFIER));
    response.addHeader("Access-Control-Allow-Headers",
            this.config.getProperty(HBNGStatics.CORS_ACCESS_CONTROL_ALLOW_HEADERS_IDENTIFIER));
    response.setHeader("Access-Control-Allow-Origin",
            this.config.getProperty(HBNGStatics.CORS_ACCESS_CONTROL_ALLOW_ORIGIN_IDENTIFIER));
    response.setHeader("Accept", this.config.getProperty(HBNGStatics.CORS_ACCEPT_IDENTIFIER));

    response.getWriter().println();//  ww  w.  j a  v a2s .  com
}

From source file:com.taobao.diamond.server.controller.ConfigController.java

public String getProbeModifyResult(HttpServletRequest request, HttpServletResponse response,
        String probeModify) {/*from  w w  w  .  j  a v a2  s.c o  m*/
    response.setHeader("Content-Type", "text/html;charset=GBK");
    final String address = getRemortIP(request);
    if (address == null) {
        // 400
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        return "400";
    }

    if (GlobalCounter.getCounter().decrementAndGet() >= 0) {
        response.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
        return "503";
    }

    final List<ConfigKey> configKeyList = getConfigKeyList(probeModify);

    StringBuilder resultBuilder = new StringBuilder();
    for (ConfigKey key : configKeyList) {
        String md5 = this.configService.getContentMD5(key.getDataId(), key.getGroup());
        if (!StringUtils.equals(md5, key.getMd5())) {
            resultBuilder.append(key.getDataId()).append(WORD_SEPARATOR).append(key.getGroup())
                    .append(LINE_SEPARATOR);
        }
    }

    String returnHeader = resultBuilder.toString();
    try {
        returnHeader = URLEncoder.encode(resultBuilder.toString(), "UTF-8");
    } catch (Exception e) {
        // ignore
    }

    request.setAttribute("content", returnHeader);
    // 
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("Expires", 0);
    response.setHeader("Cache-Control", "no-cache,no-store");
    return "200";
}