Example usage for javax.servlet.http HttpServletResponse addHeader

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

Introduction

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

Prototype

public void addHeader(String name, String value);

Source Link

Document

Adds a response header with the given name and value.

Usage

From source file:de.thm.arsnova.controller.SessionController.java

@RequestMapping(value = "/{sessionKey}/lecturerquestion/{arg1}/{arg2}/{arg3}")
public String redirectLecturerQuestionWithThreeArguments(@PathVariable final String sessionKey,
        @PathVariable final String arg1, @PathVariable final String arg2, @PathVariable final String arg3,
        final HttpServletResponse response) {
    response.addHeader(X_FORWARDED, "1");

    return String.format("forward:/lecturerquestion/%s/%s/%s/?sessionkey=%s", arg1, arg2, arg3, sessionKey);
}

From source file:de.thm.arsnova.controller.SessionController.java

@RequestMapping(value = "/{sessionKey}/audiencequestion/{arg1}/{arg2}/{arg3}")
public String redirectAudienceQuestionWithThreeArguments(@PathVariable final String sessionKey,
        @PathVariable final String arg1, @PathVariable final String arg2, @PathVariable final String arg3,
        final HttpServletResponse response) {
    response.addHeader(X_FORWARDED, "1");

    return String.format("forward:/audiencequestion/%s/%s/%s/?sessionkey=%s", arg1, arg2, arg3, sessionKey);
}

From source file:com.tasktop.c2c.server.scm.web.GitHandler.java

private void addNoCacheHeaders(HttpServletResponse response) {
    // expire in the past
    response.addHeader("Expires", "Fri, 01 Jan 2000 00:00:00 GMT");
    response.addHeader("Pragma", "no-cache");
    response.addHeader("Cache-Control", "no-cache, max-age=0, must-revalidate");
}

From source file:org.energyos.espi.datacustodian.web.customer.CustomerDownloadMyDataController.java

@RequestMapping(value = Routes.RETAIL_CUSTOMER_DOWNLOAD_MY_DATA, method = RequestMethod.GET)
public void downloadMyData(HttpServletResponse response, @PathVariable Long retailCustomerId,
        @PathVariable Long usagePointId, @RequestParam Map<String, String> params)
        throws IOException, FeedException {
    response.setContentType(MediaType.TEXT_HTML_VALUE);
    response.addHeader("Content-Disposition", "attachment; filename=GreenButtonDownload.xml");
    try {/*  w w  w.  ja  va 2  s  .  c om*/

        exportService.exportUsagePointFull(0L, retailCustomerId, usagePointId, response.getOutputStream(),
                new ExportFilter(params));

    } catch (Exception e) {
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    }
}

From source file:application.controllers.admin.EmotionList.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    response.setCharacterEncoding("UTF-8");
    response.addHeader("Content-Type", "text/html");
    String groupId = request.getParameter("groupId");

    View view = new View("admin", "EmotionList.xtm");
    View codeJSView = new View("assets", "JSEmotionList.xtm");

    //set groupId cho code js emotion
    codeJSView.setVariable("groupIdJS", groupId);
    View layout = new View("Index.xtm");
    view.setVariable("host", Registry.get("Host"));
    view.setVariable("groupId", groupId);
    EmotionBOImpl emotionImpl = new EmotionBOImpl();
    List<EmotionPOJO> listEmotionInGroup = emotionImpl.getEmotionWithGroup(groupId);
    Memcached.set("listEmotionInGroup" + groupId, 3600, listEmotionInGroup);

    //set  table list emotion
    TemplateDataDictionary listEmotionView = view.addSection("listEmotion");
    for (int i = 0; i < listEmotionInGroup.size(); i++) {
        TemplateDataDictionary emotionItem = listEmotionView.addSection("emotionItem");
        //            emotionItem.setVariable("imageId", Integer.toString(i + 1));
        emotionItem.setVariable("imageId", Integer.toString(listEmotionInGroup.get(i).emotionId));
        //lay link trong database set cho image 
        //            emotionItem.setVariable("imageLink", Registry.get("Host") + "/" + listEmotionInGroup.get(i).linkImage);
        emotionItem.setVariable("imageLink", listEmotionInGroup.get(i).linkImage);
        emotionItem.setVariable("description", listEmotionInGroup.get(i).description);
        emotionItem.setVariable("emotionId", Integer.toString(listEmotionInGroup.get(i).emotionId));
        emotionItem.setVariable("emotionIndexInGroup", Integer.toString(i));
        emotionItem.setVariable("groupId", groupId);

    }//from  w  w  w.j  a  v  a 2 s . co m
    String resourceHost = "";
    resourceHost += Registry.get("Host");
    resourceHost = resourceHost + "/resources";
    layout.setVariable("hostResource", resourceHost);

    //show view
    String content = view.render();
    String codeJS = codeJSView.render();
    layout.setVariable("content", content);
    layout.setVariable("codejs", codeJS);
    //Tao view

    String mainView = layout.render();
    response.getWriter().write(mainView);

}

