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:es.logongas.ix3.web.util.ControllerHelper.java

private void cache(HttpServletResponse httpServletResponse, long expireSeconds) {
    httpServletResponse.setHeader("Cache-Control", "private, no-transform, max-age=" + expireSeconds);
}

From source file:net.paulgray.mocklti2.tools.LtiToolController.java

@RequestMapping(value = "/api/profile", method = RequestMethod.GET)
public ResponseEntity getConsumerProfile(HttpServletRequest request, HttpServletResponse response,
        @RequestParam String toolId) {
    response.setHeader("Content-type", "application/vnd.ims.lti.v2.ToolConsumerProfile+json");
    ToolConsumer me = new ToolConsumer("guid", "version", "tcp", config);
    me.addCapabilites(Arrays.asList(LtiCapability.BASICLTI_LAUNCH, LtiCapability.USER_ID,
            LtiCapability.USER_IMAGE, LtiCapability.COURSE_SECTION_ID, LtiCapability.MEMBERSHIP_ROLE));
    String endpoint = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + request.getContextPath() + "/api/tool_proxy_registration?toolId=" + toolId;
    me.addServiceOffered(new ServiceOffered(endpoint, "tcp:ToolProxy.collection", "RestService",
            ToolProxy.CONTENT_TYPE, "POST"));
    return new ResponseEntity(me, HttpStatus.OK);
}

From source file:io.onedecision.engine.decisions.web.DecisionUIModelController.java

@RequestMapping(value = "/", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)//from   w ww  .j ava2 s  .  c  o  m
public @ResponseBody DecisionModel createModelForTenant(@PathVariable("tenantId") String tenantId,
        @RequestBody DecisionModel model, HttpServletRequest request, HttpServletResponse response) {
    DecisionModel dm = createModelForTenant(model, tenantId);
    response.setHeader("Location", String.format("%1$s%2$d", request.getRequestURL(), dm.getId()));
    return dm;
}

From source file:com.indeed.imhotep.web.ResultServlet.java

@RequestMapping("/results/{filename:.+}")
protected void doGet(final HttpServletResponse resp, @PathVariable("filename") String filename,
        @RequestParam(required = false) String view, OutputStream outputStream) throws IOException {
    resp.setHeader("Access-Control-Allow-Origin", "*");
    final boolean csv = filename.endsWith(".csv");
    final boolean avoidFileSave = view != null;

    if (!queryCache.isFileCached(filename)) {
        resp.sendError(404);/* ww  w  . ja v a  2  s. c  om*/
        return;
    }

    setContentType(resp, avoidFileSave, csv, false);
    final InputStream cacheInputStream = queryCache.getInputStream(filename);
    IQLQuery.copyStream(cacheInputStream, outputStream, Integer.MAX_VALUE, false);
    outputStream.close();

}

From source file:com.envision.envservice.filter.RedmineFilter.java

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) res;
    response.setHeader("Content-Type", "application/json; charset=utf-8");
    String requestType = request.getMethod();
    String url = "";
    String api_key = "";
    String param = "";
    String result = "";
    if (requestType == "GET" || "GET".equals(requestType)) {
        url = getRedmineUrl(request.getRequestURL().toString());
        api_key = getSessionApiKey(request);
        if (api_key == null || "".equals(api_key)) {
            return;
        }//  w  w  w  .ja  v a2 s .c  o m
        WebApplicationContext webAppContext = ContextLoader.getCurrentWebApplicationContext();
        RedmineHttpRequestService redmineHttpRequestService = (RedmineHttpRequestService) webAppContext
                .getBean("redmineHttpRequestService");
        result = redmineHttpRequestService.doGET(url, api_key);
    } else if (requestType == "POST" || "POST".equals(requestType)) {
        url = getRedmineUrl(request.getRequestURL().toString());
        api_key = getSessionApiKey(request);
        if (api_key == null || "".equals(api_key)) {
            return;
        }
        param = getParam(request.getInputStream());
        WebApplicationContext webAppContext = ContextLoader.getCurrentWebApplicationContext();
        RedmineHttpRequestService redmineHttpRequestService = (RedmineHttpRequestService) webAppContext
                .getBean("redmineHttpRequestService");
        result = redmineHttpRequestService.doPost(url, param, api_key);
    } else if (requestType == "PUT" || "PUT".equals(requestType)) {
        url = getRedmineUrl(request.getRequestURL().toString());
        api_key = getSessionApiKey(request);
        if (api_key == null || "".equals(api_key)) {
            return;
        }
        param = getParam(request.getInputStream());
        WebApplicationContext webAppContext = ContextLoader.getCurrentWebApplicationContext();
        RedmineHttpRequestService redmineHttpRequestService = (RedmineHttpRequestService) webAppContext
                .getBean("redmineHttpRequestService");
        result = redmineHttpRequestService.doPut(url, param, api_key);
    } else {
        return;
    }

    response.getWriter().write(result);
    return;

}

