Index: trunk/src/main/resources/ajaxproxy_local.properties =================================================================== diff -u --- trunk/src/main/resources/ajaxproxy_local.properties (revision 0) +++ trunk/src/main/resources/ajaxproxy_local.properties (revision 3988) @@ -0,0 +1,3 @@ +#Remote Assets Url +lemansServicesBaseUrl=http://localhost:8080 + Index: trunk/src/main/webapp/META-INF/MANIFEST.MF =================================================================== diff -u --- trunk/src/main/webapp/META-INF/MANIFEST.MF (revision 0) +++ trunk/src/main/webapp/META-INF/MANIFEST.MF (revision 3988) @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + Index: trunk/.project =================================================================== diff -u --- trunk/.project (revision 0) +++ trunk/.project (revision 3988) @@ -0,0 +1,42 @@ + + + ajaxproxy + + + + + + org.eclipse.wst.jsdt.core.javascriptValidator + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + org.maven.ide.eclipse.maven2Builder + + + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.jdt.core.javanature + org.maven.ide.eclipse.maven2Nature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.wst.jsdt.core.jsNature + + Index: trunk/.settings/.jsdtscope =================================================================== diff -u --- trunk/.settings/.jsdtscope (revision 0) +++ trunk/.settings/.jsdtscope (revision 3988) @@ -0,0 +1,11 @@ + + + + + + + + + + + Index: trunk/src/main/resources/log4j.properties =================================================================== diff -u --- trunk/src/main/resources/log4j.properties (revision 0) +++ trunk/src/main/resources/log4j.properties (revision 3988) @@ -0,0 +1,9 @@ +log4j.rootLogger=WARN, console +log4j.appender.console=org.apache.log4j.ConsoleAppender +log4j.appender.console.layout=org.apache.log4j.PatternLayout +log4j.appender.console.layout.ConversionPattern=%d %p [%c] - %m%n + +log4j.category.com.lemans=DEBUG + +log4j.category.org.apache.commons.httpclient = ERROR +log4j.category.httpclient.wire = ERROR Index: trunk/src/main/resources/ajaxproxy_wamas.properties =================================================================== diff -u --- trunk/src/main/resources/ajaxproxy_wamas.properties (revision 0) +++ trunk/src/main/resources/ajaxproxy_wamas.properties (revision 3988) @@ -0,0 +1,2 @@ +#Remote Assets Url +lemansServicesBaseUrl=http://beast3:8001 Index: trunk/.settings/org.eclipse.wst.jsdt.ui.superType.name =================================================================== diff -u --- trunk/.settings/org.eclipse.wst.jsdt.ui.superType.name (revision 0) +++ trunk/.settings/org.eclipse.wst.jsdt.ui.superType.name (revision 3988) @@ -0,0 +1 @@ +Window \ No newline at end of file Index: trunk/.classpath =================================================================== diff -u --- trunk/.classpath (revision 0) +++ trunk/.classpath (revision 3988) @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + Index: trunk/src/main/resources/ajaxproxy_prod.properties =================================================================== diff -u --- trunk/src/main/resources/ajaxproxy_prod.properties (revision 0) +++ trunk/src/main/resources/ajaxproxy_prod.properties (revision 3988) @@ -0,0 +1,2 @@ +#Remote Assets Url +lemansServicesBaseUrl=http://services.lemanscorp.com Index: trunk/.settings/org.maven.ide.eclipse.prefs =================================================================== diff -u --- trunk/.settings/org.maven.ide.eclipse.prefs (revision 0) +++ trunk/.settings/org.maven.ide.eclipse.prefs (revision 3988) @@ -0,0 +1,9 @@ +#Tue Mar 02 09:47:26 CST 2010 +activeProfiles= +eclipse.preferences.version=1 +fullBuildGoals=process-test-resources +includeModules=false +resolveWorkspaceProjects=true +resourceFilterGoals=process-resources resources\:testResources +skipCompilerPlugin=true +version=1 Index: trunk/.settings/org.eclipse.wst.jsdt.ui.superType.container =================================================================== diff -u --- trunk/.settings/org.eclipse.wst.jsdt.ui.superType.container (revision 0) +++ trunk/.settings/org.eclipse.wst.jsdt.ui.superType.container (revision 3988) @@ -0,0 +1 @@ +org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file Index: trunk/.settings/org.eclipse.jdt.core.prefs =================================================================== diff -u --- trunk/.settings/org.eclipse.jdt.core.prefs (revision 0) +++ trunk/.settings/org.eclipse.jdt.core.prefs (revision 3988) @@ -0,0 +1,13 @@ +#Tue Mar 02 09:50:26 CST 2010 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.6 Index: trunk/src/main/webapp/WEB-INF/web.xml =================================================================== diff -u --- trunk/src/main/webapp/WEB-INF/web.xml (revision 0) +++ trunk/src/main/webapp/WEB-INF/web.xml (revision 3988) @@ -0,0 +1,16 @@ + + + + ajaxHttpProxy Web Application + + ajaxproxy + com.lemans.web.httpproxy.AjaxProxyServlet + + + ajaxproxy + /* + + + Index: trunk/.settings/org.eclipse.wst.common.component =================================================================== diff -u --- trunk/.settings/org.eclipse.wst.common.component (revision 0) +++ trunk/.settings/org.eclipse.wst.common.component (revision 3988) @@ -0,0 +1,10 @@ + + + + + + + + + + Index: trunk/src/main/webapp/index.jsp =================================================================== diff -u --- trunk/src/main/webapp/index.jsp (revision 0) +++ trunk/src/main/webapp/index.jsp (revision 3988) @@ -0,0 +1,5 @@ + + +

Hello World!

