All pastes #2126184 Raw Edit

Miscellany

public text v1 · immutable
#2126184 ·published 2012-03-08 16:57 UTC
rendered paste body
package org.exoplatform.portal.gadget.core;

import com.google.inject.Singleton;

import com.google.inject.Inject;

import org.apache.shindig.gadgets.http.BasicHttpFetcher;

import org.apache.shindig.gadgets.http.HttpResponse;
import org.apache.shindig.gadgets.GadgetException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.Cookie;
import org.exoplatform.portal.webui.util.Util;

/**
 * The goal of Http Fetcher subclass is to overwrite the default timeout in BasicHttpFetcher 
 * which is quite short time to make a conversion if the server is slow.
 * 
 * @author <a href="trong.tran@exoplatform.com">Trong Tran</a>
 * @version $Revision$
 */


@Singleton
public class ExoHttpFetcher extends BasicHttpFetcher
{
   private static final int DEFAULT_CONNECT_TIMEOUT_MS = 15000;
   private static final int DEFAULT_MAX_OBJECT_SIZE = 1024 * 1024;

   @Inject
   public ExoHttpFetcher()
   {
      super(DEFAULT_MAX_OBJECT_SIZE, DEFAULT_CONNECT_TIMEOUT_MS, DEFAULT_CONNECT_TIMEOUT_MS, null);
   }
   @Override
   public HttpResponse fetch(org.apache.shindig.gadgets.http.HttpRequest request) throws GadgetException {
       client.addRequestInterceptor(new HttpRequestInterceptor() {
           public void process(
               final org.apache.http.HttpRequest request,
               final HttpContext context) throws HttpException, IOException {
                  //JBEPP-1502: Gadget Export/Import not working with Proxy that requires security Cookie - Set the request cookie
                  Cookie[] cookies = Util.getPortalRequestContext().getRequest().getCookies();
                  String cookie = "";
                  for(int i = 0; i <  cookies.length; i++){
                      cookie+=cookies[i].getName()+"="+cookies[i].getValue()+";";
                  }
                  request.addHeader("Cookie", cookie);
           }
       });
      return super.fetch(request);
   }

}