List of usage examples for javax.servlet.http HttpServletResponse addDateHeader
public void addDateHeader(String name, long date);
From source file:org.smartfrog.services.cloudfarmer.client.web.servlets.AbstractMombasaServlet.java
/** * Turn off caching and say that the response expires now * @param response the response//w w w.j av a2s. co m */ protected void disableCaching(HttpServletResponse response) { response.addDateHeader("Expires", System.currentTimeMillis()); response.addHeader("Cache-Control", "no-cache"); response.addHeader("Pragma", "no-cache"); }
From source file:org.springframework.flex.http.AmfView.java
/** * {@inheritDoc}// w w w.j a va2 s . co m */ @Override protected void prepareResponse(HttpServletRequest request, HttpServletResponse response) { response.setContentType(getContentType()); response.setCharacterEncoding("UTF-8"); if (disableCaching) { response.addHeader("Pragma", "no-cache"); response.addHeader("Cache-Control", "no-cache, no-store, max-age=0"); response.addDateHeader("Expires", 1L); } }
From source file:org.theospi.portfolio.matrix.util.MatrixJsfTool.java
@Override protected void dispatch(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { logger.debug("dispatch()"); String target = req.getPathInfo(); ToolSession session = sessionManager.getCurrentToolSession(); if (logger.isDebugEnabled()) { Map<String, String[]> reqParms = req.getParameterMap(); for (Map.Entry<String, String[]> entry : reqParms.entrySet()) { StringBuffer sb = new StringBuffer(); sb.append("REQ_PARM: "); sb.append(entry.getKey());//from w w w.j a va 2 s . co m sb.append(" = "); sb.append('['); String[] reqParm = entry.getValue(); for (int i = 0; i < reqParm.length;) { sb.append(reqParm[i]); if (++i < reqParm.length) { sb.append(", "); } } sb.append(']'); logger.debug(sb.toString()); } Enumeration<String> sessionParmNames = session.getAttributeNames(); while (sessionParmNames.hasMoreElements()) { String sessionParmName = sessionParmNames.nextElement(); logger.debug("SESS_PARM: " + sessionParmName + " = " + session.getAttribute(sessionParmName)); } } // see if this is the helper trying to return to caller if (HELPER_RETURN_NOTIFICATION.equals(target)) { target = (String) session.getAttribute(toolManager.getCurrentTool().getId() + Tool.HELPER_DONE_URL); if (target != null) { // FIXME: Workaround for // http://bugs.sakaiproject.org/jira/browse/GM-88 Object viewCollection = session.getAttribute(STORED_MYFACES_VIEW_COLLECTION); if (viewCollection != null) { session.removeAttribute(STORED_MYFACES_VIEW_COLLECTION); session.setAttribute(MYFACES_VIEW_COLLECTION, viewCollection); } session.removeAttribute(toolManager.getCurrentTool().getId() + Tool.HELPER_DONE_URL); res.sendRedirect(target); return; } } // Need this here until ToolServlet is updated to support this in // sendToHelper method // http://bugs.sakaiproject.org/jira/browse/SAK-9043 // http://bugs.sakaiproject.org/jira/browse/GM-69 Enumeration<String> params = req.getParameterNames(); while (params.hasMoreElements()) { String paramName = params.nextElement(); if (paramName.startsWith(HELPER_SESSION_PREFIX)) { String attributeName = paramName.substring(HELPER_SESSION_PREFIX.length()); session.setAttribute(attributeName, req.getParameter(paramName)); } } if (sendToHelper(req, res, target)) { return; } // see if we have a resource request - i.e. a path with an extension, // and one that is not the JSF_EXT if (isResourceRequest(target)) { // get a dispatcher to the path RequestDispatcher resourceDispatcher = getServletContext().getRequestDispatcher(target); if (resourceDispatcher != null) { resourceDispatcher.forward(req, res); return; } } if ("Title".equals(req.getParameter(PANEL))) { // This allows only one Title JSF for each tool target = "/title.jsf"; } else { if ((target == null) || "/".equals(target)) { target = computeDefaultTarget(); // make sure it's a valid path if (!target.startsWith("/")) { target = "/" + target; } // now that we've messed with the URL, send a redirect to make // it official res.sendRedirect(Web.returnUrl(req, target)); return; } // see if we want to change the specifically requested view String newTarget = redirectRequestedTarget(target); // make sure it's a valid path if (!newTarget.startsWith("/")) { newTarget = "/" + newTarget; } if (!newTarget.equals(target)) { // now that we've messed with the URL, send a redirect to make // it official res.sendRedirect(Web.returnUrl(req, newTarget)); return; } target = newTarget; // store this if (m_defaultToLastView) { session.setAttribute(LAST_VIEW_VISITED, target); } } // add the configured folder root and extension (if missing) target = m_path + target; // add the default JSF extension (if we have no extension) int lastSlash = target.lastIndexOf('/'); int lastDot = target.lastIndexOf('.'); if ((lastDot < 0) || (lastDot < lastSlash)) { target += JSF_EXT; } // set the information that can be removed from return URLs req.setAttribute(URL_PATH, m_path); req.setAttribute(URL_EXT, ".jsp"); // set the sakai request object wrappers to provide the native, not // Sakai set up, URL information // - this assures that the FacesServlet can dispatch to the proper view // based on the path info req.setAttribute(Tool.NATIVE_URL, Tool.NATIVE_URL); // TODO: Should setting the HTTP headers be moved up to the portal level // as well? 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"); // dispatch to the target /* * M_log.debug("dispatching path: " + req.getPathInfo() + " to: " + * target + " context: " + getServletContext().getServletContextName()); */ RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(target); dispatcher.forward(req, res); // restore the request object req.removeAttribute(Tool.NATIVE_URL); req.removeAttribute(URL_PATH); req.removeAttribute(URL_EXT); }
From source file:org.theospi.portfolio.portal.web.XsltPortal.java
protected void outputDocument(HttpServletRequest req, HttpServletResponse res, Session session, Document doc, Transformer transformer) throws IOException { 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"); PrintWriter out = res.getWriter(); try {//www.j a v a2s . c om StreamResult outputTarget = new StreamResult(out); transformer.transform(new DOMSource(doc), outputTarget); } catch (TransformerException e) { throw new RuntimeException(e); } }
From source file:org.wings.externalizer.AbstractExternalizeManager.java
public void deliver(ExternalizedResource extInfo, HttpServletResponse response, Device out) throws IOException { /* FIXME: re-implement. if ( extInfo.deliverOnce() ) {/*from w w w . ja v a2s . co m*/ removeExternalizedResource(identifier); } */ if (extInfo.getMimeType() != null) { response.setContentType(extInfo.getMimeType()); } // FIXME find out, if this is correct: if the content length // is not size preserving (like a gzip-device), then we must not // send the content size we know.. if (out.isSizePreserving()) { int resourceLen = extInfo.getExternalizer().getLength(extInfo.getObject()); if (resourceLen > 0) { LOG.debug(extInfo.getMimeType() + ": " + resourceLen); response.setContentLength(resourceLen); } } Collection headers = extInfo.getHeaders(); if (headers != null) { for (Object header : headers) { Map.Entry entry = (Map.Entry) header; if (entry.getValue() instanceof String) { response.addHeader((String) entry.getKey(), (String) entry.getValue()); } else if (entry.getValue() instanceof Date) { response.addDateHeader((String) entry.getKey(), ((Date) entry.getValue()).getTime()); } else if (entry.getValue() instanceof Integer) { response.addIntHeader((String) entry.getKey(), ((Integer) entry.getValue()).intValue()); } // end of if () } } if (!response.containsHeader("Expires")) { /* * This would be the correct way to do it; alas, that means, that * for static resources, after a day or so, no caching could take * place, since the last modification was at the first time, the * resource was externalized (since it doesn't change). * .. have to think about it. */ //response.setDateHeader("Expires", // (1000*FINAL_EXPIRES) // + extInfo.getLastModified()); // .. so do this for now, which is the best approximation of what // we want. response.setDateHeader("Expires", System.currentTimeMillis() + (1000 * FINAL_EXPIRES)); } try { extInfo.getExternalizer().write(extInfo.getObject(), out); } catch (ResourceNotFoundException e) { LOG.debug("Unable to deliver resource due to: " + e.getMessage() + ". Sending 404!"); response.reset(); response.sendError(404, e.getMessage()); } out.flush(); }
From source file:org.wso2.carbon.core.services.authentication.BasicAccessAuthenticator.java
/** * This method will create a 401 unauthorized response to be sent.We also need * to set ServerAuthenticator.CONTINUE_PROCESSING to "false" as we need to make sure that message will not passed * to other handlers.//ww w . ja v a2 s .c o m * @param msgContext The request message context */ private void createUnAuthorizedResponse(MessageContext msgContext) { String serverName = ServerConfiguration.getInstance().getFirstProperty("Name"); HttpServletResponse response = (HttpServletResponse) msgContext .getProperty(HTTPConstants.MC_HTTP_SERVLETRESPONSE); if (response != null) { response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); response.addHeader("Server", "WSO2 Server"); response.addDateHeader("Date", Calendar.getInstance().getTimeInMillis()); response.addHeader("WWW-Authenticate", "Basic realm=\"" + serverName + "\""); response.setContentType("text/html"); } else { // if not servlet transport assume it to be nhttp transport msgContext.setProperty("NIO-ACK-Requested", "true"); msgContext.setProperty("HTTP_SC", HttpServletResponse.SC_UNAUTHORIZED); Map<String, String> responseHeaders = new HashMap<String, String>(); responseHeaders.put("WWW-Authenticate", "Basic realm=\"" + serverName + "\""); responseHeaders.put("Server", "WSO2 Server"); responseHeaders.put("Date", Long.toString(Calendar.getInstance().getTimeInMillis())); msgContext.setProperty(MessageContext.TRANSPORT_HEADERS, responseHeaders); } msgContext.setProperty(ServerAuthenticator.CONTINUE_PROCESSING, "false"); RequestResponseTransport transportControl = (RequestResponseTransport) msgContext .getProperty(RequestResponseTransport.TRANSPORT_CONTROL); if (transportControl != null) { transportControl.setResponseWritten(true); } }