From source file:net.shopxx.controller.admin.CommonController.java

/**
 * ??/*from  w w w.j ava  2  s .c  o  m*/
 */
@RequestMapping("/admin/common/unauthorized")
public String unauthorized(HttpServletRequest request, HttpServletResponse response) {
    String requestType = request.getHeader("X-Requested-With");
    if (requestType != null && requestType.equalsIgnoreCase("XMLHttpRequest")) {
        response.addHeader("loginStatus", "unauthorized");
        try {
            response.sendError(HttpServletResponse.SC_FORBIDDEN);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
    return "/admin/common/unauthorized";
}

From source file:cz.mzk.editor.server.ScanImgServiceImpl.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    resp.addDateHeader("Last-Modified", new Date().getTime());
    resp.addHeader("Cache-Control", "max-age=" + Constants.HTTP_CACHE_SECONDS);
    resp.addDateHeader("Expires", DateUtils.addMonths(new Date(), 1).getTime());
    boolean full = ClientUtils.toBoolean(req.getParameter(Constants.URL_PARAM_FULL));
    String topSpace = req.getParameter(Constants.URL_PARAM_TOP_SPACE);
    String urlHeight = req.getParameter(Constants.URL_PARAM_HEIGHT);

    String uuid = req.getParameter(Constants.URL_PARAM_UUID);

    if (uuid == null || "".equals(uuid)) {
        uuid = req.getRequestURI().substring(req.getRequestURI().indexOf(Constants.SERVLET_SCANS_PREFIX)
                + Constants.SERVLET_SCANS_PREFIX.length() + 1);
    }//from  w w  w .jav a  2s .  c  o  m

    StringBuffer baseUrl = new StringBuffer();
    baseUrl.append("http://");
    if (!URLS.LOCALHOST()) {
        baseUrl.append(req.getServerName());
    } else {
        String hostname = config.getHostname();
        if (hostname.contains("://")) {
            baseUrl.append(hostname.substring(hostname.indexOf("://") + "://".length()));
        } else {
            baseUrl.append(hostname);
        }
    }
    StringBuffer sb = new StringBuffer();
    if (topSpace != null) {
        String metadata = IOUtils.toString(new URL(baseUrl + DJATOKA_URL_GET_METADATA + uuid),
                StandardCharsets.UTF_8);

        String height = null;
        height = metadata.substring(metadata.indexOf("ght\": \"") + 7, metadata.indexOf("\",\n\"dw"));
        String width = metadata.substring(metadata.indexOf("dth\": \"") + 7, metadata.indexOf("\",\n\"he"));

        int intHeight = Integer.parseInt(height);
        int intUrlHeight = Integer.parseInt(urlHeight);
        int intTopSpace = Integer.parseInt(topSpace);
        boolean isLower = intTopSpace > 0 && ((intHeight - intUrlHeight) < intTopSpace);
        String region = (isLower ? intHeight - intUrlHeight : (intTopSpace < 0 ? 0 : topSpace)) + ",1,"
                + urlHeight + "," + width;

        sb.append(baseUrl.toString()).append(DJATOKA_URL_FULL_PAGE_DETAIL).append(uuid)
                .append(DJATOKA_URL_REGION).append(region);

    } else {
        sb.append(baseUrl.toString())
                .append(full ? DJATOKA_URL_FULL_IMG : DJATOKA_URL + urlHeight + DJATOKA_URL_SUFFIX)
                .append(uuid);
    }
    resp.setContentType("image/jpeg");
    resp.sendRedirect(resp.encodeRedirectURL(sb.toString()));
}

From source file:com.threewks.thundr.proxy.ProxyImpl.java

protected void sendResponse(Response proxiedResponse, HttpServletResponse outboundResponse) throws IOException {
    outboundResponse.setStatus(proxiedResponse.status());

    Map<String, String> headers = proxiedResponse.headers();
    for (String name : headers.keySet()) {
        outboundResponse.addHeader(name, headers.get(name));
    }//from w  ww.  j a  va 2 s  .  c o m

    byte[] body = proxiedResponse.body();
    if (body != null) {
        OutputStream os = null;
        try {
            os = outboundResponse.getOutputStream();
            os.write(body);
        } finally {
            if (os != null) {
                os.flush();
                os.close();
            }
        }
    }
}

From source file:org.esigate.servlet.impl.ResponseSender.java

void sendHeaders(HttpResponse httpResponse, IncomingRequest httpRequest, HttpServletResponse response) {
    response.setStatus(httpResponse.getStatusLine().getStatusCode());
    for (Header header : httpResponse.getAllHeaders()) {
        String name = header.getName();
        String value = header.getValue();
        response.addHeader(name, value);
    }/*from w ww.j  a  va  2  s.  c o m*/

    // Copy new cookies
    Cookie[] newCookies = httpRequest.getNewCookies();

    for (int i = 0; i < newCookies.length; i++) {
        response.addHeader("Set-Cookie", CookieUtil.encodeCookie(newCookies[i]));
    }
    HttpEntity httpEntity = httpResponse.getEntity();
    if (httpEntity != null) {
        long contentLength = httpEntity.getContentLength();
        if (contentLength > -1 && contentLength < Integer.MAX_VALUE) {
            response.setContentLength((int) contentLength);
        }
        Header contentType = httpEntity.getContentType();
        if (contentType != null) {
            response.setContentType(contentType.getValue());
        }
        Header contentEncoding = httpEntity.getContentEncoding();
        if (contentEncoding != null) {
            response.setHeader(contentEncoding.getName(), contentEncoding.getValue());
        }
    }
}

From source file:cz.fi.muni.xkremser.editor.server.ScanImgServiceImpl.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    resp.addDateHeader("Last-Modified", new Date().getTime());
    resp.addHeader("Cache-Control", "max-age=" + Constants.HTTP_CACHE_SECONDS);
    resp.addDateHeader("Expires", DateUtils.addMonths(new Date(), 1).getTime());
    boolean full = ClientUtils.toBoolean(req.getParameter(Constants.URL_PARAM_FULL));
    String topSpace = req.getParameter(Constants.URL_PARAM_TOP_SPACE);
    String urlHeight = req.getParameter(Constants.URL_PARAM_HEIGHT);

    String uuid = req.getParameter(Constants.URL_PARAM_UUID);

    if (uuid == null || "".equals(uuid)) {
        uuid = req.getRequestURI().substring(req.getRequestURI().indexOf(Constants.SERVLET_SCANS_PREFIX)
                + Constants.SERVLET_SCANS_PREFIX.length() + 1);
    }/*  w w w .  j av a 2s.  com*/

    StringBuffer baseUrl = new StringBuffer();
    baseUrl.append("http");
    if (req.getProtocol().toLowerCase().contains("https")) {
        baseUrl.append('s');
    }
    baseUrl.append("://");
    if (!URLS.LOCALHOST()) {
        baseUrl.append(req.getServerName());
    } else {
        String hostname = config.getHostname();
        if (hostname.contains("://")) {
            baseUrl.append(hostname.substring(hostname.indexOf("://") + "://".length()));
        } else {
            baseUrl.append(hostname);
        }
    }
    StringBuffer sb = new StringBuffer();
    if (topSpace != null) {
        String metadata = RESTHelper.convertStreamToString(
                RESTHelper.get(baseUrl + DJATOKA_URL_GET_METADATA + uuid, null, null, true));
        String height = null;
        height = metadata.substring(metadata.indexOf("ght\": \"") + 7, metadata.indexOf("\",\n\"dw"));
        String width = metadata.substring(metadata.indexOf("dth\": \"") + 7, metadata.indexOf("\",\n\"he"));

        int intHeight = Integer.parseInt(height);
        int intUrlHeight = Integer.parseInt(urlHeight);
        int intTopSpace = Integer.parseInt(topSpace);
        boolean isLower = intTopSpace > 0 && ((intHeight - intUrlHeight) < intTopSpace);
        String region = (isLower ? intHeight - intUrlHeight : (intTopSpace < 0 ? 0 : topSpace)) + ",1,"
                + urlHeight + "," + width;

        sb.append(baseUrl.toString()).append(DJATOKA_URL_FULL_PAGE_DETAIL).append(uuid)
                .append(DJATOKA_URL_REGION).append(region);

    } else {
        sb.append(baseUrl.toString())
                .append(full ? DJATOKA_URL_FULL_IMG : DJATOKA_URL + urlHeight + DJATOKA_URL_SUFFIX)
                .append(uuid);
    }
    resp.setContentType("image/jpeg");
    resp.sendRedirect(resp.encodeRedirectURL(sb.toString()));
}