// Path: aemsolrsearch-services/src/main/java/com/headwire/aemsolrsearch/services/ProxyConfigurationService.java
// @Component(
//         name = "com.headwire.aemsolrsearch.services.ProxyConfigurationService",
//         label = "AEM Solr Search - Solr Proxy Service",
//         description = "A service for configuring the search proxy",
//         immediate = true,
//         metatype = true)
// @Service(ProxyConfigurationService.class)
// @Properties({
//         @Property(
//                 name = Constants.SERVICE_VENDOR,
//                 value = "headwire.com, Inc."),
//         @Property(
//                 name = Constants.SERVICE_DESCRIPTION,
//                 value = "CQ Search proxy configuration service"),
//         @Property(
//                 name = ProxyConfigurationServiceAdminConstants.HTTP_CONN_TIMEOUT,
//                 intValue = 10000,
//                 label = "Connection Timeout",
//                 description = "Connection timeout in ms"),
//         @Property(
//                 name = ProxyConfigurationServiceAdminConstants.HTTP_SO_TIMEOUT,
//                 intValue = 30000,
//                 label = "Socket Timeout",
//                 description = "Socket timeout in ms")
// })
// /**
//  * ProxyConfigurationService provides services for setting and getting proxy configuration information.
//  */
// public class ProxyConfigurationService {
// 
//     private static final Logger LOG = LoggerFactory.getLogger(ProxyConfigurationService.class);
//     private Integer httpConnTimeout;
//     private Integer httpSoTimeout;
// 
//     public static final Integer DEFAULT_HTTP_CONN_TIMEOUT = 10000;
//     public static final Integer DEFAULT_HTTP_SO_TIMEOUT= 30000;
// 
//     public Integer getHttpConnTimeout() {
//         return httpConnTimeout;
//     }
// 
//     public Integer getHttpSoTimeout() {
//         return httpSoTimeout;
//     }
// 
//     @Activate
//     protected void activate(final Map<String, Object> config) {
//         resetService(config);
//     }
// 
//     @Modified
//     protected void modified(final Map<String, Object> config) {
//         resetService(config);
//     }
// 
//     private synchronized void resetService(final Map<String, Object> config) {
//         LOG.info("Resetting CQ Search proxy configuration service using configuration: " + config);
// 
//         httpConnTimeout = config.containsKey(ProxyConfigurationServiceAdminConstants.HTTP_CONN_TIMEOUT) ?
//                 (Integer)config.get(ProxyConfigurationServiceAdminConstants.HTTP_CONN_TIMEOUT) : DEFAULT_HTTP_CONN_TIMEOUT;
// 
//         httpSoTimeout = config.containsKey(ProxyConfigurationServiceAdminConstants.HTTP_SO_TIMEOUT) ?
//                 (Integer)config.get(ProxyConfigurationServiceAdminConstants.HTTP_SO_TIMEOUT) : DEFAULT_HTTP_SO_TIMEOUT;
//     }
// }


import com.headwire.aemsolrsearch.services.ProxyConfigurationService;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.http.*;
import org.apache.http.client.HttpClient;
import org.apache.http.client.utils.URIUtils;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.apache.http.message.BasicHeader;
import org.apache.http.message.BasicHttpEntityEnclosingRequest;
import org.apache.http.message.BasicHttpRequest;
import org.apache.http.message.HeaderGroup;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.CoreConnectionPNames;
import org.apache.http.params.HttpParams;
import org.apache.http.util.EntityUtils;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.Closeable;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.URI;
import java.util.BitSet;
import java.util.Enumeration;
import java.util.Formatter;
/*
 * Author  : Gaston Gonzalez
 * Date    : 8/12/13
 * Version : $Id$
 */
package com.headwire.aemsolrsearch.services.servlets;



@Component(componentAbstract = true)
/**
 * ProxyServlet provides a basic proxy. It is based on David Smiley's HTTP-Proxy-Servlet
 * (https://github.com/dsmiley/HTTP-Proxy-Servlet).
 */
public abstract class ProxyServlet extends SlingSafeMethodsServlet {

    private static final Logger LOG = LoggerFactory.getLogger(ProxyServlet.class);
    protected HttpClient proxyClient;
    protected URI targetUri;

