List of usage examples for com.liferay.portal.kernel.servlet HttpHeaders IF_MODIFIED_SINCE
String IF_MODIFIED_SINCE
To view the source code for com.liferay.portal.kernel.servlet HttpHeaders IF_MODIFIED_SINCE.
Click Source Link
From source file:com.liferay.faces.bridge.ext.filter.internal.LiferayPortletRequest.java
License:Open Source License
public LiferayPortletRequest(PortletRequest portletRequest, String responseNamespace, PortletConfig portletConfig) {/*from w ww.j a v a2 s . c om*/ if (portletRequest != null) { while (portletRequest instanceof PortletRequestWrapper) { PortletRequestWrapper portletRequestWrapper = (PortletRequestWrapper) portletRequest; portletRequest = portletRequestWrapper.getRequest(); } } this.wrappedPortletRequest = portletRequest; this.distinctRequestScopedManagedBeans = LiferayPortletConfigParam.DistinctRequestScopedManagedBeans .getBooleanValue(portletConfig); try { Method method = wrappedPortletRequest.getClass().getMethod(METHOD_NAME_GET_PORTLET, (Class[]) null); this.portlet = (Portlet) method.invoke(wrappedPortletRequest, (Object[]) null); } catch (Exception e) { logger.error(e.getMessage(), e); } try { Method method = wrappedPortletRequest.getClass() .getMethod(METHOD_NAME_GET_ORIGINAL_HTTP_SERVLET_REQUEST, (Class[]) null); this.liferayHttpServletRequest = new LiferayHttpServletRequest( (HttpServletRequest) method.invoke(wrappedPortletRequest, (Object[]) null)); } catch (Exception e) { logger.error(e.getMessage(), e); } this.propertyNameList = new ArrayList<String>(); boolean foundIfModifiedSince = false; boolean foundUserAgent = false; Enumeration<String> propertyNames = portletRequest.getPropertyNames(); while (propertyNames.hasMoreElements() && !foundUserAgent) { String propertyName = propertyNames.nextElement(); propertyNameList.add(propertyName); if (HttpHeaders.IF_MODIFIED_SINCE.equals(propertyName)) { foundIfModifiedSince = true; } else if (HttpHeaders.USER_AGENT.equals(propertyName)) { foundUserAgent = true; } } if (!foundIfModifiedSince) { Enumeration<String> headerNames = liferayHttpServletRequest.getHeaderNames(); while (headerNames.hasMoreElements() && !foundIfModifiedSince) { String headerName = headerNames.nextElement(); foundIfModifiedSince = (HttpHeaders.IF_MODIFIED_SINCE.equalsIgnoreCase(headerName)); } if (foundIfModifiedSince) { propertyNameList.add(HttpHeaders.IF_MODIFIED_SINCE); } } if (!foundUserAgent) { Enumeration<String> headerNames = liferayHttpServletRequest.getHeaderNames(); while (headerNames.hasMoreElements() && !foundUserAgent) { String headerName = headerNames.nextElement(); foundUserAgent = (HttpHeaders.USER_AGENT.equalsIgnoreCase(headerName)); } if (foundUserAgent) { propertyNameList.add(HttpHeaders.USER_AGENT); } } this.distinctRequestScopedManagedBeans = LiferayPortletConfigParam.DistinctRequestScopedManagedBeans .getBooleanValue(portletConfig); this.responseNamespace = responseNamespace; }
From source file:com.liferay.faces.bridge.ext.filter.internal.LiferayPortletRequest.java
License:Open Source License
public Enumeration<String> getProperties(String name) { Enumeration<String> properties = wrappedPortletRequest.getProperties(name); if (!properties.hasMoreElements() && (HttpHeaders.USER_AGENT.equals(name) || HttpHeaders.IF_MODIFIED_SINCE.equals(name))) { properties = liferayHttpServletRequest.getHeaders(name); }/* www . j a va 2 s. c o m*/ return properties; }
From source file:com.liferay.httpservice.servlet.ResourceServlet.java
License:Open Source License
@Override public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { try {//from w w w .j a va 2s . c o m String requestURI = getRequestURI(request); int aliasIndex = requestURI.indexOf(_alias); if (aliasIndex == 0) { requestURI = requestURI.substring(_alias.length()); } if (Validator.isNotNull(_name)) { requestURI = _name.concat(requestURI); } URL url = _httpContext.getResource(requestURI); if (url == null) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); return; } URLConnection urlConnection = url.openConnection(); long lastModified = urlConnection.getLastModified(); if (lastModified > 0) { long ifModifiedSince = request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE); if ((ifModifiedSince > 0) && (ifModifiedSince == lastModified)) { response.setContentLength(0); response.setDateHeader(HttpHeaders.LAST_MODIFIED, lastModified); String ifNoneMatch = request.getHeader(HttpHeaders.IF_NONE_MATCH); if (Validator.isNotNull(ifNoneMatch) && !ifNoneMatch.equals('0')) { response.setHeader(HttpHeaders.ETAG, ifNoneMatch); } response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); return; } } if (lastModified > 0) { response.setDateHeader(HttpHeaders.LAST_MODIFIED, lastModified); } String fileName = getRequestURI(request); int slashIndex = fileName.lastIndexOf(StringPool.SLASH); if (slashIndex != -1) { fileName = fileName.substring(slashIndex + 1); } String contentType = _httpContext.getMimeType(fileName); if (isSupportsRangeHeader(contentType)) { sendFileWithRangeHeader(request, response, fileName, urlConnection.getInputStream(), urlConnection.getContentLength(), contentType); } else { ServletResponseUtil.sendFile(request, response, fileName, urlConnection.getInputStream(), urlConnection.getContentLength(), contentType); } } catch (Exception e) { PortalUtil.sendError(HttpServletResponse.SC_NOT_FOUND, e, request, response); } }
From source file:com.liferay.wsrp.servlet.ProxyServlet.java
License:Open Source License
protected void proxyURL(HttpServletRequest request, HttpServletResponse response, URL url) throws Exception { URLConnection urlConnection = url.openConnection(); urlConnection.setIfModifiedSince(request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE)); HttpSession session = request.getSession(); String cookie = (String) session.getAttribute(WebKeys.COOKIE); if (Validator.isNotNull(cookie)) { urlConnection.setRequestProperty(HttpHeaders.COOKIE, cookie); }/*from ww w. ja v a 2s. com*/ boolean useCaches = true; Enumeration<String> enumeration = request.getHeaderNames(); while (enumeration.hasMoreElements()) { String headerName = enumeration.nextElement(); if (StringUtil.equalsIgnoreCase(headerName, HttpHeaders.COOKIE) || StringUtil.equalsIgnoreCase(headerName, HttpHeaders.IF_MODIFIED_SINCE)) { continue; } String headerValue = request.getHeader(headerName); if (Validator.isNotNull(headerValue)) { if (StringUtil.equalsIgnoreCase(headerName, HttpHeaders.CACHE_CONTROL) && headerValue.contains(HttpHeaders.CACHE_CONTROL_NO_CACHE_VALUE)) { useCaches = false; } urlConnection.setRequestProperty(headerName, headerValue); } } urlConnection.setUseCaches(useCaches); urlConnection.connect(); response.setContentLength(urlConnection.getContentLength()); response.setContentType(urlConnection.getContentType()); Map<String, List<String>> headers = urlConnection.getHeaderFields(); for (Map.Entry<String, List<String>> entry : headers.entrySet()) { String headerName = entry.getKey(); if (Validator.isNotNull(headerName) && !response.containsHeader(headerName)) { response.setHeader(headerName, urlConnection.getHeaderField(headerName)); } } if (urlConnection instanceof HttpURLConnection) { HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection; response.setStatus(httpURLConnection.getResponseCode()); } ServletResponseUtil.write(response, urlConnection.getInputStream()); }