You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wookie.apache.org by sc...@apache.org on 2010/02/17 18:12:03 UTC
svn commit: r911077 - in /incubator/wookie/trunk:
src-tests/org/apache/wookie/tests/functional/ProxyTest.java
src/org/apache/wookie/proxy/ProxyClient.java
src/org/apache/wookie/proxy/ProxyServlet.java
Author: scottbw
Date: Wed Feb 17 17:12:02 2010
New Revision: 911077
URL: http://svn.apache.org/viewvc?rev=911077&view=rev
Log:
Ensure correct content-type is set in the prox'd request, and returned in the proxy'd response; added more test cases to check this. See WOOKIE-118 for more details
Modified:
incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/ProxyTest.java
incubator/wookie/trunk/src/org/apache/wookie/proxy/ProxyClient.java
incubator/wookie/trunk/src/org/apache/wookie/proxy/ProxyServlet.java
Modified: incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/ProxyTest.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/ProxyTest.java?rev=911077&r1=911076&r2=911077&view=diff
==============================================================================
--- incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/ProxyTest.java (original)
+++ incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/ProxyTest.java Wed Feb 17 17:12:02 2010
@@ -14,6 +14,7 @@
package org.apache.wookie.tests.functional;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.ArrayList;
@@ -35,6 +36,7 @@
private static String instance_id_key;
private static final String PROXY_URL = "http://localhost:8080/wookie/proxy";
private static final String VALID_SITE_URL = "http://incubator.apache.org/wookie/";
+ private static final String VALID_SITE_XML_URL = "http://localhost:8080/wookie/widgets?all=true";
private static final String INVALID_SITE_URL = "DFASFAFEQ3FQ32145235123452";
private static final String BLOCKED_SITE_URL = "http://very.bad.place";
private static final String PROTECTED_SITE_URL = "http://localhost:8080/wookie/admin/";
@@ -65,6 +67,29 @@
assertEquals(200,send(url,"GET"));
assertEquals(500,send(url,"POST")); // This URL doesn't support POST
}
+
+ @Test
+ public void getValidSiteAndValidXMLContentType() throws Exception{
+ String url = PROXY_URL+"?instanceid_key="+instance_id_key+"&url="+VALID_SITE_XML_URL;
+ HttpClient client = new HttpClient();
+ HttpMethod req = new GetMethod(url);
+ client.executeMethod(req);
+ int code = req.getStatusCode();
+ req.releaseConnection();
+ assertEquals(200,code);
+ assertTrue(req.getResponseHeader("Content-Type").toString().contains("text/xml"));
+ }
+ @Test
+ public void getValidSiteAndValidHTMLContentType() throws Exception{
+ String url = PROXY_URL+"?instanceid_key="+instance_id_key+"&url="+VALID_SITE_URL;
+ HttpClient client = new HttpClient();
+ HttpMethod req = new GetMethod(url);
+ client.executeMethod(req);
+ int code = req.getStatusCode();
+ req.releaseConnection();
+ assertEquals(200,code);
+ assertTrue(req.getResponseHeader("Content-Type").toString().contains("text/html"));
+ }
@Test
public void getValidSiteInvalidIdKey(){
Modified: incubator/wookie/trunk/src/org/apache/wookie/proxy/ProxyClient.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/proxy/ProxyClient.java?rev=911077&r1=911076&r2=911077&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/proxy/ProxyClient.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/proxy/ProxyClient.java Wed Feb 17 17:12:02 2010
@@ -53,7 +53,6 @@
private String fProxyPassword = null;
private String fBase64Auth = null;
private NameValuePair[] parameters = null;
-
private boolean fUseProxyAuthentication = false;
@SuppressWarnings("unchecked")
@@ -66,6 +65,7 @@
if(base64Auth != null)
this.setBase64AuthConfig(base64Auth);
filterParameters(request.getParameterMap());
+ fContentType = request.getContentType();
}
private void setProxyAuthConfig(String username, String password){
@@ -149,11 +149,11 @@
Locale locale = Locale.getDefault();
method.setRequestHeader("Accept-Language", locale.getLanguage()); //$NON-NLS-1$
-
+ method.setRequestHeader("Content-Type", fContentType);
int statusCode = client.executeMethod(method);
if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_CREATED) {
- Header hType = method.getResponseHeader("Content-type");
+ Header hType = method.getResponseHeader("Content-Type");
if (hType != null) fContentType = hType.getValue();
// for now we are only expecting Strings
//return method.getResponseBodyAsString();
Modified: incubator/wookie/trunk/src/org/apache/wookie/proxy/ProxyServlet.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/proxy/ProxyServlet.java?rev=911077&r1=911076&r2=911077&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/proxy/ProxyServlet.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/proxy/ProxyServlet.java Wed Feb 17 17:12:02 2010
@@ -95,12 +95,14 @@
ProxyClient proxyclient = new ProxyClient(request);
PrintWriter out = response.getWriter();
//TODO - find all the links etc & make them absolute - to make request come thru this servlet
- response.setContentType(proxyclient.getCType());
+ String output = "";
if(httpMethod.equals("get")){
- out.print(proxyclient.get(bean.getNewUrl().toExternalForm(), properties));
+ output = proxyclient.get(bean.getNewUrl().toExternalForm(), properties);
}else{
- out.print(proxyclient.post(bean.getNewUrl().toExternalForm(),getXmlData(request), properties));
+ output = proxyclient.post(bean.getNewUrl().toExternalForm(),getXmlData(request), properties);
}
+ response.setContentType(proxyclient.getCType());
+ out.print(output);
}
catch (Exception ex) {
try {