Example usage for javax.servlet.http HttpServletResponse SC_NOT_MODIFIED

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

Introduction

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

Prototype

int SC_NOT_MODIFIED

To view the source code for javax.servlet.http HttpServletResponse SC_NOT_MODIFIED.

Click Source Link

Document

Status code (304) indicating that a conditional GET operation found that the resource was available and not modified.

Usage

From source file:org.apache.solr.servlet.cache.HttpCacheHeaderUtil.java

public static void sendNotModified(HttpServletResponse res) throws IOException {
    res.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
}

From source file:com.handpay.ibenefit.framework.util.WebUtils.java

public static boolean checkIfModifiedSince(HttpServletRequest request, HttpServletResponse response,
        long lastModified) {
    long ifModifiedSince = request.getDateHeader("If-Modified-Since");
    if ((ifModifiedSince != -1) && (lastModified < ifModifiedSince + 1000)) {
        response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        return false;
    }/*from  ww  w  .j  a v a  2 s .  c  o  m*/
    return true;
}

From source file:com.ccf.util.ModDateHeaderUtil.java

/**
 * Sets the HTTP response status to 304 (NOT MODIFIED) if the request contains an
 * If-Modified-Since header that specifies a time that is
 * at or after the time specified by the value of lastModifiedTimeMillis
 * <em>truncated to second granularity</em>.  Returns true if
 * the response status was set, false if not.
 *
 * @param request/*from  www.j a  v a  2s  .  c  o m*/
 * @param response
 * @param lastModifiedTimeMillis
 * @return true if a response status was sent, false otherwise.
 */
public static boolean respondIfNotModified(HttpServletRequest request, HttpServletResponse response,
        long lastModifiedTimeMillis) {
    long sinceDate = request.getDateHeader("If-Modified-Since");
    // truncate to seconds
    lastModifiedTimeMillis -= (lastModifiedTimeMillis % 1000);
    log.debug("since date = " + sinceDate);
    log.debug("last mod date (trucated to seconds) = " + lastModifiedTimeMillis);
    if (lastModifiedTimeMillis <= sinceDate) {
        log.debug("NOT MODIFIED " + request.getRequestURL());
        response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        return true;
    } else {
        return false;
    }
}

From source file:org.apache.roller.weblogger.ui.rendering.util.ModDateHeaderUtil.java

/**
 * Sets the HTTP response status to 304 (NOT MODIFIED) if the request contains an
 * If-Modified-Since header that specifies a time that is
 * at or after the time specified by the value of lastModifiedTimeMillis
 * <em>truncated to second granularity</em>.  Returns true if
 * the response status was set, false if not.
 *
 * @param request//from  www . j  a  va2  s. c om
 * @param response
 * @param lastModifiedTimeMillis
 * @return true if a response status was sent, false otherwise.
 */
public static boolean respondIfNotModified(HttpServletRequest request, HttpServletResponse response,
        long lastModifiedTimeMillis) {
    long sinceDate = 0;
    try {
        sinceDate = request.getDateHeader("If-Modified-Since");
    } catch (IllegalArgumentException ex) {
        // this indicates there was some problem parsing the header value as a date
        return false;
    }

    // truncate to seconds
    lastModifiedTimeMillis -= (lastModifiedTimeMillis % 1000);
    log.debug("since date = " + sinceDate);
    log.debug("last mod date (trucated to seconds) = " + lastModifiedTimeMillis);
    if (lastModifiedTimeMillis <= sinceDate) {
        log.debug("NOT MODIFIED " + request.getRequestURL());
        response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        return true;
    } else {
        return false;
    }
}

From source file:org.openlaszlo.data.HttpData.java

/**
 * @return true if the data was "not modified"
 */
@Override
public boolean notModified() {
    return code == HttpServletResponse.SC_NOT_MODIFIED;
}

From source file:com.cnksi.core.web.utils.Servlets.java

/**
 * ??If-Modified-Since Header, ?.//from w  w  w. jav  a  2s .com
 * 
 * , checkIfModifyfalse ,304 not modify status.
 * 
 * @param lastModified ?.
 */
public static boolean checkIfModifiedSince(HttpServletRequest request, HttpServletResponse response,
        long lastModified) {

    long ifModifiedSince = request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE);
    if ((ifModifiedSince != -1) && (lastModified < ifModifiedSince + 1000)) {
        response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        return false;
    }
    return true;
}

From source file:cc.sion.core.web.Servlets.java

/**
 * ??If-Modified-Since Header, ?.//w w w . j  a va2  s.  c  om
 *
 * , checkIfModifyfalse ,304 not modify status.
 *
 * @param lastModified ?.
 */
public static boolean checkIfModifiedSince(HttpServletRequest request, HttpServletResponse response,
        long lastModified) {
    long ifModifiedSince = request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE);
    if ((ifModifiedSince != -1) && (lastModified < (ifModifiedSince + 1000))) {
        response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        return false;
    }
    return true;
}

From source file:cn.com.qiqi.order.utils.Servlets.java

/**
 * ??If-Modified-Since Header, ?./*from www . j  ava2s. c  o  m*/
 * 
 * , checkIfModifyfalse ,304 not modify status.
 * 
 * @param lastModified ?.
 */
public static boolean checkIfModifiedSince(HttpServletRequest request, HttpServletResponse response,
        long lastModified) {
    long ifModifiedSince = request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE);
    if ((ifModifiedSince != -1) && (lastModified < ifModifiedSince + 1000)) {
        response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        return false;
    }
    return true;
}

From source file:fi.aluesarjat.prototype.SubjectGraphServlet.java

@Override
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) res;

    long ifModifiedSince = request.getDateHeader("If-Modified-Since");
    if (ifModifiedSince >= LAST_MODIFIED) {
        response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        return;/*w w  w. j  a va  2s .com*/
    }

    String subject = request.getRequestURL().toString();
    RDFConnection connection = repository.openConnection();
    try {
        SPARQLQuery query = connection.createQuery(QueryLanguage.SPARQL,
                "CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o }");
        query.setBinding("s", new UID(subject));
        String contentType = getAcceptedType(request, Format.RDFXML);
        response.setDateHeader("Last-Modified", System.currentTimeMillis());
        response.setContentType(contentType);
        query.streamTriples(response.getWriter(), contentType);
    } finally {
        connection.close();
    }

}

From source file:com.dosport.system.utils.ServletUtils.java

/**
 * ??If-Modified-Since Header, ?.//from www.  j av  a 2  s.c o m
 * 
 * , checkIfModifyfalse ,304 not modify status.
 * 
 * @param lastModified
 *            ?.
 */
public static boolean checkIfModifiedSince(HttpServletRequest request, HttpServletResponse response,
        long lastModified) {
    long ifModifiedSince = request.getDateHeader("If-Modified-Since");
    if ((ifModifiedSince != -1) && (lastModified < ifModifiedSince + 1000)) {
        response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        return false;
    }
    return true;
}