From source file:com.groupon.odo.controllers.ClientController.java

@ExceptionHandler(Exception.class)
public @ResponseBody HashMap<String, Object> handleException(Exception ex, WebRequest request,
        HttpServletResponse response) {
    response.setHeader("Content-Type", "application/json");
    response.setStatus(HttpServletResponse.SC_BAD_REQUEST);

    HashMap<String, Object> returnVal = new HashMap<String, Object>();
    returnVal.put("message", ex.getMessage());
    returnVal.put("httpCode", HttpServletResponse.SC_BAD_REQUEST);

    HashMap<String, Object> errorVal = new HashMap<String, Object>();
    errorVal.put("error", returnVal);
    return errorVal;
}

From source file:be.fedict.eid.idp.sp.PhotoServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    LOG.debug("doGet");
    response.setContentType("image/jpg");
    response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate, max-age=-1"); // http 1.1
    response.setHeader("Pragma", "no-cache, no-store"); // http 1.0
    response.setDateHeader("Expires", -1);
    ServletOutputStream out = response.getOutputStream();
    HttpSession session = request.getSession();

    byte[] photoData = (byte[]) session.getAttribute(PHOTO_SESSION_ATTRIBUTE);

    if (null != photoData) {
        BufferedImage photo = ImageIO.read(new ByteArrayInputStream(photoData));
        if (null == photo) {
            /*//from   ww w  .j  av a2 s.c  om
             * In this case we render a photo containing some error message.
             */
            photo = new BufferedImage(140, 200, BufferedImage.TYPE_INT_RGB);
            Graphics2D graphics = (Graphics2D) photo.getGraphics();
            RenderingHints renderingHints = new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING,
                    RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
            graphics.setRenderingHints(renderingHints);
            graphics.setColor(Color.WHITE);
            graphics.fillRect(1, 1, 140 - 1 - 1, 200 - 1 - 1);
            graphics.setColor(Color.RED);
            graphics.setFont(new Font("Dialog", Font.BOLD, 20));
            graphics.drawString("Photo Error", 0, 200 / 2);
            graphics.dispose();
            ImageIO.write(photo, "jpg", out);
        } else {
            out.write(photoData);
        }
    }
    out.close();
}

From source file:com.zlfun.framework.excel.ExcelUtils.java

public static <T> void httpOutput(String name, Class<T> clazz, List<T> list, HttpServletRequest request,
        HttpServletResponse response) {
    try {//from   w w w. j  a v  a 2  s .  c  o  m
        request.setCharacterEncoding("UTF-8");//request???
        String fileName = name;//??
        String contentType = "application/vnd.ms-excel";//?
        String recommendedName = new String(fileName.getBytes(), "iso_8859_1");//????
        response.setContentType(contentType);//?
        response.setHeader("Content-Disposition", "attachment; filename=" + recommendedName + "\"");//
        response.resetBuffer();
        //?
        ServletOutputStream sos = response.getOutputStream();
        write(name, clazz, list, sos);
        sos.flush();
        sos.close();
    } catch (UnsupportedEncodingException ex) {
        Logger.getLogger(ExcelUtils.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(ExcelUtils.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:elw.miniweb.ViewJackson.java

public void render(Map model, HttpServletRequest request, HttpServletResponse resp) throws Exception {
    resp.setContentType(getContentType() + "; charset=UTF-8");
    resp.setCharacterEncoding("UTF-8");

    resp.setHeader("Pragma", "no-cache");
    resp.setHeader("Cache-Control", "no-cache");
    resp.setDateHeader("Expires", System.currentTimeMillis());

    MAPPER.writeValue(resp.getWriter(), stateOrData);
}