Package org.gatein.pc.api.invocation.response

Examples of org.gatein.pc.api.invocation.response.ContentResponse


               cachedEntry = null;
               userContext.setAttribute(scopeKey, null);
            }
         }

         ContentResponse fragment = cachedEntry != null ? cachedEntry.contentRef.getContent() : null;

         // If no valid fragment we must invoke
         if (fragment == null || cachedEntry.expirationTimeMillis < System.currentTimeMillis())
         {
            // Set validation token for revalidation only we have have a fragment
            if (fragment != null)
            {
               renderInvocation.setValidationToken(cachedEntry.validationToken);
            }

            // Invoke
            PortletInvocationResponse response = super.invoke(invocation);

            // Try to cache any fragment result
            CacheControl control = null;
            if (response instanceof ContentResponse)
            {
               fragment = (ContentResponse)response;
               control = fragment.getCacheControl();
            }
            else if (response instanceof RevalidateMarkupResponse)
            {
               RevalidateMarkupResponse revalidate = (RevalidateMarkupResponse)response;
               control = revalidate.getCacheControl();
View Full Code Here


      return renderString;
   }

   protected Response internalProcessResponse(PortletInvocationResponse response)
   {
      ContentResponse content = (ContentResponse)response;
      String itemString = null;
      byte[] itemBinary = null;
      String contentType = content.getContentType();
      Boolean requiresRewriting = Boolean.FALSE;
      switch (content.getType())
      {
         case ContentResponse.TYPE_CHARS:
            itemString = processFragmentString(content.getChars());
            requiresRewriting = Boolean.TRUE; // assume that if we got chars, we'll need to rewrite content
            break;
         case ContentResponse.TYPE_BYTES:
            itemBinary = content.getBytes(); // fix-me: might need to convert to Base64?
            // set rewriting to true if needed
            if (MIMEUtils.needsRewriting(contentType))
            {
               requiresRewriting = Boolean.TRUE;
            }
            break;
         case ContentResponse.TYPE_EMPTY:
            itemString = EMPTY;
            contentType = markupRequest.getMediaType(); // assume we got what we asked for :)
            break;
      }

      LocalMimeResponse mimeResponse = WSRPTypeFactory.createMimeResponse(contentType, itemString, itemBinary, getReifiedClass());

      mimeResponse.setLocale(markupRequest.getLocale());

      //TODO: figure out useCachedItem
      Boolean useCachedItem = false;
      mimeResponse.setRequiresRewriting(requiresRewriting);
      mimeResponse.setUseCachedItem(useCachedItem);

      //TODO: check if anything actually uses the ccpp profile warning
      String ccppProfileWarning = null;
      mimeResponse.setCcppProfileWarning(ccppProfileWarning);

      // cache information
      int expires = content.getCacheControl().getExpirationSecs();
      // only create a CacheControl if expiration time is not 0
      if (expires != 0)
      {
         // if expires is negative, replace by -1 to make sure
         if (expires < 0)
         {
            expires = -1;
         }

         mimeResponse.setCacheControl(WSRPTypeFactory.createCacheControl(expires, WSRPConstants.CACHE_PER_USER));
      }

      // GTNWSRP-336
      final ResponseProperties properties = content.getProperties();
      if (properties != null)
      {
         populateClientAttributesWith(mimeResponse, properties.getTransportHeaders());
         populateClientAttributesWith(mimeResponse, properties.getMarkupHeaders());
      }
View Full Code Here

            PortletInvocationResponse response = context.render(properties.getCookies(), pageNavigationalState, portlet.getContext().getId());

            //
            if (response instanceof ContentResponse)
            {
               ContentResponse fragment = (ContentResponse)response;

               //
               fragments.add(fragment);

               //
               ResponseProperties fragmentProperties = fragment.getProperties();
               if (fragmentProperties != null)
               {
                  renderProperties.append(fragmentProperties);
               }
            }
View Full Code Here

   }

   @Override
   protected ContentResponse createResponse(ResponseProperties props, Map<String, Object> attrs, String contentType, CacheControl cacheControl)
   {
      return new ContentResponse(props, attrs, contentType, cacheControl);
   }
View Full Code Here

   }

   @Override
   protected ContentResponse createResponse(ResponseProperties props, Map<String, Object> attrs, String contentType, byte[] bytes, CacheControl cacheControl)
   {
      return new ContentResponse(props, attrs, contentType, encoding,  bytes, cacheControl);
   }
