Java Code Examples for javax.servlet.http.HttpServletResponse#addDateHeader()
The following examples show how to use
javax.servlet.http.HttpServletResponse#addDateHeader() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResponseHeaderIT.java From glowroot with Apache License 2.0 | 6 votes |
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) { response.setHeader("One", "abc"); response.setHeader("one", "ab"); response.addHeader("one", "xy"); response.setHeader("Two", "1"); response.setHeader("Three", "xyz"); response.setDateHeader("Date-One", 1393553211832L); response.setDateHeader("Date-one", 1393553212832L); response.addDateHeader("Date-one", 1393553213832L); response.setDateHeader("Date-Two", 1393553214832L); response.setDateHeader("Date-Thr", 1393553215832L); response.addDateHeader("Date-Four", 1393553215832L); response.setIntHeader("Int-One", 1); response.setIntHeader("Int-one", 2); response.addIntHeader("Int-one", 3); response.setIntHeader("Int-Two", 4); response.setIntHeader("Int-Thr", 5); response.addIntHeader("Int-Four", 6); response.addHeader("X-One", "xy"); response.addDateHeader("X-one", 1393553216832L); response.addIntHeader("X-one", 6); }
Example 2
Source File: TestExpiresFilter.java From tomcatsrc with Apache License 2.0 | 6 votes |
@Test public void testExcludedResponseStatusCode() throws Exception { HttpServlet servlet = new HttpServlet() { private static final long serialVersionUID = 1L; @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); response.addHeader("ETag", "W/\"1934-1269208821000\""); response.addDateHeader("Date", System.currentTimeMillis()); } }; validate(servlet, null, HttpServletResponse.SC_NOT_MODIFIED); }
Example 3
Source File: BasicLTISecurityServiceImpl.java From sakai with Educational Community License v2.0 | 6 votes |
private void sendHTMLPage(HttpServletResponse res, String body) { try { res.setContentType("text/html; charset=UTF-8"); res.setCharacterEncoding("utf-8"); res.addDateHeader("Expires", System.currentTimeMillis() - (1000L * 60L * 60L * 24L * 365L)); res.addDateHeader("Last-Modified", System.currentTimeMillis()); res.addHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0"); res.addHeader("Pragma", "no-cache"); java.io.PrintWriter out = res.getWriter(); out.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"); out.println("<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">"); out.println("<html>\n<head>"); out.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />"); out.println("</head>\n<body>\n"); out.println(body); out.println("\n</body>\n</html>"); } catch (Exception e) { log.warn("Failed to send HTML page.", e); } }
Example 4
Source File: TestExpiresFilter.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
@Test public void testSkipBecauseExpiresIsDefined() throws Exception { HttpServlet servlet = new HttpServlet() { private static final long serialVersionUID = 1L; @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/xml; charset=utf-8"); response.addDateHeader("Expires", System.currentTimeMillis()); response.getWriter().print("Hello world"); } }; validate(servlet, null); }
Example 5
Source File: TestExpiresFilter.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Test public void testExcludedResponseStatusCode() throws Exception { HttpServlet servlet = new HttpServlet() { private static final long serialVersionUID = 1L; @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); response.addHeader("ETag", "W/\"1934-1269208821000\""); response.addDateHeader("Date", System.currentTimeMillis()); } }; validate(servlet, null, HttpServletResponse.SC_NOT_MODIFIED); }
Example 6
Source File: SkinnableCharonPortal.java From sakai with Educational Community License v2.0 | 5 votes |
public void sendResponse(PortalRenderContext rcontext, HttpServletResponse res, String template, String contentType) throws IOException { // headers if (contentType == null) { res.setContentType("text/html; charset=UTF-8"); } else { res.setContentType(contentType); } res.addDateHeader("Expires", System.currentTimeMillis() - (1000L * 60L * 60L * 24L * 365L)); res.addDateHeader("Last-Modified", System.currentTimeMillis()); res .addHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0"); res.addHeader("Pragma", "no-cache"); // get the writer PrintWriter out = res.getWriter(); try { PortalRenderEngine rengine = rcontext.getRenderEngine(); rengine.render(template, rcontext, out); } catch (Exception e) { throw new RuntimeException("Failed to render template ", e); } }
Example 7
Source File: CourierTool.java From sakai with Educational Community License v2.0 | 5 votes |
/** * Send a redirect so our "top" ends up at the url, via javascript. * * @param url * The redirect url */ protected void sendTopRedirect(HttpServletResponse res, String url) throws IOException { res.setContentType("text/plain; charset=UTF-8"); res.addDateHeader("Expires", System.currentTimeMillis() - (1000L * 60L * 60L * 24L * 365L)); res.addDateHeader("Last-Modified", System.currentTimeMillis()); res.addHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0"); res.addHeader("Pragma", "no-cache"); // get the writer PrintWriter out = res.getWriter(); // we are on deep under the main portal window out.println("parent.location.replace('" + url + "');"); }
Example 8
Source File: BinaryView.java From studio with GNU General Public License v3.0 | 5 votes |
@Override protected void prepareResponse(HttpServletRequest request, HttpServletResponse response) { response.setContentType(getContentType()); response.setCharacterEncoding(DEFAULT_CHARACTER_ENCODING); if (disableCaching) { response.addHeader(PRAGMA_HEADER_NAME, DISABLED_CACHING_PRAGMA_HEADER_VALUE); response.addHeader(CACHE_CONTROL_HEADER_NAME, DISABLED_CACHING_CACHE_CONTROL_HEADER_VALUE); response.addDateHeader(EXPIRES_HEADER_NAME, DISABLED_CACHING_EXPIRES_HEADER_VALUE); } }
Example 9
Source File: RpcServlet.java From Brutusin-RPC with Apache License 2.0 | 5 votes |
/** * * @param req * @param resp * @param cachingInfo * @param etag * @throws IOException */ private void addCacheHeaders(HttpServletRequest req, HttpServletResponse resp, CachingInfo cachingInfo, String etag) throws IOException { // max-age overrides expires. For legacy proxies (intermedy) cache control is ignored and no cache is performed, the desired behaviour for a private cache. See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9.3 resp.addDateHeader("Expires", 0); if (cachingInfo == null) { resp.addHeader("Cache-Control", "max-age=0, no-cache, no-store"); resp.addHeader("Pragma", "no-cache"); } else { StringBuilder cacheControl = new StringBuilder("max-age=").append(cachingInfo.getMaxAge()); if (cachingInfo.isShared()) { cacheControl.append(", public"); } else { cacheControl.append(", private"); } if (!cachingInfo.isStore()) { cacheControl.append(", no-store"); } cacheControl.append(", must-revalidate"); resp.addHeader("Cache-Control", cacheControl.toString()); if (etag != null) { resp.setHeader("ETag", "W/\"" + etag + "\""); } if (req.getMethod().equals("POST")) { addContentLocation(req, resp); } } }
Example 10
Source File: FastJsonJsonView.java From uavstack with Apache License 2.0 | 5 votes |
@Override protected void prepareResponse(HttpServletRequest request, // HttpServletResponse response) { setResponseContentType(request, response); response.setCharacterEncoding(fastJsonConfig.getCharset().name()); if (this.disableCaching) { response.addHeader("Pragma", "no-cache"); response.addHeader("Cache-Control", "no-cache, no-store, max-age=0"); response.addDateHeader("Expires", 1L); } }
Example 11
Source File: NoCacheFilter.java From hadoop with Apache License 2.0 | 5 votes |
@Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletResponse httpRes = (HttpServletResponse) res; httpRes.setHeader("Cache-Control", "no-cache"); long now = System.currentTimeMillis(); httpRes.addDateHeader("Expires", now); httpRes.addDateHeader("Date", now); httpRes.addHeader("Pragma", "no-cache"); chain.doFilter(req, res); }
Example 12
Source File: AbstractView.java From ymate-platform-v2 with Apache License 2.0 | 5 votes |
@Override public IView addDateHeader(String name, long date) { HttpServletResponse _response = WebContext.getResponse(); if (_response.containsHeader(name)) { _response.addDateHeader(name, date); } else { _response.setDateHeader(name, date); } return this; }
Example 13
Source File: PresenceTool.java From sakai with Educational Community License v2.0 | 5 votes |
/** * Start the response. * * @param req * @param res * @param title * @param skin * @return * @throws IOException */ protected PrintWriter startResponse(HttpServletRequest req, HttpServletResponse res, String title) throws IOException { // headers res.setContentType("text/html; charset=UTF-8"); res.addDateHeader("Expires", System.currentTimeMillis() - (1000L * 60L * 60L * 24L * 365L)); res.addDateHeader("Last-Modified", System.currentTimeMillis()); res.addHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0"); res.addHeader("Pragma", "no-cache"); // get the writer PrintWriter out = res.getWriter(); if ( "yes".equals(req.getParameter(OUTPUT_FRAGMENT) ) ) return out; // form the head out.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" " + "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">" + "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">" + " <head>" + " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />"); out.println("<title>" + rb.getString("insite") + "</title>"); // send the portal set-up head String head = (String) req.getAttribute("sakai.html.head"); if (head != null) { out.println(head); } out.println("</head>"); // Note: we ignore the portal set-up body onload // start the body out.println("<body>"); return out; }
Example 14
Source File: SkinnableLogin.java From sakai with Educational Community License v2.0 | 5 votes |
public void sendResponse(LoginRenderContext rcontext, HttpServletResponse res, String template, String contentType) throws IOException { // headers if (contentType == null) { res.setContentType("text/html; charset=UTF-8"); } else { res.setContentType(contentType); } res.addDateHeader("Expires", System.currentTimeMillis() - (1000L * 60L * 60L * 24L * 365L)); res.addDateHeader("Last-Modified", System.currentTimeMillis()); res.addHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0"); res.addHeader("Pragma", "no-cache"); // get the writer PrintWriter out = res.getWriter(); try { LoginRenderEngine rengine = rcontext.getRenderEngine(); rengine.render(template, rcontext, out); } catch (Exception e) { throw new RuntimeException("Failed to render template ", e); } }
Example 15
Source File: AuthnPortal.java From sakai with Educational Community License v2.0 | 5 votes |
protected PrintWriter startResponse(HttpServletResponse res, String title, String skin) throws IOException { // headers res.setContentType("text/html; charset=UTF-8"); res.addDateHeader("Expires", System.currentTimeMillis() - (1000L * 60L * 60L * 24L * 365L)); res.addDateHeader("Last-Modified", System.currentTimeMillis()); res.addHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0"); res.addHeader("Pragma", "no-cache"); // get the writer PrintWriter out = res.getWriter(); // form the head out.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" " + "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">" + "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">" + " <head>" + " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />"); // pick the one full portal skin if (skin == null) skin = ServerConfigurationService.getString("skin.default"); String skinRepo = ServerConfigurationService.getString("skin.repo"); out.println(" <link href=\"" + skinRepo + "/" + skin + "/portal.css\" type=\"text/css\" rel=\"stylesheet\" media=\"all\" />"); out.println(" <meta http-equiv=\"Content-Style-Type\" content=\"text/css\" />" + " <title>" + title + "</title>" + " <script type=\"text/javascript\" language=\"JavaScript\" src=\"" + getScriptPath() + "headscripts.js\"></script>" + " </head>"); // start the body out.println("<body marginwidth=\"0\" marginheight=\"0\" topmargin=\"0\" leftmargin=\"0\">"); return out; }
Example 16
Source File: AuthnPortal.java From sakai with Educational Community License v2.0 | 5 votes |
protected PrintWriter startResponse(HttpServletResponse res, String title, String skin) throws IOException { // headers res.setContentType("text/html; charset=UTF-8"); res.addDateHeader("Expires", System.currentTimeMillis() - (1000L * 60L * 60L * 24L * 365L)); res.addDateHeader("Last-Modified", System.currentTimeMillis()); res.addHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0"); res.addHeader("Pragma", "no-cache"); // get the writer PrintWriter out = res.getWriter(); // form the head out.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" " + "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">" + "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">" + " <head>" + " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />"); // pick the one full portal skin if (skin == null) skin = ServerConfigurationService.getString("skin.default"); String skinRepo = ServerConfigurationService.getString("skin.repo"); out.println(" <link href=\"" + skinRepo + "/" + skin + "/portal.css\" type=\"text/css\" rel=\"stylesheet\" media=\"all\" />"); out.println(" <meta http-equiv=\"Content-Style-Type\" content=\"text/css\" />" + " <title>" + title + "</title>" + " <script type=\"text/javascript\" language=\"JavaScript\" src=\"" + getScriptPath() + "headscripts.js\"></script>" + " </head>"); // start the body out.println("<body marginwidth=\"0\" marginheight=\"0\" topmargin=\"0\" leftmargin=\"0\">"); return out; }
Example 17
Source File: Http2JettyServlet.java From tutorials with MIT License | 5 votes |
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.addHeader("Cache-control", "no-store, no-cache, must-revalidate"); response.addDateHeader("Last-Modified", 0); response.addDateHeader("Expires", 0); String requestPath = request.getRequestURI(); InputStream input = getServletContext().getResourceAsStream(requestPath); OutputStream output = response.getOutputStream(); byte[] buffer = new byte[1024]; int read; while ((read = input.read(buffer)) >= 0) { output.write(buffer, 0, read); } }
Example 18
Source File: LtiController.java From lams with GNU General Public License v2.0 | 4 votes |
/** * Starts a lesson. Then prompts to learnerMonitor page or autosubmitForm (in case of ContentItemSelectionRequest). */ @RequestMapping("/startLesson") public String startLesson(HttpServletRequest request, HttpServletResponse response) throws IOException, UserAccessDeniedException, RepositoryCheckedException, UserInfoValidationException, UserInfoFetchException { Integer userId = getUser().getUserID(); User user = getRealUser(getUser()); String consumerKey = request.getParameter(LtiUtils.OAUTH_CONSUMER_KEY); String resourceLinkId = request.getParameter(BasicLTIConstants.RESOURCE_LINK_ID); String title = request.getParameter(CentralConstants.PARAM_TITLE); String desc = request.getParameter(CentralConstants.PARAM_DESC); String ldIdStr = request.getParameter(CentralConstants.PARAM_LEARNING_DESIGN_ID); String extCourseId = request.getParameter(BasicLTIConstants.CONTEXT_ID); Integer organisationId = WebUtil.readIntParam(request, CentralConstants.ATTR_COURSE_ID); boolean enableLessonIntro = WebUtil.readBooleanParam(request, "enableLessonIntro", false); //only monitors are allowed to create lesson if (!securityService.isGroupMonitor(organisationId, userId, "add lesson", false)) { response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a monitor in the organisation"); return null; } ExtServer extServer = integrationService.getExtServer(consumerKey); Organisation organisation = monitoringService.getOrganisation(organisationId); // 1. init lesson Boolean liveEditEnabled = extServer.getLiveEditEnabled() == null ? false : extServer.getLiveEditEnabled(); Lesson lesson = monitoringService.initializeLesson(title, desc, new Long(ldIdStr), organisation.getOrganisationId(), user.getUserId(), null, false, enableLessonIntro, extServer.getLearnerPresenceAvailable(), extServer.getLearnerImAvailable(), liveEditEnabled, extServer.getEnableLessonNotifications(), extServer.getForceLearnerRestart(), extServer.getAllowLearnerRestart(), extServer.getGradebookOnComplete(), null, null); Long lessonId = lesson.getLessonId(); // 2. create lessonClass for lesson List<User> staffList = new LinkedList<>(); staffList.add(user); List<User> learnerList = new LinkedList<>(); Vector<User> learnerVector = userManagementService .getUsersFromOrganisationByRole(organisation.getOrganisationId(), Role.LEARNER, true); learnerList.addAll(learnerVector); monitoringService.createLessonClassForLesson(lessonId, organisation, organisation.getName() + "Learners", learnerList, organisation.getName() + "Staff", staffList, user.getUserId()); // 3. start lesson monitoringService.startLesson(lessonId, user.getUserId()); // store information which extServer has started the lesson /* * Blackboard sends a resource link ID which corresponds to a content space and not the LAMS lesson which is * being created. * If we map the received ID to a newly created lesson right now, then we can not create another lesson for this * content space. It is because we receive the content space ID which is already mapped to a lesson and we * display the lesson instead of authoring interface. * The real ID is only received when an user enters the lesson and only then we can create the mapping. * * BUT if there is another integration client which does not use deep linking and sends proper resource link ID * right away, then this may need adjusting. */ integrationService.createExtServerLessonMap(lessonId, extServer); integrationService.addUsersUsingMembershipService(extServer, lessonId, extCourseId, resourceLinkId); //support for ContentItemSelectionRequest String ltiMessageType = request.getParameter(BasicLTIConstants.LTI_MESSAGE_TYPE); String contentItemReturnUrl = request.getParameter(LtiUtils.CONTENT_ITEM_RETURN_URL); if (LtiUtils.LTI_MESSAGE_TYPE_CONTENTITEMSELECTIONREQUEST.equals(ltiMessageType)) { String opaqueTCData = request.getParameter("data"); // Get the post data for the placement String returnValues = postLaunchHTML(extServer, lesson, contentItemReturnUrl, opaqueTCData); response.setContentType("text/html; charset=UTF-8"); response.setCharacterEncoding("utf-8"); response.addDateHeader("Expires", System.currentTimeMillis() - (1000L * 60L * 60L * 24L * 365L)); response.addDateHeader("Last-Modified", System.currentTimeMillis()); response.addHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0"); response.addHeader("Pragma", "no-cache"); ServletOutputStream out = response.getOutputStream(); out.println("<!DOCTYPE html>"); out.println("<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">"); out.println("<html>\n<head>"); out.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />"); out.println("</head>\n<body>"); out.println(returnValues); out.println("</body>\n</html>"); return null; //regular BasicLTI request } else { //set roles to contain monitor so that the user can see monitor link String redirectURL = "redirect:/lti/learnerMonitor.do"; redirectURL = WebUtil.appendParameterToURL(redirectURL, LtiUtils.OAUTH_CONSUMER_KEY, consumerKey); redirectURL = WebUtil.appendParameterToURL(redirectURL, BasicLTIConstants.RESOURCE_LINK_ID, resourceLinkId); redirectURL = WebUtil.appendParameterToURL(redirectURL, BasicLTIConstants.CONTEXT_ID, extCourseId); return redirectURL; } }
Example 19
Source File: JCacheFilter.java From commons-jcs with Apache License 2.0 | 4 votes |
@Override public void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse, final FilterChain filterChain) throws IOException, ServletException { boolean gzip = false; if (HttpServletRequest.class.isInstance(servletRequest)) { final Enumeration<String> acceptEncoding = HttpServletRequest.class.cast(servletRequest).getHeaders("Accept-Encoding"); while (acceptEncoding != null && acceptEncoding.hasMoreElements()) { if ("gzip".equals(acceptEncoding.nextElement())) { gzip = true; break; } } } final HttpServletResponse httpServletResponse = HttpServletResponse.class.cast(servletResponse); checkResponse(httpServletResponse); final PageKey key = new PageKey(key(servletRequest), gzip); Page page = cache.get(key); if (page == null) { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final InMemoryResponse response; if (gzip) { response = new InMemoryResponse(httpServletResponse, new GZIPOutputStream(baos)); } else { response = new InMemoryResponse(httpServletResponse, baos); } filterChain.doFilter(servletRequest, response); response.flushBuffer(); page = new Page( response.getStatus(), response.getContentType(), response.getContentLength(), response.getCookies(), response.getHeaders(), baos.toByteArray()); cache.put(key, page); } if (page.status == SC_OK) { checkResponse(httpServletResponse); if (gzip) { httpServletResponse.setHeader("Content-Encoding", "gzip"); } httpServletResponse.setStatus(page.status); if (page.contentType != null) { httpServletResponse.setContentType(page.contentType); } if (page.contentLength > 0) { httpServletResponse.setContentLength(page.contentLength); } for (final Cookie c : page.cookies) { httpServletResponse.addCookie(c); } for (final Map.Entry<String, List<Serializable>> entry : page.headers.entrySet()) { for (final Serializable value : entry.getValue()) { if (Integer.class.isInstance(value)) { httpServletResponse.addIntHeader(entry.getKey(), Integer.class.cast(value)); } else if (String.class.isInstance(value)) { httpServletResponse.addHeader(entry.getKey(), String.class.cast(value)); } else if (Long.class.isInstance(value)) { httpServletResponse.addDateHeader(entry.getKey(), Long.class.cast(value)); } } } httpServletResponse.setContentLength(page.out.length); final BufferedOutputStream bos = new BufferedOutputStream(httpServletResponse.getOutputStream()); if (page.out.length != 0) { bos.write(page.out); } else { bos.write(new byte[0]); } bos.flush(); } }
Example 20
Source File: ClientCacheTemplate.java From n2o-framework with Apache License 2.0 | 4 votes |
protected void setLastModified(HttpServletRequest req, HttpServletResponse resp, long lastModified) { resp.addDateHeader(LAST_MODIFIED, lastModified); }