List of usage examples for javax.servlet.http HttpServletResponse SC_NOT_MODIFIED
int SC_NOT_MODIFIED
To view the source code for javax.servlet.http HttpServletResponse SC_NOT_MODIFIED.
Click Source Link
From source file:fi.aluesarjat.prototype.ContextAccessServlet.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;//from w w w . j av a 2s . c o m } String context = request.getRequestURL().toString(); RDFConnection connection = repository.openConnection(); try { SPARQLQuery query = connection.createQuery(QueryLanguage.SPARQL, "CONSTRUCT { ?s ?p ?o } WHERE { GRAPH ?context { ?s ?p ?o } }"); query.setBinding("context", new UID(context)); String contentType = null; String format = request.getParameter("format"); if ("turtle".equals(format)) { contentType = Format.TURTLE.getMimetype(); } else if ("ntriples".equals(format)) { contentType = Format.NTRIPLES.getMimetype(); } else { 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.carolinarollergirls.scoreboard.jetty.XmlScoreBoardServlet.java
protected void get(HttpServletRequest request, HttpServletResponse response) throws IOException, JDOMException { XmlListener listener = getXmlListenerForRequest(request); if (null == listener) { registrationKeyNotFound(request, response); return;/*from w ww. j a v a 2 s . c om*/ } Document d = listener.getDocument(LONGPOLL_TIMEOUT); if (null == d) { if (debugGet) ScoreBoardManager.printMessage("GET to " + listener.getKey() + " no change"); response.sendError(HttpServletResponse.SC_NOT_MODIFIED); } else { if (debugGet) ScoreBoardManager .printMessage("GET to " + listener.getKey() + "\n" + prettyXmlOutputter.outputString(d)); response.setContentType("text/xml"); rawXmlOutputter.output(d, response.getOutputStream()); response.setStatus(HttpServletResponse.SC_OK); } }
From source file:com.thoughtworks.go.domain.ChecksumFileHandler.java
public boolean handleResult(int returncode, GoPublisher goPublisher) { if (returncode == HttpServletResponse.SC_NOT_FOUND) { deleteQuietly(checksumFile);//from w ww . ja va2 s . c om goPublisher.taggedConsumeLineWithPrefix(GoPublisher.ERR, "[WARN] The md5checksum property file was not found on the server. Hence, Go can not verify the integrity of the artifacts."); return true; } if (returncode == HttpServletResponse.SC_NOT_MODIFIED) { LOG.info("[Agent Fetch Artifact] Not downloading checksum file as it has not changed"); return true; } if (returncode == HttpServletResponse.SC_OK) { LOG.info("[Agent Fetch Artifact] Saved checksum property file [{}]", checksumFile); return true; } return returncode < HttpServletResponse.SC_BAD_REQUEST; }
From source file:com.handpay.ibenefit.framework.util.WebUtils.java
public static boolean checkIfNoneMatchEtag(HttpServletRequest request, HttpServletResponse response, String etag) {//from ww w . j a va 2 s . c om String headerValue = request.getHeader("If-None-Match"); if (headerValue != null) { boolean conditionSatisfied = false; if (!"*".equals(headerValue)) { StringTokenizer commaTokenizer = new StringTokenizer(headerValue, ","); while (!conditionSatisfied && commaTokenizer.hasMoreTokens()) { String currentToken = commaTokenizer.nextToken(); if (currentToken.trim().equals(etag)) { conditionSatisfied = true; } } } else { conditionSatisfied = true; } if (conditionSatisfied) { response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); response.setHeader("ETag", etag); return false; } } return true; }
From source file:com.cloud.servlet.StaticResourceServlet.java
@Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { final File requestedFile = getRequestedFile(req); if (!requestedFile.exists() || !requestedFile.isFile()) { resp.setStatus(HttpServletResponse.SC_NOT_FOUND); return;/*from w ww . j a v a 2 s . com*/ } final String etag = getEtag(requestedFile); if (etag.equals(req.getHeader("If-None-Match"))) { resp.setStatus(HttpServletResponse.SC_NOT_MODIFIED); return; } // have to send data, either compressed or the original final File compressedStatic = getCompressedVersion(requestedFile); InputStream fileContent = null; try { resp.setContentType(getContentType(requestedFile.getName())); resp.setHeader("ETag", etag); resp.setStatus(HttpServletResponse.SC_OK); if (isClientCompressionSupported(req) && compressedStatic.exists()) { // gzip compressed resp.setHeader("Content-Encoding", "gzip"); resp.setContentLength((int) compressedStatic.length()); fileContent = new FileInputStream(compressedStatic); } else { // uncompressed resp.setContentLength((int) requestedFile.length()); fileContent = new FileInputStream(requestedFile); } IOUtils.copy(fileContent, resp.getOutputStream()); } finally { IOUtils.closeQuietly(fileContent); } }
From source file:nl.b3p.viewer.stripes.ImageActionBean.java
public Resolution download() throws FileNotFoundException { final Resource r = Stripersist.getEntityManager().find(Resource.class, name); if (r == null) { return new ErrorResolution(HttpServletResponse.SC_NOT_FOUND); }//from w ww .ja va2 s. c o m if (r.getModified() != null) { long ifModifiedSince = context.getRequest().getDateHeader("If-Modified-Since"); if (ifModifiedSince != -1) { if (ifModifiedSince >= r.getModified().getTime()) { return new ErrorResolution(HttpServletResponse.SC_NOT_MODIFIED); } } } StreamingResolution res = new StreamingResolution(r.getContentType()) { @Override public void stream(HttpServletResponse response) throws Exception { OutputStream out = response.getOutputStream(); InputStream in = new ByteArrayInputStream(r.getData()); IOUtils.copy(in, out); in.close(); } }; res.setLastModified(r.getModified().getTime()); res.setFilename(r.getName()); res.setLength(r.getSize()); res.setAttachment(false); return res; }
From source file:fi.aluesarjat.prototype.AreasServlet.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 ww . j a v a2s . co m*/ } response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.setDateHeader("Last-Modified", System.currentTimeMillis()); response.setHeader("Cache-Control", "max-age=86400"); String level = request.getParameter("level"); String content; if (level == null) { content = areas; } else if ("1".equals(level)) { content = areas1; } else if ("2".equals(level)) { content = areas2; } else if ("3".equals(level)) { content = areas3; } else if ("4".equals(level)) { content = areas4; } else { throw new IllegalArgumentException("Illegal level " + level); } response.getWriter().append(content); response.getWriter().flush(); }
From source file:ch.entwine.weblounge.test.util.TestSiteUtils.java
/** * Test for the correct response when etag header is set. * //from ww w . j av a 2 s . c o m * @param request * the http request * @param eTagValue * the expected etag value * @param logger * used to log test output * @param params * the request parameters * @throws Exception * if processing the request fails */ public static void testETagHeader(HttpUriRequest request, String eTagValue, Logger logger, String[][] params) throws Exception { DefaultHttpClient httpClient = new DefaultHttpClient(); try { request.removeHeaders("If-Modified-Since"); request.setHeader("If-None-Match", eTagValue); logger.info("Sending 'If-None-Match' request to {}", request.getURI()); HttpResponse response = TestUtils.request(httpClient, request, params); assertEquals(HttpServletResponse.SC_NOT_MODIFIED, response.getStatusLine().getStatusCode()); assertNull(response.getEntity()); } finally { httpClient.getConnectionManager().shutdown(); } httpClient = new DefaultHttpClient(); try { request.removeHeaders("If-Modified-Since"); request.setHeader("If-None-Match", "\"abcdefghijklmt\""); logger.info("Sending 'If-None-Match' request to {}", request.getURI()); HttpResponse response = TestUtils.request(httpClient, request, params); assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); assertNotNull(response.getEntity()); response.getEntity().consumeContent(); } finally { httpClient.getConnectionManager().shutdown(); } }
From source file:cn.leancloud.diamond.server.controller.ConfigController.java
public String getConfig(HttpServletRequest request, HttpServletResponse response, String dataId, String group) { response.setHeader("Content-Type", "text/html;charset=UTF-8"); final String address = getRemortIP(request); if (address == null) { // ?400//from w w w . j a v a 2 s. c o m response.setStatus(HttpServletResponse.SC_BAD_REQUEST); return "400"; } if (GlobalCounter.getCounter().decrementAndGet() >= 0) { response.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); return "503"; } String md5 = this.configService.getContentMD5(dataId, group); if (md5 == null) { return "404"; } response.setHeader(Constants.CONTENT_MD5, md5); // 304???double-check?? if (diskService.isModified(dataId, group)) { response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); return "304"; } String path = configService.getConfigInfoPath(dataId, group); // ? if (diskService.isModified(dataId, group)) { response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); return "304"; } // ? response.setHeader("Pragma", "no-cache"); response.setDateHeader("Expires", 0); response.setHeader("Cache-Control", "no-cache,no-store"); return "forward:" + path; }
From source file:org.eclipse.virgo.apps.repository.web.RepositoryController.java
@RequestMapping(method = RequestMethod.GET, value = "/*") void getIndex(HttpServletRequest request, HttpServletResponse response) throws IOException { String path = request.getRequestURI(); String repository = path.substring(path.lastIndexOf('/') + 1); RepositoryIndex index = this.repositoryManager.getIndex(repository); if (index != null) { String indexETag = index.getETag(); String eTagHeader = request.getHeader(IF_NONE_MATCH_HEADER_NAME); if (eTagHeader != null) { String[] eTags = eTagHeader.split(","); for (String eTag : eTags) { if (eTag.equals(indexETag)) { response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); return; }/*w ww.j ava2 s . c o m*/ } } response.setContentType(INDEX_CONTENT_TYPE); response.setContentLength(index.getLength()); response.addHeader(ETAG_HEADER_NAME, index.getETag()); FileCopyUtils.copy(index.getInputStream(), response.getOutputStream()); } else { response.setStatus(HttpServletResponse.SC_NOT_FOUND); } }