+ + Index: trunk/pom.xml =================================================================== diff -u --- trunk/pom.xml (revision 0) +++ trunk/pom.xml (revision 3988) @@ -0,0 +1,60 @@ + + 4.0.0 + lemans + ajaxproxy + war + HEAD-SNAPSHOT + ajaxproxy + http://maven.apache.org + + ajaxproxy + + + + javax.servlet + servlet-api + 2.4 + provided + + + commons-httpclient + commons-httpclient + 3.1 + compile + + + commons-lang + commons-lang + 2.4 + compile + + + log4j + log4j + 1.2.15 + + + com.sun.jdmk + jmxtools + + + com.sun.jmx + jmxri + + + javax.jms + jms + + + javax.mail + mail + + + + + + 1.6 + 1.6 + + Index: trunk/src/main/java/com/lemans/web/httpproxy/AjaxProxyServlet.java =================================================================== diff -u --- trunk/src/main/java/com/lemans/web/httpproxy/AjaxProxyServlet.java (revision 0) +++ trunk/src/main/java/com/lemans/web/httpproxy/AjaxProxyServlet.java (revision 3988) @@ -0,0 +1,177 @@ +package com.lemans.web.httpproxy; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStreamWriter; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.httpclient.Header; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.HttpException; +import org.apache.commons.httpclient.HttpMethod; +import org.apache.commons.httpclient.NameValuePair; +import org.apache.commons.httpclient.methods.GetMethod; +import org.apache.commons.httpclient.methods.PostMethod; +import org.apache.commons.lang.NotImplementedException; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * Proxy Servlet for cross domain Ajax calls. + * + * @author vkulkarni + * + */ +public class AjaxProxyServlet extends HttpServlet { + + /* Attribute name of Properties in servlet context*/ + private static final String CONFIG_PROPERTIES = "configProperties"; + + /* Lemans Service Base URL*/ + private static final String LEMANS_SERVICES_BASE_URL = "lemansServicesBaseUrl"; + + Log logger = LogFactory.getLog(AjaxProxyServlet.class); + + + public void init(ServletConfig config) throws ServletException { + + super.init(config); + try { + //Read the property file and keep in servlet context. + ServletContext context = getServletConfig().getServletContext(); + String environment = System.getenv("environment"); + logger.error("environment = "+environment); + InputStream is = Thread.currentThread().getContextClassLoader() + .getResourceAsStream("ajaxproxy_" + environment + ".properties"); + Properties configProperties = new Properties(); + configProperties.load(is); + context.setAttribute(CONFIG_PROPERTIES, configProperties); + is.close(); + + } catch (Exception e) { + logger.error("Failed to read servlet config and properties file", e); + } + } + + /** + * Support POST methods as well. + */ + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doGet(request, response); + } + /** + * Make a proxy call to cross domain url + * + * @param request + * @param response + * @param url + * @throws IOException + */ + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + + String pathInfo = request.getPathInfo(); + logger.debug("pathInfo :" + pathInfo); + OutputStreamWriter writer = new OutputStreamWriter(response.getOutputStream()); + try { + + String lemansServicesBaseUrl = (String)((Properties)getServletConfig().getServletContext() + .getAttribute(CONFIG_PROPERTIES)).get(LEMANS_SERVICES_BASE_URL); + + logger.debug("lemansServicesBaseUrl :" + lemansServicesBaseUrl); + + String serviceUrl = lemansServicesBaseUrl + pathInfo; + logger.debug("serviceUrl :" + serviceUrl); + + Map paramMap = request.getParameterMap(); + logger.debug("paramMap :" + paramMap); + + Set keys = paramMap.keySet(); + List nvps = new ArrayList(); + + for (String key : keys) { + String[] values = paramMap.get(key); + for (String value : values) { + NameValuePair nvpMultiple = new NameValuePair(); + nvpMultiple.setName(key); + nvpMultiple.setValue((value)); + nvps.add(nvpMultiple); + } + } + HttpClient client = new HttpClient(); + HttpMethod method = populateParams(request, serviceUrl, nvps); + + // Execute the method + client.executeMethod(method); + + // Set the content type, as it comes from the server + Header[] headers = method.getResponseHeaders(); + for (Header header : headers) { + if ("Content-Type".equalsIgnoreCase(header.getName())) { + response.setContentType(header.getValue()); + } + } + writer.write(method.getResponseBodyAsString()); + logger.debug("Wrote Response back with Client"); + + } catch (HttpException e) { + logger.error("Exception while calling Http proxy", e); + writer.write(e.toString()); + throw e; + + } catch (IOException e) { + logger.error("IO Exception while calling Http proxy", e); + writer.write(e.toString()); + throw e; + } finally { + // Write the body, flush and close + writer.flush(); + writer.close(); + } + + } + + /** + * Populate parameters in the request. + * + * @param request + * @param serviceURL + * @param nvps + * @return + */ + private HttpMethod populateParams(HttpServletRequest request, + String serviceUrl, List nvps) { + + HttpMethod method = null; + // Split this according to the type of request + if (request.getMethod().equals("GET")) { + method = new GetMethod(serviceUrl); + method.setQueryString(nvps.toArray(new NameValuePair[] {})); + } else if (request.getMethod().equals("POST")) { + method = new PostMethod(serviceUrl); + for (NameValuePair nvp : nvps) { + ((PostMethod) method).addParameter(nvp.getName(), nvp + .getValue()); + } + } else { + throw new NotImplementedException( + "This proxy only supports GET and POST methods."); + } + return method; + } + +} Index: trunk/.settings/org.eclipse.wst.common.project.facet.core.xml =================================================================== diff -u --- trunk/.settings/org.eclipse.wst.common.project.facet.core.xml (revision 0) +++ trunk/.settings/org.eclipse.wst.common.project.facet.core.xml (revision 3988) @@ -0,0 +1,5 @@ + + + + +