    @Reference
// Path: aemsolrsearch-services/src/main/java/com/headwire/aemsolrsearch/services/ProxyConfigurationService.java
// @Component(
//         name = "com.headwire.aemsolrsearch.services.ProxyConfigurationService",
//         label = "AEM Solr Search - Solr Proxy Service",
//         description = "A service for configuring the search proxy",
//         immediate = true,
//         metatype = true)
// @Service(ProxyConfigurationService.class)
// @Properties({
//         @Property(
//                 name = Constants.SERVICE_VENDOR,
//                 value = "headwire.com, Inc."),
//         @Property(
//                 name = Constants.SERVICE_DESCRIPTION,
//                 value = "CQ Search proxy configuration service"),
//         @Property(
//                 name = ProxyConfigurationServiceAdminConstants.HTTP_CONN_TIMEOUT,
//                 intValue = 10000,
//                 label = "Connection Timeout",
//                 description = "Connection timeout in ms"),
//         @Property(
//                 name = ProxyConfigurationServiceAdminConstants.HTTP_SO_TIMEOUT,
//                 intValue = 30000,
//                 label = "Socket Timeout",
//                 description = "Socket timeout in ms")
// })
// /**
//  * ProxyConfigurationService provides services for setting and getting proxy configuration information.
//  */
// public class ProxyConfigurationService {
// 
//     private static final Logger LOG = LoggerFactory.getLogger(ProxyConfigurationService.class);
//     private Integer httpConnTimeout;
//     private Integer httpSoTimeout;
// 
//     public static final Integer DEFAULT_HTTP_CONN_TIMEOUT = 10000;
//     public static final Integer DEFAULT_HTTP_SO_TIMEOUT= 30000;
// 
//     public Integer getHttpConnTimeout() {
//         return httpConnTimeout;
//     }
// 
//     public Integer getHttpSoTimeout() {
//         return httpSoTimeout;
//     }
// 
//     @Activate
//     protected void activate(final Map<String, Object> config) {
//         resetService(config);
//     }
// 
//     @Modified
//     protected void modified(final Map<String, Object> config) {
//         resetService(config);
//     }
// 
//     private synchronized void resetService(final Map<String, Object> config) {
//         LOG.info("Resetting CQ Search proxy configuration service using configuration: " + config);
// 
//         httpConnTimeout = config.containsKey(ProxyConfigurationServiceAdminConstants.HTTP_CONN_TIMEOUT) ?
//                 (Integer)config.get(ProxyConfigurationServiceAdminConstants.HTTP_CONN_TIMEOUT) : DEFAULT_HTTP_CONN_TIMEOUT;
// 
//         httpSoTimeout = config.containsKey(ProxyConfigurationServiceAdminConstants.HTTP_SO_TIMEOUT) ?
//                 (Integer)config.get(ProxyConfigurationServiceAdminConstants.HTTP_SO_TIMEOUT) : DEFAULT_HTTP_SO_TIMEOUT;
//     }
// }


// Path: aemsolrsearch-services/src/main/java/com/headwire/aemsolrsearch/services/servlets/ProxyServlet.java
import com.headwire.aemsolrsearch.services.ProxyConfigurationService;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.http.*;
import org.apache.http.client.HttpClient;
import org.apache.http.client.utils.URIUtils;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.apache.http.message.BasicHeader;
import org.apache.http.message.BasicHttpEntityEnclosingRequest;
import org.apache.http.message.BasicHttpRequest;
import org.apache.http.message.HeaderGroup;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.CoreConnectionPNames;
import org.apache.http.params.HttpParams;
import org.apache.http.util.EntityUtils;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.Closeable;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.URI;
import java.util.BitSet;
import java.util.Enumeration;
import java.util.Formatter;

/*
 * Author  : Gaston Gonzalez
 * Date    : 8/12/13
 * Version : $Id$
 */
package com.headwire.aemsolrsearch.services.servlets;



@Component(componentAbstract = true)
/**
 * ProxyServlet provides a basic proxy. It is based on David Smiley's HTTP-Proxy-Servlet
 * (https://github.com/dsmiley/HTTP-Proxy-Servlet).
 */
public abstract class ProxyServlet extends SlingSafeMethodsServlet {

    private static final Logger LOG = LoggerFactory.getLogger(ProxyServlet.class);
    protected HttpClient proxyClient;
    protected URI targetUri;

    @Reference
    protected ProxyConfigurationService proxyConfigurationService;