List of usage examples for com.liferay.portal.kernel.servlet HttpHeaders COOKIE
String COOKIE
To view the source code for com.liferay.portal.kernel.servlet HttpHeaders COOKIE.
Click Source Link
From source file:com.liferay.wsrp.bind.MarkupServiceImpl.java
License:Open Source License
protected void addHeaders(MimeRequest mimeRequest, Http.Options httpOptions) { ClientData clientData = mimeRequest.getClientData(); Extension[] extensions = clientData.getExtensions(); MessageElement[] clientAttributes = ExtensionUtil.getMessageElements(extensions); for (MessageElement clientAttribute : clientAttributes) { String name = clientAttribute.getName(); String value = clientAttribute.getValue(); if (name.equalsIgnoreCase(HttpHeaders.ACCEPT_ENCODING) || name.equalsIgnoreCase(HttpHeaders.CONTENT_LENGTH) || name.equalsIgnoreCase(HttpHeaders.CONTENT_TYPE) || name.equalsIgnoreCase(HttpHeaders.COOKIE)) { continue; }//w w w . ja va 2 s . c o m httpOptions.addHeader(name, value); } }
From source file:com.liferay.wsrp.bind.V2MarkupServiceImpl.java
License:Open Source License
protected void addHeaders(MimeRequest mimeRequest, Http.Options httpOptions) { ClientData clientData = mimeRequest.getClientData(); Extension[] extensions = clientData.getExtensions(); MessageElement[] clientAttributes = ExtensionHelperUtil.getMessageElements(extensions); if (clientAttributes == null) { return;/* ww w.j a v a2 s . c o m*/ } for (MessageElement clientAttribute : clientAttributes) { String name = ExtensionHelperUtil.getNameAttribute(clientAttribute); String value = clientAttribute.getValue(); if (StringUtil.equalsIgnoreCase(name, HttpHeaders.ACCEPT_ENCODING) || StringUtil.equalsIgnoreCase(name, HttpHeaders.CONTENT_LENGTH) || StringUtil.equalsIgnoreCase(name, HttpHeaders.CONTENT_TYPE) || StringUtil.equalsIgnoreCase(name, HttpHeaders.COOKIE)) { continue; } httpOptions.addHeader(name, value); } }
From source file:com.liferay.wsrp.consumer.portlet.ConsumerPortlet.java
License:Open Source License
protected void proxyURL(ResourceRequest resourceRequest, ResourceResponse resourceResponse, String url) throws Exception { PortletSession portletSession = resourceRequest.getPortletSession(); WSRPConsumerPortlet wsrpConsumerPortlet = getWSRPConsumerPortlet(); WSRPConsumer wsrpConsumer = WSRPConsumerLocalServiceUtil .getWSRPConsumer(wsrpConsumerPortlet.getWsrpConsumerId()); Http.Options options = new Http.Options(); options.setLocation(url);// www. j a v a 2s . co m String cookieKey = getSessionKey(WebKeys.COOKIE, resourceRequest, wsrpConsumer); String cookie = (String) portletSession.getAttribute(cookieKey, PortletSession.APPLICATION_SCOPE); if (Validator.isNotNull(cookie)) { Map<String, String> headers = new HashMap<String, String>(); headers.put(HttpHeaders.COOKIE, cookie); options.setHeaders(headers); } byte[] bytes = HttpUtil.URLtoByteArray(options); Http.Response response = options.getResponse(); String contentDisposition = response.getHeader(HttpHeaders.CONTENT_DISPOSITION); if (Validator.isNotNull(contentDisposition)) { resourceResponse.setProperty(HttpHeaders.CONTENT_DISPOSITION, contentDisposition); } int contentLength = response.getContentLength(); if (contentLength >= 0) { resourceResponse.setContentLength(contentLength); } String contentType = response.getContentType(); if (Validator.isNotNull(contentType)) { resourceResponse.setContentType(contentType); } String charSet = getCharSet(contentType); if (ParamUtil.getBoolean(resourceRequest, "wsrp-requiresRewrite")) { String content = rewriteURLs(resourceRequest, resourceResponse, new String(bytes, charSet)); PortletResponseUtil.write(resourceResponse, content); } else { PortletResponseUtil.write(resourceResponse, bytes); } }
From source file:com.liferay.wsrp.portlet.ConsumerPortlet.java
License:Open Source License
protected void proxyURL(ResourceRequest resourceRequest, ResourceResponse resourceResponse, String url) throws Exception { PortletSession portletSession = resourceRequest.getPortletSession(); WSRPConsumerPortlet wsrpConsumerPortlet = getWSRPConsumerPortlet(); WSRPConsumer wsrpConsumer = WSRPConsumerLocalServiceUtil .getWSRPConsumer(wsrpConsumerPortlet.getWsrpConsumerId()); Http.Options options = new Http.Options(); options.setLocation(url);// ww w . j av a2s .c o m String cookieKey = getSessionKey(WebKeys.COOKIE, resourceRequest, wsrpConsumer); String cookie = (String) portletSession.getAttribute(cookieKey, PortletSession.APPLICATION_SCOPE); if (Validator.isNotNull(cookie)) { Map<String, String> headers = new HashMap<String, String>(); headers.put(HttpHeaders.COOKIE, cookie); options.setHeaders(headers); } byte[] bytes = HttpUtil.URLtoByteArray(options); Http.Response response = options.getResponse(); int contentLength = response.getContentLength(); if (contentLength >= 0) { resourceResponse.setContentLength(contentLength); } String contentType = response.getContentType(); if (Validator.isNotNull(contentType)) { resourceResponse.setContentType(contentType); } PortletResponseUtil.write(resourceResponse, bytes); }
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); }// ww w .j ava 2 s. 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()); }