View Full Code Here

   }

   @Override
   protected ContentResponse createResponse(ResponseProperties props, Map<String, Object> attrs, String contentType, String chars, CacheControl cacheControl)
   {
      return new ContentResponse(props, attrs, contentType, encoding, chars, cacheControl);
   }
View Full Code Here

      }
   }

   protected ContentResponse createMarkupResponse(ResponseProperties properties, Map<String, Object> attributeMap, String contentType, byte[] bytes, String chars, CacheControl cacheControl)
   {
      return new ContentResponse(
         properties,
         attributeMap,
         contentType,
         bytes,
         chars,
View Full Code Here

               userContext.setAttribute(scopeKey, null);
            }
         }

         //
         final ContentResponse cachedContent = cachedEntry != null ? cachedEntry.contentRef.getContent() : null;

         // If no valid content we must invoke
         long now = System.currentTimeMillis();
         if (cachedContent == null || cachedEntry.expirationTimeMillis < now)
         {
            // Set validation token for revalidation only we have have a content
            if (cachedContent != null)
            {
               renderInvocation.setValidationToken(cachedEntry.validationToken);
            }

            // Invoke
            PortletInvocationResponse response = super.invoke(invocation);

            // If we had a cached content that was revalidated we substitute
            if (response instanceof RevalidateMarkupResponse && cachedContent != null)
            {
               // Normally we receive such response when the validation token was set which implies we have an existing content
               // We substitute with the appropriate content response
               RevalidateMarkupResponse revalidate = (RevalidateMarkupResponse)response;
               CacheControl control = revalidate.getCacheControl();
               if (cachedContent instanceof FragmentResponse)
               {
                  response = new FragmentResponse((FragmentResponse)cachedContent, control);
               }
               else
               {
                  response = new ContentResponse(cachedContent, control);
               }
            }

            // If we have a content cache it whenever it is possible
            if (response instanceof ContentResponse)
            {
               ContentResponse contentResponse = (ContentResponse)response;
               CacheControl control = contentResponse.getCacheControl();

               //
               if (control != null)
               {
                  // Compute expiration time, i.e when it will expire
View Full Code Here

                                                             ResponseProperties properties, String mimeType, byte[] bytes, String markup,
                                                             org.gatein.pc.api.cache.CacheControl cacheControl)
   {
      if (markup != null)
      {
         return new ContentResponse(properties, null, mimeType, null, markup, cacheControl);
      }
      else
      {
         return new ContentResponse(properties, null, mimeType, MIMEUtils.UTF_8, bytes, cacheControl);
      }
   }
View Full Code Here

            PortletInvocationResponse pir = resourceResponse.getResponse();

            //
            if (pir instanceof ContentResponse)
            {
               ContentResponse contentResponse = (ContentResponse)pir;

               //
               if (contentResponse.getType() == ContentResponse.TYPE_EMPTY)
               {
                  resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
               }
               else
               {
                  String contentType = contentResponse.getContentType();
                  if (contentType != null)
                  {
                     resp.setContentType(contentType);
                  }

                  //
                  if (contentResponse.getType() == ContentResponse.TYPE_BYTES)
                  {
                     ServletOutputStream out = null;
                     try
                     {
                        out = resp.getOutputStream();
                        out.write(contentResponse.getBytes());
                     }
                     finally
                     {
                        IOTools.safeClose(out);
                     }
                  }
                  else
                  {
                     Writer writer = null;
                     try
                     {
                        writer = resp.getWriter();
                        writer.write(contentResponse.getChars());
                     }
                     finally
                     {
                        writer.close();
                     }
View Full Code Here

TOP

Related Classes of org.gatein.pc.api.invocation.response.ContentResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.