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

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


                    charset = null;
                    transportHeaders = null;
                    content = null;
                } else {
                    //
                    ContentResponse piResponse = (ContentResponse) portletResponse;
                    ResponseProperties properties = piResponse.getProperties();
                    transportHeaders = properties != null ? properties.getTransportHeaders() : null;

                    // Look at status code if there is one and honour it
                    String status = transportHeaders != null ? transportHeaders.getValue(ResourceResponse.HTTP_STATUS_CODE)
                            : null;
                    if (status != null) {
                        try {
                            statusCode = Integer.parseInt(status);
                        } catch (NumberFormatException e) {
                            statusCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
                        }
                    } else {
                        statusCode = HttpServletResponse.SC_OK;
                    }

                    //
                    contentType = piResponse.getContentType();
                    charset = piResponse.getEncoding();

                    //
                    log.trace("Try to get a resource of type: " + contentType + " for the portlet: "
                            + uiPortlet.getId());
                    if (piResponse.getChars() != null) {
                        content = piResponse.getChars();
                    } else if (piResponse.getBytes() != null) {
                        content = piResponse.getBytes();
                    } else {
                        content = null;
                    }
                }
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;
      }

      // create the appropriate MimeResponse subclass based on content of the portlet container ContentResponse
      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: make sure we transmit response properties to the consumer
      final ResponseProperties properties = content.getProperties();
      if (properties != null)
      {
         populateClientAttributesWith(mimeResponse, properties.getTransportHeaders());
         populateClientAttributesWith(mimeResponse, properties.getMarkupHeaders());
      }
View Full Code Here

   protected PortletInvocationResponse createContentResponse(LocalMimeResponse mimeResponse, Invocation invocation,
                                                             ResponseProperties properties, Map<String, Object> attributes,
                                                             String mimeType, byte[] bytes, String markup,
                                                             org.gatein.pc.api.cache.CacheControl cacheControl)
   {
      return new ContentResponse(properties, attributes, mimeType, bytes, markup, cacheControl);
   }
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

                    charset = null;
                    transportHeaders = null;
                    content = null;
                } else {
                    //
                    ContentResponse piResponse = (ContentResponse) portletResponse;
                    ResponseProperties properties = piResponse.getProperties();
                    transportHeaders = properties != null ? properties.getTransportHeaders() : null;

                    // Look at status code if there is one and honour it
                    String status = transportHeaders != null ? transportHeaders.getValue(ResourceResponse.HTTP_STATUS_CODE)
                            : null;
                    if (status != null) {
                        try {
                            statusCode = Integer.parseInt(status);
                        } catch (NumberFormatException e) {
                            statusCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
                        }
                    } else {
                        statusCode = HttpServletResponse.SC_OK;
                    }

                    //
                    contentType = piResponse.getContentType();
                    charset = piResponse.getEncoding();

                    //
                    log.trace("Try to get a resource of type: " + contentType + " for the portlet: "
                            + uiPortlet.getPortletContext());
                    if (piResponse.getChars() != null) {
                        content = piResponse.getChars();
                    } else if (piResponse.getBytes() != null) {
                        content = piResponse.getBytes();
                    } else {
                        content = null;
                    }
                }
View Full Code Here

      return super.createRenderURL();
   }

   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

                  throw new Exception("Unexpected response type [" + portletResponse
                     + "]. Expected a ContentResponse or an ErrorResponse.");
               }
            }

            ContentResponse piResponse = (ContentResponse)portletResponse;

            //
            //Manage headers
            if (piResponse.getProperties() != null && piResponse.getProperties().getTransportHeaders() != null)
            {
               MultiValuedPropertyMap<String> transportHeaders = piResponse.getProperties().getTransportHeaders();
               Map<String, String> headers = new HashMap<String, String>();

               for (String key : transportHeaders.keySet())
               {
                  for (String value : transportHeaders.getValues(key))
                  {
                     headers.put(key, value);
                  }
               }
               context.setHeaders(headers);
            }

            String contentType = piResponse.getContentType();

            if (contentType == null)
            {
               return;
            }

            log.trace("Try to get a resource of type: " + contentType + " for the portlet: "
               + uiPortlet.getPortletContext());
            if (contentType.startsWith("text"))
            {
               context.getResponse().setContentType(contentType);
               context.getWriter().write(piResponse.getContent());
            }
            else
            {
               response.setContentType(contentType);
               if (piResponse.getBytes() != null)
               {
                   OutputStream stream = response.getOutputStream();
                 stream.write(piResponse.getBytes());
               }
               else
               {
                 if (piResponse.getChars() != null)
                 {
                   log.error("Received a content type of " + contentType + " but it contains no bytes of data. Chars were unexpectantly returned instead : " + piResponse.getChars());
                 }
                 else
                 {
                   log.error("Received a content type of " + contentType + " but it contains no bytes of data.");
                 }
View Full Code Here

                    charset = null;
                    transportHeaders = null;
                    content = null;
                } else {
                    //
                    ContentResponse piResponse = (ContentResponse) portletResponse;
                    ResponseProperties properties = piResponse.getProperties();
                    transportHeaders = properties != null ? properties.getTransportHeaders() : null;

                    // Look at status code if there is one and honour it
                    String status = transportHeaders != null ? transportHeaders.getValue(ResourceResponse.HTTP_STATUS_CODE)
                            : null;
                    if (status != null) {
                        try {
                            statusCode = Integer.parseInt(status);
                        } catch (NumberFormatException e) {
                            statusCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
                        }
                    } else {
                        statusCode = HttpServletResponse.SC_OK;
                    }

                    //
                    contentType = piResponse.getContentType();
                    charset = piResponse.getEncoding();

                    //
                    log.trace("Try to get a resource of type: " + contentType + " for the portlet: "
                            + uiPortlet.getPortletContext());
                    if (piResponse.getChars() != null) {
                        content = piResponse.getChars();
                    } else if (piResponse.getBytes() != null) {
                        content = piResponse.getBytes();
                    } else {
                        content = null;
                    }
                }
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

                  throw new Exception("Unexpected response type [" + portletResponse
                     + "]. Expected a ContentResponse or an ErrorResponse.");
               }
            }

            ContentResponse piResponse = (ContentResponse)portletResponse;

            //
            //Manage headers
            if (piResponse.getProperties() != null && piResponse.getProperties().getTransportHeaders() != null)
            {
               MultiValuedPropertyMap<String> transportHeaders = piResponse.getProperties().getTransportHeaders();
               Map<String, String> headers = new HashMap<String, String>();

               for (String key : transportHeaders.keySet())
               {
                  for (String value : transportHeaders.getValues(key))
                  {
                     headers.put(key, value);
                  }
               }
               context.setHeaders(headers);
            }

            String contentType = piResponse.getContentType();

            if (contentType == null)
            {
               return;
            }

            log.trace("Try to get a resource of type: " + contentType + " for the portlet: "
               + uiPortlet.getPortletContext());
            if (contentType.startsWith("text"))
            {
               context.getResponse().setContentType(contentType);
               context.getWriter().write(piResponse.getContent());
            }
            else
            {
               response.setContentType(contentType);
               if (piResponse.getBytes() != null)
               {
                   OutputStream stream = response.getOutputStream();
                 stream.write(piResponse.getBytes());
               }
               else
               {
                 if (piResponse.getChars() != null)
                 {
                   log.error("Received a content type of " + contentType + " but it contains no bytes of data. Chars were unexpectantly returned instead : " + piResponse.getChars());
                 }
                 else
                 {
                   log.error("Received a content type of " + contentType + " but it contains no bytes of data.");
                 }
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.